VTK
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 <string>
17 #include "vtkOBJImporter.h"
18 #include "vtkPolyDataAlgorithm.h"
19 #include <memory>
20 #include <vector>
21 #include <map>
22 #include "vtkActor.h"
23 
24 const int OBJ_FILENAME_LENGTH = 8192;
25 const int MATERIAL_NAME_SIZE = 8192;
26 
28 {
29  char name[MATERIAL_NAME_SIZE]; // use std::array<char,N> when got {gcc4.7+,vs2012+}
31  double amb[3];
32  double diff[3];
33  double spec[3];
34  double reflect;
35  double refract;
36  double trans;
37  double shiny;
38  double glossy;
39  double refract_index;
40  double get_amb_coeff()
41  {
42  return sqrt( amb[0]*amb[0]+amb[1]*amb[1]+amb[2]*amb[2] );
43  }
44  double get_diff_coeff()
45  {
46  return sqrt( diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2] );
47  }
48  double get_spec_coeff()
49  {
50  return sqrt( spec[0]*spec[0]+spec[1]*spec[1]+spec[2]*spec[2] );
51  }
52  const char *GetClassName() {return "vtkOBJImportedMaterial";}
54 };
55 
56 
58 
59 struct vtkOBJImportedPolyDataWithMaterial;
60 
62 {
63 public:
64  static vtkOBJPolyDataProcessor *New();
66  void PrintSelf(ostream& os, vtkIndent indent) override;
67 
68  // Description:
69  // Specify file name of Wavefront .obj file.
70  void SetFileName(const char* arg)
71  {
72  if (arg == nullptr)
73  {
74  return;
75  }
76  if (!strcmp(this->FileName.c_str(), arg))
77  {
78  return;
79  }
80  FileName = std::string(arg);
81  }
82  void SetMTLfileName( const char* arg )
83  {
84  if (arg == nullptr)
85  {
86  return;
87  }
88  if (!strcmp(this->MTLFileName.c_str(), arg))
89  {
90  return;
91  }
92  MTLFileName = std::string(arg);
93  this->DefaultMTLFileName = false;
94  }
95  void SetTexturePath( const char* arg )
96  {
97  TexturePath = std::string(arg);
98  if(TexturePath.empty())
99  return;
100 #if defined(_WIN32)
101  const char sep = '\\';
102 #else
103  const char sep = '/';
104 #endif
105  if(TexturePath.at(TexturePath.size()-1) != sep )
106  TexturePath += sep;
107  }
108  const std::string& GetTexturePath( ) const
109  {
110  return TexturePath;
111  }
112 
113  const std::string& GetFileName( ) const
114  {
115  return FileName;
116  }
117 
118  const std::string& GetMTLFileName( ) const
119  {
120  return MTLFileName;
121  }
122 
123  vtkSetMacro(VertexScale,double)
124  vtkGetMacro(VertexScale,double)
125  vtkGetMacro(SuccessParsingFiles,int)
126 
127  virtual vtkPolyData* GetOutput(int idx);
128 
130 
131  std::string GetTextureFilename( int idx ); // return string by index
132 
133  double VertexScale; // scale vertices by this during import
134 
135  std::vector<vtkOBJImportedMaterial*> parsedMTLs;
136  std::map<std::string,vtkOBJImportedMaterial*> mtlName_to_mtlData;
137 
138  // our internal parsing/storage
139  std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
140 
141  // what gets returned to client code via GetOutput()
142  std::vector<vtkSmartPointer<vtkPolyData> > outVector_of_vtkPolyData;
143 
144  std::vector<vtkSmartPointer<vtkActor> > actor_list;
146 
147  std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename,int& result_code);
148 
149  void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
150 protected:
152  ~vtkOBJPolyDataProcessor() override;
154  vtkInformationVector **, vtkInformationVector *) override /*override*/;
155 
157 
158  std::string FileName; // filename (.obj) being read
159  std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
160  bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used
161  std::string TexturePath;
163 
164 private:
166  void operator=(const vtkOBJPolyDataProcessor&) = delete;
167 };
168 
169 class vtkRenderWindow;
170 class vtkRenderer;
172  vtkRenderer* renderer,
173  vtkOBJPolyDataProcessor* reader );
174 
175 #endif
176 // VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
~vtkOBJPolyDataProcessor() override
void SetMTLfileName(const char *arg)
Store vtkAlgorithm input/output information.
const int MATERIAL_NAME_SIZE
const int OBJ_FILENAME_LENGTH
char texture_filename[OBJ_FILENAME_LENGTH]
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
abstract specification for renderers
Definition: vtkRenderer.h:63
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)
const std::string & GetMTLFileName() const
std::vector< vtkOBJImportedMaterial * > ParseOBJandMTL(std::string filename, int &result_code)
std::string GetTextureFilename(int idx)
vtkOBJImportedMaterial * GetMaterial(int k)
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
const std::string & GetTexturePath() const
const std::string & GetFileName() const
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
std::vector< vtkOBJImportedMaterial * > parsedMTLs
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
std::vector< vtkSmartPointer< vtkActor > > actor_list
std::map< std::string, vtkOBJImportedMaterial * > mtlName_to_mtlData
create a window for renderers to draw into
void SetTexturePath(const char *arg)
Store zero or more vtkInformation instances.
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
static vtkOBJPolyDataProcessor * New()
void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints *points, const bool use_scale)
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
represent and manipulate 3D points
Definition: vtkPoints.h:39
char name[MATERIAL_NAME_SIZE]