VTK  9.0.1
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 "vtkActor.h"
18 #include "vtkOBJImporter.h"
19 #include "vtkPolyDataAlgorithm.h"
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 struct 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;
38  double specularPower;
39  double glossy;
40  double refract_index;
41  const char* GetClassName() { return "vtkOBJImportedMaterial"; }
43 };
44 
45 VTKIOIMPORT_EXPORT
47 
48 struct vtkOBJImportedPolyDataWithMaterial;
49 
50 class VTKIOIMPORT_EXPORT vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
51 {
52 public:
53  static vtkOBJPolyDataProcessor* New();
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 
109  int GetNumberOfOutputs();
110 
111  vtkOBJImportedMaterial* GetMaterial(int k);
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 
134 protected:
136  ~vtkOBJPolyDataProcessor() override;
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 
148 private:
150  void operator=(const vtkOBJPolyDataProcessor&) = delete;
151 };
152 
153 class vtkRenderWindow;
154 class vtkRenderer;
155 VTKIOIMPORT_EXPORT
157  vtkRenderWindow* renderWindow, vtkRenderer* renderer, vtkOBJPolyDataProcessor* reader);
158 
159 #endif
160 #endif
161 // VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkOBJImporter.h
vtkOBJPolyDataProcessor::SetMTLfileName
void SetMTLfileName(const char *arg)
Definition: vtkOBJImporterInternals.h:71
vtkOBJImportedMaterial::glossy
double glossy
Definition: vtkOBJImporterInternals.h:39
vtkOBJImportedMaterial::texture_filename
std::string texture_filename
Definition: vtkOBJImporterInternals.h:28
vtkOBJPolyDataProcessor::DefaultMTLFileName
bool DefaultMTLFileName
Definition: vtkOBJImporterInternals.h:144
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkOBJImportedMaterial::reflect
double reflect
Definition: vtkOBJImporterInternals.h:35
vtkOBJPolyDataProcessor::poly_list
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
Definition: vtkOBJImporterInternals.h:121
vtkOBJImportedMaterial::GetClassName
const char * GetClassName()
Definition: vtkOBJImporterInternals.h:41
vtkOBJPolyDataProcessor::MTLFileName
std::string MTLFileName
Definition: vtkOBJImporterInternals.h:143
vtkOBJImportedMaterial::refract_index
double refract_index
Definition: vtkOBJImporterInternals.h:40
vtkOBJPolyDataProcessor::TexturePath
std::string TexturePath
Definition: vtkOBJImporterInternals.h:145
vtkPolyDataAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkOBJPolyDataProcessor::SetFileName
void SetFileName(const char *arg)
Definition: vtkOBJImporterInternals.h:59
obj_set_material_defaults
VTKIOIMPORT_EXPORT void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
vtkOBJImportedMaterial
Definition: vtkOBJImporterInternals.h:25
vtkOBJPolyDataProcessor
Definition: vtkOBJImporterInternals.h:50
vtkOBJPolyDataProcessor::GetMTLFileName
const std::string & GetMTLFileName() const
Definition: vtkOBJImporterInternals.h:101
vtkPolyDataAlgorithm.h
vtkOBJImportedMaterial::name
std::string name
Definition: vtkOBJImporterInternals.h:27
vtkOBJPolyDataProcessor::mtlName_to_mtlData
std::map< std::string, vtkOBJImportedMaterial * > mtlName_to_mtlData
Definition: vtkOBJImporterInternals.h:118
vtkX3D::points
@ points
Definition: vtkX3D.h:452
vtkPolyDataAlgorithm::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
bindTexturedPolydataToRenderWindow
VTKIOIMPORT_EXPORT void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)
vtkOBJPolyDataProcessor::GetTexturePath
const std::string & GetTexturePath() const
Definition: vtkOBJImporterInternals.h:97
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkOBJPolyDataProcessor::VertexScale
double VertexScale
Definition: vtkOBJImporterInternals.h:115
vtkOBJPolyDataProcessor::SuccessParsingFiles
int SuccessParsingFiles
Definition: vtkOBJImporterInternals.h:146
vtkActor.h
vtkOBJPolyDataProcessor::GetFileName
const std::string & GetFileName() const
Definition: vtkOBJImporterInternals.h:99
vtkOBJImportedMaterial::trans
double trans
Definition: vtkOBJImporterInternals.h:37
vtkOBJImportedMaterial::illum
int illum
Definition: vtkOBJImporterInternals.h:34
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:73
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkOBJImportedMaterial::specularPower
double specularPower
Definition: vtkOBJImporterInternals.h:38
vtkOBJPolyDataProcessor::FileName
std::string FileName
Definition: vtkOBJImporterInternals.h:140
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:67
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
vtkOBJPolyDataProcessor::outVector_of_vtkPolyData
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
Definition: vtkOBJImporterInternals.h:124
vtkOBJPolyDataProcessor::actor_list
std::vector< vtkSmartPointer< vtkActor > > actor_list
Definition: vtkOBJImporterInternals.h:126
vtkOBJPolyDataProcessor::parsedMTLs
std::vector< vtkOBJImportedMaterial * > parsedMTLs
Definition: vtkOBJImporterInternals.h:117
vtkOBJPolyDataProcessor::SetTexturePath
void SetTexturePath(const char *arg)
Definition: vtkOBJImporterInternals.h:84
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:93
vtkOBJImportedMaterial::refract
double refract
Definition: vtkOBJImporterInternals.h:36
vtkPolyDataAlgorithm::GetOutput
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
vtkPolyDataAlgorithm::New
static vtkPolyDataAlgorithm * New()
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:41