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"
19#include <memory>
20#include <vector>
21#include <map>
22#include "vtkActor.h"
23
24const int OBJ_FILENAME_LENGTH = 8192;
25const 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;
41 {
42 return sqrt( amb[0]*amb[0]+amb[1]*amb[1]+amb[2]*amb[2] );
43 }
45 {
46 return sqrt( diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2] );
47 }
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
59struct vtkOBJImportedPolyDataWithMaterial;
60
62{
63public:
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 {
78 }
79 void SetTexturePath( const char* arg )
80 {
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 }
93 {
94 return TexturePath;
95 }
96
97 const std::string& GetFileName( ) const
98 {
99 return FileName;
100 }
101
103 {
104 return MTLFileName;
105 }
106
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);
135protected:
139 vtkInformationVector **, vtkInformationVector *) /*override*/;
140
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;
147
148private:
149 vtkOBJPolyDataProcessor(const vtkOBJPolyDataProcessor&) VTK_DELETE_FUNCTION;
150 void operator=(const vtkOBJPolyDataProcessor&) VTK_DELETE_FUNCTION;
151};
152
153class vtkRenderWindow;
154class vtkRenderer;
156 vtkRenderer* renderer,
157 vtkOBJPolyDataProcessor* reader );
158
159#endif
160// VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:52
a simple class to control print indentation
Definition: vtkIndent.h:40
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)
std::vector< std::string > outVector_of_textureFilnames
std::vector< vtkSmartPointer< vtkActor > > actor_list
void SetTexturePath(const char *arg)
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::map< std::string, vtkOBJImportedMaterial * > mtlName_to_mtlData
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints *points, const bool use_scale)
static vtkOBJPolyDataProcessor * New()
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
const std::string & GetTexturePath() const
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
std::vector< vtkOBJImportedMaterial * > ParseOBJandMTL(std::string filename, int &result_code)
void SetMTLfileName(const char *arg)
represent and manipulate 3D points
Definition: vtkPoints.h:40
Superclass for algorithms that produce only polydata as output.
vtkPolyData * GetOutput()
Get the output data object for a port on this algorithm.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:64
Hold a reference to a vtkObjectBase instance.
@ points
Definition: vtkX3D.h:446
@ vector
Definition: vtkX3D.h:237
@ string
Definition: vtkX3D.h:490
char name[MATERIAL_NAME_SIZE]
char texture_filename[OBJ_FILENAME_LENGTH]
void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)
const int OBJ_FILENAME_LENGTH
const int MATERIAL_NAME_SIZE
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.