Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/extensions/authoring/source/NvBlastExtAuthoringMeshNoiser.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 #ifndef NVBLASTEXTAUTHORINGMESHNOISER_H
00030 #define NVBLASTEXTAUTHORINGMESHNOISER_H
00031 #include <vector>
00032 #include <map>
00033 #include "NvBlastExtAuthoringInternalCommon.h"
00034 
00035 namespace Nv
00036 {
00037     namespace Blast
00038     {
00039         class SimplexNoise;
00040 
00044         struct EdgeToTriangles
00045         {
00046             int32_t tr[2];
00047             int32_t c;
00048             EdgeToTriangles()
00049             {
00050                 c = 0;
00051             }
00055             void    add(int32_t t)
00056             {
00057                 tr[c] = t;
00058                 ++c;
00059             }
00063             void    replace(int32_t from, int32_t to)
00064             {
00065                 if (tr[0] == from)
00066                 {
00067                     tr[0] = to;
00068                 }
00069                 else
00070                 {
00071                     if (c == 2 && tr[1] == from)
00072                     {
00073                         tr[1] = to;
00074                     }
00075                 }
00076             }
00080             int32_t getNot(int32_t id)
00081             {
00082                 if (tr[0] != id)
00083                 {
00084                     return tr[0];
00085                 }
00086                 if (c == 2 && tr[1] != id)
00087                 {
00088                     return tr[1];
00089                 }
00090                 return -1;
00091             }
00092 
00093         };
00094 
00099         class MeshNoiser
00100         {
00101         public:
00102             MeshNoiser()
00103             {
00104                 reset();
00105             }
00106 
00107             void reset();
00108 
00112             enum EdgeFlag { INTERNAL_EDGE, EXTERNAL_BORDER_EDGE, INTERNAL_BORDER_EDGE, EXTERNAL_EDGE, NONE };
00113 
00114     
00118             void setMesh(const std::vector<Triangle>& mesh);
00119 
00124             void                            tesselateInternalSurface(float maxLen);
00125 
00133             void                            applyNoise(SimplexNoise& noise, float falloff, int32_t relaxIterations, float relaxFactor);
00134 
00135             std::vector<Triangle>           getMesh();
00136 
00137         private:
00138             physx::PxVec3                       mOffset;
00139             float                               mScale;
00140             bool                                isTesselated;
00144             std::vector<Vertex>                 mVertices;
00145             std::vector<TriangleIndexed>        mTriangles;
00146             std::vector<Edge>                   mEdges;
00147             std::map<Vertex, int32_t, VrtComp>  mVertMap;
00148             std::map<Edge, int32_t>             mEdgeMap;
00149 
00150 
00154             std::vector<Triangle>           mResultTriangles;
00155 
00156 
00157             int32_t                         addVerticeIfNotExist(const Vertex& p);
00158             int32_t                         addEdge(const Edge& e);
00159             int32_t                         findEdge(const Edge& e);
00160 
00161 
00162 
00163             void                            collapseEdge(int32_t id);
00164             void                            divideEdge(int32_t id);
00165             void                            updateVertEdgeInfo();
00166             void                            updateEdgeTriangleInfo();
00167             void                            relax(int32_t iterations, float factor, std::vector<Vertex>& vertices);
00168             void                            recalcNoiseDirs();
00169 
00170 
00171             std::vector<bool>                           mRestrictionFlag;
00172             std::vector<EdgeFlag>                       mEdgeFlag;
00173             std::vector<EdgeToTriangles>                mTrMeshEdToTr;
00174             std::vector<int32_t>                        mVertexValence;
00175             std::vector<std::vector<int32_t> >          mVertexToTriangleMap;
00176 
00177 
00178 
00179             std::vector<float>                          mVerticesDistances;
00180             std::vector<physx::PxVec3>                  mVerticesNormalsSmoothed;
00181             std::vector<uint32_t>                       mPositionMappedVrt;
00182             std::vector<std::vector<int32_t> >          mGeometryGraph;
00183 
00184             void                                        prebuildEdgeFlagArray();
00185             void                                        computePositionedMapping();
00186             void                                        computeFalloffAndNormals();
00187 
00188             void                                        prebuildTesselatedTriangles();
00189         };
00190 
00191     } // namespace Blast
00192 } // namespace Nv
00193 #endif // ! NVBLASTEXTAUTHORINGMESHNOISER_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com