VTK  9.5.20251110
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
8#include <map> // for std::map
9#include <string> // for std::string
10#include <vector> // for std::vector
11
12VTK_ABI_NAMESPACE_BEGIN
13class vtkActor;
16
17struct VTKIOIMPORT_EXPORT vtkOBJImportedMaterial
18{
19 std::string name;
20 std::string texture_filename;
21 double amb[3];
22 double diff[3];
23 double spec[3];
24 double map_Kd_scale[3];
25 double map_Kd_offset[3];
26 int illum;
27 double reflect;
28 double refract;
29 double trans;
31 double glossy;
33 const char* GetClassName() { return "vtkOBJImportedMaterial"; }
35};
36
37VTKIOIMPORT_EXPORT
39
40struct vtkOBJImportedPolyDataWithMaterial;
41
42class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
49 // Description:
50 // Specify filenames / streams to read of Wavefront .obj file.
51 void SetStream(vtkResourceStream* stream) { this->Stream = stream; }
52 void SetFileName(const char* arg)
53 {
54 if (arg == nullptr)
55 {
56 return;
57 }
58 if (this->FileName == arg)
59 {
60 return;
61 }
62 this->FileName = std::string(arg);
63 }
64 void SetMTLStream(vtkResourceStream* mtlStream) { this->MTLStream = mtlStream; }
65 void SetMTLfileName(const char* arg)
66 {
67 if (arg == nullptr)
68 {
69 return;
70 }
71 if (this->MTLFileName == arg)
72 {
73 return;
74 }
75 this->MTLFileName = std::string(arg);
76 this->DefaultMTLFileName = false;
77 }
78 void SetTextureStreams(std::map<std::string, vtkResourceStream*> streamMap)
79 {
80 this->TextureStreams = streamMap;
81 }
82 void SetTexturePath(const char* arg)
83 {
84 this->TexturePath = std::string(arg);
85 if (this->TexturePath.empty())
86 {
87 return;
88 }
89#if defined(_WIN32)
90 const char sep = '\\';
91#else
92 const char sep = '/';
93#endif
94 if (this->TexturePath.at(this->TexturePath.size() - 1) != sep)
95 {
96 this->TexturePath += sep;
97 }
98 this->DefaultTexturePath = false;
99 }
100 const std::string& GetTexturePath() const { return this->TexturePath; }
101 const std::map<std::string, vtkResourceStream*>& GetTextureStreams() const
102 {
103 return this->TextureStreams;
104 }
105
106 const std::string& GetFileName() const { return this->FileName; }
107
108 const std::string& GetMTLFileName() const { return this->MTLFileName; }
109
110 vtkSetMacro(VertexScale, double);
111 vtkGetMacro(VertexScale, double);
112 vtkGetMacro(SuccessParsingFiles, int);
113
114 virtual vtkPolyData* GetOutput(int idx);
115
117
119
120 std::string GetTextureFilename(int idx); // return string by index
121
122 double VertexScale; // scale vertices by this during import
123
124 std::vector<vtkOBJImportedMaterial*> parsedMTLs;
125 std::map<std::string, vtkOBJImportedMaterial*> mtlName_to_mtlData;
126
127 // our internal parsing/storage
128 std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
129
130 // what gets returned to client code via GetOutput()
131 std::vector<vtkSmartPointer<vtkPolyData>> outVector_of_vtkPolyData;
132
133 std::vector<vtkSmartPointer<vtkActor>> actor_list;
135
136 std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(
137 vtkResourceStream* mtlStream, int& result_code);
138
139 void ReadVertices(bool gotFirstUseMaterialTag, char* pLine, float xyz, int lineNr, double v_scale,
140 bool everything_ok, vtkPoints* points, bool use_scale);
141
142protected:
146 /*override*/;
147
148 vtkSetMacro(SuccessParsingFiles, int);
149
150 vtkResourceStream* Stream = nullptr; // Stream of obj being read
151 std::string FileName; // filename (.obj) being read
152
153 bool DefaultMTLFileName; // tells whether default MTL should be used
154 std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
155 vtkResourceStream* MTLStream = nullptr; // Stream of associated MTL file
156
157 bool DefaultTexturePath; // tells whether default texture path should be used
158 std::string TexturePath; // Texture path to read
159 std::map<std::string, vtkResourceStream*> TextureStreams;
160
162
163private:
165 void operator=(const vtkOBJPolyDataProcessor&) = delete;
166};
167
168class vtkRenderWindow;
169class vtkRenderer;
170VTKIOIMPORT_EXPORT
172 vtkOBJPolyDataProcessor* reader, vtkActorCollection* actorCollection);
173
174VTK_ABI_NAMESPACE_END
175#endif
an ordered list of actors
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:151
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
void SetStream(vtkResourceStream *stream)
const std::string & GetFileName() const
std::string GetTextureFilename(int idx)
vtkOBJImportedMaterial * GetMaterial(int k)
void SetTextureStreams(std::map< std::string, vtkResourceStream * > streamMap)
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
std::vector< vtkSmartPointer< vtkActor > > actor_list
void SetTexturePath(const char *arg)
void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, double v_scale, bool everything_ok, vtkPoints *points, bool use_scale)
std::vector< vtkOBJImportedMaterial * > ParseOBJandMTL(vtkResourceStream *mtlStream, int &result_code)
void SetFileName(const char *arg)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetMTLStream(vtkResourceStream *mtlStream)
const std::string & GetMTLFileName() const
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
virtual vtkPolyData * GetOutput(int idx)
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
const std::map< std::string, vtkResourceStream * > & GetTextureStreams() const
void SetMTLfileName(const char *arg)
std::map< std::string, vtkResourceStream * > TextureStreams
represent and manipulate 3D points
Definition vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
create a window for renderers to draw into
abstract specification for renderers
Abstract class used for custom streams.
VTKIOIMPORT_EXPORT bool bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader, vtkActorCollection *actorCollection)
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)