00001 /* 00002 * lib-spamod : Visualisation des objets en discret. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-spamod 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 /****************************************************************************** 00025 * Fichier : Ineq_Table2.h * 00026 * Auteur : DEXET Martine * 00027 *----------------------------------------------------------------------------* 00028 * Ce fichier contient la spécification de la classe Ineq_Table2. Cette * 00029 * classe permet de représenter un tableau d'inéquations, comportant deux * 00030 * éléments. * 00031 * * 00032 *****************************************************************************/ 00033 00034 00035 #ifndef INEQ_TABLE2_H 00036 #define INEQ_TABLE2_H 00037 00038 #include "inequation.hh" 00039 00040 00041 00042 /****************************************************************************** 00043 * Classe Ineq_Table2 * 00044 *****************************************************************************/ 00045 00046 class Ineq_Table2 { 00047 00048 public: 00049 00050 // Constructeurs. 00051 Ineq_Table2(); 00052 Ineq_Table2(Ineq_Table2 const & other); 00053 Ineq_Table2(CVertex const & p1, CVertex const & p2, CVertex const & p3); 00054 00055 // Méthode permettant la lecture d'une des équation du tableau. 00056 Inequation * Get_Ineq(int num); 00057 00058 // Méthode permettant l'écriture d'une équation dans le tableau. 00059 void Set_Ineq(int num, Inequation const & i); 00060 00061 00062 private: 00063 00064 // Tableau comportant deux cases, et contenant des objets de la classe 00065 // Inequation. 00066 Inequation tab[2]; 00067 }; 00068 00069 /****************************************************************************** 00070 * Fichier : Ineq_Table2.inl * 00071 * Auteur : DEXET Martine * 00072 *----------------------------------------------------------------------------* 00073 * Ce fichier contient l'implémentation des méthodes de la classe * 00074 * Ineq_Table2. * 00075 * * 00076 *****************************************************************************/ 00077 00078 00079 #include "vector3d.hh" 00080 00081 00082 00083 // Constructeurs. 00084 inline 00085 Ineq_Table2::Ineq_Table2() 00086 {} 00087 00088 inline 00089 Ineq_Table2::Ineq_Table2(Ineq_Table2 const & other) 00090 { 00091 for (int i=0 ; i<2 ; i++) 00092 tab[i] = other.tab[i]; 00093 } 00094 00095 inline 00096 Ineq_Table2::Ineq_Table2(CVertex const & p1, 00097 CVertex const & p2, 00098 CVertex const & p3) 00099 { 00100 float d; 00101 Vector3D normal; 00102 00103 Vector3D v1(p2.getX()-p1.getX(), 00104 p2.getY()-p1.getY(), 00105 p2.getZ()-p1.getZ()); 00106 00107 Vector3D v2(p3.getX()-p1.getX(), 00108 p3.getY()-p1.getY(), 00109 p3.getZ()-p1.getZ()); 00110 00111 normal = v1.Vect_Product(v2); 00112 00113 tab[0].SetA(normal.getX()); 00114 tab[0].SetB(normal.getY()); 00115 tab[0].SetC(normal.getZ()); 00116 tab[1].SetA(-tab[0].GetA()); 00117 tab[1].SetB(-tab[0].GetB()); 00118 tab[1].SetC(-tab[0].GetC()); 00119 00120 d = -(tab[0].GetA()*p1.getX() + 00121 tab[0].GetB()*p1.getY() + 00122 tab[0].GetC()*p1.getZ()); 00123 00124 tab[0].SetW((fabs(tab[0].GetA()) + 00125 fabs(tab[0].GetB()) + 00126 fabs(tab[0].GetC()))/2.0); 00127 00128 tab[1].SetW(tab[0].GetW() + d); 00129 tab[0].SetW(tab[0].GetW() - d); 00130 } 00131 00132 00133 // Méthode permettant la lecture d'une des équation du tableau. 00134 inline 00135 Inequation * Ineq_Table2::Get_Ineq(int num) 00136 { 00137 assert(num >= 0 && num <= 1); 00138 return &tab[num]; 00139 } 00140 00141 00142 // Méthode permettant l'écriture d'une équation dans le tableau. 00143 inline 00144 void Ineq_Table2::Set_Ineq(int num, Inequation const & i) 00145 { 00146 assert(num >= 0 && num <= 1); 00147 tab[num] = i; 00148 } 00149 00150 #endif