TTK
Loading...
Searching...
No Matches
ttkTriangulationWriter.cpp
Go to the documentation of this file.
1#include <Triangulation.h>
3
4#include <array>
5
6#include <vtkDataArray.h>
7#include <vtkExecutive.h>
8#include <vtkImageData.h>
9#include <vtkInformation.h>
10#include <vtkObjectFactory.h>
11#include <vtkPointData.h>
12#include <vtkUnstructuredGrid.h>
13
15
17 this->SetNumberOfInputPorts(1);
18 this->setDebugMsgPrefix("TriangulationWriter");
19}
20
22 vtkInformation *info) {
23 if(port == 0) {
24 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
25 return 1;
26 }
27 return 0;
28}
29
31
32 std::ofstream f(Filename, std::ios::out | std::ios::binary);
33
34 if(!f.fail()) {
35 Stream = std::move(f);
36 } else {
37 return -1;
38 }
39
40 return 0;
41}
42
44
45 ttk::Timer tm{};
46 this->setDebugLevel(3);
47
48 const auto dataset = vtkDataSet::SafeDownCast(this->GetInput());
49 if(dataset == nullptr) {
50 this->printErr("Invalid dataset");
51 return 1;
52 }
53 if(!dataset->IsA("vtkUnstructuredGrid")) {
54 this->printErr("This filter only works on Explicit Triangulations");
55 return 1;
56 }
57 const auto triangulation = ttkAlgorithm::GetTriangulation(dataset);
58 if(triangulation == nullptr) {
59 this->printErr("Invalid triangulation");
60 return 1;
61 }
62
63 // basic preconditions
64 triangulation->preconditionEdges();
65 if(triangulation->getDimensionality() > 2) {
66 triangulation->preconditionTriangles();
67 }
68
69 const auto explTri
70 = static_cast<ttk::ExplicitTriangulation *>(triangulation->getData());
71
72 if(this->OpenFile() == -1) {
73 this->printErr("Could not open file `" + std::string{Filename} + "' :(");
74 return 1;
75 }
76
77 if(this->UseASCIIFormat) {
78 explTri->writeToFileASCII(this->Stream);
79 } else {
80 explTri->writeToFile(this->Stream);
81 }
82 this->Stream.flush();
83
84 this->printMsg("Wrote triangulation to " + std::string{this->Filename}, 1.0,
85 tm.getElapsedTime(), 1);
86
87 return 0;
88}
89
91 // copied from ParaView's vtkWriter::GetInput()
92 if(this->GetNumberOfInputConnections(0) < 1) {
93 return nullptr;
94 }
95 return this->GetExecutive()->GetInputData(0, 0);
96}
97
98void ttkTriangulationWriter::SetInputData(vtkDataObject *input) {
99 // copied from ParaView's vtkWriter::SetInputData()
100 this->SetInputDataInternal(0, input);
101}
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
ttkTriangulationWriter - Explicit Triangulation Writer
void SetInputData(vtkDataObject *input)
int FillInputPortInformation(int port, vtkInformation *info) override
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
virtual int setDebugLevel(const int &debugLevel)
Definition Debug.cpp:147
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
ExplicitTriangulation is a class that provides time efficient traversal methods on triangulations of ...
int writeToFileASCII(std::ofstream &stream) const
Write internal state to disk using an ASCII format.
vtkStandardNewMacro(ttkTriangulationWriter)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)