Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SmHQSphere.h
Go to the documentation of this file.
1 #ifndef COIN_SMHQSPHERE_H
2 #define COIN_SMHQSPHERE_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/nodes/SoSubNode.h>
37 #include <Inventor/nodes/SoShape.h>
38 #include <Inventor/fields/SoSFFloat.h>
39 #include <Inventor/fields/SoSFInt32.h>
40 #include <Inventor/SbLinear.h>
41 #include <SmallChange/basic.h>
42 
43 class SmHQSphereP;
44 class SbBSPTree;
45 
46 class SMALLCHANGE_DLL_API SmHQSphere : public SoShape {
47  typedef SoShape inherited;
48 
50 
51 public:
52  static void initClass(void);
53  SmHQSphere(void);
54 
57 
58  virtual void GLRender(SoGLRenderAction * action);
59  virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
60  virtual void rayPick(SoRayPickAction * action);
61 
62 protected:
63  virtual ~SmHQSphere();
64  virtual void generatePrimitives(SoAction * action);
65  virtual void computeBBox(SoAction * action, SbBox3f & box, SbVec3f & center);
66 
67 private:
68  SmHQSphereP * pimpl;
69 };
70 
71 class SMALLCHANGE_DLL_API HQSphereGenerator {
72 public:
74  this->orgobject = NULL;
75  this->init();
76  }
78  delete this->orgobject;
79  }
80 
81  class triangle {
82  public:
83  triangle(void) { }
84  triangle(const SbVec3f & p0, const SbVec3f & p1, const SbVec3f & p2) {
85  pt[0] = p0;
86  pt[1] = p1;
87  pt[2] = p2;
88  }
89  public:
90  SbVec3f pt[3];
91  };
92 
93  class object {
94  public:
95  object(int npoly, const triangle * poly) {
96  this->npoly = npoly;
97  this->poly = new triangle[npoly];
98  if (poly) {
99  memcpy(this->poly, poly, npoly*sizeof(triangle));
100  }
101  }
103  delete[] this->poly;
104  }
105  public:
106  int npoly; /* # of triangles in object */
107  triangle * poly; /* Triangles */
108  };
109 
110  void generate(const int level, SbBSPTree & bsp, SbList <int> & idx);
111 
112  SbVec3f normalize(const SbVec3f & p);
113  SbVec3f midpoint(const SbVec3f & a, const SbVec3f & b);
114 
115 private:
116  void convert(object * obj, SbBSPTree & bsp, SbList <int> & idx);
117  void init(void);
118  object * orgobject;
119 };
120 
121 #endif // COIN_SMHQSPHERE_H
Definition: SmHQSphere.h:93
triangle(void)
Definition: SmHQSphere.h:83
HQSphereGenerator(void)
Definition: SmHQSphere.h:73
#define SO_NODE_HEADER(classname)
virtual void GLRender(SoGLRenderAction *action)
Definition: SmHQSphere.h:71
object(int npoly, const triangle *poly)
Definition: SmHQSphere.h:95
~object()
Definition: SmHQSphere.h:102
triangle * poly
Definition: SmHQSphere.h:107
virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action)
SoSFInt32 level
Definition: SmHQSphere.h:56
static void initClass(void)
virtual void generatePrimitives(SoAction *action)=0
Definition: SmHQSphere.h:46
triangle(const SbVec3f &p0, const SbVec3f &p1, const SbVec3f &p2)
Definition: SmHQSphere.h:84
virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center)=0
~HQSphereGenerator(void)
Definition: SmHQSphere.h:77
int npoly
Definition: SmHQSphere.h:106
SoSFFloat radius
Definition: SmHQSphere.h:55
Definition: SmHQSphere.h:81
virtual void rayPick(SoRayPickAction *action)