Fix bug 17598: restore fix for 12874 in 4.X.

This commit is contained in:
jfa 2007-12-05 12:37:56 +00:00
parent 76b38a4f25
commit 4ed263105c
5 changed files with 268 additions and 171 deletions

View File

@ -379,11 +379,10 @@ SetDeflection(float theDeflection, bool theIsRelative)
SetModified();
}
void
GEOM_Actor::
SetShape(const TopoDS_Shape& theShape,
void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
float theDeflection,
bool theIsRelative)
bool theIsRelative,
bool theIsVector)
{
myShape = theShape;
@ -395,7 +394,8 @@ SetShape(const TopoDS_Shape& theShape,
myShadingFaceSource->Clear();
TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
for(; aVertexExp.More(); aVertexExp.Next()){
for (; aVertexExp.More(); aVertexExp.Next())
{
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
myVertexSource->AddVertex(aVertex);
}
@ -405,18 +405,17 @@ SetShape(const TopoDS_Shape& theShape,
TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
SetShape(theShape,anEdgeMap);
SetShape(theShape,anEdgeMap,theIsVector);
}
void
GEOM_Actor::
SetShape(const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap)
void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
bool theIsVector)
{
if (theShape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator anItr(theShape);
for (; anItr.More(); anItr.Next()) {
SetShape(anItr.Value(),theEdgeMap);
SetShape(anItr.Value(),theEdgeMap,theIsVector);
}
}
@ -426,14 +425,14 @@ SetShape(const TopoDS_Shape& theShape,
for (; anEdgeExp.More(); anEdgeExp.Next()){
const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
if (!BRep_Tool::Degenerated(anEdge))
myIsolatedEdgeSource->AddEdge(anEdge);
myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
}
break;
}
case TopAbs_EDGE: {
const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
if (!BRep_Tool::Degenerated(anEdge))
myIsolatedEdgeSource->AddEdge(anEdge);
myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
break;
}
case TopAbs_VERTEX: {
@ -453,13 +452,13 @@ SetShape(const TopoDS_Shape& theShape,
int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
switch(aNbOfFaces){
case 0: // isolated edge
myIsolatedEdgeSource->AddEdge(anEdge);
myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
break;
case 1: // edge in only one face
myOneFaceEdgeSource->AddEdge(anEdge);
myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
break;
default: // edge shared by at least two faces
mySharedEdgeSource->AddEdge(anEdge);
mySharedEdgeSource->AddEdge(anEdge,theIsVector);
}
}
}

View File

@ -64,7 +64,8 @@ public:
void SetShape(const TopoDS_Shape& theShape,
float theDeflection,
bool theIsRelative);
bool theIsRelative,
bool theIsVector = false);
void SetDeflection(float theDeflection, bool theIsRelative);
float GetDeflection() const{ return myDeflection;}
@ -164,7 +165,8 @@ public:
protected:
void SetShape(const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap);
const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
bool theIsVector = false);
void SetModified();

View File

@ -207,7 +207,7 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap
vtkActorCollection* AISActors = vtkActorCollection::New();
MeshShape(myShape,deflection,forced);
GEOM_Actor* aGeomActor = GEOM_Actor::New();
aGeomActor->SetShape(myShape,(float)deflection,false);
aGeomActor->SetShape(myShape,(float)deflection,false,isVector);
AISActors->AddItem(aGeomActor);
aGeomActor->Delete();

View File

@ -24,11 +24,11 @@ GEOM_EdgeSource::~GEOM_EdgeSource()
{
}
void
GEOM_EdgeSource::
AddEdge(const TopoDS_Edge& theEdge)
void GEOM_EdgeSource::AddEdge (const TopoDS_Edge& theEdge,
bool theIsVector)
{
myEdgeSet.Add(theEdge);
myIsVector = theIsVector;
}
void
@ -44,15 +44,14 @@ Execute()
TEdgeSet::Iterator anIter (myEdgeSet);
for (; anIter.More(); anIter.Next()) {
const TopoDS_Edge& anEdge = anIter.Value();
OCC2VTK(anEdge,aPolyData,aPts);
OCC2VTK(anEdge,aPolyData,aPts,myIsVector);
}
}
void
GEOM_EdgeSource::
OCC2VTK(const TopoDS_Edge& theEdge,
void GEOM_EdgeSource::OCC2VTK (const TopoDS_Edge& theEdge,
vtkPolyData* thePolyData,
vtkPoints* thePts)
vtkPoints* thePts,
bool theIsVector)
{
Handle(Poly_PolygonOnTriangulation) aEdgePoly;
Standard_Integer i = 1;
@ -76,10 +75,15 @@ OCC2VTK(const TopoDS_Edge& theEdge,
edgeTransf = aEdgeLoc.Transformation();
}
gp_Pnt aP1, aP2;
if (aEdgePoly.IsNull()) {
Standard_Integer aNbNodes = P->NbNodes();
const TColgp_Array1OfPnt& aNodesP = P->Nodes();
aP1 = aNodesP(1);
aP2 = aNodesP(aNbNodes);
for (int j = 1; j < aNbNodes; j++) {
gp_Pnt pt1 = aNodesP(j);
gp_Pnt pt2 = aNodesP(j+1);
@ -104,6 +108,9 @@ OCC2VTK(const TopoDS_Edge& theEdge,
const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes();
const TColgp_Array1OfPnt& anId2Pnts = T->Nodes();
aP1 = anId2Pnts(1);
aP2 = anId2Pnts(aNbNodes);
for(int j = 1; j < aNbNodes; j++) {
Standard_Integer id1 = aNodeIds(j);
Standard_Integer id2 = aNodeIds(j+1);
@ -127,4 +134,88 @@ OCC2VTK(const TopoDS_Edge& theEdge,
thePolyData->InsertNextCell(VTK_LINE,2,anIds);
}
}
// vector representation has an arrow on its end
if (theIsVector)
{
if (!isidtrsf) {
// apply edge transformation
aP1.Transform(edgeTransf);
aP2.Transform(edgeTransf);
}
// draw an arrow
gp_Vec aDirVec (aP1, aP2);
Standard_Real aDist = aDirVec.Magnitude();
if (aDist < gp::Resolution()) return;
gp_Dir aDirection (aDirVec);
Standard_Real anAngle = PI/180.*5.;
Standard_Real aLength = aDist/10.;
Standard_Real dx,dy,dz;
aDirection.Coord(dx,dy,dz);
// Pointe de la fleche
Standard_Real xo,yo,zo;
aP2.Coord(xo,yo,zo);
// Centre du cercle base de la fleche
gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
// Construction d'un repere i,j pour le cercle
gp_Dir aDirN;
if (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
else aDirN = gp::DZ();
gp_Dir aDirI = aDirection ^ aDirN;
gp_Dir aDirJ = aDirection ^ aDirI;
// Add points and segments, composing the arrow
Standard_Real cosinus, sinus, Tg = tan(anAngle);
float coord[3] = {xo, yo, zo};
vtkIdType ptLoc = thePts->InsertNextPoint(coord);
vtkIdType ptFirst = 0;
vtkIdType ptPrev = 0;
vtkIdType ptCur = 0;
vtkIdType pts[2];
int NbPoints = 15;
for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
{
cosinus = cos(2. * PI / NbPoints * (i-1));
sinus = sin(2. * PI / NbPoints * (i-1));
gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
coord[0] = aP.X();
coord[1] = aP.Y();
coord[2] = aP.Z();
// insert pts
ptCur = thePts->InsertNextPoint(coord);
pts[0] = ptCur;
if (i == 1) {
ptFirst = ptCur;
}
else {
// insert line (ptCur,ptPrev)
pts[1] = ptPrev;
thePolyData->InsertNextCell(VTK_LINE,2,pts);
}
// insert line (ptCur,ptLoc)
pts[1] = ptLoc;
thePolyData->InsertNextCell(VTK_LINE,2,pts);
}
// insert line (ptCur,ptFirst)
pts[0] = ptCur;
pts[1] = ptFirst;
thePolyData->InsertNextCell(VTK_LINE,2,pts);
}
}

View File

@ -17,16 +17,21 @@ public:
vtkTypeMacro(GEOM_EdgeSource,vtkPolyDataSource);
static GEOM_EdgeSource* New();
void AddEdge(const TopoDS_Edge& theEdge);
void AddEdge (const TopoDS_Edge& theEdge,
bool theIsVector = false);
void Clear(){ myEdgeSet.Clear();}
static
void OCC2VTK(const TopoDS_Edge& theEdge,
vtkPolyData* thePolyData,
vtkPoints* thePts);
vtkPoints* thePts,
bool theIsVector = false);
protected:
TEdgeSet myEdgeSet;
// The <myIsVector> flag is common for all edges, because the shape,
// representing a vector, can have only one edge.
bool myIsVector;
void Execute();