VTK  9.5.20250608
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;
15
16struct VTKIOIMPORT_EXPORT vtkOBJImportedMaterial
17{
18 std::string name;
19 std::string texture_filename;
20 double amb[3];
21 double diff[3];
22 double spec[3];
23 double map_Kd_scale[3];
24 double map_Kd_offset[3];
25 int illum;
26 double reflect;
27 double refract;
28 double trans;
30 double glossy;
32 const char* GetClassName() { return "vtkOBJImportedMaterial"; }
34};
35
36VTKIOIMPORT_EXPORT
38
39struct vtkOBJImportedPolyDataWithMaterial;
40
41class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
42{
43public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
48 // Description:
49 // Specify file name of Wavefront .obj file.
50 void SetFileName(const char* arg)
51 {
52 if (arg == nullptr)
53 {
54 return;
55 }
56 if (this->FileName == arg)
57 {
58 return;
59 }
60 this->FileName = std::string(arg);
61 }
62 void SetMTLfileName(const char* arg)
63 {
64 if (arg == nullptr)
65 {
66 return;
67 }
68 if (this->MTLFileName == arg)
69 {
70 return;
71 }
72 this->MTLFileName = std::string(arg);
73 this->DefaultMTLFileName = false;
74 }
75 void SetTexturePath(const char* arg)
76 {
77 this->TexturePath = std::string(arg);
78 if (this->TexturePath.empty())
79 {
80 return;
81 }
82#if defined(_WIN32)
83 const char sep = '\\';
84#else
85 const char sep = '/';
86#endif
87 if (this->TexturePath.at(this->TexturePath.size() - 1) != sep)
88 {
89 this->TexturePath += sep;
90 }
91 this->DefaultTexturePath = false;
92 }
93 const std::string& GetTexturePath() const { return this->TexturePath; }
94
95 const std::string& GetFileName() const { return this->FileName; }
96
97 const std::string& GetMTLFileName() const { return this->MTLFileName; }
98
99 vtkSetMacro(VertexScale, double);
100 vtkGetMacro(VertexScale, double);
101 vtkGetMacro(SuccessParsingFiles, int);
102
103 virtual vtkPolyData* GetOutput(int idx);
104
106
108
109 std::string GetTextureFilename(int idx); // return string by index
110
111 double VertexScale; // scale vertices by this during import
112
113 std::vector<vtkOBJImportedMaterial*> parsedMTLs;
114 std::map<std::string, vtkOBJImportedMaterial*> mtlName_to_mtlData;
115
116 // our internal parsing/storage
117 std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
118
119 // what gets returned to client code via GetOutput()
120 std::vector<vtkSmartPointer<vtkPolyData>> outVector_of_vtkPolyData;
121
122 std::vector<vtkSmartPointer<vtkActor>> actor_list;
124
125 std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename, int& result_code);
126
127 void ReadVertices(bool gotFirstUseMaterialTag, char* pLine, float xyz, int lineNr, double v_scale,
128 bool everything_ok, vtkPoints* points, bool use_scale);
129
130protected:
134 /*override*/;
135
136 vtkSetMacro(SuccessParsingFiles, int);
137
138 std::string FileName; // filename (.obj) being read
139 std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
140 bool DefaultMTLFileName; // tells whether default MTL should be used
141 std::string TexturePath;
142 bool DefaultTexturePath; // tells whether default texture path should be used
144
145private:
147 void operator=(const vtkOBJPolyDataProcessor&) = delete;
148};
149
150class vtkRenderWindow;
151class vtkRenderer;
152VTKIOIMPORT_EXPORT
154 vtkOBJPolyDataProcessor* reader, vtkActorCollection* actorCollection);
155
156VTK_ABI_NAMESPACE_END
157#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.
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 ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, double v_scale, bool everything_ok, vtkPoints *points, bool use_scale)
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)
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: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
VTKIOIMPORT_EXPORT bool bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader, vtkActorCollection *actorCollection)
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)