1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GEOM_WireframeFace.h"
22 #include <GEOMUtils_Hatcher.hxx>
24 #include <vtkObjectFactory.h>
26 #include <vtkPoints.h>
27 #include <vtkCellArray.h>
29 #include <vtkPolyDataMapper.h>
30 #include <vtkPolyData.h>
31 #include <vtkInformation.h>
32 #include <vtkInformationVector.h>
34 #include <Adaptor3d_HCurve.hxx>
35 #include <BRep_Tool.hxx>
36 #include <TColStd_Array1OfReal.hxx>
38 vtkStandardNewMacro(GEOM_WireframeFace);
40 GEOM_WireframeFace::GEOM_WireframeFace():
46 this->SetNumberOfInputPorts(0);
49 GEOM_WireframeFace::~GEOM_WireframeFace()
53 int GEOM_WireframeFace::RequestData(vtkInformation *vtkNotUsed(request),
54 vtkInformationVector **vtkNotUsed(inputVector),
55 vtkInformationVector *outputVector)
57 vtkInformation *outInfo = outputVector->GetInformationObject(0);
58 vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
59 outInfo->Get(vtkDataObject::DATA_OBJECT()));
61 aPolyData->Allocate();
62 vtkPoints* aPts = vtkPoints::New();
63 aPolyData->SetPoints(aPts);
66 TFaceSet::Iterator anIter(myFaceSet);
67 for(; anIter.More(); anIter.Next()){
68 const TopoDS_Face& aFace = anIter.Value();
69 OCC2VTK(aFace,aPolyData,aPts,NbIso,Discret);
74 void GEOM_WireframeFace::SetNbIso(const int theNb[2])
76 if ( theNb[0] == NbIso[0] && theNb[1] == NbIso[1])
85 void GEOM_WireframeFace::GetNbIso(int &theNbU,int &theNbV)
93 OCC2VTK(const TopoDS_Face& theFace,
94 vtkPolyData* thePolyData,
96 const int theNbIso[2],
99 TopoDS_Face aFace = theFace;
100 aFace.Orientation(TopAbs_FORWARD);
101 CreateIso(aFace,theNbIso,theDiscret,thePolyData,thePts);
106 CreateIso(const TopoDS_Face& theFace,
107 const int theNbIso[2],
108 const int theDiscret,
109 vtkPolyData* thePolyData,
112 GEOMUtils::Hatcher aHatcher(theFace);
114 aHatcher.Init(theNbIso[0], theNbIso[1]);
117 if (aHatcher.IsDone()) {
118 // Push iso lines in vtk kernel
119 CreateIso(aHatcher, Standard_True, theDiscret, thePolyData, thePts);
120 CreateIso(aHatcher, Standard_False, theDiscret, thePolyData, thePts);
128 CreateIso(const GEOMUtils::Hatcher &theHatcher,
129 const Standard_Boolean IsUIso,
130 const int theDiscret,
131 vtkPolyData *thePolyData,
134 Handle(TColStd_HArray1OfInteger) anIndices;
135 Handle(TColStd_HArray1OfReal) aParams;
139 anIndices = theHatcher.GetUIndices();
140 aParams = theHatcher.GetUParams();
143 anIndices = theHatcher.GetVIndices();
144 aParams = theHatcher.GetVParams();
147 if (anIndices.IsNull() == Standard_False &&
148 aParams.IsNull() == Standard_False) {
149 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
150 Standard_Integer anIsoInd = anIndices->Lower();
152 for (; anIsoInd <= anIndices->Upper(); anIsoInd++) {
153 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
155 if (aHatchingIndex != 0) {
156 const Standard_Real aParam = aParams->Value(anIsoInd);
157 const Standard_Integer aNbDomains =
158 theHatcher.GetNbDomains(aHatchingIndex);
160 if (aNbDomains >= 0) {
161 Standard_Integer anIDom = 1;
165 for (; anIDom <= aNbDomains; anIDom++) {
166 if (theHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
167 CreateIso_(theHatcher.GetFace(), aType, aParam, aV1, aV2,
168 theDiscret, thePolyData, thePts);
181 CreateIso_(const TopoDS_Face& theFace,
182 GeomAbs_IsoType theIsoType,
186 const int theDiscret,
187 vtkPolyData* thePolyData,
190 Standard_Real U1, U2, V1, V2, stepU=0., stepV=0.;
194 TopLoc_Location aLoc;
195 const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,aLoc);
198 BRepAdaptor_Surface S(theFace,Standard_False);
200 GeomAbs_SurfaceType SurfType = S.GetType();
202 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
204 Standard_Integer Intrv, nbIntv;
205 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
206 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
207 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
209 if(theIsoType == GeomAbs_IsoU){
210 S.VIntervals(TI, GeomAbs_CN);
218 S.UIntervals(TI, GeomAbs_CN);
230 for(Intrv = 1; Intrv <= nbIntv; Intrv++){
231 if(TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
233 if(TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
235 if(theIsoType == GeomAbs_IsoU){
236 V1 = Max(T1, TI(Intrv));
237 V2 = Min(T2, TI(Intrv + 1));
238 stepV = (V2 - V1) / theDiscret;
240 U1 = Max(T1, TI(Intrv));
241 U2 = Min(T2, TI(Intrv + 1));
242 stepU = (U2 - U1) / theDiscret;
248 case GeomAbs_Cylinder :
250 if(theIsoType == GeomAbs_IsoV){
251 for(j = 1; j < theDiscret; j++){
255 DrawTo(P,thePolyData,thePts);
259 case GeomAbs_Sphere :
261 case GeomAbs_OffsetSurface :
262 case GeomAbs_OtherSurface :
263 for(j = 1; j < theDiscret; j++){
267 DrawTo(P,thePolyData,thePts);
270 case GeomAbs_BezierSurface :
271 case GeomAbs_BSplineSurface :
272 for(j = 1; j <= theDiscret/2; j++){
273 Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.;
274 CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts);
279 case GeomAbs_SurfaceOfExtrusion :
280 case GeomAbs_SurfaceOfRevolution :
281 if((theIsoType == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
282 (theIsoType == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion))
284 if(SurfType == GeomAbs_SurfaceOfExtrusion)
286 for(j = 1; j < theDiscret; j++){
290 DrawTo(P,thePolyData,thePts);
293 CurvType = (S.BasisCurve())->GetType();
297 case GeomAbs_Circle :
298 case GeomAbs_Ellipse :
299 for (j = 1; j < theDiscret; j++) {
303 DrawTo(P,thePolyData,thePts);
306 case GeomAbs_Parabola :
307 case GeomAbs_Hyperbola :
308 case GeomAbs_BezierCurve :
309 case GeomAbs_BSplineCurve :
310 case GeomAbs_OtherCurve :
311 for(j = 1; j <= theDiscret/2; j++){
312 Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.;
313 CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts);
323 DrawTo(P,thePolyData,thePts);
332 CreateIso__(const BRepAdaptor_Surface& theSurface,
333 GeomAbs_IsoType theIsoType,
336 Standard_Real theStep,
337 vtkPolyData* thePolyData,
341 if (theIsoType == GeomAbs_IsoU) {
342 theSurface.D0(theU, theV, Pl);
343 theSurface.D0(theU, theV + theStep/2., Pm);
344 theSurface.D0(theU, theV + theStep, Pr);
346 theSurface.D0(theU, theV, Pl);
347 theSurface.D0(theU + theStep/2., theV, Pm);
348 theSurface.D0(theU + theStep, theV, Pr);
351 static Standard_Real ISO_RATIO = 1.001;
352 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= ISO_RATIO*Pl.Distance(Pr)) {
353 DrawTo(Pr,thePolyData,thePts);
355 if (theIsoType == GeomAbs_IsoU) {
356 CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts);
357 Standard_Real aLocalV = theV + theStep/2 ;
358 CreateIso__(theSurface, theIsoType, theU, aLocalV , theStep/2, thePolyData, thePts);
360 CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts);
361 Standard_Real aLocalU = theU + theStep/2 ;
362 CreateIso__(theSurface, theIsoType, aLocalU , theV, theStep/2, thePolyData, thePts);