FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
math_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "occtools.h"
19 
20 #include <utility>
21 #include <gp_Ax3.hxx>
22 #include <gp_Vec.hxx>
23 #include <gp_Trsf.hxx>
24 #include <TopAbs_Orientation.hxx>
25 class Poly_Triangle;
26 class TColgp_Array1OfPnt;
27 
28 namespace occ {
29 
31 {
32 public:
33  static gp_Trsf displacement(const gp_Ax3& srcSys, const gp_Ax3& dstSys);
34  static gp_Trsf transformation(const gp_Ax3& srcSys, const gp_Ax3& dstSys);
35  static gp_Trsf transformation(const gp_Ax3& dstSys);
36  static gp_Trsf transformation(const gp_Quaternion& q, const gp_Vec& vec);
37 
38  static gp_Pnt projectPointOnPlane(const gp_Pnt& p, const gp_Vec& n);
39  static std::pair<gp_Pnt, bool> projectPointOnTriangle(
40  const gp_Pnt& p,
41  const gp_Pnt& v0, const gp_Pnt& v1, const gp_Pnt& v2);
42 
43  static Standard_Real euclideanNorm(const gp_Vec& vec);
44  static Standard_Real squaredEuclideanNorm(const gp_Vec& vec);
45  static Standard_Real manhattanNorm(const gp_Vec& vec);
46  static Standard_Real maximumNorm(const gp_Vec& vec);
47 
48  template<typename NORM>
49  static bool isNull(const gp_Vec& vec, const NORM& norm);
50 
51  static gp_Vec triangleNormal(
52  const TColgp_Array1OfPnt& nodes,
53  const Poly_Triangle& triangle,
54  TopAbs_Orientation ori = TopAbs_FORWARD);
55 
56  template<typename OCC_PNT_VEC, typename TEXT_STREAM>
57  static TEXT_STREAM& printOccPntVec(TEXT_STREAM& ts, const OCC_PNT_VEC& v);
58 };
59 
60 const gp_Pnt2d origin2d(0, 0);
61 const gp_Dir2d xDir2d(1, 0);
62 const gp_Dir2d yDir2d(0, 1);
63 
64 const gp_Pnt origin3d(0, 0, 0);
65 const gp_Dir xDir3d(1, 0, 0);
66 const gp_Dir yDir3d(0, 1, 0);
67 const gp_Dir zDir3d(0, 0, 1);
68 
69 } // namespace occ
70 
71 OCCTOOLS_EXPORT gp_Vec operator-(const gp_Pnt& p1, const gp_Pnt& p2);
72 OCCTOOLS_EXPORT gp_Pnt operator-(const gp_Pnt& p, const gp_Vec& v);
73 OCCTOOLS_EXPORT gp_Pnt operator+(const gp_Pnt& p, const gp_Vec& v);
74 
75 template<typename TEXT_STREAM>
76 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Pnt& p);
77 
78 template<typename TEXT_STREAM>
79 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Vec& v);
80 
81 template<typename TEXT_STREAM>
82 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Dir& d);
83 
84 //--
85 //-- Implementation
86 //--
87 
88 template<typename NORM>
89 bool occ::MathUtils::isNull(const gp_Vec& vec, const NORM& norm)
90 {
91  return norm(vec) <= 0.000000000001;
92 }
93 
94 template<typename OCC_PNT_VEC, typename TEXT_STREAM>
95 TEXT_STREAM &occ::MathUtils::printOccPntVec(TEXT_STREAM &ts, const OCC_PNT_VEC &v)
96 {
97  return ts << "(" << v.X() << ", " << v.Y() << ", " << v.Z() << ")";
98 }
99 
101 template<typename TEXT_STREAM>
102 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Pnt& p)
103 {
104  return occ::MathUtils::printOccPntVec(ts, p);
105 }
106 
108 template<typename TEXT_STREAM>
109 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Vec& v)
110 {
111  return occ::MathUtils::printOccPntVec(ts, v);
112 }
113 
115 template<typename TEXT_STREAM>
116 TEXT_STREAM& operator<<(TEXT_STREAM& ts, const gp_Dir& d)
117 {
118  return occ::MathUtils::printOccPntVec(ts, d);
119 }
const gp_Dir2d yDir2d(0, 1)
TEXT_STREAM & operator<<(TEXT_STREAM &ts, const gp_Pnt &p)
Print (dump) in the text stream ts the point p.
Definition: math_utils.h:102
TEXT_STREAM & operator<<(TEXT_STREAM &os, const FixedArray< T, S > &coords)
Definition: fixed_array.h:201
const gp_Dir yDir3d(0, 1, 0)
const gp_Pnt origin3d(0, 0, 0)
static bool isNull(const gp_Vec &vec, const NORM &norm)
Definition: math_utils.h:89
#define OCCTOOLS_EXPORT
Definition: occtools.h:27
Collection of tools for the Math toolkit.
Definition: math_utils.h:30
const gp_Dir zDir3d(0, 0, 1)
const gp_Pnt2d origin2d(0, 0)
static TEXT_STREAM & printOccPntVec(TEXT_STREAM &ts, const OCC_PNT_VEC &v)
Definition: math_utils.h:95
const Quantity< NUMERIC_TRAITS, TRAIT > operator-(const Quantity< NUMERIC_TRAITS, TRAIT > &lhs, const Quantity< NUMERIC_TRAITS, TRAIT > &rhs)
Definition: quantity.h:315
Definition: ais_text.cpp:31
const Quantity< NUMERIC_TRAITS, TRAIT > operator+(const Quantity< NUMERIC_TRAITS, TRAIT > &lhs, const Quantity< NUMERIC_TRAITS, TRAIT > &rhs)
Definition: quantity.h:286
const gp_Dir xDir3d(1, 0, 0)
const gp_Dir2d xDir2d(1, 0)