8c79bbb2b6
- completata l'implementazione della tassellazione adattiva per una superficie di bezier ( si può migliorare il costo di memoria e computazionale) - manca la gestione del trim dello spazio parametrico.
94 lines
4.6 KiB
C++
94 lines
4.6 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2023
|
|
//----------------------------------------------------------------------------
|
|
// File : Tree.h Data : 21.04.23 Versione :
|
|
// Contenuto : Implementazione della classe Cell di un albero binario Tree.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 21.04.23 DB Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include <map>
|
|
#include "tree.h"
|
|
#include "SurfBezier.h"
|
|
#include "GeoConst.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
class Cell
|
|
{
|
|
public :
|
|
~Cell( void) ;
|
|
Cell( void) ;
|
|
Cell( Point3d ptBL, Point3d ptTR) ;
|
|
inline bool IsSame( Cell cOtherCell) ;
|
|
void SetBottomLeft( Point3d ptBL) { m_ptPbl = ptBL ; }
|
|
void SetTopRight( Point3d ptTR) { m_ptPtr = ptTR ; }
|
|
void SetSplitDirVert( bool bVert) { m_bSplitVert = bVert ; }
|
|
void SetParent(int nParent) { m_nParent = nParent ; }
|
|
Point3d GetBottomLeft( void) { return m_ptPbl ; }
|
|
Point3d GetTopRight( void) { return m_ptPtr ; }
|
|
bool IsSplitVert( void) { return m_bSplitVert ; }
|
|
bool IsLeaf( void) ;
|
|
bool IsProcessed( void) const { return m_bProcessed ; }
|
|
void Processed( void) { m_bProcessed = true ; }
|
|
//bool operator- ( const Cell &other) const { return m_ptPbl.x < other.m_ptPbl.x ; }
|
|
//bool operator| ( const Cell &other) const { return m_ptPbl.y < other.m_ptPbl.y ; }
|
|
static bool minorX ( const Cell& c1, const Cell& c2) { return c1.m_ptPbl.x < c2.m_ptPbl.x ; }
|
|
static bool minorY ( const Cell& c1, const Cell& c2) { return c1.m_ptPbl.y < c2.m_ptPbl.y ; }
|
|
|
|
public :
|
|
int m_nId ; // Id della cella
|
|
int m_nTop ; // cella adiacente al lato top
|
|
int m_nBottom ; // cella adiacente al lato bottom
|
|
int m_nLeft ; // cella adiacente al lato left
|
|
int m_nRight ; // cella adiacente al lato right
|
|
int m_nParent ; // cella genitore
|
|
int m_nDepth ; // profondità della cella rispetto a root
|
|
int m_nChild1 ; // prima cella figlio
|
|
int m_nChild2 ; // seconda cella figlio
|
|
|
|
private :
|
|
Point3d m_ptPbl ; // punto bottom left
|
|
Point3d m_ptPtr ; // punto top right
|
|
bool m_bProcessed ; // flag che indica se la cella è stata processata
|
|
bool m_bSplitVert ; // flag che indica in quale direzione è stata divisa la cella
|
|
// double m_dSplit ; // lunghezza normalizzata a cui è stata splittata la cella
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
class Tree
|
|
{
|
|
public :
|
|
~Tree( void) ;
|
|
Tree( void) ;
|
|
Tree ( const SurfBezier* pSrfBz) ;
|
|
void SetSurf( const SurfBezier* pSrfBz) ;
|
|
bool BuildTree( double dLinTol = LIN_TOL_STD, double dSideMax = INFINITO) ; // dSidemax è il massimo per la dimensione maggiore di un triangolo della trimesh
|
|
bool GetPolygons( POLYLINEVECTOR& vPolygons) ;
|
|
|
|
private :
|
|
void Split( int nId) ; // funzione di split di una cella dell'albero
|
|
void Balance ( INTVECTOR vCheck) ; // creo rami in modo che tutte tutte le foglie abbiano come adiacenti foglie ad una profonditù di +- 1
|
|
int GetHeightLeaves ( int nId, INTVECTOR& vnLeaves, int d = 0) ; // altezza del subtree a partire dal nodo nId
|
|
int GetDepth ( int nId, int nRef) ; // livello del nodo nId
|
|
void GetTopNeigh( int nId, INTVECTOR& vTopNeighs) ;
|
|
void GetBottomNeigh( int nId, INTVECTOR& vBottomNeighs) ;
|
|
void GetLeftNeigh( int nId, INTVECTOR& vLeftNeighs) ;
|
|
void GetRightNeigh( int nId, INTVECTOR& vRightNeighs) ;
|
|
|
|
|
|
private :
|
|
double m_dLinTol ; // errore dell'approssimazione
|
|
int m_nRoot ; // cella base
|
|
const SurfBezier* m_pSrfBz ; // root
|
|
bool m_bTrimmed ; // superficie trimmata
|
|
POLYLINEVECTOR m_vPolygons ; // vettore dei poligoni del kd-tree
|
|
std::map<int,Cell> m_mTree ; // mappa che contiene tutti i nodi e le foglie dell'albero. -2 è puntatore Null e -1 è root
|
|
INTVECTOR m_vnLeaves ; // vettore delle foglie
|
|
} ; |