MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteData

Method WriteData

IO/Export/vtkOBJExporter.cxx:52–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void vtkOBJExporter::WriteData()
53{
54 // make sure the user specified a filename
55 if (this->FilePrefix == nullptr)
56 {
57 vtkErrorMacro(<< "Please specify file prefix to use");
58 return;
59 }
60
61 vtkRenderer* ren = this->ActiveRenderer;
62 if (!ren)
63 {
64 ren = this->RenderWindow->GetRenderers()->GetFirstRenderer();
65 }
66
67 // make sure it has at least one actor
68 if (ren->GetActors()->GetNumberOfItems() < 1)
69 {
70 vtkErrorMacro(<< "no actors found for writing .obj file.");
71 return;
72 }
73
74 // try opening the files
75 std::string objFilePath = std::string(this->FilePrefix) + ".obj";
76 std::string filePrefix(this->FilePrefix);
77 // get the model name which isthe last component of the FilePrefix
78 std::string modelName;
79 if (filePrefix.find_last_of('/') != std::string::npos)
80 {
81 modelName = filePrefix.substr(filePrefix.find_last_of('/') + 1);
82 }
83 else
84 {
85 modelName = filePrefix;
86 }
87
88 vtksys::ofstream fpObj(objFilePath.c_str(), ios::out);
89 if (!fpObj)
90 {
91 vtkErrorMacro(<< "unable to open " << objFilePath);
92 return;
93 }
94 std::string mtlFilePath = std::string(this->FilePrefix) + ".mtl";
95 vtksys::ofstream fpMtl(mtlFilePath.c_str(), ios::out);
96 if (!fpMtl)
97 {
98 fpMtl.close();
99 vtkErrorMacro(<< "unable to open .mtl files ");
100 return;
101 }
102
103 //
104 // Write header
105 //
106 vtkDebugMacro("Writing wavefront files");
107 if (this->GetOBJFileComment())
108 {
109 fpObj << "# " << this->GetOBJFileComment() << "\n\n";

Callers

nothing calls this directly

Calls 15

WriteAnActorMethod · 0.95
GetFirstRendererMethod · 0.80
GetRenderersMethod · 0.80
GetNextActorMethod · 0.80
GetLastNodeMethod · 0.80
stringClass · 0.50
NewFunction · 0.50
GetNumberOfItemsMethod · 0.45
GetActorsMethod · 0.45
c_strMethod · 0.45
closeMethod · 0.45
InitTraversalMethod · 0.45

Tested by

no test coverage detected