BaseModel.h
Go to the documentation of this file.
1 // BaseModel.h: interface for the CBaseModel class.
2 //
4 #pragma once
5 
6 #include "Point3D.h"
7 #include <string>
8 #include <vector>
9 #include <map>
10 #include <set>
11 using namespace std;
12 
13 class CBaseModel
14 {
15 public:
16  CBaseModel(const string& filename);
17 public:
18  struct CFace
19  {
20  int verts[3];
21  CFace(){}
22  CFace(int x, int y, int z)
23  {
24  verts[0] = x;
25  verts[1] = y;
26  verts[2] = z;
27  }
28  int& operator[](int index)
29  {
30  return verts[index];
31  }
32  int operator[](int index) const
33  {
34  return verts[index];
35  }
36  };
37  vector<CFace> m_Faces;
38  vector<CPoint3D> m_Verts;
39 protected:
40  vector<CPoint3D> m_NormalsToVerts;
41  set<int> m_UselessFaces;
42  string m_filename;
43  double m_scale;
44 
45 protected:
46  void ReadMFile(const string& filename);
47  void ReadFile(const string& filename);
48  void ReadObjFile(const string& filename);
49  void ReadOffFile(const string& filename);
50  void ComputeScaleAndNormals();
51 public:
52  virtual void LoadModel();
53  int GetVertexID(const CPoint3D& pt) const;
54  void SaveMFile(const string& filename) const;
55  void SaveOffFile(const string& filename) const;
56  void SaveObjFile(const string& filename) const;
57  void SaveScalarFieldObjFile(const vector<double>& vals, const string& filename) const;
58  void SaveScalarFieldObjFile(const vector<double>& vals, double maxV, const string& filename) const;
59  void SaveScalarFieldObjFile(const vector<double>& vals, const string& comments, const string& filename) const;
60  void SavePamametrizationObjFile(const vector<pair<double, double>>& uvs, const string& filename) const;
61  static vector<double> GetScalarField(string filename);
62  static string GetComments(const char* filename);
63  virtual void PrintInfo(ostream& out) const;
64 // virtual void Render() const;
65  inline int GetNumOfVerts() const;
66  inline int GetNumOfFaces() const;
67  string GetFileShortName() const;
68  string GetFileShortNameWithoutExtension() const;
69  string GetFileFullName() const;
70  inline const CPoint3D& Vert(int vertIndex) const;
71  inline const CPoint3D& Normal(int vertIndex) const;
72  inline const CFace& Face(int faceIndex) const;
73  CPoint3D GetShiftVertex(int indexOfVert) const;
74  //CPoint3D ShiftVertex(int indexOfVert, double epsilon) const;
75  double GetScale() const {return m_scale;}
76  void SetFaces(const vector<CBaseModel::CFace>& faces);
77  const vector<CBaseModel::CFace>& GetFaces() const;
78 };
79 
81 {
82  return (int)m_Verts.size();
83 }
84 
86 {
87  return (int)m_Faces.size();
88 }
89 
90 const CPoint3D& CBaseModel::Vert(int vertIndex) const
91 {
92  return m_Verts[vertIndex];
93 }
94 
95 const CPoint3D& CBaseModel::Normal(int vertIndex) const
96 {
97  return m_NormalsToVerts[vertIndex];
98 }
99 
100 const CBaseModel::CFace& CBaseModel::Face(int faceIndex) const
101 {
102  return m_Faces[faceIndex];
103 }
104 
vector< CPoint3D > m_Verts
Definition: BaseModel.h:38
double GetScale() const
Definition: BaseModel.h:75
int GetNumOfFaces() const
Definition: BaseModel.h:85
string m_filename
Definition: BaseModel.h:42
CFace(int x, int y, int z)
Definition: BaseModel.h:22
int operator[](int index) const
Definition: BaseModel.h:32
const CPoint3D & Normal(int vertIndex) const
Definition: BaseModel.h:95
vector< CFace > m_Faces
Definition: BaseModel.h:37
int GetNumOfVerts() const
Definition: BaseModel.h:80
const CPoint3D & Vert(int vertIndex) const
Definition: BaseModel.h:90
vector< CPoint3D > m_NormalsToVerts
Definition: BaseModel.h:40
const CFace & Face(int faceIndex) const
Definition: BaseModel.h:100
set< int > m_UselessFaces
Definition: BaseModel.h:41
int & operator[](int index)
Definition: BaseModel.h:28
double m_scale
Definition: BaseModel.h:43


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:39