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) VTK_OVERRIDE;
67 
68  // Description:
69  // Specify file name of Wavefront .obj file.
70  void SetFileName(const char* arg)
71  { // by default assume prefix.obj => prefix.obj.mtl
72  FileName = std::string(arg);
73  MTLFileName = FileName + ".mtl";
74  }
75  void SetMTLfileName( const char* arg )
76  {
77  MTLFileName = std::string(arg);
78  }
79  void SetTexturePath( const char* arg )
80  {
81  TexturePath = std::string(arg);
82  if(TexturePath.empty())
83  return;
84 #if defined(_WIN32)
85  const char sep = '\\';
86 #else
87  const char sep = '/';
88 #endif
89  if(TexturePath.at(TexturePath.size()-1) != sep )
90  TexturePath += sep;
91  }
92  const std::string& GetTexturePath( ) const
93  {
94  return TexturePath;
95  }
96 
97  const std::string& GetFileName( ) const
98  {
99  return FileName;
100  }
101 
102  const std::string& GetMTLFileName( ) const
103  {
104  return MTLFileName;
105  }
106 
107  vtkSetMacro(VertexScale,double)
108  vtkGetMacro(VertexScale,double)
109  vtkGetMacro(SuccessParsingFiles,int)
110 
111  virtual vtkPolyData* GetOutput(int idx);
112 
114 
115  std::string GetTextureFilename( int idx ); // return string by index
116 
117  double VertexScale; // scale vertices by this during import
118 
120 
121  // our internal parsing/storage
122  std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
123 
124  // what gets returned to client code via GetOutput()
126 
128 
131 
132  std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename,int& result_code);
133 
134  void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
135 protected:
137  ~vtkOBJPolyDataProcessor();
139  vtkInformationVector **, vtkInformationVector *) /*override*/;
140 
141  vtkSetMacro(SuccessParsingFiles,int)
142 
143  std::string FileName; // filename (.obj) being read
144  std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
145  std::string TexturePath;
146  int SuccessParsingFiles;
147 
148 private:
149  vtkOBJPolyDataProcessor(const vtkOBJPolyDataProcessor&) VTK_DELETE_FUNCTION;
150  void operator=(const vtkOBJPolyDataProcessor&) VTK_DELETE_FUNCTION;
151 };
152 
153 class vtkRenderWindow;
154 class vtkRenderer;
155 void bindTexturedPolydataToRenderWindow( vtkRenderWindow* renderWindow,
156  vtkRenderer* renderer,
157  vtkOBJPolyDataProcessor* reader );
158 
159 #endif
160 // VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
void SetMTLfileName(const char *arg)
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:51
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
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
abstract specification for renderers
Definition: vtkRenderer.h:63
Hold a reference to a vtkObjectBase instance.
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)
const std::string & GetFileName() const
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
std::vector< std::string > outVector_of_textureFilnames
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
const std::string & GetTexturePath() const
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]