Simbody
3.4 (development)
|
00001 #ifndef SimTK_BICUBIC_SURFACE_H_ 00002 #define SimTK_BICUBIC_SURFACE_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKmath * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2011-12 Stanford University and the Authors. * 00013 * Authors: Matthew Millard, Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00031 #include "SimTKcommon.h" 00032 #include "simmath/internal/common.h" 00033 #include "simmath/internal/Geo.h" 00034 #include "simmath/internal/Geo_BicubicHermitePatch.h" 00035 #include "simmath/internal/Geo_BicubicBezierPatch.h" 00036 00037 #include <limits> 00038 00039 namespace SimTK { 00040 00041 //============================================================================== 00042 // CLASS BICUBIC SURFACE 00043 //============================================================================== 00158 class SimTK_SIMMATH_EXPORT BicubicSurface { 00159 public: 00160 class PatchHint; // See below for definition of PatchHint. 00161 00164 BicubicSurface() : guts(0) {} 00167 ~BicubicSurface(); 00170 BicubicSurface(const BicubicSurface& source); 00175 BicubicSurface& operator=(const BicubicSurface& source); 00176 00177 00201 BicubicSurface(const Vector& x, const Vector& y, const Matrix& f, 00202 Real smoothness=0); 00203 00231 BicubicSurface(const Vec2& XY, const Vec2& spacing, 00232 const Matrix& f, Real smoothness=0); 00233 00247 Real calcValue(const Vec2& XY, PatchHint& hint) const; 00248 00252 Real calcValue(const Vec2& XY) const; 00253 00266 UnitVec3 calcUnitNormal(const Vec2& XY, PatchHint& hint) const; 00267 00271 UnitVec3 calcUnitNormal(const Vec2& XY) const; 00272 00298 Real calcDerivative(const Array_<int>& derivComponents, 00299 const Vec2& XY, PatchHint& hint) const; 00300 00304 Real calcDerivative(const Array_<int>& derivComponents, 00305 const Vec2& XY) const; 00306 00318 bool isSurfaceDefined(const Vec2& XY) const; 00319 00322 Vec2 getMinXY() const; 00325 Vec2 getMaxXY() const; 00326 00335 PolygonalMesh createPolygonalMesh(Real resolution=1) const; 00336 00337 //-------------------------------------------------------------------------- 00347 int getNumAccesses() const; 00353 int getNumAccessesSamePoint() const; 00359 int getNumAccessesSamePatch() const; 00366 int getNumAccessesNearbyPatch() const; 00371 void resetStatistics() const; 00375 //-------------------------------------------------------------------------- 00393 BicubicSurface(const Vector& x, const Vector& y, const Matrix& f, 00394 const Matrix& fx, const Matrix& fy, const Matrix& fxy); 00396 BicubicSurface(const Vec2& XY, const Vec2& spacing, const Matrix& f, 00397 const Matrix& fx, const Matrix& fy, const Matrix& fxy); 00398 00423 void calcParaboloid(const Vec2& XY, PatchHint& hint, 00424 Transform& X_SP, Vec2& k) const; 00428 void calcParaboloid(const Vec2& XY, Transform& X_SP, Vec2& k) const; 00429 00433 void getNumPatches(int& nx, int& ny) const; 00434 00438 Geo::BicubicHermitePatch calcHermitePatch(int x, int y) const; 00439 00443 Geo::BicubicBezierPatch calcBezierPatch(int x, int y) const; 00446 //-------------------------------------------------------------------------- 00455 bool isEmpty() const {return guts==0;} 00456 00462 void clear(); // Hide from Doxygen. 00466 class Guts; // Opaque implementation class. 00467 const BicubicSurface::Guts& getGuts() const 00468 { assert(guts); return *guts; } 00470 private: 00471 BicubicSurface::Guts* guts; 00472 }; // END class BicubicSurface 00473 00474 00475 00476 //============================================================================== 00477 // CLASS BICUBIC FUNCTION :: PATCH HINT 00478 //============================================================================== 00482 class SimTK_SIMMATH_EXPORT BicubicSurface::PatchHint { 00483 public: 00486 PatchHint(); 00489 PatchHint(const PatchHint& source); 00493 PatchHint& operator=(const PatchHint& source); 00495 ~PatchHint(); 00496 00499 bool isEmpty() const; 00502 void clear(); 00503 // Hide from Doxygen 00505 class Guts; // Hidden implementation of PatchHint. 00506 const Guts& getGuts() const {return *guts;} 00507 Guts& updGuts() {return *guts;} 00509 private: 00510 Guts* guts; 00511 }; 00512 00513 00514 00515 //============================================================================== 00516 // CLASS BICUBIC FUNCTION 00517 //============================================================================== 00518 00532 class SimTK_SIMMATH_EXPORT BicubicFunction : public Function_<Real> { 00533 public: 00536 BicubicFunction(const BicubicSurface& surface) : surface(surface) {} 00537 00540 const BicubicSurface& getBicubicSurface() const {return surface;} 00541 00549 virtual Real calcValue(const Vector& XY) const { 00550 SimTK_ERRCHK1(XY.size()==2, "BicubicFunction::calcValue()", 00551 "The argument Vector XY must have exactly 2 elements but had %d.", 00552 XY.size()); 00553 return surface.calcValue(Vec2(XY[0],XY[1]), hint); 00554 } 00555 00575 virtual Real calcDerivative(const Array_<int>& derivComponents, 00576 const Vector& XY) const { 00577 SimTK_ERRCHK1(XY.size()==2, "BicubicFunction::calcDerivative()", 00578 "The argument Vector XY must have exactly 2 elements but had %d.", 00579 XY.size()); 00580 return surface.calcDerivative(derivComponents, Vec2(XY[0],XY[1]), hint); 00581 } 00582 00585 virtual int getArgumentSize() const {return 2;} 00586 00592 virtual int getMaxDerivativeOrder() const 00593 { return std::numeric_limits<int>::max(); } 00594 private: 00595 BicubicSurface surface; 00596 mutable BicubicSurface::PatchHint hint; 00597 }; 00598 00599 00600 00601 }; //namespace 00602 //============================================================================= 00603 //============================================================================= 00604 00605 #endif // SimTK_BICUBIC_SURFACE_H_