Example #1
0
/*! \brief Returns the oriented normal of a triangle
 *
 *  \warning The returned vector is not normalized
 *
 *  \param nodes  Vertices of the triangulation that \p triangle belongs to
 *  \param triangle  Triangle whose normal has to be computed
 *  \param ori  Orientation of the triangle (generally inherited from the
 *              triangulated face)
 */
gp_Vec MathUtils::triangleNormal(
        const TColgp_Array1OfPnt &nodes,
        const Poly_Triangle &triangle,
        TopAbs_Orientation ori)
{
    Standard_Integer n1, n2, n3;
    if (ori == TopAbs_REVERSED)
        triangle.Get(n1, n3, n2);
    else
        triangle.Get(n1, n2, n3);
    assert(nodes.Lower() <= n1 && n1 <= nodes.Upper());
    assert(nodes.Lower() <= n2 && n2 <= nodes.Upper());
    assert(nodes.Lower() <= n3 && n3 <= nodes.Upper());
    const gp_Vec v1(nodes(n1), nodes(n2)); // V1=(P1,P2)
    const gp_Vec v2(nodes(n2), nodes(n3)); // V2=(P2,P3)
    const gp_Vec v3(nodes(n3), nodes(n1)); // V3=(P3,P1)

    if ((v1.SquareMagnitude() > 1.e-10)
            && (v2.SquareMagnitude() > 1.e-10)
            && (v3.SquareMagnitude() > 1.e-10))
    {
        return v1.Crossed(v2);
    }
    return v1;
}
Example #2
0
Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Array1OfPnt& points, 
                                                                unsigned short usIter,
                                                                bool  bParaCor,
                                                                float fSizeFactor)
{
  if (_pvcPoints != NULL)
  {
    delete _pvcPoints;
    _pvcPoints = NULL;
    delete _pvcUVParam;
    _pvcUVParam = NULL;
  }
  _pvcPoints = new TColgp_Array1OfPnt(points.Lower(), points.Upper());
  *_pvcPoints = points;
  _pvcUVParam = new TColgp_Array1OfPnt2d(points.Lower(), points.Upper());

  if (_usUCtrlpoints*_usVCtrlpoints > _pvcPoints->Length())
    return NULL; //LGS unterbestimmt
  if(!DoInitialParameterCorrection(fSizeFactor))
    return NULL;

  if (bParaCor)
    DoParameterCorrection(usIter);

  return new Geom_BSplineSurface
                      (_vCtrlPntsOfSurf,
                       _vUKnots, 
                       _vVKnots,
                       _vUMults,
                       _vVMults,
                       _usUOrder-1,
                       _usVOrder-1);
}
//================================================================
// Function : Convert_Presentation::sampleBezier
// Purpose  : 
//================================================================
void Convert_Presentation::sampleBezier()
{
  TCollection_AsciiString aText (
    "  Standard_Real aPolesCoords[][3] = {" EOL
    "    {0,0,0},{0,1,0},{1,1,0},{1,2,0},{2,2,0},{2,1,0},{3,1,0},{3,0,0},{2,0,0},{2,-1,0}," EOL
    "    {3,-1,0},{3,-2,0},{4,-2,0},{4,-1,0},{5,-1,0},{5,0,0},{6,0,0},{6,-1,0},{7,-1,0}," EOL
    "    {7,0,0},{8,0,0},{8,1,0}" EOL
    "  };" EOL
    "  TColgp_Array1OfPnt aPoles (1, sizeof(aPolesCoords)/(sizeof(Standard_Real)*2));" EOL
    " " EOL
    "  for (Standard_Integer i=1; i <= aPoles.Upper(); i++)" EOL
    "    aPoles(i) = gp_Pnt (aPolesCoords[i-1][0]*100, " EOL
    "                        aPolesCoords[i-1][1]*100, " EOL
    "                        aPolesCoords[i-1][2]*100);" EOL
    "  " EOL
    "  Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve (aPoles);" EOL
    );

  Standard_Real aPolesCoords[][3] = {
    {0,0,0},{0,1,0},{1,1,0},{1,2,0},{2,2,0},{2,1,0},{3,1,0},{3,0,0},{2,0,0},{2,-1,0},
    {3,-1,0},{3,-2,0},{4,-2,0},{4,-1,0},{5,-1,0},{5,0,0},{6,0,0},{6,-1,0},{7,-1,0},
    {7,0,0},{8,0,0},{8,1,0}
  };
  TColgp_Array1OfPnt aPoles (1, sizeof(aPolesCoords)/(sizeof(Standard_Real)*3));
 
  for (Standard_Integer i=1; i <= aPoles.Upper(); i++)
    aPoles(i) = gp_Pnt (aPolesCoords[i-1][0]*150-500, 
                        aPolesCoords[i-1][1]*150, 
                        aPolesCoords[i-1][2]*150);
  
  Handle(Geom_BezierCurve) aCurve = new Geom_BezierCurve (aPoles);

  drawCurveAndItsBSpline (aCurve, "BezierCurve", aText);
}