VTK  9.4.20241118
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 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 MTLFileName = std::string(arg);
73 this->DefaultMTLFileName = false;
74 }
75 void SetTexturePath(const char* arg)
76 {
77 TexturePath = std::string(arg);
78 if (TexturePath.empty())
79 return;
80#if defined(_WIN32)
81 const char sep = '\\';
82#else
83 const char sep = '/';
84#endif
85 if (TexturePath.at(TexturePath.size() - 1) != sep)
86 TexturePath += sep;
87 }
88 const std::string& GetTexturePath() const { return TexturePath; }
89
90 const std::string& GetFileName() const { return FileName; }
91
92 const std::string& GetMTLFileName() const { return MTLFileName; }
93
94 vtkSetMacro(VertexScale, double);
95 vtkGetMacro(VertexScale, double);
96 vtkGetMacro(SuccessParsingFiles, int);
97
98 virtual vtkPolyData* GetOutput(int idx);
99
101
103
104 std::string GetTextureFilename(int idx); // return string by index
105
106 double VertexScale; // scale vertices by this during import
107
108 std::vector<vtkOBJImportedMaterial*> parsedMTLs;
109 std::map<std::string, vtkOBJImportedMaterial*> mtlName_to_mtlData;
110
111 // our internal parsing/storage
112 std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
113
114 // what gets returned to client code via GetOutput()
115 std::vector<vtkSmartPointer<vtkPolyData>> outVector_of_vtkPolyData;
116
117 std::vector<vtkSmartPointer<vtkActor>> actor_list;
119
120 std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename, int& result_code);
121
122 void ReadVertices(bool gotFirstUseMaterialTag, char* pLine, float xyz, int lineNr, double v_scale,
123 bool everything_ok, vtkPoints* points, bool use_scale);
124
125protected:
129 /*override*/;
130
131 vtkSetMacro(SuccessParsingFiles, int);
132
133 std::string FileName; // filename (.obj) being read
134 std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
135 bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used
136 std::string TexturePath;
138
139private:
141 void operator=(const vtkOBJPolyDataProcessor&) = delete;
142};
143
144class vtkRenderWindow;
145class vtkRenderer;
146VTKIOIMPORT_EXPORT
148 vtkOBJPolyDataProcessor* reader, vtkActorCollection* actorCollection);
149
150VTK_ABI_NAMESPACE_END
151#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)