TTK
Loading...
Searching...
No Matches
ttkOBJWriter.cpp
Go to the documentation of this file.
1#include <ttkOBJWriter.h>
2
3#include <vtkCell.h>
4#include <vtkDataSet.h>
5#include <vtkObjectFactory.h>
6
8
9// Public
10// {{{
11
12void ttkOBJWriter::PrintSelf(std::ostream &os, vtkIndent indent) {
13 this->Superclass::PrintSelf(os, indent);
14
15 os << indent << "File Name: " << (this->Filename ? this->Filename : "(none)")
16 << std::endl;
17}
18
19// }}}
20// Protected
21// {{{
22
24 this->setDebugMsgPrefix("OBJWriter");
25}
26
28
30
31 std::ofstream f(Filename, ios::out);
32
33 if(!f.fail()) {
34 Stream = std::move(f);
35 } else {
36 return -1;
37 }
38
39 return 0;
40}
41
43
44 auto dataSet = vtkDataSet::SafeDownCast(this->GetInput());
45
46 if(dataSet == nullptr)
47 return;
48
49 if(this->OpenFile() == -1) {
50 this->printErr("Could not open file `" + std::string{Filename} + "' :(");
51 return;
52 }
53
54 double p[3];
55 for(vtkIdType i = 0; i < dataSet->GetNumberOfPoints(); i++) {
56 dataSet->GetPoint(i, p);
57 Stream << "v " << p[0] << " " << p[1] << " " << p[2] << " " << std::endl;
58 }
59
60 for(vtkIdType i = 0; i < dataSet->GetNumberOfCells(); i++) {
61 vtkCell *c = dataSet->GetCell(i);
62
63 Stream << "f ";
64 for(int j = 0; j < c->GetNumberOfPoints(); j++) {
65 Stream << c->GetPointId(j) + 1 << " ";
66 }
67
68 Stream << std::endl;
69 }
70}
71
72// }}}
ttkOBJWriter - Object File Format Writer
void PrintSelf(std::ostream &os, vtkIndent indent) override
char * Filename
std::ofstream Stream
void WriteData() override
~ttkOBJWriter() override
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
vtkStandardNewMacro(ttkOBJWriter)