plane_3d.h 4.12 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
4
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library is distributed in the hope that it will be useful, but WITHOUT  *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
20
 * Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#ifndef __PLANE_3D__
#define __PLANE_3D__

28 29
#include "Geometry/vector_gen.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
namespace CGoGN
{

namespace Geom
{

typedef enum 
{
	ON = 0,
	OVER,
	UNDER
} Orientation3D ;

/*
 * Class for the representation of 3d planes
 */
template <typename T>
class Plane3D
{
	public:
50 51 52

		static std::string CGoGNnameOfType() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
53 54 55 56
		/**********************************************/
		/*                CONSTRUCTORS                */
		/**********************************************/

57
		Plane3D(int d = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

		Plane3D(const Plane3D<T>& p);

		// construct the plane from a normal vector and a scalar
		Plane3D(const Vector<3,T>& n, T d);

		// construct the plane with normal vector n and going through p
		Plane3D(const Vector<3,T>& n, const Vector<3,T>& p);

		// construct the plane going through p1, p2 and p3
		Plane3D(const Vector<3,T>& p1, const Vector<3,T>& p2, const Vector<3,T>& p3);

		/**********************************************/
		/*                 ACCESSORS                  */
		/**********************************************/

		Vector<3,T>& normal();

		const Vector<3,T>& normal() const;

		T& d();

		const T& d() const;

		/**********************************************/
		/*             UTILITY FUNCTIONS              */
		/**********************************************/

		// compute the distance between the plane and point p
		T distance(const Vector<3,T>& p) const;

		// project the point p onto the plane
		void project(Vector<3,T>& p) const;

Thomas's avatar
Thomas committed
92
		// return on/over/under according to the side of the plane where point p is
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94
		Orientation3D orient(const Vector<3,T>& p) const;

Sylvain Thery's avatar
Sylvain Thery committed
95 96 97 98 99
		// return on/over/under according to the side of the plane where point p is
		// return the distance to the point in dist reference
		Orientation3D orient(const Vector<3,T>& p, T& dist) const;


Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102 103 104 105 106 107 108 109 110
		/**********************************************/
		/*             STREAM OPERATORS               */
		/**********************************************/

		template <typename TT>
		friend std::ostream& operator<<(std::ostream& out, const Plane3D<TT>& p);

		template <typename TT>
		friend std::istream& operator>>(std::istream& in, Plane3D<TT>& p);

	private:
Thomas Pitiot 's avatar
reparé  
Thomas Pitiot committed
111 112
        Vector<3,T> m_normal ; // normale au plan
        T m_d ; //distance a l'origine
Pierre Kraemer's avatar
Pierre Kraemer committed
113 114 115 116 117 118
} ;

} // namespace Geom

} // namespace CGoGN

119
#include "Geometry/plane_3d.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
120 121

#endif