vtkOBJImporterInternals.h 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*=========================================================================
  Program:   Visualization Toolkit
  Module:    vtkOBJImporterInternals.h
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.
=========================================================================*/

Bill Lorensen's avatar
Bill Lorensen committed
13 14
#ifndef vtkOBJImporterInternals_h
#define vtkOBJImporterInternals_h
15
#ifndef __VTK_WRAP__
16

17 18 19 20 21 22 23 24
#include <string>
#include "vtkOBJImporter.h"
#include "vtkPolyDataAlgorithm.h"
#include <memory>
#include <vector>
#include <map>
#include "vtkActor.h"

25
struct vtkOBJImportedMaterial
26
{
27 28
  std::string name;
  std::string texture_filename;
29 30 31
  double amb[3];
  double diff[3];
  double spec[3];
32 33 34
  double map_Kd_scale[3];
  double map_Kd_offset[3];
  int illum;
35 36 37
  double reflect;
  double refract;
  double trans;
38
  double specularPower;
39 40
  double glossy;
  double refract_index;
Bill Lorensen's avatar
Bill Lorensen committed
41
  const char *GetClassName() {return "vtkOBJImportedMaterial";}
42
  vtkOBJImportedMaterial();
43 44 45
};


46
void obj_set_material_defaults(vtkOBJImportedMaterial* mtl);
47

48
struct vtkOBJImportedPolyDataWithMaterial;
49

50
class vtkOBJPolyDataProcessor : public vtkPolyDataAlgorithm
51 52
{
public:
53
  static vtkOBJPolyDataProcessor *New();
54
  vtkTypeMacro(vtkOBJPolyDataProcessor,vtkPolyDataAlgorithm)
55
  void PrintSelf(ostream& os, vtkIndent indent) override;
56 57 58 59

  // Description:
  // Specify file name of Wavefront .obj file.
  void SetFileName(const char* arg)
60
  {
61
    if (arg == nullptr)
62 63 64 65 66 67 68
    {
      return;
    }
    if (!strcmp(this->FileName.c_str(), arg))
    {
      return;
    }
69 70
    FileName    = std::string(arg);
  }
71 72
  void SetMTLfileName( const char* arg )
  {
73
    if (arg == nullptr)
74 75 76 77 78 79 80
    {
      return;
    }
    if (!strcmp(this->MTLFileName.c_str(), arg))
    {
      return;
    }
Bill Lorensen's avatar
Bill Lorensen committed
81
    MTLFileName = std::string(arg);
82
    this->DefaultMTLFileName = false;
83
  }
84 85 86
  void SetTexturePath( const char* arg )
  {
    TexturePath = std::string(arg);
87 88
    if(TexturePath.empty())
      return;
89
#if defined(_WIN32)
90 91 92
    const char sep = '\\';
#else
    const char sep = '/';
93 94 95 96 97 98 99 100
#endif
    if(TexturePath.at(TexturePath.size()-1) != sep )
      TexturePath += sep;
  }
  const std::string& GetTexturePath(  ) const
  {
    return TexturePath;
  }
101

102 103 104 105 106 107 108
  const std::string& GetFileName(  ) const
  {
    return FileName;
  }

  const std::string& GetMTLFileName(  ) const
  {
Bill Lorensen's avatar
Bill Lorensen committed
109
    return MTLFileName;
110 111
  }

112 113
  vtkSetMacro(VertexScale,double)
  vtkGetMacro(VertexScale,double)
114
  vtkGetMacro(SuccessParsingFiles,int)
115 116 117

  virtual vtkPolyData* GetOutput(int idx);

118
  vtkOBJImportedMaterial*  GetMaterial(int k);
119 120 121 122 123

  std::string GetTextureFilename( int idx ); // return string by index

  double VertexScale; // scale vertices by this during import

Ken Martin's avatar
Ken Martin committed
124
  std::vector<vtkOBJImportedMaterial*>  parsedMTLs;
125
  std::map<std::string,vtkOBJImportedMaterial*>  mtlName_to_mtlData;
126 127

  // our internal parsing/storage
128
  std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
129 130 131 132 133 134 135

  // what gets returned to client code via GetOutput()
  std::vector<vtkSmartPointer<vtkPolyData> >  outVector_of_vtkPolyData;

  std::vector<vtkSmartPointer<vtkActor> >  actor_list;
  /////////////////////

136 137
  std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename,int& result_code);

138
  void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
139
protected:
140
  vtkOBJPolyDataProcessor();
141
  ~vtkOBJPolyDataProcessor() override;
142
  int RequestData(vtkInformation *,
143
                  vtkInformationVector **, vtkInformationVector *) override /*override*/;
144

Bill Lorensen's avatar
Bill Lorensen committed
145 146
  vtkSetMacro(SuccessParsingFiles,int)

147
  std::string FileName;     // filename (.obj) being read
Bill Lorensen's avatar
Bill Lorensen committed
148
  std::string MTLFileName;  // associated .mtl to *.obj, typically it is *.obj.mtl
149
  bool DefaultMTLFileName;  // tells whether default of *.obj.mtl to be used
150
  std::string TexturePath;
151
  int         SuccessParsingFiles;
152 153

private:
154 155
  vtkOBJPolyDataProcessor(const vtkOBJPolyDataProcessor&) = delete;
  void operator=(const vtkOBJPolyDataProcessor&) = delete;
156 157 158 159 160 161
};

class vtkRenderWindow;
class vtkRenderer;
void  bindTexturedPolydataToRenderWindow( vtkRenderWindow* renderWindow,
                                          vtkRenderer* renderer,
162
                                          vtkOBJPolyDataProcessor* reader );
163

164
#endif
165 166
#endif
// VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h