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