| 50 | } |
| 51 | |
| 52 | void 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"; |
nothing calls this directly
no test coverage detected