Equalizer  1.6.1
eqPly/vertexData.h
1 
2 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
3  * 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 
31 #ifndef MESH_VERTEXDATA_H
32 #define MESH_VERTEXDATA_H
33 
34 
35 #include "typedefs.h"
36 #include <vector>
37 
38 
39 // defined elsewhere
40 struct PlyFile;
41 
42 namespace mesh
43 {
44  /* Holds the flat data and offers routines to read, scale and sort it. */
45  class VertexData
46  {
47  public:
48  VertexData();
49 
50  bool readPlyFile( const std::string& file );
51  void sort( const Index start, const Index length, const Axis axis );
52  void scale( const float baseSize = 2.0f );
53  void calculateNormals();
54  void calculateBoundingBox();
55  const BoundingBox& getBoundingBox() const { return _boundingBox; }
56  Axis getLongestAxis( const size_t start, const size_t elements ) const;
57 
58  void useInvertedFaces() { _invertFaces = true; }
59 
60  std::vector< Vertex > vertices;
61  std::vector< Color > colors;
62  std::vector< Normal > normals;
63  std::vector< Triangle > triangles;
64 
65  private:
66  void readVertices( PlyFile* file, const int nVertices,
67  const bool readColors );
68  void readTriangles( PlyFile* file, const int nFaces );
69 
70  BoundingBox _boundingBox;
71  bool _invertFaces;
72  };
73 }
74 
75 
76 #endif // MESH_VERTEXDATA_H