File indexing completed on 2025-01-18 10:03:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Graphic3d_ClipPlane_HeaderFile
0017 #define _Graphic3d_ClipPlane_HeaderFile
0018
0019 #include <gp_Pln.hxx>
0020 #include <Graphic3d_AspectFillArea3d.hxx>
0021 #include <Graphic3d_BndBox3d.hxx>
0022 #include <Graphic3d_CappingFlags.hxx>
0023 #include <Graphic3d_TextureMap.hxx>
0024 #include <NCollection_Vec4.hxx>
0025 #include <Standard_Macro.hxx>
0026 #include <Standard_TypeDef.hxx>
0027 #include <Standard_Transient.hxx>
0028
0029
0030 enum Graphic3d_ClipState
0031 {
0032 Graphic3d_ClipState_Out,
0033 Graphic3d_ClipState_In,
0034 Graphic3d_ClipState_On,
0035 };
0036
0037
0038
0039
0040 class Graphic3d_ClipPlane : public Standard_Transient
0041 {
0042 DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
0043 public:
0044
0045
0046 typedef Graphic3d_Vec4d Equation;
0047
0048 public:
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 Standard_EXPORT Graphic3d_ClipPlane();
0060
0061
0062
0063 Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
0064
0065
0066
0067
0068 Standard_EXPORT Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation);
0069
0070
0071
0072
0073 Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
0074
0075
0076
0077
0078 Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
0079
0080
0081
0082
0083 Standard_EXPORT void SetEquation (const Graphic3d_Vec4d& theEquation);
0084
0085
0086
0087 const Graphic3d_Vec4d& GetEquation() const { return myEquation; }
0088
0089
0090
0091 const Graphic3d_Vec4d& ReversedEquation() const { return myEquationRev; }
0092
0093
0094
0095 Standard_Boolean IsOn() const
0096 {
0097 return myIsOn;
0098 }
0099
0100
0101
0102
0103 Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
0104
0105
0106
0107
0108
0109
0110 Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
0111
0112
0113
0114 Standard_Boolean IsCapping() const
0115 {
0116 return myIsCapping;
0117 }
0118
0119
0120
0121 const gp_Pln& ToPlane() const { return myPlane; }
0122
0123
0124
0125
0126
0127 Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
0128
0129 public:
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 Standard_Boolean IsChain() const { return !myNextInChain.IsNull(); }
0145
0146
0147
0148
0149
0150 Handle(Graphic3d_ClipPlane) ChainPreviousPlane() const { return myPrevInChain; }
0151
0152
0153
0154
0155 const Handle(Graphic3d_ClipPlane)& ChainNextPlane() const { return myNextInChain; }
0156
0157
0158
0159 Standard_Integer NbChainNextPlanes() const { return myChainLenFwd; }
0160
0161
0162
0163
0164 Standard_EXPORT void SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane);
0165
0166 public:
0167
0168
0169 Quantity_Color CappingColor() const { return myAspect->FrontMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT ? myAspect->FrontMaterial().Color() : myAspect->InteriorColor(); }
0170
0171
0172 Standard_EXPORT void SetCappingColor (const Quantity_Color& theColor);
0173
0174
0175
0176 Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
0177
0178
0179 const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); }
0180
0181
0182
0183 Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
0184
0185
0186 Handle(Graphic3d_TextureMap) CappingTexture() const { return !myAspect->TextureSet().IsNull() && !myAspect->TextureSet()->IsEmpty()
0187 ? myAspect->TextureSet()->First()
0188 : Handle(Graphic3d_TextureMap)(); }
0189
0190
0191
0192 Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
0193
0194
0195 Aspect_HatchStyle CappingHatch() const { return (Aspect_HatchStyle)myAspect->HatchStyle()->HatchType(); }
0196
0197
0198
0199 Standard_EXPORT void SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle);
0200
0201
0202 const Handle(Graphic3d_HatchStyle)& CappingCustomHatch() const { return myAspect->HatchStyle(); }
0203
0204
0205 Standard_EXPORT void SetCappingHatchOn();
0206
0207
0208 Standard_EXPORT void SetCappingHatchOff();
0209
0210
0211 Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; }
0212
0213
0214
0215
0216
0217
0218
0219
0220 const TCollection_AsciiString& GetId() const
0221 {
0222 return myId;
0223 }
0224
0225 public:
0226
0227
0228
0229 const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; }
0230
0231
0232 Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
0233
0234
0235
0236 bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; }
0237
0238
0239 void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); }
0240
0241
0242
0243 bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; }
0244
0245
0246 void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); }
0247
0248
0249
0250 bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; }
0251
0252
0253 void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); }
0254
0255
0256 bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; }
0257
0258 public:
0259
0260
0261 Graphic3d_ClipState ProbePoint (const Graphic3d_Vec4d& thePoint) const
0262 {
0263 Graphic3d_ClipState aState = Graphic3d_ClipState_Out;
0264 for (const Graphic3d_ClipPlane* aPlaneIter = this; aPlaneIter != NULL; aPlaneIter = aPlaneIter->myNextInChain.get())
0265 {
0266 Graphic3d_ClipState aPlnState = aPlaneIter->ProbePointHalfspace (thePoint);
0267 if (aPlnState == Graphic3d_ClipState_In)
0268 {
0269 return Graphic3d_ClipState_In;
0270 }
0271 else if (aPlnState != Graphic3d_ClipState_Out)
0272 {
0273 aState = Graphic3d_ClipState_On;
0274 }
0275 }
0276 return aState;
0277 }
0278
0279
0280 Graphic3d_ClipState ProbeBox (const Graphic3d_BndBox3d& theBox) const
0281 {
0282 Graphic3d_ClipState aState = Graphic3d_ClipState_Out;
0283 for (const Graphic3d_ClipPlane* aPlaneIter = this; aPlaneIter != NULL; aPlaneIter = aPlaneIter->myNextInChain.get())
0284 {
0285 if (aPlaneIter->IsBoxFullInHalfspace (theBox))
0286 {
0287
0288 return Graphic3d_ClipState_In;
0289 }
0290 else if (!aPlaneIter->IsBoxFullOutHalfspace (theBox))
0291 {
0292
0293 aState = Graphic3d_ClipState_On;
0294 }
0295 }
0296 return aState;
0297 }
0298
0299
0300 Standard_Boolean ProbeBoxTouch (const Graphic3d_BndBox3d& theBox) const
0301 {
0302 for (const Graphic3d_ClipPlane* aPlaneIter = this; aPlaneIter != NULL; aPlaneIter = aPlaneIter->myNextInChain.get())
0303 {
0304 if (aPlaneIter->IsBoxFullInHalfspace (theBox))
0305 {
0306
0307 return Standard_False;
0308 }
0309 else if (!aPlaneIter->IsBoxFullOutHalfspace (theBox))
0310 {
0311
0312 if (ProbeBoxMaxPointHalfspace (theBox) != Graphic3d_ClipState_Out)
0313 {
0314 return Standard_True;
0315 }
0316 }
0317 }
0318 return Standard_False;
0319 }
0320
0321 public:
0322
0323
0324 Graphic3d_ClipState ProbePointHalfspace (const Graphic3d_Vec4d& thePoint) const
0325 {
0326 const Standard_Real aVal = myEquation.Dot (thePoint);
0327 return aVal < 0.0
0328 ? Graphic3d_ClipState_Out
0329 : (aVal == 0.0
0330 ? Graphic3d_ClipState_On
0331 : Graphic3d_ClipState_In);
0332 }
0333
0334
0335 Graphic3d_ClipState ProbeBoxHalfspace (const Graphic3d_BndBox3d& theBox) const
0336 {
0337 if (IsBoxFullOutHalfspace (theBox))
0338 {
0339 return Graphic3d_ClipState_Out;
0340 }
0341 return IsBoxFullInHalfspace (theBox)
0342 ? Graphic3d_ClipState_In
0343 : Graphic3d_ClipState_On;
0344 }
0345
0346
0347 bool IsPointOutHalfspace (const Graphic3d_Vec4d& thePoint) const { return ProbePointHalfspace (thePoint) == Graphic3d_ClipState_Out; }
0348
0349
0350 bool IsBoxFullOutHalfspace (const Graphic3d_BndBox3d& theBox) const
0351 {
0352 const Graphic3d_Vec4d aMaxPnt (myEquation.x() > 0.0 ? theBox.CornerMax().x() : theBox.CornerMin().x(),
0353 myEquation.y() > 0.0 ? theBox.CornerMax().y() : theBox.CornerMin().y(),
0354 myEquation.z() > 0.0 ? theBox.CornerMax().z() : theBox.CornerMin().z(),
0355 1.0);
0356 return IsPointOutHalfspace (aMaxPnt);
0357 }
0358
0359
0360 Graphic3d_ClipState ProbeBoxMaxPointHalfspace (const Graphic3d_BndBox3d& theBox) const
0361 {
0362 const Graphic3d_Vec4d aMaxPnt (myEquation.x() > 0.0 ? theBox.CornerMax().x() : theBox.CornerMin().x(),
0363 myEquation.y() > 0.0 ? theBox.CornerMax().y() : theBox.CornerMin().y(),
0364 myEquation.z() > 0.0 ? theBox.CornerMax().z() : theBox.CornerMin().z(),
0365 1.0);
0366 return ProbePointHalfspace (aMaxPnt);
0367 }
0368
0369
0370 bool IsBoxFullInHalfspace (const Graphic3d_BndBox3d& theBox) const
0371 {
0372 const Graphic3d_Vec4d aMinPnt (myEquation.x() > 0.0 ? theBox.CornerMin().x() : theBox.CornerMax().x(),
0373 myEquation.y() > 0.0 ? theBox.CornerMin().y() : theBox.CornerMax().y(),
0374 myEquation.z() > 0.0 ? theBox.CornerMin().z() : theBox.CornerMax().z(),
0375 1.0);
0376 return !IsPointOutHalfspace (aMinPnt);
0377 }
0378
0379
0380 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0381
0382 public:
0383
0384
0385 unsigned int MCountEquation() const
0386 {
0387 return myEquationMod;
0388 }
0389
0390
0391 unsigned int MCountAspect() const
0392 {
0393 return myAspectMod;
0394 }
0395
0396 private:
0397
0398
0399 void makeId();
0400
0401
0402 Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag);
0403
0404
0405 void updateChainLen();
0406
0407
0408 void updateInversedPlane()
0409 {
0410 gp_Pln aPlane = myPlane;
0411 aPlane.SetAxis (aPlane.Axis().Reversed());
0412 aPlane.Coefficients (myEquationRev[0], myEquationRev[1], myEquationRev[2], myEquationRev[3]);
0413 }
0414
0415 private:
0416
0417 Handle(Graphic3d_AspectFillArea3d) myAspect;
0418 Handle(Graphic3d_ClipPlane) myNextInChain;
0419 Graphic3d_ClipPlane* myPrevInChain;
0420 TCollection_AsciiString myId;
0421 gp_Pln myPlane;
0422 Graphic3d_Vec4d myEquation;
0423 Graphic3d_Vec4d myEquationRev;
0424 Standard_Integer myChainLenFwd;
0425 unsigned int myFlags;
0426 unsigned int myEquationMod;
0427 unsigned int myAspectMod;
0428 Standard_Boolean myIsOn;
0429 Standard_Boolean myIsCapping;
0430
0431 };
0432
0433 DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)
0434
0435 #endif