VTK: IO/Import/vtkOBJImporterInternals.h Source File

| VTK 9.3.1

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