File indexing completed on 2024-05-12 15:20:08
0001 /************************************************************************************* 0002 * Copyright (C) 2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #ifndef MARCHINGSQUARES_H 0020 #define MARCHINGSQUARES_H 0021 0022 #include "quadtree.h" 0023 0024 #include <QList> 0025 #include <QPair> 0026 #include <QVector> 0027 #include <qmath.h> 0028 #include <QLineF> 0029 0030 struct sLimitesEspacio2D { 0031 double minX; 0032 double maxX; 0033 double minY; 0034 double maxY; 0035 }; 0036 0037 struct sMarching_Square { 0038 QPointF centro; 0039 double medio_lado; 0040 unsigned short int tipo; 0041 double vertices[4]; 0042 }; 0043 0044 struct sArista2D { 0045 QPointF corte; 0046 unsigned int vertices[2]; 0047 }; 0048 0049 //TODO very bad implementation ... we need to use interval arithmetic plus root finding 0050 //to know if a 0 belongs to f(square) 0051 0052 class MarchingSquares 0053 { 0054 public: 0055 virtual double evalScalarField(double x, double y) = 0; 0056 0057 void setWorld(double minx, double maxx, double miny, double maxy); 0058 0059 public: 0060 private: 0061 double largo_mundo; 0062 double min_grid; 0063 sLimitesEspacio2D mundo; 0064 //Evaluar un cubo 0065 sMarching_Square evaluar_cubo(const Square& cubo); 0066 0067 //Busqueda recursiva (breadth search) 0068 QList<Square> breadth_rec(int cubos_lado); 0069 0070 //Busqueda recursiva (depth search) 0071 QList<sMarching_Square> depth_rec(Quadtree *arbol, QNode *nodo); 0072 0073 public: 0074 MarchingSquares(/*double min_grid, double arista_mundo, sLimitesEspacio2D limites*/); 0075 0076 virtual ~MarchingSquares(); 0077 0078 QList<sMarching_Square> ejecutar(); 0079 0080 friend class ImplicitSurf; 0081 public: 0082 void buildGeometry(); 0083 0084 QVector< QPair< QPointF, QPointF > > _faces_; 0085 0086 void _addTri(const QPointF &a, const QPointF &b); 0087 0088 private: 0089 QList<sArista2D> calcular_cortes(const sMarching_Square &cubo); 0090 bool signo_opuesto(double a, double b); 0091 double lineal(double vert_1, double vert_2); 0092 void agregar_triangulos(QList<QPointF> &lista_triangulos); 0093 void identificar_tipo(const sMarching_Square &cubo); 0094 void tipo01(QList<sArista2D> aristas); 0095 void tipo05(QList<sArista2D> aristas, const sMarching_Square &cubo); 0096 0097 private: 0098 double fixed_x; 0099 double fixed_y; 0100 0101 double fy(double y) { return evalScalarField(fixed_x, y); } 0102 double fx(double x) { return evalScalarField(x, fixed_y); } 0103 }; 0104 0105 #endif