//================================================================
// Function : drawVector
// Purpose  : displays a given vector in 3d viewer
//            (segment of line starting at thePnt with the arrow at the end,
//             the length of segment is the length of the vector)
//================================================================
Handle_AIS_InteractiveObject OCCDemo_Presentation::drawVector 
                                  (const gp_Pnt& thePnt,
                                   const gp_Vec& theVec,
                                   const Quantity_Color& theColor,
                                   const Standard_Boolean toDisplay)
{
  Standard_Real aLength = theVec.Magnitude();
  if (aLength < Precision::Confusion())
    return Handle(AIS_InteractiveObject)();

  Handle(Geom_Curve) aCurve = new Geom_Line (thePnt, theVec);
  aCurve = new Geom_TrimmedCurve (aCurve, 0, aLength);

  Handle(ISession_Curve) aGraphicCurve = new ISession_Curve (aCurve);

  getAISContext()->SetColor (aGraphicCurve, theColor, toDisplay);
  Handle(Prs3d_Drawer) aDrawer = aGraphicCurve->Attributes()->Link();
  aDrawer->SetLineArrowDraw(Standard_True);
  aDrawer->ArrowAspect()->SetLength(aLength/10);
  if (toDisplay) {
    if (FitMode){
		getAISContext()->Display (aGraphicCurve, Standard_False);
		COCCDemoDoc::Fit();
	}
	else
		getAISContext()->Display (aGraphicCurve);
  }

  return aGraphicCurve;
}
ISession_Direction::ISession_Direction (const gp_Pnt& aPnt,
                                        const gp_Vec& aVec,
                                        Standard_Real anArrowLength)
: myPnt (aPnt),
  myDir (aVec),
  myArrowLength (anArrowLength)
{
  myLength = aVec.Magnitude();
}
void CCPACSFuselageProfileGetPointAlgo::GetPointTangent(const double& alpha, gp_Pnt& point, gp_Vec& tangent)
{
    // alpha<0.0 : use line in the direction of the tangent at alpha=0.0
    if (alpha<0.0) {
        // get startpoint
        gp_Pnt startpoint;
        WireGetPointTangent(wire, 0.0, startpoint, tangent);
        // length of tangent has to be equal two the length of the profile curve
        tangent = wireLength * tangent/tangent.Magnitude();
        // get direction vector
        gp_Dir dir(-1.0*tangent);
        // construct line
        Geom_Line line(startpoint, dir);
        // map [-infinity, 0.0] to [0.0, infinity] and scale by profile length
        Standard_Real zeta = wireLength*(-1.0*alpha);
        // get point on line at distance zeta from the start point
        line.D0(zeta, point);
    }
    else if (alpha>=0.0 && alpha<=1.0) {
        WireGetPointTangent(wire, alpha, point, tangent);
        // length of tangent has to be equal two the length of the profile curve
        tangent = wireLength * tangent/tangent.Magnitude();
    }
    // alpha>1.0 : use line in the direction of the tangent at alpha=1.0
    else {
        // get startpoint
        gp_Pnt startpoint;
        WireGetPointTangent(wire, 1.0, startpoint, tangent);
        // length of tangent has to be equal two the length of the profile curve
        tangent = wireLength * tangent/tangent.Magnitude();
        // get direction vector
        gp_Dir dir(tangent);
        // construct line
        Geom_Line line(startpoint, dir);
        // map [1.0, infinity] to [0.0, infinity] and scale by profile length
        Standard_Real zeta = wireLength*(alpha - 1.0);
        // get point on line at distance zeta from the start point
        line.D0(zeta, point);
    }
}
Пример #4
0
void CreateExtrusions(const std::list<TopoDS_Shape> &faces_or_wires, std::list<TopoDS_Shape>& new_shapes, const gp_Vec& extrude_vector, double taper_angle, bool solid_if_possible)
{
	try{
		for(std::list<TopoDS_Shape>::const_iterator It = faces_or_wires.begin(); It != faces_or_wires.end(); It++)
		{
			const TopoDS_Shape& face_or_wire = *It;
			if(fabs(taper_angle) > 0.0000001)
			{
				// make an offset face
				double distance = tan(taper_angle * M_PI/180) * extrude_vector.Magnitude();
				bool wire = (face_or_wire.ShapeType() == TopAbs_WIRE);
				BRepOffsetAPI_MakeOffset offset;
				if(wire)
					offset = BRepOffsetAPI_MakeOffset(TopoDS::Wire(face_or_wire));
				else
					continue; // can't do CreateRuledSurface on faces yet
                offset.Perform(distance);

				// parallel
				std::list<TopoDS_Wire> wire_list;
				wire_list.push_back(TopoDS::Wire(face_or_wire));
				wire_list.push_back(TopoDS::Wire(offset.Shape()));

				gp_Trsf mat;
				mat.SetTranslation(extrude_vector);
				BRepBuilderAPI_Transform myBRepTransformation(wire_list.back(),mat);
				wire_list.back() = TopoDS::Wire(myBRepTransformation.Shape());

				TopoDS_Shape new_shape;
				if(CreateRuledSurface(wire_list, new_shape, solid_if_possible))
				{
					new_shapes.push_back(new_shape);
				}
            }
			else
			{
				BRepPrimAPI_MakePrism generator( face_or_wire, extrude_vector );
				generator.Build();
				new_shapes.push_back(generator.Shape());
			}
		}
	}
	catch (Standard_Failure) {
		Handle_Standard_Failure e = Standard_Failure::Caught();
		wxMessageBox(wxString(_("Error making extruded solid")) + _T(": ") + Ctt(e->GetMessageString()));
	}
	catch(...)
	{
		wxMessageBox(_("Fatal error making extruded solid"));
	}

}
Пример #5
0
void WireGetPointTangent(const TopoDS_Wire& wire, double alpha, gp_Pnt& point, gp_Vec& tangent)
{
    if (alpha < 0.0 || alpha > 1.0) {
        throw tigl::CTiglError("Error: Parameter alpha not in the range 0.0 <= alpha <= 1.0 in WireGetPointTangent", TIGL_ERROR);
    }
    // ETA 3D point
    BRepAdaptor_CompCurve aCompoundCurve(wire, Standard_True);

    Standard_Real len =  GCPnts_AbscissaPoint::Length( aCompoundCurve );
    GCPnts_AbscissaPoint algo(aCompoundCurve, len*alpha, aCompoundCurve.FirstParameter());
    if (algo.IsDone()) {
        double par = algo.Parameter();
        aCompoundCurve.D1( par, point, tangent );
        // normalize tangent to length of the curve
        tangent = len*tangent/tangent.Magnitude();
    }
    else {
        throw tigl::CTiglError("WireGetPointTangent: Cannot compute point on curve.", TIGL_MATH_ERROR);
    }
}
Пример #6
0
void EdgeGetPointTangent(const TopoDS_Edge& edge, double alpha, gp_Pnt& point, gp_Vec& tangent)
{
    if (alpha < 0.0 || alpha > 1.0) {
        throw tigl::CTiglError("Error: Parameter alpha not in the range 0.0 <= alpha <= 1.0 in EdgeGetPointTangent", TIGL_ERROR);
    }
    // ETA 3D point
    Standard_Real umin, umax;
    Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, umin, umax);
    GeomAdaptor_Curve adaptorCurve(curve, umin, umax);
    Standard_Real len =  GCPnts_AbscissaPoint::Length( adaptorCurve, umin, umax );
    GCPnts_AbscissaPoint algo(adaptorCurve, len*alpha, umin);
    if (algo.IsDone()) {
        double par = algo.Parameter();
        adaptorCurve.D1( par, point, tangent );
        // normalize tangent to length of the curve
        tangent = len*tangent/tangent.Magnitude();
    }
    else {
        throw tigl::CTiglError("EdgeGetPointTangent: Cannot compute point on curve.", TIGL_MATH_ERROR);
    }
}
Пример #7
0
/*! \brief Returns the component of \p vec having the maximum absolute value */
Standard_Real MathTools::maximumNorm(const gp_Vec &vec)
{
  return std::max(std::fabs(vec.X()), std::max(std::fabs(vec.Y()), std::fabs(vec.Z())));
}
Пример #8
0
Standard_Real MathTools::manhattanNorm(const gp_Vec &vec)
{
  return std::fabs(vec.X()) + std::fabs(vec.Y()) + std::fabs(vec.Z());
}
Пример #9
0
Standard_Real MathTools::squaredEuclideanNorm(const gp_Vec &vec)
{
  return vec.X() * vec.X() + vec.Y() * vec.Y() + vec.Z() * vec.Z();
}
Пример #10
0
//! \relates MathTools
gp_Pnt operator+(const gp_Pnt& p, const gp_Vec& v)
{
  return gp_Pnt(p.X() + v.X(), p.Y() + v.Y(), p.Z() + v.Z());
}
Пример #11
0
gp_Pnt MathUtils::projectPointOnPlane(const gp_Pnt &p, const gp_Vec &n)
{
    const gp_Vec pVec(p.X(), p.Y(), p.Z());
    const Standard_Real dotVN = pVec.Dot(n);
    return p.Translated(-dotVN * n);
}