[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [analitza] analitzaplot/private: Clean source code: remove spanish comments and translate some code
From: Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date: 2014-03-30 21:30:49
Message-ID: E1WUNJZ-0006GF-LO () scm ! kde ! org
[Download RAW message or body]
Git commit d3f828ac36edeae1432624667cb9ef343fbd5aa8 by Percy Camilo Triveño \
Aucahuasi. Committed on 30/03/2014 at 21:30.
Pushed by aucahuasi into branch 'master'.
Clean source code: remove spanish comments and translate some code to english
M +1 -1 analitzaplot/private/backends/implicitsurface.cpp
M +212 -218 analitzaplot/private/utils/marchingcubes.cpp
M +31 -93 analitzaplot/private/utils/marchingcubes.h
M +1 -122 analitzaplot/private/utils/marchingsquares.cpp
M +0 -25 analitzaplot/private/utils/marchingsquares.h
M +38 -38 analitzaplot/private/utils/octree.cpp
M +18 -21 analitzaplot/private/utils/octree.h
M +10 -11 analitzaplot/private/utils/quadtree.cpp
M +3 -4 analitzaplot/private/utils/quadtree.h
http://commits.kde.org/analitza/d3f828ac36edeae1432624667cb9ef343fbd5aa8
diff --git a/analitzaplot/private/backends/implicitsurface.cpp \
b/analitzaplot/private/backends/implicitsurface.cpp index 83fa488..68c7918 100644
--- a/analitzaplot/private/backends/implicitsurface.cpp
+++ b/analitzaplot/private/backends/implicitsurface.cpp
@@ -68,7 +68,7 @@ ImplicitSurf::ImplicitSurf(const Analitza::Expression& e, \
Analitza::Variables* v
void ImplicitSurf::update(const QVector3D & oppositecorner1, const QVector3D & \
oppositecorner2) {
- sLimitesEspacio spaceLimits;
+ SpaceLimits spaceLimits;
double tmpsize = 4.0;
diff --git a/analitzaplot/private/utils/marchingcubes.cpp \
b/analitzaplot/private/utils/marchingcubes.cpp index 9965f56..49331f1 100644
--- a/analitzaplot/private/utils/marchingcubes.cpp
+++ b/analitzaplot/private/utils/marchingcubes.cpp
@@ -76,21 +76,21 @@
// 4---------6
// 9
-sMarching_Cube MarchingCubes::evaluar_cubo(Cube cubo){
+sMarching_Cube MarchingCubes::evalCube(Cube cubo){
sMarching_Cube res;
QVector3D punto;
unsigned short int val;
- //Datos generales
- res.centro = cubo.center();
- res.medio_lado = cubo.halfEdge();
+ //basic data
+ res.center = cubo.center();
+ res.half_size = cubo.halfEdge();
- //Llenar vertices
- double x = res.centro.x();
- double y = res.centro.y();
- double z = res.centro.z();
- double hedge = res.medio_lado;
+ //fill vertices
+ double x = res.center.x();
+ double y = res.center.y();
+ double z = res.center.z();
+ double hedge = res.half_size;
res.vertices[0] = evalScalarField(x-hedge, y-hedge, z-hedge);
@@ -102,25 +102,27 @@ sMarching_Cube MarchingCubes::evaluar_cubo(Cube cubo){
res.vertices[6] = evalScalarField(x+hedge, y+hedge, z-hedge);
res.vertices[7] = evalScalarField(x+hedge, y+hedge, z+hedge);
- //Definir tipo
- res.tipo = 0;
+ //define topology type
+ res.type = 0;
val=1;
- //Sumar cada vertice segun su posicion
+
+ //sum each vertex based on position
for(unsigned int i=0;i<8;i++){
if(res.vertices[i] > 0){
- res.tipo += val;
+ res.type += val;
}
val*=2;
}
+
return res;
}
-QList<Cube> MarchingCubes::breadth_rec(int cubos_lado){
+QList<Cube> MarchingCubes::breadthSearch(int cubos_lado){
Cube cubo;
sMarching_Cube m_cubo;
bool salir = false;
QList<Cube> cubos;
- cubo.setHalfEdge(largo_mundo/(2*cubos_lado));
+ cubo.setHalfEdge(m_worldLength/(2*cubos_lado));
double x = 0;
double y = 0;
@@ -128,50 +130,48 @@ QList<Cube> MarchingCubes::breadth_rec(int cubos_lado){
// static const double iteration_square_val = 0.5;
- for(int i=mundo.minX;i<=mundo.maxX;i++){
+ for(int i=m_worldLimits.minX;i<=m_worldLimits.maxX;i++){
// cubo.centro.x() = (2*i+1)*cubo.medio_lado;
x = (2*i+1)*cubo.halfEdge();
- for(int j=mundo.minY;j<=mundo.maxY;j++){
+ for(int j=m_worldLimits.minY;j<=m_worldLimits.maxY;j++){
y = (2*j+1)*cubo.halfEdge();
- for(int k=mundo.minZ;k<=mundo.maxZ;k++){
+ for(int k=m_worldLimits.minZ;k<=m_worldLimits.maxZ;k++){
z = (2*k+1)*cubo.halfEdge();
cubo.setCenter(x,y,z);
- m_cubo = evaluar_cubo(cubo);
- if(m_cubo.tipo != 0 && m_cubo.tipo != 255){
- //Esta dentro del cubo. Detener busqueda
+ m_cubo = evalCube(cubo);
+ if(m_cubo.type != 0 && m_cubo.type != 255){
+ //if is inside the cube, stop the search ...
salir = true;
cubos.append(cubo);
}
}
}
}
- if(!salir && 2*cubo.halfEdge() > min_grid){
- cubos.append(breadth_rec(cubos_lado*2));
+ if(!salir && 2*cubo.halfEdge() > m_minCubeSize){
+ cubos.append(breadthSearch(cubos_lado*2));
//mundo.maxX*=2; mundo.maxY*=2; mundo.maxZ*=2;
}
return cubos;
}
-QList<sMarching_Cube> MarchingCubes::depth_rec(Octree *arbol, sNodo *nodo){
+QList<sMarching_Cube> MarchingCubes::depthSearch(Octree *arbol, sNode *nodo){
QList<sMarching_Cube> cubos;
sMarching_Cube m_cubo;
- //Calcular si la superfice lo corta
- m_cubo = evaluar_cubo(nodo->cubo);
+ //test if surface "cut" the cube
+ m_cubo = evalCube(nodo->cube);
- if(m_cubo.tipo != 0 && m_cubo.tipo != 255){
- //Superfice corta
- if(m_cubo.medio_lado*2 > min_grid){
+ if(m_cubo.type != 0 && m_cubo.type != 255){
+ //if intersection
+ if(m_cubo.half_size*2 > m_minCubeSize){
//Seguir bajando
- arbol->bajarNivel(nodo);
+ arbol->downLevel(nodo);
for(unsigned int i=0; i<8; i++){
- cubos.append(depth_rec(arbol,nodo->nodos[i]));
+ cubos.append(depthSearch(arbol,nodo->nodes[i]));
}
- //No ayuda mucho, pero se puede borrar el arbol conforme ya no se \
necesite
- //arbol->borrarHijos(nodo);
} else {
- //Detener
+ //stop condition
cubos.append(m_cubo);
}
}
@@ -183,35 +183,33 @@ MarchingCubes::MarchingCubes()
}
-void MarchingCubes::setupSpace(const sLimitesEspacio &spaceLimits)
+void MarchingCubes::setupSpace(const SpaceLimits &spaceLimits)
{
- //TODO no magc numbers
- min_grid = 0.2;
- largo_mundo = 1;
- mundo = spaceLimits;
+ //TODO no magic numbers
+ m_minCubeSize = 0.2;
+ m_worldLength = 1;
+ m_worldLimits = spaceLimits;
}
MarchingCubes::~MarchingCubes()
{
}
-QList<sMarching_Cube> MarchingCubes::ejecutar()
+QList<sMarching_Cube> MarchingCubes::getCubes()
{
QList<sMarching_Cube> cubos;
- QList<Cube> found = breadth_rec(largo_mundo);
+ QList<Cube> found = breadthSearch(m_worldLength);
- //Ubicar los cubos (depth search octree)
foreach(const Cube& iterador, found){
Octree* arbol = new Octree(iterador);
- cubos.append(depth_rec(arbol, arbol->get_raiz()));
+ cubos.append(depthSearch(arbol, arbol->getRoot()));
delete arbol;
}
- //Devolver los cubos
return cubos;
}
-void MarchingCubes::_addTri(const QVector3D& a, const QVector3D& b, const QVector3D& \
c) +void MarchingCubes::apendTriangle(const QVector3D& a, const QVector3D& b, const \
QVector3D& c) {
QVector3D n = QVector3D::crossProduct(b - a, c - b).normalized();
@@ -226,113 +224,113 @@ void MarchingCubes::_addTri(const QVector3D& a, const \
QVector3D& b, const QVecto _indexes.append(_indexes.size());
}
-QList<sArista> MarchingCubes::calcular_cortes(sMarching_Cube cubo){
- QList<sArista> aristas;
- sArista temp;
+QList<Edge> MarchingCubes::computeIntersections(sMarching_Cube cubo){
+ QList<Edge> aristas;
+ Edge temp;
//0-1
- if(signo_opuesto(cubo.vertices[0],cubo.vertices[1])){
- temp.corte = QVector3D(cubo.centro.x()-cubo.medio_lado,
- cubo.centro.y()-cubo.medio_lado,
- \
cubo.centro.z()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[1]));
+ if(oppositeSign(cubo.vertices[0],cubo.vertices[1])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size,
+ cubo.center.y()-cubo.half_size,
+ \
cubo.center.z()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[0],cubo.vertices[1]));
temp.vertices[0] = 0;
temp.vertices[1] = 1;
aristas.append(temp);
}
//0-2
- if(signo_opuesto(cubo.vertices[0],cubo.vertices[2])){
- temp.corte = QVector3D(cubo.centro.x()-cubo.medio_lado,
- \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[2]),
- cubo.centro.z()-cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[0],cubo.vertices[2])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size,
+ \
cubo.center.y()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[0],cubo.vertices[2]),
+ cubo.center.z()-cubo.half_size);
temp.vertices[0] = 0;
temp.vertices[1] = 2;
aristas.append(temp);
}
//0-4
- if(signo_opuesto(cubo.vertices[0],cubo.vertices[4])){
- temp.corte = \
QVector3D(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[4]),
- cubo.centro.y()-cubo.medio_lado,
- cubo.centro.z()-cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[0],cubo.vertices[4])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[0],cubo.vertices[4]),
+ cubo.center.y()-cubo.half_size,
+ cubo.center.z()-cubo.half_size);
temp.vertices[0] = 0;
temp.vertices[1] = 4;
aristas.append(temp);
}
//1-3
- if(signo_opuesto(cubo.vertices[1],cubo.vertices[3])){
- temp.corte = QVector3D(cubo.centro.x()-cubo.medio_lado,
- \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[1],cubo.vertices[3]),
- cubo.centro.z()+cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[1],cubo.vertices[3])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size,
+ \
cubo.center.y()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[1],cubo.vertices[3]),
+ cubo.center.z()+cubo.half_size);
temp.vertices[0] = 1;
temp.vertices[1] = 3;
aristas.append(temp);
}
//1-5
- if(signo_opuesto(cubo.vertices[1],cubo.vertices[5])){
- temp.corte = \
QVector3D(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[1],cubo.vertices[5]),
- cubo.centro.y()-cubo.medio_lado,
- cubo.centro.z()+cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[1],cubo.vertices[5])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[1],cubo.vertices[5]),
+ cubo.center.y()-cubo.half_size,
+ cubo.center.z()+cubo.half_size);
temp.vertices[0] = 1;
temp.vertices[1] = 5;
aristas.append(temp);
}
//2-3
- if(signo_opuesto(cubo.vertices[2],cubo.vertices[3])){
- temp.corte = QVector3D(cubo.centro.x()-cubo.medio_lado,
- cubo.centro.y()+cubo.medio_lado,
- \
cubo.centro.z()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[2],cubo.vertices[3]));
+ if(oppositeSign(cubo.vertices[2],cubo.vertices[3])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size,
+ cubo.center.y()+cubo.half_size,
+ \
cubo.center.z()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[2],cubo.vertices[3]));
temp.vertices[0] = 2;
temp.vertices[1] = 3;
aristas.append(temp);
}
//2-6
- if(signo_opuesto(cubo.vertices[2],cubo.vertices[6])){
- temp.corte = \
QVector3D(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[2],cubo.vertices[6]),
- cubo.centro.y()+cubo.medio_lado,
- cubo.centro.z()-cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[2],cubo.vertices[6])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[2],cubo.vertices[6]),
+ cubo.center.y()+cubo.half_size,
+ cubo.center.z()-cubo.half_size);
temp.vertices[0] = 2;
temp.vertices[1] = 6;
aristas.append(temp);
}
//3-7
- if(signo_opuesto(cubo.vertices[3],cubo.vertices[7])){
- temp.corte = \
QVector3D(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[3],cubo.vertices[7]),
- cubo.centro.y()+cubo.medio_lado,
- cubo.centro.z()+cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[3],cubo.vertices[7])){
+ temp.cut = QVector3D(cubo.center.x()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[3],cubo.vertices[7]),
+ cubo.center.y()+cubo.half_size,
+ cubo.center.z()+cubo.half_size);
temp.vertices[0] = 3;
temp.vertices[1] = 7;
aristas.append(temp);
}
//4-5
- if(signo_opuesto(cubo.vertices[4],cubo.vertices[5])){
- temp.corte = QVector3D(cubo.centro.x()+cubo.medio_lado,
- cubo.centro.y()-cubo.medio_lado,
- \
cubo.centro.z()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[4],cubo.vertices[5]));
+ if(oppositeSign(cubo.vertices[4],cubo.vertices[5])){
+ temp.cut = QVector3D(cubo.center.x()+cubo.half_size,
+ cubo.center.y()-cubo.half_size,
+ \
cubo.center.z()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[4],cubo.vertices[5]));
temp.vertices[0] = 4;
temp.vertices[1] = 5;
aristas.append(temp);
}
//4-6
- if(signo_opuesto(cubo.vertices[4],cubo.vertices[6])){
- temp.corte = QVector3D(cubo.centro.x()+cubo.medio_lado,
- \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[4],cubo.vertices[6]),
- cubo.centro.z()-cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[4],cubo.vertices[6])){
+ temp.cut = QVector3D(cubo.center.x()+cubo.half_size,
+ \
cubo.center.y()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[4],cubo.vertices[6]),
+ cubo.center.z()-cubo.half_size);
temp.vertices[0] = 4;
temp.vertices[1] = 6;
aristas.append(temp);
}
//5-7
- if(signo_opuesto(cubo.vertices[5],cubo.vertices[7])){
- temp.corte = QVector3D(cubo.centro.x()+cubo.medio_lado,
- \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[5],cubo.vertices[7]),
- cubo.centro.z()+cubo.medio_lado);
+ if(oppositeSign(cubo.vertices[5],cubo.vertices[7])){
+ temp.cut = QVector3D(cubo.center.x()+cubo.half_size,
+ \
cubo.center.y()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[5],cubo.vertices[7]),
+ cubo.center.z()+cubo.half_size);
temp.vertices[0] = 5;
temp.vertices[1] = 7;
aristas.append(temp);
}
//6-7
- if(signo_opuesto(cubo.vertices[6],cubo.vertices[7])){
- temp.corte = QVector3D(cubo.centro.x()+cubo.medio_lado,
- cubo.centro.y()+cubo.medio_lado,
- \
cubo.centro.z()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[6],cubo.vertices[7]));
+ if(oppositeSign(cubo.vertices[6],cubo.vertices[7])){
+ temp.cut = QVector3D(cubo.center.x()+cubo.half_size,
+ cubo.center.y()+cubo.half_size,
+ \
cubo.center.z()-cubo.half_size+2*cubo.half_size*linearInterpolation(cubo.vertices[6],cubo.vertices[7]));
temp.vertices[0] = 6;
temp.vertices[1] = 7;
aristas.append(temp);
@@ -340,39 +338,38 @@ QList<sArista> MarchingCubes::calcular_cortes(sMarching_Cube \
cubo){ return aristas;
}
-bool MarchingCubes::signo_opuesto(double a, double b){
+bool MarchingCubes::oppositeSign(double a, double b){
return ((a > 0 && b <= 0) || (a <= 0 && b > 0));
}
-double MarchingCubes::lineal(double vert_1, double vert_2){
+double MarchingCubes::linearInterpolation(double vert_1, double vert_2){
//Posicion de 0 a 1
return qAbs(vert_1/(vert_1 - vert_2));
}
-void MarchingCubes::agregar_triangulos(QList<QVector3D> &lista_triangulos){
+void MarchingCubes::appendTriangles(QList<QVector3D> &lista_triangulos){
for(int i=0; i<lista_triangulos.count();i+=3){
if (lista_triangulos.size()-3 < i)
continue;
- _addTri(lista_triangulos.at(i),lista_triangulos.at(i+1),lista_triangulos.at(i+2));
+ apendTriangle(lista_triangulos.at(i),lista_triangulos.at(i+1),lista_triangulos.at(i+2));
}
}
-//Tipos:
-void MarchingCubes::identificar_tipo(const sMarching_Cube& cubo){
- QList<sArista> aristas;
+void MarchingCubes::computeTopologyType(const sMarching_Cube& cubo){
+ QList<Edge> aristas;
QList<unsigned int> vertices;
unsigned int it;
//Conseguir aristas y vertices
- aristas = calcular_cortes(cubo);
+ aristas = computeIntersections(cubo);
it=0;
for(unsigned int i=1; i<129; i*=2){
- if((cubo.tipo & i) == i){
+ if((cubo.type & i) == i){
vertices.append(it);
}
it++;
@@ -381,41 +378,41 @@ void MarchingCubes::identificar_tipo(const sMarching_Cube& \
cubo){ it=0;
vertices.clear();
for(unsigned int i=1; i<129; i*=2){
- if((cubo.tipo & i) != i){
+ if((cubo.type & i) != i){
vertices.append(it);
}
it++;
}
}
- //Identificar tipo
+ //get type
switch(aristas.count()){
case 3:
- //Tipo 1
- tipo01(aristas, vertices);
+ //type 1
+ type01(aristas, vertices);
return ;
case 4:
- //Tipo 2, 5
+ //types 2, 5
if(vertices.count() == 2){
- //Tipo 2
- tipo02(aristas);
+ //type 2
+ type02(aristas);
return ;
} else {
- //Tipo 5
- tipo05(aristas, vertices);
+ //type 5
+ type05(aristas, vertices);
return ;
}
case 5:
{
- //Tipo 4
- tipo04(aristas, vertices);
+ //type 4
+ type04(aristas, vertices);
return ;
}
case 6:
- //Tipo 3, 8, 9, 10, 14
+ //types 3, 8, 9, 10, 14
if(vertices.count() == 2){
- //Tipo 3 o 10 -> El tipo01 es capaz de dibujar estos casos
- tipo01(aristas, vertices); return ;
+ //types 3 or 10 -> type01 can draw this cases too
+ type01(aristas, vertices); return ;
} else {
for(int i=0; i<vertices.count(); i++){
bool tiene_arista = false;
@@ -427,23 +424,23 @@ void MarchingCubes::identificar_tipo(const sMarching_Cube& \
cubo){ }
if(!tiene_arista){
//Tipo 8
- tipo08(aristas, vertices, i);
+ type08(aristas, vertices, i);
return ;
}
}
- //Tipo 9 o 14 (son iguales)
- tipo09(aristas,vertices);
+ //types 9 or 14 (are the same)
+ type09(aristas,vertices);
return ;
}
case 7:
- //Tipo 11
+ //type 11
{
- tipo11(aristas, vertices);
+ type11(aristas, vertices);
return ;
}
case 8:
{
- //Tipo 6, 13
+ //types 6, 13
bool encontrado;
for(int i=0; i<vertices.count()-1; i++){
encontrado = true;
@@ -457,62 +454,61 @@ void MarchingCubes::identificar_tipo(const sMarching_Cube& \
cubo){ }
}
if(encontrado){
- //Tipo 6
- tipo06(aristas, vertices, i);
+ //type 6
+ type06(aristas, vertices, i);
return ;
}
}
- //Tipo 13
- tipo13(aristas, vertices);
+ //type 13
+ type13(aristas, vertices);
return ;
}
case 9:
- //Tipo 12 -> El tipo01 es capaz de dibujar este caso
+ //type 12 -> type01 can draw this case
{
- tipo01(aristas, vertices);
+ type01(aristas, vertices);
return ;
}
case 12:
- //Tipo 7 -> El tipo01 es capaz de dibujar este caso
+ //type 7 -> type01 can draw this case
{
- tipo01(aristas, vertices);
+ type01(aristas, vertices);
return ;
}
- default: qDebug() << "Error al calcular el tipo"; break;
-// printf("Error al calcular tipo\n");
+ default: qDebug() << "Can't compute the surface type"; break;
}
}
-void MarchingCubes::tipo01(QList<sArista> aristas, QList<unsigned int> vertices){
+void MarchingCubes::type01(QList<Edge> aristas, QList<unsigned int> vertices){
QList<QVector3D> triangulos;
- //Pintar los triangulos
+
for(int i=0; i<vertices.count(); i++){
for(int j=0; j<aristas.count(); j++){
if(aristas.at(j).vertices[0]==vertices[i] || \
aristas.at(j).vertices[1]==vertices[i]){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
}
}
}
- agregar_triangulos(triangulos);
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo02(QList<sArista> aristas){
+void MarchingCubes::type02(QList<Edge> aristas){
QList<QVector3D> triangulos;
- triangulos << aristas.at(0).corte;
- triangulos << aristas.at(1).corte;
- triangulos << aristas.at(2).corte;
- triangulos << aristas.at(1).corte;
- triangulos << aristas.at(2).corte;
- triangulos << aristas.at(3).corte;
- agregar_triangulos(triangulos);
+ triangulos << aristas.at(0).cut;
+ triangulos << aristas.at(1).cut;
+ triangulos << aristas.at(2).cut;
+ triangulos << aristas.at(1).cut;
+ triangulos << aristas.at(2).cut;
+ triangulos << aristas.at(3).cut;
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo04(QList<sArista> aristas, QList<unsigned int> vertices){
+void MarchingCubes::type04(QList<Edge> aristas, QList<unsigned int> vertices){
QList<QVector3D> triangulos;
unsigned int encontrado, sentido, pos_arista;
QList< QList<unsigned int> > pos;
- //Encontrar el vertice con solo un corte asociado
+ //find the vertex with just one cut
for(int i=0;i<vertices.count();i++){
encontrado = 0;
for(int j=0; j<aristas.count(); j++){
@@ -525,16 +521,16 @@ void MarchingCubes::tipo04(QList<sArista> aristas, \
QList<unsigned int> vertices) }
}
if(encontrado == 1){
- //Tengo el vertice solitario en ´i ´, pintar primer triangulo
+ //we have the singleton vertex in i, so we can get first triangle
sentido = \
aristas.at(pos_arista).vertices[1]-aristas.at(pos_arista).vertices[0]; for(int j=0; \
j<aristas.count(); j++){
if(aristas.at(j).vertices[1] - aristas.at(j).vertices[0] == \
sentido){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
}
}
aristas.removeAt(pos_arista);
- //Agrupar por vertice comun
+ //group by common vertex
for(int k=0;k<vertices.count();k++){
if(i==k){
continue;
@@ -547,32 +543,32 @@ void MarchingCubes::tipo04(QList<sArista> aristas, \
QList<unsigned int> vertices) }
}
- //Primer triangulo
- triangulos << aristas.at(pos.at(0).at(0)).corte;
- triangulos << aristas.at(pos.at(0).at(1)).corte;
+ //first triangle
+ triangulos << aristas.at(pos.at(0).at(0)).cut;
+ triangulos << aristas.at(pos.at(0).at(1)).cut;
for(int j=0; j<pos.at(1).count(); j++){
if(aristas.at(pos.at(1).at(j)).vertices[1] - \
aristas.at(pos.at(1).at(j)).vertices[0] == sentido){
- triangulos << aristas.at(pos.at(1).at(j)).corte;
+ triangulos << aristas.at(pos.at(1).at(j)).cut;
}
}
- //Segundo triangulo
- triangulos << aristas.at(pos.at(1).at(0)).corte;
- triangulos << aristas.at(pos.at(1).at(1)).corte;
+ //second triangle
+ triangulos << aristas.at(pos.at(1).at(0)).cut;
+ triangulos << aristas.at(pos.at(1).at(1)).cut;
for(int j=0; j<pos.at(0).count(); j++){
if(aristas.at(pos.at(0).at(j)).vertices[1] - \
aristas.at(pos.at(0).at(j)).vertices[0] != sentido){
- triangulos << aristas.at(pos.at(0).at(j)).corte;
+ triangulos << aristas.at(pos.at(0).at(j)).cut;
}
}
break;
}
}
- agregar_triangulos(triangulos);
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo05(QList<sArista> aristas, QList<unsigned int> vertices){
+void MarchingCubes::type05(QList<Edge> aristas, QList<unsigned int> vertices){
QList<QVector3D> triangulos;
int vertice_arista[4];
- //Identificar cada vertice con su arista (los vertices estan ordenados de menor \
a mayor) + //indentify each vertex with its edges (vertices are sort from low to \
high) for(int i=0; i<vertices.count(); i++){
for(int j=0; j<aristas.count(); j++){
if(aristas.at(j).vertices[0] == vertices.at(i) || \
aristas.at(j).vertices[1] == vertices.at(i)){ @@ -582,20 +578,20 @@ void \
MarchingCubes::tipo05(QList<sArista> aristas, QList<unsigned int> vertices) }
}
//Pintar triangulos
- triangulos << aristas.at(vertice_arista[0]).corte;
- triangulos << aristas.at(vertice_arista[1]).corte;
- triangulos << aristas.at(vertice_arista[2]).corte;
+ triangulos << aristas.at(vertice_arista[0]).cut;
+ triangulos << aristas.at(vertice_arista[1]).cut;
+ triangulos << aristas.at(vertice_arista[2]).cut;
triangulos << triangulos.at(1);
triangulos << triangulos.at(2);
- triangulos << aristas.at(vertice_arista[3]).corte;
+ triangulos << aristas.at(vertice_arista[3]).cut;
- agregar_triangulos(triangulos);
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo06(QList<sArista> aristas, QList<unsigned int> vertices, int \
ind_vertice_solitario){
- //Tipo 1 + 4
- QList<sArista> aristas2;
+void MarchingCubes::type06(QList<Edge> aristas, QList<unsigned int> vertices, int \
ind_vertice_solitario){ + //type 1 + 4
+ QList<Edge> aristas2;
QList<unsigned int> vertices2;
- //Generar el aristas2
+ //generate edge2
for(int i=0; i<aristas.count();i++){
if(aristas.at(i).vertices[0] != vertices.at(ind_vertice_solitario)
&& aristas.at(i).vertices[1] != vertices.at(ind_vertice_solitario)){
@@ -608,7 +604,7 @@ void MarchingCubes::tipo06(QList<sArista> aristas, QList<unsigned \
int> vertices, vertices.removeAt(ind_vertice_solitario);
}
-void MarchingCubes::tipo08(QList<sArista> aristas, QList<unsigned int> vertices, \
unsigned int ind_vertice_solitario){ +void MarchingCubes::type08(QList<Edge> aristas, \
QList<unsigned int> vertices, unsigned int ind_vertice_solitario){ QList<QVector3D> \
triangulos; unsigned int ind_vert = 0, sentido;
QList<int> orden;
@@ -616,21 +612,21 @@ void MarchingCubes::tipo08(QList<sArista> aristas, \
QList<unsigned int> vertices, ind_vert = 1;
}
- //Unir dos puntos asociados al primer vertice
+ //join 2 points associated with first vertex
for(int j=0; j<aristas.count(); j++){
if(aristas.at(j).vertices[0] == vertices.at(ind_vert) || \
aristas.at(j).vertices[1] == vertices.at(ind_vert)){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
orden.append(j);
}
}
- //Unir con los puntos asociados al 2do vertice
+ //join with points associated with 2nd vertex
sentido = aristas.at(orden.at(0)).vertices[1] - \
aristas.at(orden.at(0)).vertices[0]; for(int j=0; j<aristas.count(); j++){
if(orden.at(0) == j || orden.at(1) == j){
continue;
}
if(aristas.at(j).vertices[1] - aristas.at(j).vertices[0] == sentido){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
orden.append(j);
for(int k=0; k<vertices.count(); k++){
if(aristas.at(j).vertices[0] == vertices.at(k) || \
aristas.at(j).vertices[1] == vertices.at(k)){ @@ -646,12 +642,12 @@ void \
MarchingCubes::tipo08(QList<sArista> aristas, QList<unsigned int> vertices, for(int \
j=0; j<aristas.count(); j++){
if((aristas.at(j).vertices[0] == vertices.at(ind_vert) || \
aristas.at(j).vertices[1] == vertices.at(ind_vert))
&& (aristas.at(j).vertices[1] - aristas.at(j).vertices[0] != sentido)){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
orden.append(j);
break;
}
}
- //2 triangulos pintados, faltan 2
+ //2 triangles, we need 2 more ...
sentido = aristas.at(orden.at(1)).vertices[1] - \
aristas.at(orden.at(1)).vertices[0]; triangulos << triangulos.at(0);
triangulos << triangulos.at(2);
@@ -661,7 +657,7 @@ void MarchingCubes::tipo08(QList<sArista> aristas, QList<unsigned \
int> vertices, continue;
}
if(aristas.at(j).vertices[1] - aristas.at(j).vertices[0] == sentido){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
orden.append(j);
for(int k=0; k<vertices.count(); k++){
if(aristas.at(j).vertices[0] == vertices.at(k) || \
aristas.at(j).vertices[1] == vertices.at(k)){ @@ -677,22 +673,22 @@ void \
MarchingCubes::tipo08(QList<sArista> aristas, QList<unsigned int> vertices, for(int \
j=0; j<aristas.count(); j++){
if((aristas.at(j).vertices[0] == vertices.at(ind_vert) || \
aristas.at(j).vertices[1] == vertices.at(ind_vert))
&& (aristas.at(j).vertices[1] - aristas.at(j).vertices[0] != sentido)){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
orden.append(j);
break;
}
}
- agregar_triangulos(triangulos);
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo09(QList<sArista> aristas, QList<unsigned int> vertices){
+void MarchingCubes::type09(QList<Edge> aristas, QList<unsigned int> vertices){
QList<QVector3D> triangulos;
QList<int> vertices_doble;
QList< QList<int> > aristas_doble;
bool doble;
unsigned int sentido, eje_compartido;
- //Encontrar los vertices dobles
+ //find double vertices
for(int i=0; i<vertices.count(); i++){
doble = false;
for(int j=0; j<aristas.count(); j++){
@@ -706,7 +702,7 @@ void MarchingCubes::tipo09(QList<sArista> aristas, QList<unsigned \
int> vertices) }
}
}
- //Encontrar aristas de los vertices dobles
+ //find vertices of double vertices
aristas_doble.append(QList<int>());
aristas_doble.append(QList<int>());
for(int j=0; j<aristas.count(); j++){
@@ -716,7 +712,7 @@ void MarchingCubes::tipo09(QList<sArista> aristas, QList<unsigned \
int> vertices) aristas_doble.back().append(j);
}
}
- //Encontrar eje compartido
+ //find shared axis
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
if(aristas.at(aristas_doble.at(0).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(0).at(i)).vertices[0] == @@ -726,75 +722,75 @@ void \
MarchingCubes::tipo09(QList<sArista> aristas, QList<unsigned int> vertices) }
}
}
- //Primer triangulo
+ //first triangle
for(int i=0; i<2; i++){
- triangulos << aristas.at(aristas_doble.at(0).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(0).at(i)).cut;
}
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(1).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(1).at(i)).vertices[0] == eje_compartido){
- triangulos << aristas.at(aristas_doble.at(1).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(1).at(i)).cut;
break;
}
}
- //Segundo triangulo
+ //second triangle
for(int i=0; i<2; i++){
- triangulos << aristas.at(aristas_doble.at(1).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(1).at(i)).cut;
}
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(0).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(0).at(i)).vertices[0] == eje_compartido){
- triangulos << aristas.at(aristas_doble.at(0).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(0).at(i)).cut;
break;
}
}
- //Tercer triangulo
+ //third triangle
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(0).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(0).at(i)).vertices[0] == eje_compartido){
- triangulos << aristas.at(aristas_doble.at(0).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(0).at(i)).cut;
break;
}
}
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(1).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(1).at(i)).vertices[0] != eje_compartido){
- triangulos << aristas.at(aristas_doble.at(1).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(1).at(i)).cut;
sentido = aristas.at(aristas_doble.at(1).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(1).at(i)).vertices[0]; break;
}
}
for(int j=0; j<aristas.count(); j++){
if(aristas.at(j).vertices[1] - aristas.at(j).vertices[0] == sentido){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
}
}
- //Cuarto triangulo
+ //four triangle
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(0).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(0).at(i)).vertices[0] != eje_compartido){
- triangulos << aristas.at(aristas_doble.at(0).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(0).at(i)).cut;
sentido = aristas.at(aristas_doble.at(0).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(0).at(i)).vertices[0]; break;
}
}
for(int i=0; i<2; i++){
if(aristas.at(aristas_doble.at(1).at(i)).vertices[1] - \
aristas.at(aristas_doble.at(1).at(i)).vertices[0] == eje_compartido){
- triangulos << aristas.at(aristas_doble.at(1).at(i)).corte;
+ triangulos << aristas.at(aristas_doble.at(1).at(i)).cut;
break;
}
}
for(int j=0; j<aristas.count(); j++){
if(aristas.at(j).vertices[1] - aristas.at(j).vertices[0] == sentido){
- triangulos << aristas.at(j).corte;
+ triangulos << aristas.at(j).cut;
}
}
- agregar_triangulos(triangulos);
+ appendTriangles(triangulos);
}
-void MarchingCubes::tipo11(QList<sArista> aristas, QList<unsigned int> vertices){
- //Tipo 1 + 2
+void MarchingCubes::type11(QList<Edge> aristas, QList<unsigned int> vertices){
+ //type 1 + 2
unsigned int vert_solitario;
bool encontrado;
- QList<sArista> aristas2;
+ QList<Edge> aristas2;
- //Buscar el vertice solitario
+ //find singleton vertex
for(int i=0; i<vertices.count()-1; i++){
encontrado = true;
for(int j=i+1;j<vertices.count();j++){
@@ -811,7 +807,7 @@ void MarchingCubes::tipo11(QList<sArista> aristas, QList<unsigned \
int> vertices) break;
}
}
- //Generar el aristas2
+ //generate edge2
for(int i=0; i<aristas.count();i++){
if(aristas.at(i).vertices[0] != vert_solitario
&& aristas.at(i).vertices[1] != vert_solitario){
@@ -824,12 +820,12 @@ void MarchingCubes::tipo11(QList<sArista> aristas, \
QList<unsigned int> vertices) vertices.append(vert_solitario);
}
-void MarchingCubes::tipo13(QList<sArista> aristas, QList<unsigned int> vertices){
- //Tipo 2 + 2
+void MarchingCubes::type13(QList<Edge> aristas, QList<unsigned int> vertices){
+ //type 2 + 2
unsigned int verts[2];
- QList<sArista> aristas2;
+ QList<Edge> aristas2;
- //Encontrar un par de vertices
+ //find couple of vertices
verts[0] = vertices.at(0);
for(int i=1; i<vertices.count(); i++){
if(vertices.at(i) - verts[0] == 1 ||
@@ -839,7 +835,7 @@ void MarchingCubes::tipo13(QList<sArista> aristas, QList<unsigned \
int> vertices) break;
}
}
- //Generar el aristas2
+ //generate edge2
for(int i=0; i<aristas.count();i++){
if(aristas.at(i).vertices[0] != verts[0]
&& aristas.at(i).vertices[1] != verts[0]
@@ -858,16 +854,14 @@ void MarchingCubes::buildGeometry()
_normals.clear();
_indexes.clear();
- QList<sMarching_Cube> cubos = ejecutar();
-// printf("Cubos: %d\n",cubos.count());
+ QList<sMarching_Cube> cubos = getCubes();
sMarching_Cube cubo;
foreach(cubo, cubos) {
- //Puede que ahora sea innecesario cambiar el tipo...
- if(cubo.tipo > 127){
- cubo.tipo = 255 - cubo.tipo;
+ //we can change the type now ...
+ if(cubo.type > 127){
+ cubo.type = 255 - cubo.type;
}
- identificar_tipo(cubo);
+ computeTopologyType(cubo);
}
}
-
diff --git a/analitzaplot/private/utils/marchingcubes.h \
b/analitzaplot/private/utils/marchingcubes.h index 12af111..ef0b0c4 100644
--- a/analitzaplot/private/utils/marchingcubes.h
+++ b/analitzaplot/private/utils/marchingcubes.h
@@ -16,7 +16,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA \
*
*************************************************************************************/
-
#ifndef FUNCTIONGRAPH2_H_mcub
#define FUNCTIONGRAPH2_H_mcub
@@ -24,7 +23,7 @@
#include <QVector>
-struct sLimitesEspacio {
+struct SpaceLimits {
double minX;
double maxX;
double minY;
@@ -34,126 +33,65 @@ struct sLimitesEspacio {
};
struct sMarching_Cube{
- QVector3D centro;
- double medio_lado;
- unsigned short int tipo;
+ QVector3D center;
+ double half_size;
+ unsigned short int type;
double vertices[8];
};
-struct sArista{
- QVector3D corte;
+struct Edge{
+ QVector3D cut;
unsigned int vertices[2];
};
//TODO very bad implementation ... we need to use interval arithmetic plus root \
finding //to know if a 0 belongs to f(square)
-
-//TODO esta clase se debe parametrizar para que pueda ser usada por implictcurves:
-//MarchingSquares ... en general debe recibir como parametro el tree \
(octree,kdtree...)
-//y las subclases deben implementar evalScalarfield ...pues esta clase sirve para \
eso:
-//para convertir un campo K escalar en poligonos.
class MarchingCubes
{
+friend class ImplicitSurf;
public:
virtual double evalScalarField(double x, double y, double z) = 0;
-public:
-
-// double funcion(double x, double y, double z)
-// {
-// // if(MarchingCubes::esSolido) {
-// // if(punto.x()==0 || punto.y()==0 || punto.z()==0)
-// // return qPow(punto.x()-MarchingCubes::constantes.at(0),2) + \
qPow(punto.y()-MarchingCubes::constantes.at(1),2) + \
qPow(punto.z()-MarchingCubes::constantes.at(2),2) - \
qPow(MarchingCubes::constantes.at(3),2);
-// // else
-// // return 1;
-// // }else {
-// // return qPow(punto.x()-MarchingCubes::constantes.at(0),2) + \
qPow(punto.y()-MarchingCubes::constantes.at(1),2) + \
qPow(punto.z()-MarchingCubes::constantes.at(2),2) - \
qPow(MarchingCubes::constantes.at(3),2);
-// // } return 0.0;
-//
-// // return punto.x()*punto.x() + punto.y()*punto.y() + punto.z()*punto.z() - \
4;
-//
-//
-// // return cos(x) + cos(y) + cos(z);
-//
-// // return 3*(cos(x) + cos(y) + cos(z)) + 4* cos(x) * cos(y) * cos(z);
-//
-// float ret = 0;
-// if (x*x + y*y +z*z < 35)
-// ret = 2 - (cos(x + (1+sqrt(5))/2*y) + cos(x - (1+sqrt(5))/2*y) + \
cos(y +
-// (1+sqrt(5))/2*z) + cos(y - (1+sqrt(5))/2*z) + cos(z - \
(1+sqrt(5))/2*x) + cos(z + (1+sqrt(5))/2*x));
-// else ret = 1;
-//
-//
-// return ret;
-//
-//
-// }
-
-private:
- /*
- largo_mundo: arista del mundo
- min_grid: arista minima del cubo a evaluar
- */
- double largo_mundo;
- double min_grid;
- sLimitesEspacio mundo;
- //Evaluar un cubo
- sMarching_Cube evaluar_cubo(Cube cubo);
-
- //Busqueda recursiva (breadth search)
- QList<Cube> breadth_rec(int cubos_lado);
-
- //Busqueda recursiva (depth search)
- QList<sMarching_Cube> depth_rec(Octree *arbol, sNodo *nodo);
-
-public:
- //Recibe el size de grilla deseado y el largo del mundo
- //Produce un min_grid menor o igual al proporcionado
MarchingCubes();
//here we put the size of intervals for x,z,and z ... call setupSpace before \
buildGeometry
- void setupSpace(const sLimitesEspacio &spaceLimits);
+ void setupSpace(const SpaceLimits &spaceLimits);
- //Destructor
~MarchingCubes();
- //Ejecutar
- QList<sMarching_Cube> ejecutar();
-
- friend class ImplicitSurf;
-public:
void buildGeometry();
QVector<double> _vertices;
QVector<double> _normals;
QVector<unsigned int> _indexes;
- void _addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c);
+private:
+ QList<sMarching_Cube> getCubes();
+ sMarching_Cube evalCube(Cube cubo);
+ QList<Cube> breadthSearch(int cubos_lado);
+ QList<sMarching_Cube> depthSearch(Octree *arbol, sNode *nodo);
+ QList<Edge> computeIntersections(sMarching_Cube cubo);
+ bool oppositeSign(double a, double b);
+ double linearInterpolation(double vert_1, double vert_2);
+ void apendTriangle(const QVector3D &a, const QVector3D &b, const QVector3D &c);
+ void appendTriangles(QList<QVector3D> &lista_triangulos);
+ void computeTopologyType(const sMarching_Cube& cubo);
+ void type01(QList<Edge> aristas, QList<unsigned int> vertices);
+ void type02(QList<Edge> aristas);
+ void type04(QList<Edge> aristas, QList<unsigned int> vertices);
+ void type05(QList<Edge> aristas, QList<unsigned int> vertices);
+ void type06(QList<Edge> aristas, QList<unsigned int> vertices, int \
ind_vertice_solitario); + void type08(QList<Edge> aristas, QList<unsigned int> \
vertices, unsigned int ind_vertice_solitario); + void type09(QList<Edge> aristas, \
QList<unsigned int> vertices); + void type11(QList<Edge> aristas, QList<unsigned \
int> vertices); + void type13(QList<Edge> aristas, QList<unsigned int> vertices);
private:
- //Calcular los cortes
- QList<sArista> calcular_cortes(sMarching_Cube cubo);
- bool signo_opuesto(double a, double b);
-
- //Calcular la posicion en la arista
- double lineal(double vert_1, double vert_2);
-
- //Agregar triangulos
- void agregar_triangulos(QList<QVector3D> &lista_triangulos);
-
- //Tipos:
- void identificar_tipo(const sMarching_Cube& cubo);
- void tipo01(QList<sArista> aristas, QList<unsigned int> vertices);
- void tipo02(QList<sArista> aristas);
- void tipo04(QList<sArista> aristas, QList<unsigned int> vertices);
- void tipo05(QList<sArista> aristas, QList<unsigned int> vertices);
- void tipo06(QList<sArista> aristas, QList<unsigned int> vertices, int \
ind_vertice_solitario);
- void tipo08(QList<sArista> aristas, QList<unsigned int> vertices, unsigned int \
ind_vertice_solitario);
- void tipo09(QList<sArista> aristas, QList<unsigned int> vertices);
- void tipo11(QList<sArista> aristas, QList<unsigned int> vertices);
- void tipo13(QList<sArista> aristas, QList<unsigned int> vertices);
+ double m_worldLength;
+ double m_minCubeSize;
+ SpaceLimits m_worldLimits;
};
#endif
diff --git a/analitzaplot/private/utils/marchingsquares.cpp \
b/analitzaplot/private/utils/marchingsquares.cpp index b8345ce..3bcc98c 100644
--- a/analitzaplot/private/utils/marchingsquares.cpp
+++ b/analitzaplot/private/utils/marchingsquares.cpp
@@ -28,11 +28,9 @@ sMarching_Square MarchingSquares::evaluar_cubo(const Square& cubo)
QPointF punto;
unsigned short int val;
- //Datos generales
res.centro = cubo.center();
res.medio_lado = cubo.halfEdge();
- //Llenar vertices
double x = res.centro.x();
double y = res.centro.y();
double hedge = res.medio_lado;
@@ -42,7 +40,6 @@ sMarching_Square MarchingSquares::evaluar_cubo(const Square& cubo)
res.vertices[2] = evalScalarField(x+hedge, y-hedge);
res.vertices[3] = evalScalarField(x+hedge, y+hedge);
-// //Definir tipo
// -----
// |1|3|
@@ -106,21 +103,15 @@ QList<sMarching_Square> MarchingSquares::depth_rec(Quadtree \
*arbol, QNode *nodo) QList<sMarching_Square> cubos;
sMarching_Square m_cubo;
- //Calcular si la superfice lo corta
m_cubo = evaluar_cubo(nodo->cubo);
if(m_cubo.tipo != 0 && m_cubo.tipo != 15) {
- //Superfice corta
if(m_cubo.medio_lado*2 > min_grid) {
- //Seguir bajando
arbol->bajarNivel(nodo);
for(unsigned int i=0; i<4; i++) {
cubos.append(depth_rec(arbol,nodo->nodos[i]));
}
- //No ayuda mucho, pero se puede borrar el arbol conforme ya no se \
necesite
- //arbol->borrarHijos(nodo);
} else {
- //Detener
cubos.append(m_cubo);
}
}
@@ -130,20 +121,6 @@ QList<sMarching_Square> MarchingSquares::depth_rec(Quadtree \
*arbol, QNode *nodo) MarchingSquares::MarchingSquares(/*double min_grid, double \
arista_mundo, sLimitesEspacio2D limites*/
) {
- //TODO enlazar con arg interval
-// sLimitesEspacio2D _esp;
-//
-// double a = 4;
-//
-// _esp.minX = -a;
-// _esp.maxX = a;
-// _esp.minY = -a;
-// _esp.maxY = a;
-//
-// //a mas pequenio el size se detectan las singularidades
-// this->min_grid = 0.05;
-// largo_mundo = 2*4;
-// mundo = _esp;
}
MarchingSquares::~MarchingSquares() {
@@ -155,22 +132,17 @@ QList<sMarching_Square> MarchingSquares::ejecutar() {
Square iterador;
Quadtree *arbol;
- //Buscar la superficie (breadth search octree)
encontrados = breadth_rec(largo_mundo);
- //Si no encuentra la superficie, retorna lista vacia
if(encontrados.isEmpty()) {
return cubos;
}
-// printf("Encontrados: %d\n",encontrados.count());
- //Ubicar los cubos (depth search octree)
foreach(iterador, encontrados) {
arbol = new Quadtree(iterador);
cubos.append(depth_rec(arbol, arbol->get_raiz()));
delete arbol;
}
- //Devolver los cubos
return cubos;
}
@@ -181,31 +153,6 @@ void MarchingSquares::_addTri(const QPointF& a, const QPointF& \
b)
}
-// #include <boost/math/tools/roots.hpp>
-// #include "boost/bind.hpp"
-//
-// struct TerminationCondition {
-// bool operator() (double min, double max) {
-// return abs(min - max) <= 0.0000001;
-// }
-// };
-/*
-// ...
-using boost::math::tools::bisect;
-using boost::math::tools::toms748_solve;
-
-// double root = (result.first + result.second) / 2; // = 0.381966...
-
-using namespace boost::math::policies;
-typedef policy<
- domain_error<ignore_error>,
- pole_error<ignore_error>,
- overflow_error<ignore_error>,
- evaluation_error<ignore_error>
-> my_policy;
-
-uintmax_t maxiters = 100;*/
-
QList<sArista2D> MarchingSquares::calcular_cortes(sMarching_Square cubo) {
QList<sArista2D> aristas;
sArista2D temp;
@@ -225,18 +172,6 @@ QList<sArista2D> \
MarchingSquares::calcular_cortes(sMarching_Square cubo) { QPointF v3 = \
QPointF(x+hedge, y+hedge);
//0-1
-// fixed_x = v0.x();
-// std::pair<double, double> r = bisect(boost::bind(&MarchingSquares::fy,this, \
_1), v0.y(), v1.y(), TerminationCondition(),maxiters, my_policy());
-// if (fy(r.first) * fy(r.second) <= 0) //corte
-// {
-// temp.corte = QPointF(cubo.centro.x()-cubo.medio_lado,
-// \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[1]));
-// temp.vertices[0] = 0;
-// temp.vertices[1] = 1;
-// aristas.append(temp);
-// }
-
- //0-1
if(signo_opuesto(cubo.vertices[0],cubo.vertices[1])) {
//al primero luego sumale
temp.corte = QPointF(cubo.centro.x()-cubo.medio_lado,
@@ -247,18 +182,6 @@ QList<sArista2D> \
MarchingSquares::calcular_cortes(sMarching_Square cubo) { }
//1-3
-// fixed_y = v1.y();
-// r = bisect(boost::bind(&MarchingSquares::fx,this, _1), v1.x(), v3.x(), \
TerminationCondition(),maxiters, my_policy());
-// if (fx(r.first) * fx(r.second) <= 0) //corte
-// {
-// temp.corte = \
QPointF(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[1],cubo.vertices[3]),
-// cubo.centro.y()+cubo.medio_lado);
-// temp.vertices[0] = 1;
-// temp.vertices[1] = 3;
-// aristas.append(temp);
-// }
-
- //1-3
if(signo_opuesto(cubo.vertices[1],cubo.vertices[3])) {
temp.corte = \
QPointF(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[1],cubo.vertices[3]),
cubo.centro.y()+cubo.medio_lado);
@@ -268,18 +191,6 @@ QList<sArista2D> \
MarchingSquares::calcular_cortes(sMarching_Square cubo) { }
//2-3
-// fixed_x = v2.x();
-// r = bisect(boost::bind(&MarchingSquares::fy,this, _1), v2.y(), v3.y(), \
TerminationCondition(),maxiters, my_policy());
-// if (fy(r.first) * fy(r.second) <= 0) //corte
-// {
-// temp.corte = QPointF(cubo.centro.x()+cubo.medio_lado,
-// \
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[2],cubo.vertices[3]));
-// temp.vertices[0] = 2;
-// temp.vertices[1] = 3;
-// aristas.append(temp);
-// }
-
- //2-3
if(signo_opuesto(cubo.vertices[2],cubo.vertices[3])) {
temp.corte = QPointF(cubo.centro.x()+cubo.medio_lado,
\
cubo.centro.y()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[2],cubo.vertices[3]));
@@ -295,18 +206,6 @@ QList<sArista2D> \
MarchingSquares::calcular_cortes(sMarching_Square cubo) { // -----
//0-2
-// fixed_y = v0.y();
-// r = bisect(boost::bind(&MarchingSquares::fx,this, _1), v0.x(), v2.x(), \
TerminationCondition(),maxiters, my_policy());
-// if (fx(r.first) * fx(r.second) <= 0) //corte
-// {
-// temp.corte = \
QPointF(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[2]),
-// cubo.centro.y()-cubo.medio_lado);
-// temp.vertices[0] = 0;
-// temp.vertices[1] = 2;
-// aristas.append(temp);
-// }
-
- //0-2
if(signo_opuesto(cubo.vertices[0],cubo.vertices[2])) {
temp.corte = \
QPointF(cubo.centro.x()-cubo.medio_lado+2*cubo.medio_lado*lineal(cubo.vertices[0],cubo.vertices[2]),
cubo.centro.y()-cubo.medio_lado);
@@ -315,9 +214,6 @@ QList<sArista2D> \
MarchingSquares::calcular_cortes(sMarching_Square cubo) { aristas.append(temp);
}
-// if (cubo.tipo == 5)
-// qDebug() << "ASIZE" <<aristas.size();
-
return aristas;
}
@@ -326,7 +222,6 @@ bool MarchingSquares::signo_opuesto(double a, double b) {
}
double MarchingSquares::lineal(double vert_1, double vert_2) {
- //Posicion de 0 a 1
return qAbs(vert_1/(vert_1 - vert_2));
}
@@ -342,21 +237,16 @@ void MarchingSquares::agregar_triangulos(QList<QPointF> \
&lista_triangulos) { }
}
-//Tipos:
void MarchingSquares::identificar_tipo(sMarching_Square cubo) {
QList<sArista2D> aristas;
QList<unsigned int> vertices;
unsigned int it;
- //Conseguir aristas y vertices
aristas = calcular_cortes(cubo);
unsigned short int type = cubo.tipo;
-// if (type == 1)
-// qDebug( ) << aristas.size();
-
switch (type)
{
case 1:
@@ -393,8 +283,6 @@ void MarchingSquares::tipo01(QList<sArista2D> aristas)
QList<QPointF> triangulos;
- //en este tipo hay 2 aristas
-
triangulos << aristas[0].corte << aristas[1].corte;
agregar_triangulos(triangulos);
@@ -404,7 +292,6 @@ void MarchingSquares::tipo05(QList<sArista2D> \
aristas,sMarching_Square cubo) {
if (aristas.isEmpty()) return;
- // en los tipos 10 y 5 hay 4 aristas
QList<QPointF> triangulos;
// -----
@@ -413,8 +300,6 @@ void MarchingSquares::tipo05(QList<sArista2D> \
aristas,sMarching_Square cubo) // |0|2|
// -----
-// qDebug() << "singular510";
-
if (cubo.tipo == 5)
triangulos << aristas[0].corte << aristas[2].corte;
@@ -431,13 +316,8 @@ void MarchingSquares::buildGeometry()
sMarching_Square cubo;
cubos = ejecutar();
-// printf("Cubos: %d\n",cubos.count());
foreach(cubo,cubos) {
- //Puede que ahora sea innecesario cambiar el tipo...
-// if(cubo.tipo > 127){
-// cubo.tipo = 255 - cubo.tipo;
-// }
identificar_tipo(cubo);
}
@@ -455,11 +335,10 @@ void MarchingSquares::setWorld(double minx, double maxx, double \
miny, double max
largo_mundo = 1;
- // a mas pequenio el size se detectan las singularidades
min_grid = qMin(fabs(maxx-minx), fabs(maxy-miny))/256;
if (min_grid>0.05 && min_grid < 1)
- min_grid = 0.05; // 0.05 es el minimo valor para la presicion
+ min_grid = 0.05;
mundo = _esp;
}
diff --git a/analitzaplot/private/utils/marchingsquares.h \
b/analitzaplot/private/utils/marchingsquares.h index 07246e4..ade938e 100644
--- a/analitzaplot/private/utils/marchingsquares.h
+++ b/analitzaplot/private/utils/marchingsquares.h
@@ -49,10 +49,6 @@ struct sArista2D {
//TODO very bad implementation ... we need to use interval arithmetic plus root \
finding //to know if a 0 belongs to f(square)
-//TODO esta clase se debe parametrizar para que pueda ser usada por implictcurves:
-//MarchingSquares ... en general debe recibir como parametro el tree \
(octree,kdtree...)
-//y las subclases deben implementar evalScalarfield ...pues esta clase sirve para \
eso:
-//para convertir un campo K escalar en poligonos.
class MarchingSquares
{
public:
@@ -62,10 +58,6 @@ public:
public:
private:
- /*
- largo_mundo: arista del mundo
- min_grid: arista minima del cubo a evaluar
- */
double largo_mundo;
double min_grid;
sLimitesEspacio2D mundo;
@@ -79,14 +71,10 @@ private:
QList<sMarching_Square> depth_rec(Quadtree *arbol, QNode *nodo);
public:
- //Recibe el tamaño de grilla deseado y el largo del mundo
- //Produce un min_grid menor o igual al proporcionado
MarchingSquares(/*double min_grid, double arista_mundo, sLimitesEspacio2D \
limites*/);
- //Destructor
virtual ~MarchingSquares();
- //Ejecutar
QList<sMarching_Square> ejecutar();
friend class ImplicitSurf;
@@ -98,25 +86,12 @@ public:
void _addTri(const QPointF &a, const QPointF &b);
private:
-
- //Calcular los cortes
QList<sArista2D> calcular_cortes(sMarching_Square cubo);
bool signo_opuesto(double a, double b);
-
- //Calcular la posicion en la arista
double lineal(double vert_1, double vert_2);
-
- //Agregar triangulos
void agregar_triangulos(QList<QPointF> &lista_triangulos);
-
- //Tipos:
void identificar_tipo(sMarching_Square cubo);
- // corta 2 aristas y tiene un vertice en el cruce de las aristas
- //el tipo 1 cubre los casos: 1,2,3,4,6,7,8,9,11,12,13,14
void tipo01(QList<sArista2D> aristas);
-
- //el tipo 5 cubre los casos 5 y 10
- // los casos 5 y 10 son donde se presnetan singularidades: cortes, cusps, etc
void tipo05(QList<sArista2D> aristas, sMarching_Square cubo);
private:
diff --git a/analitzaplot/private/utils/octree.cpp \
b/analitzaplot/private/utils/octree.cpp index 7e52868..6106120 100644
--- a/analitzaplot/private/utils/octree.cpp
+++ b/analitzaplot/private/utils/octree.cpp
@@ -20,90 +20,90 @@
Octree::Octree(double largo_mundo){
- raiz = new sNodo;
+ m_root = new sNode;
- raiz->cubo.setCenter(largo_mundo/2,largo_mundo/2,largo_mundo/2);
+ m_root->cube.setCenter(largo_mundo/2,largo_mundo/2,largo_mundo/2);
- raiz->cubo.setHalfEdge(largo_mundo/2);
+ m_root->cube.setHalfEdge(largo_mundo/2);
for(unsigned int i=0;i<8;i++){
- raiz->nodos[i]=NULL;
+ m_root->nodes[i]=NULL;
}
}
Octree::Octree(Cube cubo){
- raiz = new sNodo;
- raiz->cubo = cubo;
+ m_root = new sNode;
+ m_root->cube = cubo;
for(unsigned int i=0;i<8;i++){
- raiz->nodos[i]=NULL;
+ m_root->nodes[i]=NULL;
}
}
Octree::~Octree(){
- borrar_rec(raiz);
+ recursiveDelete(m_root);
}
-void Octree::inicializar_nodos(sNodo* padre){
+void Octree::initNodes(sNode* padre){
for(unsigned int i=0;i<8;i++){
- padre->nodos[i] = new sNodo;
- padre->nodos[i]->cubo.setHalfEdge(padre->cubo.halfEdge()/2);
+ padre->nodes[i] = new sNode;
+ padre->nodes[i]->cube.setHalfEdge(padre->cube.halfEdge()/2);
for(unsigned int j=0;j<8;j++){
- padre->nodos[i]->nodos[j]=NULL;
+ padre->nodes[i]->nodes[j]=NULL;
}
}
- double x = padre->cubo.center().x();
- double y = padre->cubo.center().y();
- double z = padre->cubo.center().z();
- double hhedge = padre->cubo.halfEdge()/2;
+ double x = padre->cube.center().x();
+ double y = padre->cube.center().y();
+ double z = padre->cube.center().z();
+ double hhedge = padre->cube.halfEdge()/2;
- padre->nodos[0]->cubo.setCenter(x-hhedge, y-hhedge, z-hhedge);
- padre->nodos[1]->cubo.setCenter(x-hhedge, y-hhedge, z+hhedge);
- padre->nodos[2]->cubo.setCenter(x-hhedge, y+hhedge, z-hhedge);
- padre->nodos[3]->cubo.setCenter(x-hhedge, y+hhedge, z+hhedge);
- padre->nodos[4]->cubo.setCenter(x+hhedge, y-hhedge, z-hhedge);
- padre->nodos[5]->cubo.setCenter(x+hhedge, y-hhedge, z+hhedge);
- padre->nodos[6]->cubo.setCenter(x+hhedge, y+hhedge, z-hhedge);
- padre->nodos[7]->cubo.setCenter(x+hhedge, y+hhedge, z+hhedge);
+ padre->nodes[0]->cube.setCenter(x-hhedge, y-hhedge, z-hhedge);
+ padre->nodes[1]->cube.setCenter(x-hhedge, y-hhedge, z+hhedge);
+ padre->nodes[2]->cube.setCenter(x-hhedge, y+hhedge, z-hhedge);
+ padre->nodes[3]->cube.setCenter(x-hhedge, y+hhedge, z+hhedge);
+ padre->nodes[4]->cube.setCenter(x+hhedge, y-hhedge, z-hhedge);
+ padre->nodes[5]->cube.setCenter(x+hhedge, y-hhedge, z+hhedge);
+ padre->nodes[6]->cube.setCenter(x+hhedge, y+hhedge, z-hhedge);
+ padre->nodes[7]->cube.setCenter(x+hhedge, y+hhedge, z+hhedge);
}
-void Octree::borrar_rec(sNodo* nodo){
+void Octree::recursiveDelete(sNode* nodo){
if(nodo == NULL){
return;
}
for(unsigned int i=0;i<8;i++){
- borrar_rec(nodo->nodos[i]);
+ recursiveDelete(nodo->nodes[i]);
}
delete nodo;
}
-void Octree::crear_rec(sNodo* nodo, unsigned int nivel_actual, unsigned int \
nivel_max){ +void Octree::recursiveCreate(sNode* nodo, unsigned int nivel_actual, \
unsigned int nivel_max){ if(nivel_actual > nivel_max){
return;
}
- inicializar_nodos(nodo);
+ initNodes(nodo);
for(unsigned int i=0;i<8;i++){
- crear_rec(nodo->nodos[i],nivel_actual+1,nivel_max);
+ recursiveCreate(nodo->nodes[i],nivel_actual+1,nivel_max);
}
}
-sNodo* Octree::get_raiz(){
- return raiz;
+sNode* Octree::getRoot(){
+ return m_root;
}
-void Octree::crearNivel(unsigned int nivel){
- crear_rec(raiz,0,nivel);
+void Octree::createLevel(unsigned int nivel){
+ recursiveCreate(m_root,0,nivel);
}
-void Octree::bajarNivel(sNodo* nodo){
- inicializar_nodos(nodo);
+void Octree::downLevel(sNode* nodo){
+ initNodes(nodo);
}
-void Octree::borrarHijos(sNodo* padre){
+void Octree::deleteChildren(sNode* padre){
for(unsigned int i=0;i<8;i++){
- borrar_rec(padre->nodos[i]);
- padre->nodos[i] = NULL;
+ recursiveDelete(padre->nodes[i]);
+ padre->nodes[i] = NULL;
}
}
diff --git a/analitzaplot/private/utils/octree.h \
b/analitzaplot/private/utils/octree.h index 377b21f..1cf4b24 100644
--- a/analitzaplot/private/utils/octree.h
+++ b/analitzaplot/private/utils/octree.h
@@ -16,16 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA \
*
*************************************************************************************/
-
-
#ifndef FUNCTIONGRAPH2_H__Q
#define FUNCTIONGRAPH2_H__Q
+#include <QVector3D>
/*
- Indice de los nodos
+ Node index
- Capa z+
+ layer z+
y+
-----
|3|7|
@@ -33,7 +32,7 @@ y+
|1|5|
----- x+
- Capa z-
+ layer z-
y+
-----
|2|6|
@@ -42,7 +41,6 @@ y+
----- x+
*/
-#include <QVector3D>
struct Cube
{
@@ -60,32 +58,31 @@ struct Cube
};
-struct sNodo{
- Cube cubo;
- sNodo* nodos[8];
+struct sNode{
+ Cube cube;
+ sNode* nodes[8];
};
-
-//TODO replace by kdtree using ANN library
+//TODO we can replace this by kdtree (ANN library)
class Octree
{
private:
- sNodo* raiz;
+ sNode* m_root;
- //Crea los hijos con los valores adecuados en los vertices
- void inicializar_nodos(sNodo* padre);
+ //create children with correct vertex values
+ void initNodes(sNode* parent);
- void borrar_rec(sNodo* nodo);
- void crear_rec(sNodo* nodo, unsigned int nivel_actual, unsigned int nivel_max);
+ void recursiveDelete(sNode* node);
+ void recursiveCreate(sNode* node, unsigned int current_level, unsigned int \
max_level); public:
- Octree(double largo_mundo);
+ Octree(double world_size);
Octree(Cube cubo);
~Octree();
- sNodo* get_raiz();
- void crearNivel(unsigned int nivel);
- void bajarNivel(sNodo* nodo);
- void borrarHijos(sNodo* padre);
+ sNode* getRoot();
+ void createLevel(unsigned int level);
+ void downLevel(sNode* node);
+ void deleteChildren(sNode* parent);
};
diff --git a/analitzaplot/private/utils/quadtree.cpp \
b/analitzaplot/private/utils/quadtree.cpp index 2e8af29..8a0201e 100644
--- a/analitzaplot/private/utils/quadtree.cpp
+++ b/analitzaplot/private/utils/quadtree.cpp
@@ -64,32 +64,31 @@ void Square::setHalfEdge(double he)
Quadtree::Quadtree(double largo_mundo) {
- raiz = new QNode;
+ root = new QNode;
- raiz->cubo.setCenter(largo_mundo/2,largo_mundo/2);
+ root->cubo.setCenter(largo_mundo/2,largo_mundo/2);
- raiz->cubo.setHalfEdge(largo_mundo/2);
+ root->cubo.setHalfEdge(largo_mundo/2);
for(unsigned int i=0; i<8; i++) {
- raiz->nodos[i]=NULL;
+ root->nodos[i]=NULL;
}
}
Quadtree::Quadtree(Square cubo) {
- raiz = new QNode;
- raiz->cubo = cubo;
+ root = new QNode;
+ root->cubo = cubo;
for(unsigned int i=0; i<8; i++) {
- raiz->nodos[i]=NULL;
+ root->nodos[i]=NULL;
}
}
Quadtree::~Quadtree() {
- borrar_rec(raiz);
+ borrar_rec(root);
}
void Quadtree::inicializar_nodos(QNode* padre)
{
double hhedge = padre->cubo.halfEdge()/2;
- //2 a la dim
for(unsigned int i=0; i<4; i++) {
padre->nodos[i] = new QNode;
padre->nodos[i]->cubo.setHalfEdge(hhedge);
@@ -128,11 +127,11 @@ void Quadtree::crear_rec(QNode* nodo, unsigned int \
nivel_actual, unsigned int ni }
QNode* Quadtree::get_raiz() {
- return raiz;
+ return root;
}
void Quadtree::crearNivel(unsigned int nivel) {
- crear_rec(raiz,0,nivel);
+ crear_rec(root,0,nivel);
}
void Quadtree::bajarNivel(QNode* nodo) {
diff --git a/analitzaplot/private/utils/quadtree.h \
b/analitzaplot/private/utils/quadtree.h index bea1f65..5ef0435 100644
--- a/analitzaplot/private/utils/quadtree.h
+++ b/analitzaplot/private/utils/quadtree.h
@@ -25,7 +25,6 @@
class Square : public QRectF
{
public:
- // QRectF(menor, mayor); en coordenadas de mundo
Square(const QPointF &c = QPointF(0,0), double hEdge = 1);
Square(double x, double y, double hEdge = 1);
@@ -45,7 +44,7 @@ struct QNode
/*
- Indice de los nodos
+ node index
-----
|2|4|
@@ -59,9 +58,9 @@ struct QNode
class Quadtree
{
private:
- QNode* raiz;
+ QNode* root;
- //Crea los hijos con los valores adecuados en los vertices
+ //create children with correct vertex values
void inicializar_nodos(QNode* padre);
void borrar_rec(QNode* nodo);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic