~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (c) 2006 Werner Mayer <wmayer@users.sourceforge.net>        *
 
2
 *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
3
 *                                                                         *
4
4
 *   This file is part of the FreeCAD CAx development system.              *
5
5
 *                                                                         *
28
28
# include <Inventor/SoPickedPoint.h>
29
29
# include <Inventor/details/SoFaceDetail.h>
30
30
# include <Inventor/nodes/SoBaseColor.h>
 
31
# include <Inventor/nodes/SoCoordinate3.h>
31
32
# include <Inventor/nodes/SoDrawStyle.h>
 
33
# include <Inventor/nodes/SoIndexedLineSet.h>
32
34
# include <Inventor/nodes/SoMaterial.h>
33
35
# include <Inventor/nodes/SoMaterialBinding.h>
34
36
# include <Inventor/nodes/SoPolygonOffset.h>
69
71
#include <Mod/Mesh/App/Core/Iterator.h>
70
72
#include <Mod/Mesh/App/Core/MeshIO.h>
71
73
#include <Mod/Mesh/App/Core/MeshKernel.h>
72
 
#include <Mod/Mesh/App/Core/Triangulation.h>
 
74
#include <Mod/Mesh/App/Core/Triangulation.h>
73
75
#include <Mod/Mesh/App/Core/Visitor.h>
74
76
#include <Mod/Mesh/App/Mesh.h>
75
77
#include <Mod/Mesh/App/MeshFeature.h>
76
78
#include <Mod/Mesh/App/MeshProperties.h>
77
79
 
78
80
#include "ViewProviderMeshFaceSet.h"
79
 
#include "SoFCMeshObject.h"
80
 
#include "SoFCIndexedFaceSet.h"
 
81
#include "SoFCMeshObject.h"
 
82
#include "SoFCIndexedFaceSet.h"
81
83
 
82
84
 
83
85
using namespace MeshGui;
87
89
 
88
90
ViewProviderMeshFaceSet::ViewProviderMeshFaceSet()
89
91
{
90
 
    directRendering = false;
91
 
    triangleCount = 500000;
 
92
    directRendering = false;
 
93
    triangleCount = 500000;
92
94
 
93
95
    pcMeshNode = new SoFCMeshObjectNode;
94
96
    pcMeshNode->ref();
159
161
        showOpenEdges(OpenEdges.getValue());
160
162
    }
161
163
}
162
 
 
163
 
void ViewProviderMeshFaceSet::createMesh(const MeshCore::MeshKernel& rcMesh)
164
 
{
165
 
    // set the point coordinates
166
 
    const MeshCore::MeshPointArray& cP = rcMesh.GetPoints();
167
 
    pcMeshCoord->point.setNum(rcMesh.CountPoints());
168
 
    SbVec3f* verts = pcMeshCoord->point.startEditing();
169
 
    unsigned long i=0;
170
 
    for (MeshCore::MeshPointArray::_TConstIterator it = cP.begin(); it != cP.end(); ++it, i++) {
171
 
        verts[i].setValue(it->x, it->y, it->z);
172
 
    }
173
 
    pcMeshCoord->point.finishEditing();
174
 
 
175
 
    // set the face indices
176
 
    unsigned long j=0;
177
 
    const MeshCore::MeshFacetArray& cF = rcMesh.GetFacets();
178
 
    pcMeshFaces->coordIndex.setNum(4*rcMesh.CountFacets());
179
 
    int32_t* indices = pcMeshFaces->coordIndex.startEditing();
180
 
    for (MeshCore::MeshFacetArray::_TConstIterator it = cF.begin(); it != cF.end(); ++it, j++) {
181
 
        for (int i=0; i<3; i++) {
182
 
            indices[4*j+i] = it->_aulPoints[i];
183
 
        }
184
 
        indices[4*j+3] = SO_END_FACE_INDEX;
185
 
    }
186
 
    pcMeshFaces->coordIndex.finishEditing();
187
 
}
 
164
 
 
165
void ViewProviderMeshFaceSet::createMesh(const MeshCore::MeshKernel& rcMesh)
 
166
{
 
167
    // set the point coordinates
 
168
    const MeshCore::MeshPointArray& cP = rcMesh.GetPoints();
 
169
    pcMeshCoord->point.setNum(rcMesh.CountPoints());
 
170
    SbVec3f* verts = pcMeshCoord->point.startEditing();
 
171
    unsigned long i=0;
 
172
    for (MeshCore::MeshPointArray::_TConstIterator it = cP.begin(); it != cP.end(); ++it, i++) {
 
173
        verts[i].setValue(it->x, it->y, it->z);
 
174
    }
 
175
    pcMeshCoord->point.finishEditing();
 
176
 
 
177
    // set the face indices
 
178
    unsigned long j=0;
 
179
    const MeshCore::MeshFacetArray& cF = rcMesh.GetFacets();
 
180
    pcMeshFaces->coordIndex.setNum(4*rcMesh.CountFacets());
 
181
    int32_t* indices = pcMeshFaces->coordIndex.startEditing();
 
182
    for (MeshCore::MeshFacetArray::_TConstIterator it = cF.begin(); it != cF.end(); ++it, j++) {
 
183
        for (int i=0; i<3; i++) {
 
184
            indices[4*j+i] = it->_aulPoints[i];
 
185
        }
 
186
        indices[4*j+3] = SO_END_FACE_INDEX;
 
187
    }
 
188
    pcMeshFaces->coordIndex.finishEditing();
 
189
}
188
190
 
189
191
void ViewProviderMeshFaceSet::showOpenEdges(bool show)
190
192
{
199
201
        pcOpenEdge->addChild(pcLineStyle);
200
202
        pcOpenEdge->addChild(pOpenColor);
201
203
 
202
 
        if (directRendering) {
 
204
        if (directRendering) {
203
205
            pcOpenEdge->addChild(pcMeshNode);
204
206
            pcOpenEdge->addChild(new SoFCMeshObjectBoundary);
205
207
        }
206
208
        else {
207
209
            pcOpenEdge->addChild(pcMeshCoord);
208
 
            SoIndexedLineSet* lines = new SoIndexedLineSet;
 
210
            SoIndexedLineSet* lines = new SoIndexedLineSet;
209
211
            pcOpenEdge->addChild(lines);
210
 
 
211
 
            // Build up the lines with indices to the list of vertices 'pcMeshCoord'
212
 
            int index=0;
213
 
            const MeshCore::MeshKernel& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue().getKernel();
214
 
            const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets();
215
 
            for (MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) {
216
 
                for (int i=0; i<3; i++) {
217
 
                    if (it->_aulNeighbours[i] == ULONG_MAX) {
218
 
                        lines->coordIndex.set1Value(index++,it->_aulPoints[i]);
219
 
                        lines->coordIndex.set1Value(index++,it->_aulPoints[(i+1)%3]);
220
 
                        lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX);
221
 
                    }
222
 
                }
223
 
            }
 
212
 
 
213
            // Build up the lines with indices to the list of vertices 'pcMeshCoord'
 
214
            int index=0;
 
215
            const MeshCore::MeshKernel& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue().getKernel();
 
216
            const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets();
 
217
            for (MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) {
 
218
                for (int i=0; i<3; i++) {
 
219
                    if (it->_aulNeighbours[i] == ULONG_MAX) {
 
220
                        lines->coordIndex.set1Value(index++,it->_aulPoints[i]);
 
221
                        lines->coordIndex.set1Value(index++,it->_aulPoints[(i+1)%3]);
 
222
                        lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX);
 
223
                    }
 
224
                }
 
225
            }
224
226
        }
225
227
 
226
228
        // add to the highlight node
227
229
        pcRoot->addChild(pcOpenEdge);
228
230
    }
229
231
}
230
 
 
231
 
SoShape* ViewProviderMeshFaceSet::getShapeNode() const
232
 
{
233
 
    if (directRendering)
234
 
        return this->pcMeshShape;
235
 
    return this->pcMeshFaces;
236
 
}
 
232
 
 
233
SoShape* ViewProviderMeshFaceSet::getShapeNode() const
 
234
{
 
235
    if (directRendering)
 
236
        return this->pcMeshShape;
 
237
    return this->pcMeshFaces;
 
238
}