Skip to content
Snippets Groups Projects
Select Git revision
  • 8cda8cc2c87136943d2913b96d9841eac3c6b965
  • master default
  • cgnsUnstructured
  • partitioning
  • poppler
  • HighOrderBLCurving
  • gmsh_3_0_4
  • gmsh_3_0_3
  • gmsh_3_0_2
  • gmsh_3_0_1
  • gmsh_3_0_0
  • gmsh_2_16_0
  • gmsh_2_15_0
  • gmsh_2_14_1
  • gmsh_2_14_0
  • gmsh_2_13_2
  • gmsh_2_13_1
  • gmsh_2_12_0
  • gmsh_2_11_0
  • gmsh_2_10_1
  • gmsh_2_10_0
  • gmsh_2_9_3
  • gmsh_2_9_2
  • gmsh_2_9_1
  • gmsh_2_9_0
  • gmsh_2_8_6
26 results

SmoothData.h

Blame
  • Forked from gmsh / gmsh
    Source project has a limited visibility.
    SmoothData.h 3.10 KiB
    #ifndef _SMOOTH_DATA_H_
    #define _SMOOTH_DATA_H_
    
    // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
    //
    // This program is free software; you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation; either version 2 of the License, or
    // (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with this program; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    // USA.
    // 
    // Please report all bugs and problems to <gmsh@geuz.org>.
    
    #include <set>
    #include <vector>
    #include <string>
    
    // Basic coordinate-based floating point data averager
    
    struct xyzv {
      double x, y, z, *vals;
      int nbvals;
      int nboccurences;
      static double eps;
      xyzv(double xx, double yy, double zz)
        : x(xx), y(yy), z(zz), vals(0), nbvals(0), nboccurences(0) {}
      ~xyzv(){ if(vals) delete [] vals; }
      // these are needed for set<> operations since the default copy
      // constructor won't allocate *vals
      xyzv(const xyzv & other);
      xyzv & operator = (const xyzv &other);
      void update(int n, double *v);
    };
    
    struct lessthanxyzv {
      bool operator () (const xyzv &p2, const xyzv &p1) const
      {
        if(p1.x - p2.x > xyzv::eps)
          return true;
        if(p1.x - p2.x < -xyzv::eps)
          return false;
        if(p1.y - p2.y > xyzv::eps)
          return true;
        if(p1.y - p2.y < -xyzv::eps)
          return false;
        if(p1.z - p2.z > xyzv::eps)
          return true;
        return false;
      }
    };
    
    class smooth_data{
     private:
      std::set<xyzv, lessthanxyzv> c;  
     public:
      smooth_data() {}
      void add(double x, double y, double z, int n, double *vals);
      bool get(double x, double y, double z, int n, double *vals);
      void normalize();
      bool exportview(std::string filename);
    };
    
    // Normal smoother with threshold (saves memory by storing normals as
    // chars and coordinates as floats)
    
    struct nnb
    {
      char nx, ny, nz;
      unsigned char nb;
    };
    
    struct xyzn
    {
      float x, y, z;
      std::vector<nnb> n;
      static float eps;
      xyzn(float xx, float yy, float zz) : x(xx), y(yy), z(zz){}
      ~xyzn(){}
      float angle(int i, char n0, char n1, char n2);
      void update(char n0, char n1, char n2, float tol);
    };
    
    struct lessthanxyzn
    {
      bool operator () (const xyzn &p2, const xyzn &p1) const
      {
        if(p1.x - p2.x > xyzn::eps)
          return true;
        if(p1.x - p2.x < -xyzn::eps)
          return false;
        if(p1.y - p2.y > xyzn::eps)
          return true;
        if(p1.y - p2.y < -xyzn::eps)
          return false;
        if(p1.z - p2.z > xyzn::eps)
          return true;
        return false;
      }
    };
    
    class smooth_normals{
     private:
      float tol;
      std::set<xyzn, lessthanxyzn> c;  
     public:
      smooth_normals(double angle) : tol(angle) {}
      void add(double x, double y, double z, double nx, double ny, double nz);
      bool get(double x, double y, double z, double &nx, double &ny, double &nz);
    };
    
    #endif