1 /* 2 This file is a part of the RepSnapper project. 3 Copyright (C) 2010 Kulitorum 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #pragma once 21 22 #include "stdafx.h" 23 #include "string.h" 24 #include "math.h" 25 26 27 enum AXIS {NEGX, POSX, NEGY, POSY, NEGZ, POSZ, NOT_ALIGNED}; 28 29 30 class Triangle 31 { 32 public: Triangle(const Vector3d & Norml,const Vector3d & Point1,const Vector3d & Point2,const Vector3d & Point3)33 Triangle(const Vector3d &Norml, const Vector3d &Point1, 34 const Vector3d &Point2, const Vector3d &Point3) 35 { Normal = Norml ; A=Point1;B=Point2;C=Point3;} 36 Triangle(const Vector3d &Point1, 37 const Vector3d &Point2, const Vector3d &Point3); Triangle()38 Triangle() {}; 39 40 Triangle transformed(const Matrix4d &T) const; 41 42 /* Represent the triangle as an array of length 3 {A, B, C} */ 43 Vector3d const & operator[](uint index) const; 44 Vector3d & operator[](uint index); 45 46 /* void SetPoints(const Vector3d &P1, const Vector3d &P2, const Vector3d &P3) { A=P1;B=P2;C=P3; } */ 47 /* void SetNormal(const Vector3d &Norml) { Normal=Norml;} */ 48 void calcNormal(); 49 void invertNormal(); 50 void mirrorX(const Vector3d ¢er); 51 double area() const; 52 double slopeAngle(const Matrix4d &T=Matrix4d::IDENTITY) const; 53 54 void rotate(const Vector3d &axis, double angle); 55 56 AXIS axis; // Used for auto-rotation 57 Vector3d A,B,C,Normal; // p1,p2,p3, Normal 58 Vector3d GetMax(const Matrix4d &T=Matrix4d::IDENTITY) const; 59 Vector3d GetMin(const Matrix4d &T=Matrix4d::IDENTITY) const; 60 61 void AccumulateMinMax(Vector3d &min, Vector3d &max, 62 const Matrix4d &T=Matrix4d::IDENTITY); 63 void Translate(const Vector3d &vector); 64 int CutWithPlane(double z, const Matrix4d &T, 65 Vector2d &lineStart, Vector2d &lineEnd) const; 66 bool isInZrange(double zmin, double zmax, const Matrix4d &T) const; 67 int SplitAtPlane(double z, 68 vector<Triangle> &uppertriangles, 69 vector<Triangle> &lowertriangles, 70 const Matrix4d &T=Matrix4d::IDENTITY) const; 71 string getSTLfacet(const Matrix4d &T=Matrix4d::IDENTITY) const; 72 void draw(int gl_type) const; 73 74 double projectedvolume(const Matrix4d &T=Matrix4d::IDENTITY) const; 75 76 bool isConnectedTo(Triangle const &other, double maxsqerr=0.0001) const; 77 bool wrongOrientationWith(Triangle const &other, double maxsqerr) const; 78 79 string info() const; 80 }; 81 82