From 83d9315e6433b3c63da2db028aff567b43427b73 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 1 Nov 2013 11:38:20 -0700 Subject: [PATCH] Fix Chaikin tag parsing Also: - add 2 shape examples with Chaikin rule tag - add shapes to the glViewer - add a stub in the documentation Note: the Chaikin rule currently applied by Hbr appears to be somewhat off... fixes #236 --- documentation/subdivision_surfaces.rst | 8 ++ examples/glViewer/viewer.cpp | 6 + regression/common/shape_utils.h | 32 +++++- regression/shapes/catmark_chaikin0.h | 153 +++++++++++++++++++++++++ regression/shapes/catmark_chaikin1.h | 153 +++++++++++++++++++++++++ 5 files changed, 348 insertions(+), 4 deletions(-) create mode 100644 regression/shapes/catmark_chaikin0.h create mode 100644 regression/shapes/catmark_chaikin1.h diff --git a/documentation/subdivision_surfaces.rst b/documentation/subdivision_surfaces.rst index 8c953203..4de01130 100644 --- a/documentation/subdivision_surfaces.rst +++ b/documentation/subdivision_surfaces.rst @@ -216,6 +216,14 @@ to make the crease semi-sharp. ---- +Chaikin Rule +============ + +Chaikin's curve subdivision algorithm improves the appearance of multi-edge +semi-sharp creases with vayring weights. + +---- + Hierarchical Edits ================== diff --git a/examples/glViewer/viewer.cpp b/examples/glViewer/viewer.cpp index 28943b1a..74c43652 100644 --- a/examples/glViewer/viewer.cpp +++ b/examples/glViewer/viewer.cpp @@ -382,6 +382,12 @@ initializeShapes( ) { #include g_defaultShapes.push_back(SimpleShape(catmark_edgeonly, "catmark_edgeonly", kCatmark)); +#include + g_defaultShapes.push_back(SimpleShape(catmark_chaikin0, "catmark_chaikin0", kCatmark)); + +#include + g_defaultShapes.push_back(SimpleShape(catmark_chaikin1, "catmark_chaikin1", kCatmark)); + #include g_defaultShapes.push_back(SimpleShape(catmark_fan, "catmark_fan", kCatmark)); diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 46369d51..fba0561c 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -431,6 +431,30 @@ void applyTags( OpenSubdiv::HbrMesh * mesh, shape const * sh ) { mesh->SetFVarPropagateCorners( t->intargs[0] != 0 ); else printf( "expecting single int argument for \"facevaryingpropagatecorners\"\n" ); + } else if (t->name=="smoothtriangles") { + + OpenSubdiv::HbrCatmarkSubdivision * scheme = + dynamic_cast *>( mesh->GetSubdivision() ); + + if (not scheme) { + printf("the \"creasemethod\" tag can only be applied to Catmark meshes\n"); + continue; + } + + if ((int)t->intargs.size()==0) { + printf("the \"creasemethod\" tag expects an int argument\n"); + continue; + } + + if( t->intargs[0]==1 ) + scheme->SetTriangleSubdivisionMethod( + OpenSubdiv::HbrCatmarkSubdivision::k_Old); + else if( t->intargs[0]==2 ) + scheme->SetTriangleSubdivisionMethod( + OpenSubdiv::HbrCatmarkSubdivision::k_New); + else + printf("the \"creasemethod\" tag only accepts \"normal\" or \"chaikin\" as value (%s)\n", t->stringargs[0].c_str()); + } else if (t->name=="creasemethod") { OpenSubdiv::HbrCatmarkSubdivision * scheme = @@ -447,11 +471,11 @@ void applyTags( OpenSubdiv::HbrMesh * mesh, shape const * sh ) { } if( t->stringargs[0]=="normal" ) - scheme->SetTriangleSubdivisionMethod( - OpenSubdiv::HbrCatmarkSubdivision::k_Old); + scheme->SetCreaseSubdivisionMethod( + OpenSubdiv::HbrSubdivision::k_CreaseNormal); else if( t->stringargs[0]=="chaikin" ) - scheme->SetTriangleSubdivisionMethod( - OpenSubdiv::HbrCatmarkSubdivision::k_New); + scheme->SetCreaseSubdivisionMethod( + OpenSubdiv::HbrSubdivision::k_CreaseChaikin); else printf("the \"creasemethod\" tag only accepts \"normal\" or \"chaikin\" as value (%s)\n", t->stringargs[0].c_str()); diff --git a/regression/shapes/catmark_chaikin0.h b/regression/shapes/catmark_chaikin0.h new file mode 100644 index 00000000..f2c22738 --- /dev/null +++ b/regression/shapes/catmark_chaikin0.h @@ -0,0 +1,153 @@ +// +// Copyright 2013 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// + +static const std::string catmark_chaikin0 = +"# This file uses centimeters as units for non-parametric coordinates.\n" +"\n" +"v -0.500000 -1.500000 0.500000\n" +"v 0.500000 -1.500000 0.500000\n" +"v -0.500000 -0.900000 0.500000\n" +"v 0.500000 -0.900000 0.500000\n" +"v -0.500000 -0.300000 0.500000\n" +"v 0.500000 -0.300000 0.500000\n" +"v -0.500000 0.300000 0.500000\n" +"v 0.500000 0.300000 0.500000\n" +"v -0.500000 0.900000 0.500000\n" +"v 0.500000 0.900000 0.500000\n" +"v -0.500000 1.500000 0.500000\n" +"v 0.500000 1.500000 0.500000\n" +"v -0.500000 1.500000 -0.500000\n" +"v 0.500000 1.500000 -0.500000\n" +"v -0.500000 0.900000 -0.500000\n" +"v 0.500000 0.900000 -0.500000\n" +"v -0.500000 0.300000 -0.500000\n" +"v 0.500000 0.300000 -0.500000\n" +"v -0.500000 -0.300000 -0.500000\n" +"v 0.500000 -0.300000 -0.500000\n" +"v -0.500000 -0.900000 -0.500000\n" +"v 0.500000 -0.900000 -0.500000\n" +"v -0.500000 -1.500000 -0.500000\n" +"v 0.500000 -1.500000 -0.500000\n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vn -0.577350 -0.577350 0.577350\n" +"vn 0.577350 -0.577350 0.577350\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.577350 0.577350 0.577350\n" +"vn 0.577350 0.577350 0.577350\n" +"vn -0.577350 0.577350 -0.577350\n" +"vn 0.577350 0.577350 -0.577350\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.577350 -0.577350 -0.577350\n" +"vn 0.577350 -0.577350 -0.577350\n" +"s off\n" +"f 1/1/1 2/2/2 4/4/4 3/3/3\n" +"f 3/3/3 4/4/4 6/6/6 5/5/5\n" +"f 5/5/5 6/6/6 8/8/8 7/7/7\n" +"f 7/7/7 8/8/8 10/10/10 9/9/9\n" +"f 9/9/9 10/10/10 12/12/12 11/11/11\n" +"f 11/11/11 12/12/12 14/14/14 13/13/13\n" +"f 13/13/13 14/14/14 16/16/16 15/15/15\n" +"f 15/15/15 16/16/16 18/18/18 17/17/17\n" +"f 17/17/17 18/18/18 20/20/20 19/19/19\n" +"f 19/19/19 20/20/20 22/22/22 21/21/21\n" +"f 21/21/21 22/22/22 24/24/24 23/23/23\n" +"f 23/23/23 24/24/24 2/2/2 1/1/1\n" +"f 2/2/2 24/24/24 22/22/22 4/4/4\n" +"f 4/4/4 22/22/22 20/20/20 6/6/6\n" +"f 6/6/6 20/20/20 18/18/18 8/8/8\n" +"f 8/8/8 18/18/18 16/16/16 10/10/10\n" +"f 10/10/10 16/16/16 14/14/14 12/12/12\n" +"f 23/23/23 1/1/1 3/3/3 21/21/21\n" +"f 21/21/21 3/3/3 5/5/5 19/19/19\n" +"f 19/19/19 5/5/5 7/7/7 17/17/17\n" +"f 17/17/17 7/7/7 9/9/9 15/15/15\n" +"f 15/15/15 9/9/9 11/11/11 13/13/13\n" +"t crease 2/1/0 0 1 5.000000\n" +"t crease 2/1/0 10 11 5.000000\n" +"t crease 2/1/0 12 13 5.000000\n" +"t crease 2/1/0 22 23 5.000000\n" +"t crease 2/1/0 0 2 1.000000\n" +"t crease 2/1/0 1 3 1.000000\n" +"t crease 2/1/0 2 4 2.000000\n" +"t crease 2/1/0 3 5 2.000000\n" +"t crease 2/1/0 4 6 3.000000\n" +"t crease 2/1/0 5 7 3.000000\n" +"t crease 2/1/0 6 8 4.000000\n" +"t crease 2/1/0 7 9 4.000000\n" +"t crease 2/1/0 8 10 5.000000\n" +"t crease 2/1/0 9 11 5.000000\n" +"t crease 2/1/0 10 12 5.000000\n" +"t crease 2/1/0 11 13 5.000000\n" +"t crease 2/1/0 12 14 5.000000\n" +"t crease 2/1/0 13 15 5.000000\n" +"t crease 2/1/0 14 16 4.000000\n" +"t crease 2/1/0 15 17 4.000000\n" +"t crease 2/1/0 16 18 3.000000\n" +"t crease 2/1/0 17 19 3.000000\n" +"t crease 2/1/0 18 20 2.000000\n" +"t crease 2/1/0 19 21 2.000000\n" +"t crease 2/1/0 20 22 1.000000\n" +"t crease 2/1/0 21 23 1.000000\n" +"t crease 2/1/0 22 0 5.000000\n" +"t crease 2/1/0 23 1 5.000000\n" +"t creasemethod 0/0/1 normal\n" +"\n" +; diff --git a/regression/shapes/catmark_chaikin1.h b/regression/shapes/catmark_chaikin1.h new file mode 100644 index 00000000..1fec61fa --- /dev/null +++ b/regression/shapes/catmark_chaikin1.h @@ -0,0 +1,153 @@ +// +// Copyright 2013 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// + +static const std::string catmark_chaikin1 = +"# This file uses centimeters as units for non-parametric coordinates.\n" +"\n" +"v -0.500000 -1.500000 0.500000\n" +"v 0.500000 -1.500000 0.500000\n" +"v -0.500000 -0.900000 0.500000\n" +"v 0.500000 -0.900000 0.500000\n" +"v -0.500000 -0.300000 0.500000\n" +"v 0.500000 -0.300000 0.500000\n" +"v -0.500000 0.300000 0.500000\n" +"v 0.500000 0.300000 0.500000\n" +"v -0.500000 0.900000 0.500000\n" +"v 0.500000 0.900000 0.500000\n" +"v -0.500000 1.500000 0.500000\n" +"v 0.500000 1.500000 0.500000\n" +"v -0.500000 1.500000 -0.500000\n" +"v 0.500000 1.500000 -0.500000\n" +"v -0.500000 0.900000 -0.500000\n" +"v 0.500000 0.900000 -0.500000\n" +"v -0.500000 0.300000 -0.500000\n" +"v 0.500000 0.300000 -0.500000\n" +"v -0.500000 -0.300000 -0.500000\n" +"v 0.500000 -0.300000 -0.500000\n" +"v -0.500000 -0.900000 -0.500000\n" +"v 0.500000 -0.900000 -0.500000\n" +"v -0.500000 -1.500000 -0.500000\n" +"v 0.500000 -1.500000 -0.500000\n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vt 0 0 \n" +"vn -0.577350 -0.577350 0.577350\n" +"vn 0.577350 -0.577350 0.577350\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.707107 0.000000 0.707107\n" +"vn 0.707107 0.000000 0.707107\n" +"vn -0.577350 0.577350 0.577350\n" +"vn 0.577350 0.577350 0.577350\n" +"vn -0.577350 0.577350 -0.577350\n" +"vn 0.577350 0.577350 -0.577350\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.707107 0.000000 -0.707107\n" +"vn 0.707107 0.000000 -0.707107\n" +"vn -0.577350 -0.577350 -0.577350\n" +"vn 0.577350 -0.577350 -0.577350\n" +"s off\n" +"f 1/1/1 2/2/2 4/4/4 3/3/3\n" +"f 3/3/3 4/4/4 6/6/6 5/5/5\n" +"f 5/5/5 6/6/6 8/8/8 7/7/7\n" +"f 7/7/7 8/8/8 10/10/10 9/9/9\n" +"f 9/9/9 10/10/10 12/12/12 11/11/11\n" +"f 11/11/11 12/12/12 14/14/14 13/13/13\n" +"f 13/13/13 14/14/14 16/16/16 15/15/15\n" +"f 15/15/15 16/16/16 18/18/18 17/17/17\n" +"f 17/17/17 18/18/18 20/20/20 19/19/19\n" +"f 19/19/19 20/20/20 22/22/22 21/21/21\n" +"f 21/21/21 22/22/22 24/24/24 23/23/23\n" +"f 23/23/23 24/24/24 2/2/2 1/1/1\n" +"f 2/2/2 24/24/24 22/22/22 4/4/4\n" +"f 4/4/4 22/22/22 20/20/20 6/6/6\n" +"f 6/6/6 20/20/20 18/18/18 8/8/8\n" +"f 8/8/8 18/18/18 16/16/16 10/10/10\n" +"f 10/10/10 16/16/16 14/14/14 12/12/12\n" +"f 23/23/23 1/1/1 3/3/3 21/21/21\n" +"f 21/21/21 3/3/3 5/5/5 19/19/19\n" +"f 19/19/19 5/5/5 7/7/7 17/17/17\n" +"f 17/17/17 7/7/7 9/9/9 15/15/15\n" +"f 15/15/15 9/9/9 11/11/11 13/13/13\n" +"t crease 2/1/0 0 1 5.000000\n" +"t crease 2/1/0 10 11 5.000000\n" +"t crease 2/1/0 12 13 5.000000\n" +"t crease 2/1/0 22 23 5.000000\n" +"t crease 2/1/0 0 2 1.000000\n" +"t crease 2/1/0 1 3 1.000000\n" +"t crease 2/1/0 2 4 2.000000\n" +"t crease 2/1/0 3 5 2.000000\n" +"t crease 2/1/0 4 6 3.000000\n" +"t crease 2/1/0 5 7 3.000000\n" +"t crease 2/1/0 6 8 4.000000\n" +"t crease 2/1/0 7 9 4.000000\n" +"t crease 2/1/0 8 10 5.000000\n" +"t crease 2/1/0 9 11 5.000000\n" +"t crease 2/1/0 10 12 5.000000\n" +"t crease 2/1/0 11 13 5.000000\n" +"t crease 2/1/0 12 14 5.000000\n" +"t crease 2/1/0 13 15 5.000000\n" +"t crease 2/1/0 14 16 4.000000\n" +"t crease 2/1/0 15 17 4.000000\n" +"t crease 2/1/0 16 18 3.000000\n" +"t crease 2/1/0 17 19 3.000000\n" +"t crease 2/1/0 18 20 2.000000\n" +"t crease 2/1/0 19 21 2.000000\n" +"t crease 2/1/0 20 22 1.000000\n" +"t crease 2/1/0 21 23 1.000000\n" +"t crease 2/1/0 22 0 5.000000\n" +"t crease 2/1/0 23 1 5.000000\n" +"t creasemethod 0/0/1 chaikin\n" +"\n" +;