VTK  9.2.6
vtkOBJImporterInternals.h
Go to the documentation of this file.
1/*=========================================================================
2 Program: Visualization Toolkit
3 Module: vtkOBJImporterInternals.h
4 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
5 All rights reserved.
6 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
7
8 This software is distributed WITHOUT ANY WARRANTY; without even
9 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 PURPOSE. See the above copyright notice for more information.
11=========================================================================*/
12
13#ifndef vtkOBJImporterInternals_h
14#define vtkOBJImporterInternals_h
15
16#include "vtkIOImportModule.h" // For export macro
18#include <map> // for std::map
19#include <string> // for std::string
20#include <vector> // for std::vector
21
22class vtkActor;
23
24struct VTKIOIMPORT_EXPORT vtkOBJImportedMaterial
25{
26 std::string name;
27 std::string texture_filename;
28 double amb[3];
29 double diff[3];
30 double spec[3];
31 double map_Kd_scale[3];
32 double map_Kd_offset[3];
33 int illum;
34 double reflect;
35 double refract;
36 double trans;
38 double glossy;
40 const char* GetClassName() { return "vtkOBJImportedMaterial"; }
42};
43
44VTKIOIMPORT_EXPORT
46
47struct vtkOBJImportedPolyDataWithMaterial;
48
49class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
50{
51public:
54 void PrintSelf(ostream& os, vtkIndent indent) override;
55
56 // Description:
57 // Specify file name of Wavefront .obj file.
58 void SetFileName(const char* arg)
59 {
60 if (arg == nullptr)
61 {
62 return;
63 }
64 if (!strcmp(this->FileName.c_str(), arg))
65 {
66 return;
67 }
68 FileName = std::string(arg);
69 }
70 void SetMTLfileName(const char* arg)
71 {
72 if (arg == nullptr)
73 {
74 return;
75 }
76 if (!strcmp(this->MTLFileName.c_str(), arg))
77 {
78 return;
79 }
80 MTLFileName = std::string(arg);
81 this->DefaultMTLFileName = false;
82 }
83 void SetTexturePath(const char* arg)
84 {
85 TexturePath = std::string(arg);
86 if (TexturePath.empty())
87 return;
88#if defined(_WIN32)
89 const char sep = '\\';
90#else
91 const char sep = '/';
92#endif
93 if (TexturePath.at(TexturePath.size() - 1) != sep)
94 TexturePath += sep;
95 }
96 const std::string& GetTexturePath() const { return TexturePath; }
97
98 const std::string& GetFileName() const { return FileName; }
99
100 const std::string& GetMTLFileName() const { return MTLFileName; }
101
102 vtkSetMacro(VertexScale, double);
103 vtkGetMacro(VertexScale, double);
104 vtkGetMacro(SuccessParsingFiles, int);
105
106 virtual vtkPolyData* GetOutput(int idx);
107
109
111
112 std::string GetTextureFilename(int idx); // return string by index
113
114 double VertexScale; // scale vertices by this during import
115
116 std::vector<vtkOBJImportedMaterial*> parsedMTLs;
117 std::map<std::string, vtkOBJImportedMaterial*> mtlName_to_mtlData;
118
119 // our internal parsing/storage
120 std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
121
122 // what gets returned to client code via GetOutput()
123 std::vector<vtkSmartPointer<vtkPolyData>> outVector_of_vtkPolyData;
124
125 std::vector<vtkSmartPointer<vtkActor>> actor_list;
127
128 std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename, int& result_code);
129
130 void ReadVertices(bool gotFirstUseMaterialTag, char* pLine, float xyz, int lineNr,
131 const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
132
133protected:
137 /*override*/;
138
139 vtkSetMacro(SuccessParsingFiles, int);
140
141 std::string FileName; // filename (.obj) being read
142 std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
143 bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used
144 std::string TexturePath;
146
147private:
149 void operator=(const vtkOBJPolyDataProcessor&) = delete;
150};
151
152class vtkRenderWindow;
153class vtkRenderer;
154VTKIOIMPORT_EXPORT
156 vtkRenderWindow* renderWindow, vtkRenderer* renderer, vtkOBJPolyDataProcessor* reader);
157
158#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:52
a simple class to control print indentation
Definition vtkIndent.h:40
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
const std::string & GetFileName() const
std::string GetTextureFilename(int idx)
vtkOBJImportedMaterial * GetMaterial(int k)
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
std::vector< vtkSmartPointer< vtkActor > > actor_list
void SetTexturePath(const char *arg)
void SetFileName(const char *arg)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const std::string & GetMTLFileName() const
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
virtual vtkPolyData * GetOutput(int idx)
void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints *points, const bool use_scale)
static vtkOBJPolyDataProcessor * New()
std::vector< vtkOBJImportedMaterial * > parsedMTLs
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
const std::string & GetTexturePath() const
std::map< std::string, vtkOBJImportedMaterial * > mtlName_to_mtlData
~vtkOBJPolyDataProcessor() override
std::vector< vtkOBJImportedMaterial * > ParseOBJandMTL(std::string filename, int &result_code)
void SetMTLfileName(const char *arg)
represent and manipulate 3D points
Definition vtkPoints.h:40
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:91
create a window for renderers to draw into
abstract specification for renderers
Definition vtkRenderer.h:73
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
VTKIOIMPORT_EXPORT void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)