1 // Copyright (C) 2007-2022 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 <BRep_Tool.hxx>
35 #include <TColStd_Array1OfReal.hxx>
37 #include <Basics_OCCTVersion.hxx>
39 #if OCC_VERSION_LARGE < 0x07070000
40 #include <Adaptor3d_HCurve.hxx>
42 #include <Adaptor3d_Curve.hxx>
45 vtkStandardNewMacro(GEOM_WireframeFace)
47 GEOM_WireframeFace::GEOM_WireframeFace():
53 this->SetNumberOfInputPorts(0);
56 GEOM_WireframeFace::~GEOM_WireframeFace()
60 int GEOM_WireframeFace::RequestData(vtkInformation *vtkNotUsed(request),
61 vtkInformationVector **vtkNotUsed(inputVector),
62 vtkInformationVector *outputVector)
64 vtkInformation *outInfo = outputVector->GetInformationObject(0);
65 vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
66 outInfo->Get(vtkDataObject::DATA_OBJECT()));
68 aPolyData->Allocate();
69 vtkPoints* aPts = vtkPoints::New();
70 aPolyData->SetPoints(aPts);
73 TFaceSet::Iterator anIter(myFaceSet);
74 for(; anIter.More(); anIter.Next()){
75 const TopoDS_Face& aFace = anIter.Value();
76 OCC2VTK(aFace,aPolyData,aPts,NbIso,Discret);
81 void GEOM_WireframeFace::SetNbIso(const int theNb[2])
83 if ( theNb[0] == NbIso[0] && theNb[1] == NbIso[1])
92 void GEOM_WireframeFace::GetNbIso(int &theNbU,int &theNbV)
100 OCC2VTK(const TopoDS_Face& theFace,
101 vtkPolyData* thePolyData,
103 const int theNbIso[2],
104 const int theDiscret)
106 TopoDS_Face aFace = theFace;
107 aFace.Orientation(TopAbs_FORWARD);
108 CreateIso(aFace,theNbIso,theDiscret,thePolyData,thePts);
113 CreateIso(const TopoDS_Face& theFace,
114 const int theNbIso[2],
115 const int theDiscret,
116 vtkPolyData* thePolyData,
119 GEOMUtils::Hatcher aHatcher(theFace);
121 aHatcher.Init(theNbIso[0], theNbIso[1]);
124 if (aHatcher.IsDone()) {
125 // Push iso lines in vtk kernel
126 CreateIso(aHatcher, Standard_True, theDiscret, thePolyData, thePts);
127 CreateIso(aHatcher, Standard_False, theDiscret, thePolyData, thePts);
135 CreateIso(const GEOMUtils::Hatcher &theHatcher,
136 const Standard_Boolean IsUIso,
137 const int theDiscret,
138 vtkPolyData *thePolyData,
141 Handle(TColStd_HArray1OfInteger) anIndices;
142 Handle(TColStd_HArray1OfReal) aParams;
146 anIndices = theHatcher.GetUIndices();
147 aParams = theHatcher.GetUParams();
150 anIndices = theHatcher.GetVIndices();
151 aParams = theHatcher.GetVParams();
154 if (anIndices.IsNull() == Standard_False &&
155 aParams.IsNull() == Standard_False) {
156 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
157 Standard_Integer anIsoInd = anIndices->Lower();
159 for (; anIsoInd <= anIndices->Upper(); anIsoInd++) {
160 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
162 if (aHatchingIndex != 0) {
163 const Standard_Real aParam = aParams->Value(anIsoInd);
164 const Standard_Integer aNbDomains =
165 theHatcher.GetNbDomains(aHatchingIndex);
167 if (aNbDomains >= 0) {
168 Standard_Integer anIDom = 1;
172 for (; anIDom <= aNbDomains; anIDom++) {
173 if (theHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
174 CreateIso_(theHatcher.GetFace(), aType, aParam, aV1, aV2,
175 theDiscret, thePolyData, thePts);
188 CreateIso_(const TopoDS_Face& theFace,
189 GeomAbs_IsoType theIsoType,
193 const int theDiscret,
194 vtkPolyData* thePolyData,
197 Standard_Real U1, U2, V1, V2, stepU=0., stepV=0.;
201 TopLoc_Location aLoc;
202 const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,aLoc);
205 BRepAdaptor_Surface S(theFace,Standard_False);
207 GeomAbs_SurfaceType SurfType = S.GetType();
209 GeomAbs_CurveType CurvType = GeomAbs_OtherCurve;
211 Standard_Integer Intrv, nbIntv;
212 Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN);
213 Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN);
214 TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1);
216 if(theIsoType == GeomAbs_IsoU){
217 S.VIntervals(TI, GeomAbs_CN);
225 S.UIntervals(TI, GeomAbs_CN);
237 for(Intrv = 1; Intrv <= nbIntv; Intrv++){
238 if(TI(Intrv) <= T1 && TI(Intrv + 1) <= T1)
240 if(TI(Intrv) >= T2 && TI(Intrv + 1) >= T2)
242 if(theIsoType == GeomAbs_IsoU){
243 V1 = Max(T1, TI(Intrv));
244 V2 = Min(T2, TI(Intrv + 1));
245 stepV = (V2 - V1) / theDiscret;
247 U1 = Max(T1, TI(Intrv));
248 U2 = Min(T2, TI(Intrv + 1));
249 stepU = (U2 - U1) / theDiscret;
255 case GeomAbs_Cylinder :
257 if(theIsoType == GeomAbs_IsoV){
258 for(j = 1; j < theDiscret; j++){
262 DrawTo(P,thePolyData,thePts);
266 case GeomAbs_Sphere :
268 case GeomAbs_OffsetSurface :
269 case GeomAbs_OtherSurface :
270 for(j = 1; j < theDiscret; j++){
274 DrawTo(P,thePolyData,thePts);
277 case GeomAbs_BezierSurface :
278 case GeomAbs_BSplineSurface :
279 for(j = 1; j <= theDiscret/2; j++){
280 Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.;
281 CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts);
286 case GeomAbs_SurfaceOfExtrusion :
287 case GeomAbs_SurfaceOfRevolution :
288 if((theIsoType == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) ||
289 (theIsoType == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion))
291 if(SurfType == GeomAbs_SurfaceOfExtrusion)
293 for(j = 1; j < theDiscret; j++){
297 DrawTo(P,thePolyData,thePts);
300 CurvType = (S.BasisCurve())->GetType();
304 case GeomAbs_Circle :
305 case GeomAbs_Ellipse :
306 for (j = 1; j < theDiscret; j++) {
310 DrawTo(P,thePolyData,thePts);
313 case GeomAbs_Parabola :
314 case GeomAbs_Hyperbola :
315 case GeomAbs_BezierCurve :
316 case GeomAbs_BSplineCurve :
317 case GeomAbs_OtherCurve :
318 for(j = 1; j <= theDiscret/2; j++){
319 Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.;
320 CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts);
332 DrawTo(P,thePolyData,thePts);
341 CreateIso__(const BRepAdaptor_Surface& theSurface,
342 GeomAbs_IsoType theIsoType,
345 Standard_Real theStep,
346 vtkPolyData* thePolyData,
350 if (theIsoType == GeomAbs_IsoU) {
351 theSurface.D0(theU, theV, Pl);
352 theSurface.D0(theU, theV + theStep/2., Pm);
353 theSurface.D0(theU, theV + theStep, Pr);
355 theSurface.D0(theU, theV, Pl);
356 theSurface.D0(theU + theStep/2., theV, Pm);
357 theSurface.D0(theU + theStep, theV, Pr);
360 static Standard_Real ISO_RATIO = 1.001;
361 if (Pm.Distance(Pl) + Pm.Distance(Pr) <= ISO_RATIO*Pl.Distance(Pr)) {
362 DrawTo(Pr,thePolyData,thePts);
364 if (theIsoType == GeomAbs_IsoU) {
365 CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts);
366 Standard_Real aLocalV = theV + theStep/2 ;
367 CreateIso__(theSurface, theIsoType, theU, aLocalV , theStep/2, thePolyData, thePts);
369 CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts);
370 Standard_Real aLocalU = theU + theStep/2 ;
371 CreateIso__(theSurface, theIsoType, aLocalU , theV, theStep/2, thePolyData, thePts);