00001 #include "plocha.h"
00002
00003 using namespace std;
00004
00005
00006
00007
00008
00009
00010 short Plocha::shoda[KR_PLOCHA_BODU];
00011 double const ** Plocha::xyz;
00012
00013 Plocha::Plocha(const double **xyz, long * bodyp, long pbp, long prvek, long plocha):
00014
00015 prvek(prvek),
00016 plocha(plocha),
00017 pbp(pbp),
00018 bodyp(bodyp),
00019 typ(NEVI_SE),
00020 size_sousedni(0),
00021 vyhodit(false)
00022 {
00023 Plocha::xyz = xyz;
00024 }
00025
00026
00027 Plocha::~Plocha()
00028 {
00029 if (size_sousedni > 0) delete [] sousedni;
00030 delete [] bodyp;
00031
00032 }
00033
00034
00035 void Plocha::vlozSousedniPlochu(Plocha * sousedni_plocha)
00036 {
00037
00038 if (!size_sousedni)
00039 {
00040 sousedni = new Plocha *[++size_sousedni];
00041 sousedni[0] = sousedni_plocha;
00042 return;
00043 }
00044
00045 Plocha ** p = new Plocha *[++size_sousedni];
00046 for (short i = 0; i < size_sousedni-1; i++)
00047 p[i] = sousedni[i];
00048
00049 p[size_sousedni - 1] = sousedni_plocha;
00050 delete [] sousedni;
00051 sousedni = p;
00052 }
00053
00054
00055 bool Plocha::operator==( Plocha & p)const
00056 {
00057 if(pbp < p.pbp)
00058 {
00059 return cmp(*this, p);
00060 }
00061 return cmp(p , *this);
00062 }
00063
00064 bool Plocha::operator!=( Plocha & p)const
00065 {
00066 return !(*this == p);
00067 }
00068
00069
00070
00071 bool Plocha::cmp(const Plocha & p1,const Plocha & p2)const
00072 {
00073 short h;
00074 FOR(h,KR_PLOCHA_BODU) shoda[h]= -1;
00075 bool equal;
00076 for(short i = 0; i < p1.pbp; i++)
00077 {
00078 equal = false;
00079 for(short j = 0; j < p2.pbp; j++)
00080 {
00081 if (shoda[j] != -1)continue;
00082 if ( stejneXYZ(p1.bodyp[i], p2.bodyp[j]) )
00083 {
00084 equal = true;
00085 shoda[i] = j;
00086 break;
00087 }
00088 }
00089 if(!equal) return false;
00090 }
00091 return true;
00092 }
00093
00094
00095 inline bool Plocha::stejneXYZ(const long cb1,const long cb2)const
00096 {
00097 return ( xyz[cb1][0] == xyz[cb2][0] &&
00098 xyz[cb1][1] == xyz[cb2][1] &&
00099 xyz[cb1][2] == xyz[cb2][2] );
00100 }
00101
00102
00103 ostream& operator<<(ostream &os, Plocha &n)
00104 {
00105 for(long i = 0; i < n.pbp; i++)
00106 os << n.bodyp[i]+1 << " ";
00107 return os;
00108 }
00109