VTK  9.1.0
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#ifndef __VTK_WRAP__
16
17#include "vtkIOImportModule.h" // For export macro
19#include <map> // for std::map
20#include <string> // for std::string
21#include <vector> // for std::vector
22
23class vtkActor;
24
25struct VTKIOIMPORT_EXPORT vtkOBJImportedMaterial
26{
29 double amb[3];
30 double diff[3];
31 double spec[3];
32 double map_Kd_scale[3];
33 double map_Kd_offset[3];
34 int illum;
35 double reflect;
36 double refract;
37 double trans;
39 double glossy;
41 const char* GetClassName() { return "vtkOBJImportedMaterial"; }
43};
44
45VTKIOIMPORT_EXPORT
47
48struct vtkOBJImportedPolyDataWithMaterial;
49
50class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
51{
52public:
55 void PrintSelf(ostream& os, vtkIndent indent) override;
56
57 // Description:
58 // Specify file name of Wavefront .obj file.
59 void SetFileName(const char* arg)
60 {
61 if (arg == nullptr)
62 {
63 return;
64 }
65 if (!strcmp(this->FileName.c_str(), arg))
66 {
67 return;
68 }
69 FileName = std::string(arg);
70 }
71 void SetMTLfileName(const char* arg)
72 {
73 if (arg == nullptr)
74 {
75 return;
76 }
77 if (!strcmp(this->MTLFileName.c_str(), arg))
78 {
79 return;
80 }
81 MTLFileName = std::string(arg);
82 this->DefaultMTLFileName = false;
83 }
84 void SetTexturePath(const char* arg)
85 {
86 TexturePath = std::string(arg);
87 if (TexturePath.empty())
88 return;
89#if defined(_WIN32)
90 const char sep = '\\';
91#else
92 const char sep = '/';
93#endif
94 if (TexturePath.at(TexturePath.size() - 1) != sep)
95 TexturePath += sep;
96 }
97 const std::string& GetTexturePath() const { return TexturePath; }
98
99 const std::string& GetFileName() const { return FileName; }
100
101 const std::string& GetMTLFileName() const { return MTLFileName; }
102
103 vtkSetMacro(VertexScale, double);
104 vtkGetMacro(VertexScale, double);
105 vtkGetMacro(SuccessParsingFiles, int);
106
107 virtual vtkPolyData* GetOutput(int idx);
108
110
112
113 std::string GetTextureFilename(int idx); // return string by index
114
115 double VertexScale; // scale vertices by this during import
116
117 std::vector<vtkOBJImportedMaterial*> parsedMTLs;
118 std::map<std::string, vtkOBJImportedMaterial*> mtlName_to_mtlData;
119
120 // our internal parsing/storage
121 std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
122
123 // what gets returned to client code via GetOutput()
124 std::vector<vtkSmartPointer<vtkPolyData>> outVector_of_vtkPolyData;
125
126 std::vector<vtkSmartPointer<vtkActor>> actor_list;
128
129 std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename, int& result_code);
130
131 void ReadVertices(bool gotFirstUseMaterialTag, char* pLine, float xyz, int lineNr,
132 const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
133
134protected:
138 /*override*/;
139
140 vtkSetMacro(SuccessParsingFiles, int);
141
142 std::string FileName; // filename (.obj) being read
143 std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
144 bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used
147
148private:
150 void operator=(const vtkOBJPolyDataProcessor&) = delete;
151};
152
153class vtkRenderWindow;
154class vtkRenderer;
155VTKIOIMPORT_EXPORT
157 vtkRenderWindow* renderWindow, vtkRenderer* renderer, vtkOBJPolyDataProcessor* reader);
158
159#endif
160#endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:155
a simple class to control print indentation
Definition: vtkIndent.h:113
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:143
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:195
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:173
@ points
Definition: vtkX3D.h:452
@ string
Definition: vtkX3D.h:496
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
VTKIOIMPORT_EXPORT void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)