VTK  9.3.0
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;
14
15struct 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;
29 double glossy;
31 const char* GetClassName() { return "vtkOBJImportedMaterial"; }
33};
34
35VTKIOIMPORT_EXPORT
37
38struct vtkOBJImportedPolyDataWithMaterial;
39
40class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
41{
42public:
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
100
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
124protected:
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;
137
138private:
140 void operator=(const vtkOBJPolyDataProcessor&) = delete;
141};
142
143class vtkRenderWindow;
144class vtkRenderer;
145VTKIOIMPORT_EXPORT
147 vtkRenderWindow* renderWindow, vtkRenderer* renderer, vtkOBJPolyDataProcessor* reader);
148
149VTK_ABI_NAMESPACE_END
150#endif
represents an object (geometry & properties) in a rendered scene
Definition vtkActor.h:41
a simple class to control print indentation
Definition vtkIndent.h:29
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:29
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:80
create a window for renderers to draw into
abstract specification for renderers
Definition vtkRenderer.h:59
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
VTKIOIMPORT_EXPORT void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)