SoFCMeshFaceSet.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef MESHGUI_SOFC_MESHFACESET_H
00024 #define MESHGUI_SOFC_MESHFACESET_H
00025 
00026 #include <Inventor/fields/SoSField.h>
00027 #include <Inventor/fields/SoSubField.h>
00028 #include <Mod/Mesh/App/Core/Elements.h>
00029 
00030 
00031 #include <Inventor/elements/SoReplacedElement.h>
00032 #include <Inventor/nodes/SoNode.h>
00033 #include <Inventor/nodes/SoShape.h>
00034 #include <Inventor/fields/SoMFVec3f.h>
00035 #include <Inventor/fields/SoMFInt32.h>
00036 
00037 class SoMaterialBundle;
00038 
00039 namespace Mesh {
00040 class Feature;
00041 }
00042 
00043 namespace MeshGui {
00044 
00045 class MeshGuiExport SoSFMeshFacetArray : public SoSField {
00046   typedef SoSField inherited;
00047 
00048   SO_SFIELD_HEADER(SoSFMeshFacetArray, MeshCore::MeshFacetArray*, MeshCore::MeshFacetArray*);
00049 
00050 public:
00051   static void initClass(void);
00052   void setValue(const MeshCore::MeshFacetArray& p);
00053 
00054 protected:
00055   SbBool readBinaryValues(SoInput * in, unsigned long numarg);
00056   SbBool read1Value(SoInput * in, unsigned long idx);
00057   void writeBinaryValues(SoOutput * out) const;
00058   void write1Value(SoOutput * out, unsigned long idx) const;
00059   int getNumValuesPerLine() const;
00060 };
00061 
00062 // -------------------------------------------------------
00063 
00064 class MeshGuiExport SoFCMeshFacetElement : public SoReplacedElement {
00065   typedef SoReplacedElement inherited;
00066 
00067   SO_ELEMENT_HEADER(SoFCMeshFacetElement);
00068 
00069 public:
00070   static void initClass(void);
00071 
00072   virtual void init(SoState * state);
00073   static void set(SoState * const state, SoNode * const node, const MeshCore::MeshFacetArray * const coords);
00074   static const MeshCore::MeshFacetArray * get(SoState * const state);
00075   static const SoFCMeshFacetElement * getInstance(SoState * state);
00076   virtual void print(FILE * file) const;
00077 
00078 protected:
00079   virtual ~SoFCMeshFacetElement();
00080   const MeshCore::MeshFacetArray *coordIndex;
00081 };
00082 
00083 // -------------------------------------------------------
00084 
00085 class MeshGuiExport SoFCMeshFacet : public SoNode {
00086   typedef SoSField inherited;
00087 
00088   SO_NODE_HEADER(SoFCMeshFacet);
00089 
00090 public:
00091   static void initClass(void);
00092   SoFCMeshFacet(void);
00093 
00094   SoSFMeshFacetArray coordIndex;
00095 
00096   virtual void doAction(SoAction * action);
00097   virtual void GLRender(SoGLRenderAction * action);
00098   virtual void callback(SoCallbackAction * action);
00099   virtual void getBoundingBox(SoGetBoundingBoxAction * action);
00100   virtual void pick(SoPickAction * action);
00101   virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
00102 
00103 protected:
00104   virtual ~SoFCMeshFacet();
00105 };
00106 
00107 // -------------------------------------------------------
00108 
00121 class MeshGuiExport SoFCMeshFaceSet : public SoShape {
00122   typedef SoShape inherited;
00123 
00124   SO_NODE_HEADER(SoFCMeshFaceSet);
00125     
00126 public:
00127   static void initClass();
00128   SoFCMeshFaceSet();
00129 
00130   unsigned int MaximumTriangles;
00131 
00132 protected:
00133   virtual void GLRender(SoGLRenderAction *action);
00134   virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center);
00135   virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
00136   virtual void  rayPick (SoRayPickAction *action);
00137   virtual void generatePrimitives(SoAction *action);
00138   virtual SoDetail * createTriangleDetail(SoRayPickAction * action,
00139                                           const SoPrimitiveVertex * v1,
00140                                           const SoPrimitiveVertex * v2,
00141                                           const SoPrimitiveVertex * v3,
00142                                           SoPickedPoint * pp);
00143 
00144 private:
00145   enum Binding {
00146     OVERALL = 0,
00147     PER_FACE_INDEXED,
00148     PER_VERTEX_INDEXED,
00149     NONE = OVERALL
00150   };
00151 
00152 private:
00153   // Force using the reference count mechanism.
00154   virtual ~SoFCMeshFaceSet() {};
00155   virtual void notify(SoNotList * list);
00156   Binding findMaterialBinding(SoState * const state) const;
00157   // Draw faces
00158   void drawFaces(const MeshCore::MeshPointArray *, const MeshCore::MeshFacetArray*, SoMaterialBundle* mb, Binding bind, 
00159                  SbBool needNormals, SbBool ccw) const;
00160   void drawPoints(const MeshCore::MeshPointArray *, const MeshCore::MeshFacetArray*, SbBool needNormals, SbBool ccw) const;
00161   unsigned int countTriangles(SoAction * action) const;
00162   void createProxyModel(const MeshCore::MeshPointArray *, const MeshCore::MeshFacetArray*, SbBool simplest);
00163 
00164 private:
00165   bool meshChanged;
00166   SoMFVec3f point;
00167   SoMFInt32 coordIndex;
00168 };
00169 
00170 // ------------------------------------------------------------
00171 
00172 class MeshGuiExport SoFCMeshOpenEdgeSet : public SoShape {
00173   typedef SoShape inherited;
00174 
00175   SO_NODE_HEADER(SoFCMeshOpenEdgeSet);
00176     
00177 public:
00178   static void initClass();
00179   SoFCMeshOpenEdgeSet();
00180 
00181 protected:
00182   virtual void GLRender(SoGLRenderAction *action);
00183   virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center);
00184   virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
00185   virtual void generatePrimitives(SoAction *action);
00186 private:
00187   // Force using the reference count mechanism.
00188   virtual ~SoFCMeshOpenEdgeSet() {};
00189   void drawLines(const MeshCore::MeshPointArray *, const MeshCore::MeshFacetArray*) const ;
00190 };
00191 
00192 } // namespace MeshGui
00193 
00194 
00195 #endif // MESHGUI_SOFC_MESHFACESET_H
00196 

Generated on Wed Nov 23 19:00:39 2011 for FreeCAD by  doxygen 1.6.1