From e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2019 06:17:24 +0200 Subject: ClangFormat: apply to source, most of intern Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat --- .../freestyle/intern/application/AppCanvas.cpp | 208 +- .../freestyle/intern/application/AppCanvas.h | 127 +- .../freestyle/intern/application/AppConfig.cpp | 73 +- .../freestyle/intern/application/AppConfig.h | 90 +- .../freestyle/intern/application/AppView.cpp | 188 +- .../blender/freestyle/intern/application/AppView.h | 414 +- .../freestyle/intern/application/Controller.cpp | 1440 +++---- .../freestyle/intern/application/Controller.h | 346 +- .../intern/blender_interface/BlenderFileLoader.cpp | 1314 +++--- .../intern/blender_interface/BlenderFileLoader.h | 141 +- .../blender_interface/BlenderStrokeRenderer.cpp | 1479 +++---- .../blender_interface/BlenderStrokeRenderer.h | 113 +- .../intern/blender_interface/BlenderStyleModule.h | 96 +- .../intern/blender_interface/FRS_freestyle.cpp | 1093 ++--- source/blender/freestyle/intern/geometry/BBox.h | 222 +- .../blender/freestyle/intern/geometry/Bezier.cpp | 130 +- source/blender/freestyle/intern/geometry/Bezier.h | 80 +- .../blender/freestyle/intern/geometry/FastGrid.cpp | 66 +- .../blender/freestyle/intern/geometry/FastGrid.h | 68 +- .../blender/freestyle/intern/geometry/FitCurve.cpp | 670 +-- .../blender/freestyle/intern/geometry/FitCurve.h | 141 +- source/blender/freestyle/intern/geometry/Geom.h | 62 +- .../freestyle/intern/geometry/GeomCleaner.cpp | 357 +- .../freestyle/intern/geometry/GeomCleaner.h | 367 +- .../freestyle/intern/geometry/GeomUtils.cpp | 1191 +++--- .../blender/freestyle/intern/geometry/GeomUtils.h | 146 +- source/blender/freestyle/intern/geometry/Grid.cpp | 606 +-- source/blender/freestyle/intern/geometry/Grid.h | 633 +-- .../freestyle/intern/geometry/GridHelpers.cpp | 30 +- .../freestyle/intern/geometry/GridHelpers.h | 268 +- .../blender/freestyle/intern/geometry/HashGrid.cpp | 20 +- .../blender/freestyle/intern/geometry/HashGrid.h | 120 +- source/blender/freestyle/intern/geometry/Noise.cpp | 327 +- source/blender/freestyle/intern/geometry/Noise.h | 59 +- source/blender/freestyle/intern/geometry/Polygon.h | 339 +- .../blender/freestyle/intern/geometry/SweepLine.h | 548 +-- source/blender/freestyle/intern/geometry/VecMat.h | 1576 ++++--- .../freestyle/intern/geometry/matrix_util.cpp | 426 +- .../freestyle/intern/geometry/matrix_util.h | 34 +- .../freestyle/intern/geometry/normal_cycle.cpp | 75 +- .../freestyle/intern/geometry/normal_cycle.h | 146 +- .../freestyle/intern/image/GaussianFilter.cpp | 89 +- .../freestyle/intern/image/GaussianFilter.h | 189 +- source/blender/freestyle/intern/image/Image.h | 725 ++-- .../freestyle/intern/image/ImagePyramid.cpp | 216 +- .../blender/freestyle/intern/image/ImagePyramid.h | 144 +- .../blender/freestyle/intern/python/BPy_BBox.cpp | 115 +- source/blender/freestyle/intern/python/BPy_BBox.h | 5 +- .../intern/python/BPy_BinaryPredicate0D.cpp | 216 +- .../intern/python/BPy_BinaryPredicate0D.h | 8 +- .../intern/python/BPy_BinaryPredicate1D.cpp | 270 +- .../intern/python/BPy_BinaryPredicate1D.h | 7 +- .../intern/python/BPy_ContextFunctions.cpp | 408 +- .../freestyle/intern/python/BPy_Convert.cpp | 990 ++--- .../blender/freestyle/intern/python/BPy_Convert.h | 88 +- .../freestyle/intern/python/BPy_Freestyle.cpp | 860 ++-- .../freestyle/intern/python/BPy_FrsMaterial.cpp | 797 ++-- .../freestyle/intern/python/BPy_FrsMaterial.h | 7 +- .../freestyle/intern/python/BPy_FrsNoise.cpp | 466 ++- .../blender/freestyle/intern/python/BPy_FrsNoise.h | 7 +- source/blender/freestyle/intern/python/BPy_Id.cpp | 245 +- source/blender/freestyle/intern/python/BPy_Id.h | 3 +- .../intern/python/BPy_IntegrationType.cpp | 328 +- .../freestyle/intern/python/BPy_IntegrationType.h | 3 +- .../freestyle/intern/python/BPy_Interface0D.cpp | 392 +- .../freestyle/intern/python/BPy_Interface0D.h | 8 +- .../freestyle/intern/python/BPy_Interface1D.cpp | 445 +- .../freestyle/intern/python/BPy_Interface1D.h | 9 +- .../freestyle/intern/python/BPy_Iterator.cpp | 304 +- .../blender/freestyle/intern/python/BPy_Iterator.h | 4 +- .../freestyle/intern/python/BPy_MediumType.cpp | 114 +- .../freestyle/intern/python/BPy_MediumType.h | 8 +- .../blender/freestyle/intern/python/BPy_Nature.cpp | 417 +- .../blender/freestyle/intern/python/BPy_Nature.h | 2 +- .../freestyle/intern/python/BPy_Operators.cpp | 1347 +++--- .../freestyle/intern/python/BPy_Operators.h | 3 +- .../blender/freestyle/intern/python/BPy_SShape.cpp | 356 +- .../blender/freestyle/intern/python/BPy_SShape.h | 5 +- .../intern/python/BPy_StrokeAttribute.cpp | 985 +++-- .../freestyle/intern/python/BPy_StrokeAttribute.h | 8 +- .../freestyle/intern/python/BPy_StrokeShader.cpp | 402 +- .../freestyle/intern/python/BPy_StrokeShader.h | 8 +- .../intern/python/BPy_UnaryFunction0D.cpp | 171 +- .../freestyle/intern/python/BPy_UnaryFunction0D.h | 6 +- .../intern/python/BPy_UnaryFunction1D.cpp | 163 +- .../freestyle/intern/python/BPy_UnaryFunction1D.h | 6 +- .../intern/python/BPy_UnaryPredicate0D.cpp | 236 +- .../freestyle/intern/python/BPy_UnaryPredicate0D.h | 6 +- .../intern/python/BPy_UnaryPredicate1D.cpp | 323 +- .../freestyle/intern/python/BPy_UnaryPredicate1D.h | 6 +- .../freestyle/intern/python/BPy_ViewMap.cpp | 236 +- .../blender/freestyle/intern/python/BPy_ViewMap.h | 3 +- .../freestyle/intern/python/BPy_ViewShape.cpp | 489 +-- .../freestyle/intern/python/BPy_ViewShape.h | 7 +- .../python/BinaryPredicate1D/BPy_FalseBP1D.cpp | 109 +- .../python/BinaryPredicate1D/BPy_FalseBP1D.h | 2 +- .../python/BinaryPredicate1D/BPy_Length2DBP1D.cpp | 111 +- .../python/BinaryPredicate1D/BPy_Length2DBP1D.h | 5 +- .../BinaryPredicate1D/BPy_SameShapeIdBP1D.cpp | 109 +- .../python/BinaryPredicate1D/BPy_SameShapeIdBP1D.h | 5 +- .../python/BinaryPredicate1D/BPy_TrueBP1D.cpp | 109 +- .../intern/python/BinaryPredicate1D/BPy_TrueBP1D.h | 2 +- .../BPy_ViewMapGradientNormBP1D.cpp | 157 +- .../BPy_ViewMapGradientNormBP1D.h | 4 +- .../blender/freestyle/intern/python/Director.cpp | 474 +-- source/blender/freestyle/intern/python/Director.h | 24 +- .../intern/python/Interface0D/BPy_CurvePoint.cpp | 388 +- .../intern/python/Interface0D/BPy_CurvePoint.h | 4 +- .../intern/python/Interface0D/BPy_SVertex.cpp | 652 +-- .../intern/python/Interface0D/BPy_SVertex.h | 4 +- .../intern/python/Interface0D/BPy_ViewVertex.cpp | 228 +- .../intern/python/Interface0D/BPy_ViewVertex.h | 4 +- .../Interface0D/CurvePoint/BPy_StrokeVertex.cpp | 539 +-- .../Interface0D/CurvePoint/BPy_StrokeVertex.h | 7 +- .../Interface0D/ViewVertex/BPy_NonTVertex.cpp | 166 +- .../python/Interface0D/ViewVertex/BPy_NonTVertex.h | 4 +- .../python/Interface0D/ViewVertex/BPy_TVertex.cpp | 299 +- .../python/Interface0D/ViewVertex/BPy_TVertex.h | 4 +- .../intern/python/Interface1D/BPy_FEdge.cpp | 476 ++- .../intern/python/Interface1D/BPy_FEdge.h | 4 +- .../intern/python/Interface1D/BPy_FrsCurve.cpp | 301 +- .../intern/python/Interface1D/BPy_FrsCurve.h | 4 +- .../intern/python/Interface1D/BPy_Stroke.cpp | 658 +-- .../intern/python/Interface1D/BPy_Stroke.h | 6 +- .../intern/python/Interface1D/BPy_ViewEdge.cpp | 451 +- .../intern/python/Interface1D/BPy_ViewEdge.h | 4 +- .../intern/python/Interface1D/Curve/BPy_Chain.cpp | 262 +- .../intern/python/Interface1D/Curve/BPy_Chain.h | 4 +- .../python/Interface1D/FEdge/BPy_FEdgeSharp.cpp | 572 +-- .../python/Interface1D/FEdge/BPy_FEdgeSharp.h | 4 +- .../python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp | 334 +- .../python/Interface1D/FEdge/BPy_FEdgeSmooth.h | 7 +- .../python/Iterator/BPy_AdjacencyIterator.cpp | 301 +- .../intern/python/Iterator/BPy_AdjacencyIterator.h | 9 +- .../python/Iterator/BPy_ChainPredicateIterator.cpp | 282 +- .../python/Iterator/BPy_ChainPredicateIterator.h | 10 +- .../Iterator/BPy_ChainSilhouetteIterator.cpp | 210 +- .../python/Iterator/BPy_ChainSilhouetteIterator.h | 6 +- .../python/Iterator/BPy_ChainingIterator.cpp | 383 +- .../intern/python/Iterator/BPy_ChainingIterator.h | 7 +- .../python/Iterator/BPy_CurvePointIterator.cpp | 222 +- .../python/Iterator/BPy_CurvePointIterator.h | 7 +- .../python/Iterator/BPy_Interface0DIterator.cpp | 333 +- .../python/Iterator/BPy_Interface0DIterator.h | 11 +- .../intern/python/Iterator/BPy_SVertexIterator.cpp | 267 +- .../intern/python/Iterator/BPy_SVertexIterator.h | 7 +- .../python/Iterator/BPy_StrokeVertexIterator.cpp | 427 +- .../python/Iterator/BPy_StrokeVertexIterator.h | 13 +- .../python/Iterator/BPy_ViewEdgeIterator.cpp | 343 +- .../intern/python/Iterator/BPy_ViewEdgeIterator.h | 7 +- .../Iterator/BPy_orientedViewEdgeIterator.cpp | 239 +- .../python/Iterator/BPy_orientedViewEdgeIterator.h | 10 +- .../StrokeShader/BPy_BackboneStretcherShader.cpp | 127 +- .../StrokeShader/BPy_BackboneStretcherShader.h | 6 +- .../python/StrokeShader/BPy_BezierCurveShader.cpp | 127 +- .../python/StrokeShader/BPy_BezierCurveShader.h | 7 +- .../StrokeShader/BPy_BlenderTextureShader.cpp | 162 +- .../python/StrokeShader/BPy_BlenderTextureShader.h | 8 +- .../python/StrokeShader/BPy_CalligraphicShader.cpp | 162 +- .../python/StrokeShader/BPy_CalligraphicShader.h | 4 +- .../python/StrokeShader/BPy_ColorNoiseShader.cpp | 125 +- .../python/StrokeShader/BPy_ColorNoiseShader.h | 7 +- .../StrokeShader/BPy_ConstantColorShader.cpp | 137 +- .../python/StrokeShader/BPy_ConstantColorShader.h | 7 +- .../StrokeShader/BPy_ConstantThicknessShader.cpp | 125 +- .../StrokeShader/BPy_ConstantThicknessShader.h | 6 +- .../BPy_ConstrainedIncreasingThicknessShader.cpp | 138 +- .../BPy_ConstrainedIncreasingThicknessShader.h | 6 +- .../python/StrokeShader/BPy_GuidingLinesShader.cpp | 141 +- .../python/StrokeShader/BPy_GuidingLinesShader.h | 7 +- .../StrokeShader/BPy_IncreasingColorShader.cpp | 168 +- .../StrokeShader/BPy_IncreasingColorShader.h | 7 +- .../StrokeShader/BPy_IncreasingThicknessShader.cpp | 137 +- .../StrokeShader/BPy_IncreasingThicknessShader.h | 6 +- .../StrokeShader/BPy_PolygonalizationShader.cpp | 139 +- .../StrokeShader/BPy_PolygonalizationShader.h | 6 +- .../python/StrokeShader/BPy_SamplingShader.cpp | 121 +- .../python/StrokeShader/BPy_SamplingShader.h | 7 +- .../python/StrokeShader/BPy_SmoothingShader.cpp | 178 +- .../python/StrokeShader/BPy_SmoothingShader.h | 7 +- .../python/StrokeShader/BPy_SpatialNoiseShader.cpp | 162 +- .../python/StrokeShader/BPy_SpatialNoiseShader.h | 7 +- .../StrokeShader/BPy_StrokeTextureStepShader.cpp | 125 +- .../StrokeShader/BPy_StrokeTextureStepShader.h | 7 +- .../StrokeShader/BPy_ThicknessNoiseShader.cpp | 129 +- .../python/StrokeShader/BPy_ThicknessNoiseShader.h | 7 +- .../python/StrokeShader/BPy_TipRemoverShader.cpp | 123 +- .../python/StrokeShader/BPy_TipRemoverShader.h | 7 +- .../UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp | 276 +- .../UnaryFunction0D/BPy_UnaryFunction0DDouble.h | 8 +- .../BPy_UnaryFunction0DEdgeNature.cpp | 181 +- .../BPy_UnaryFunction0DEdgeNature.h | 7 +- .../UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp | 240 +- .../UnaryFunction0D/BPy_UnaryFunction0DFloat.h | 8 +- .../UnaryFunction0D/BPy_UnaryFunction0DId.cpp | 174 +- .../python/UnaryFunction0D/BPy_UnaryFunction0DId.h | 8 +- .../BPy_UnaryFunction0DMaterial.cpp | 181 +- .../UnaryFunction0D/BPy_UnaryFunction0DMaterial.h | 7 +- .../BPy_UnaryFunction0DUnsigned.cpp | 182 +- .../UnaryFunction0D/BPy_UnaryFunction0DUnsigned.h | 7 +- .../UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp | 188 +- .../UnaryFunction0D/BPy_UnaryFunction0DVec2f.h | 8 +- .../UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp | 180 +- .../UnaryFunction0D/BPy_UnaryFunction0DVec3f.h | 8 +- .../BPy_UnaryFunction0DVectorViewShape.cpp | 196 +- .../BPy_UnaryFunction0DVectorViewShape.h | 7 +- .../BPy_UnaryFunction0DViewShape.cpp | 198 +- .../UnaryFunction0D/BPy_UnaryFunction0DViewShape.h | 7 +- .../UnaryFunction0D_Id/BPy_ShapeIdF0D.cpp | 132 +- .../UnaryFunction0D_Id/BPy_ShapeIdF0D.h | 3 +- .../UnaryFunction0D_Material/BPy_MaterialF0D.cpp | 138 +- .../UnaryFunction0D_Material/BPy_MaterialF0D.h | 6 +- .../BPy_CurveNatureF0D.cpp | 120 +- .../BPy_CurveNatureF0D.h | 6 +- .../UnaryFunction0D_Vec2f/BPy_Normal2DF0D.cpp | 124 +- .../UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h | 6 +- .../BPy_VertexOrientation2DF0D.cpp | 128 +- .../BPy_VertexOrientation2DF0D.h | 5 +- .../BPy_VertexOrientation3DF0D.cpp | 128 +- .../BPy_VertexOrientation3DF0D.h | 5 +- .../BPy_GetOccludeeF0D.cpp | 118 +- .../UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h | 6 +- .../UnaryFunction0D_ViewShape/BPy_GetShapeF0D.cpp | 118 +- .../UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h | 6 +- .../BPy_Curvature2DAngleF0D.cpp | 128 +- .../BPy_Curvature2DAngleF0D.h | 6 +- .../UnaryFunction0D_double/BPy_DensityF0D.cpp | 138 +- .../UnaryFunction0D_double/BPy_DensityF0D.h | 3 +- .../BPy_GetProjectedXF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetProjectedXF0D.h | 6 +- .../BPy_GetProjectedYF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetProjectedYF0D.h | 6 +- .../BPy_GetProjectedZF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetProjectedZF0D.h | 6 +- .../UnaryFunction0D_double/BPy_GetXF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetXF0D.h | 3 +- .../UnaryFunction0D_double/BPy_GetYF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetYF0D.h | 3 +- .../UnaryFunction0D_double/BPy_GetZF0D.cpp | 118 +- .../UnaryFunction0D_double/BPy_GetZF0D.h | 3 +- .../BPy_LocalAverageDepthF0D.cpp | 134 +- .../BPy_LocalAverageDepthF0D.h | 6 +- .../BPy_ZDiscontinuityF0D.cpp | 128 +- .../UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h | 6 +- .../BPy_GetCurvilinearAbscissaF0D.cpp | 124 +- .../BPy_GetCurvilinearAbscissaF0D.h | 5 +- .../UnaryFunction0D_float/BPy_GetParameterF0D.cpp | 118 +- .../UnaryFunction0D_float/BPy_GetParameterF0D.h | 6 +- .../BPy_GetViewMapGradientNormF0D.cpp | 134 +- .../BPy_GetViewMapGradientNormF0D.h | 5 +- .../BPy_ReadCompleteViewMapPixelF0D.cpp | 130 +- .../BPy_ReadCompleteViewMapPixelF0D.h | 5 +- .../UnaryFunction0D_float/BPy_ReadMapPixelF0D.cpp | 132 +- .../UnaryFunction0D_float/BPy_ReadMapPixelF0D.h | 6 +- .../BPy_ReadSteerableViewMapPixelF0D.cpp | 138 +- .../BPy_ReadSteerableViewMapPixelF0D.h | 5 +- .../BPy_QuantitativeInvisibilityF0D.cpp | 134 +- .../BPy_QuantitativeInvisibilityF0D.h | 5 +- .../BPy_GetOccludersF0D.cpp | 120 +- .../BPy_GetOccludersF0D.h | 6 +- .../UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp | 380 +- .../UnaryFunction1D/BPy_UnaryFunction1DDouble.h | 8 +- .../BPy_UnaryFunction1DEdgeNature.cpp | 241 +- .../BPy_UnaryFunction1DEdgeNature.h | 7 +- .../UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp | 231 +- .../UnaryFunction1D/BPy_UnaryFunction1DFloat.h | 8 +- .../BPy_UnaryFunction1DUnsigned.cpp | 242 +- .../UnaryFunction1D/BPy_UnaryFunction1DUnsigned.h | 7 +- .../UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp | 247 +- .../UnaryFunction1D/BPy_UnaryFunction1DVec2f.h | 8 +- .../UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp | 239 +- .../UnaryFunction1D/BPy_UnaryFunction1DVec3f.h | 8 +- .../BPy_UnaryFunction1DVectorViewShape.cpp | 288 +- .../BPy_UnaryFunction1DVectorViewShape.h | 7 +- .../UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp | 267 +- .../UnaryFunction1D/BPy_UnaryFunction1DVoid.h | 8 +- .../BPy_CurveNatureF1D.cpp | 139 +- .../BPy_CurveNatureF1D.h | 6 +- .../UnaryFunction1D_Vec2f/BPy_Normal2DF1D.cpp | 127 +- .../UnaryFunction1D_Vec2f/BPy_Normal2DF1D.h | 6 +- .../UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.cpp | 127 +- .../UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.h | 6 +- .../UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.cpp | 127 +- .../UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h | 6 +- .../BPy_Curvature2DAngleF1D.cpp | 132 +- .../BPy_Curvature2DAngleF1D.h | 6 +- .../UnaryFunction1D_double/BPy_DensityF1D.cpp | 155 +- .../UnaryFunction1D_double/BPy_DensityF1D.h | 3 +- .../BPy_GetCompleteViewMapDensityF1D.cpp | 163 +- .../BPy_GetCompleteViewMapDensityF1D.h | 5 +- .../BPy_GetDirectionalViewMapDensityF1D.cpp | 174 +- .../BPy_GetDirectionalViewMapDensityF1D.h | 5 +- .../BPy_GetProjectedXF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetProjectedXF1D.h | 6 +- .../BPy_GetProjectedYF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetProjectedYF1D.h | 6 +- .../BPy_GetProjectedZF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetProjectedZF1D.h | 6 +- .../BPy_GetSteerableViewMapDensityF1D.cpp | 156 +- .../BPy_GetSteerableViewMapDensityF1D.h | 5 +- .../BPy_GetViewMapGradientNormF1D.cpp | 157 +- .../BPy_GetViewMapGradientNormF1D.h | 7 +- .../UnaryFunction1D_double/BPy_GetXF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetXF1D.h | 3 +- .../UnaryFunction1D_double/BPy_GetYF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetYF1D.h | 3 +- .../UnaryFunction1D_double/BPy_GetZF1D.cpp | 127 +- .../UnaryFunction1D_double/BPy_GetZF1D.h | 3 +- .../BPy_LocalAverageDepthF1D.cpp | 147 +- .../BPy_LocalAverageDepthF1D.h | 6 +- .../BPy_ZDiscontinuityF1D.cpp | 135 +- .../UnaryFunction1D_double/BPy_ZDiscontinuityF1D.h | 6 +- .../BPy_QuantitativeInvisibilityF1D.cpp | 139 +- .../BPy_QuantitativeInvisibilityF1D.h | 5 +- .../BPy_GetOccludeeF1D.cpp | 114 +- .../BPy_GetOccludeeF1D.h | 6 +- .../BPy_GetOccludersF1D.cpp | 114 +- .../BPy_GetOccludersF1D.h | 6 +- .../BPy_GetShapeF1D.cpp | 114 +- .../BPy_GetShapeF1D.h | 6 +- .../BPy_ChainingTimeStampF1D.cpp | 114 +- .../BPy_ChainingTimeStampF1D.h | 6 +- .../BPy_IncrementChainingTimeStampF1D.cpp | 113 +- .../BPy_IncrementChainingTimeStampF1D.h | 5 +- .../UnaryFunction1D_void/BPy_TimeStampF1D.cpp | 110 +- .../UnaryFunction1D_void/BPy_TimeStampF1D.h | 6 +- .../python/UnaryPredicate0D/BPy_FalseUP0D.cpp | 105 +- .../intern/python/UnaryPredicate0D/BPy_FalseUP0D.h | 2 +- .../python/UnaryPredicate0D/BPy_TrueUP0D.cpp | 105 +- .../intern/python/UnaryPredicate0D/BPy_TrueUP0D.h | 2 +- .../python/UnaryPredicate1D/BPy_ContourUP1D.cpp | 107 +- .../python/UnaryPredicate1D/BPy_ContourUP1D.h | 5 +- .../UnaryPredicate1D/BPy_DensityLowerThanUP1D.cpp | 135 +- .../UnaryPredicate1D/BPy_DensityLowerThanUP1D.h | 5 +- .../BPy_EqualToChainingTimeStampUP1D.cpp | 128 +- .../BPy_EqualToChainingTimeStampUP1D.h | 4 +- .../UnaryPredicate1D/BPy_EqualToTimeStampUP1D.cpp | 127 +- .../UnaryPredicate1D/BPy_EqualToTimeStampUP1D.h | 5 +- .../UnaryPredicate1D/BPy_ExternalContourUP1D.cpp | 115 +- .../UnaryPredicate1D/BPy_ExternalContourUP1D.h | 5 +- .../python/UnaryPredicate1D/BPy_FalseUP1D.cpp | 105 +- .../intern/python/UnaryPredicate1D/BPy_FalseUP1D.h | 2 +- .../BPy_QuantitativeInvisibilityUP1D.cpp | 136 +- .../BPy_QuantitativeInvisibilityUP1D.h | 4 +- .../python/UnaryPredicate1D/BPy_ShapeUP1D.cpp | 129 +- .../intern/python/UnaryPredicate1D/BPy_ShapeUP1D.h | 2 +- .../python/UnaryPredicate1D/BPy_TrueUP1D.cpp | 105 +- .../intern/python/UnaryPredicate1D/BPy_TrueUP1D.h | 2 +- .../BPy_WithinImageBoundaryUP1D.cpp | 129 +- .../UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.h | 4 +- .../freestyle/intern/scene_graph/DrawingStyle.h | 169 +- .../freestyle/intern/scene_graph/FrsMaterial.h | 759 ++-- .../intern/scene_graph/IndexedFaceSet.cpp | 545 +-- .../freestyle/intern/scene_graph/IndexedFaceSet.h | 537 +-- .../freestyle/intern/scene_graph/LineRep.cpp | 64 +- .../blender/freestyle/intern/scene_graph/LineRep.h | 221 +- source/blender/freestyle/intern/scene_graph/Node.h | 133 +- .../freestyle/intern/scene_graph/NodeCamera.cpp | 140 +- .../freestyle/intern/scene_graph/NodeCamera.h | 316 +- .../intern/scene_graph/NodeDrawingStyle.cpp | 15 +- .../intern/scene_graph/NodeDrawingStyle.h | 140 +- .../freestyle/intern/scene_graph/NodeGroup.cpp | 121 +- .../freestyle/intern/scene_graph/NodeGroup.h | 65 +- .../freestyle/intern/scene_graph/NodeLight.cpp | 66 +- .../freestyle/intern/scene_graph/NodeLight.h | 133 +- .../freestyle/intern/scene_graph/NodeShape.cpp | 34 +- .../freestyle/intern/scene_graph/NodeShape.h | 101 +- .../freestyle/intern/scene_graph/NodeTransform.cpp | 216 +- .../freestyle/intern/scene_graph/NodeTransform.h | 125 +- .../freestyle/intern/scene_graph/NodeViewLayer.cpp | 4 +- .../freestyle/intern/scene_graph/NodeViewLayer.h | 43 +- .../intern/scene_graph/OrientedLineRep.cpp | 12 +- .../freestyle/intern/scene_graph/OrientedLineRep.h | 55 +- source/blender/freestyle/intern/scene_graph/Rep.h | 271 +- .../freestyle/intern/scene_graph/SceneHash.cpp | 62 +- .../freestyle/intern/scene_graph/SceneHash.h | 60 +- .../intern/scene_graph/ScenePrettyPrinter.cpp | 63 +- .../intern/scene_graph/ScenePrettyPrinter.h | 120 +- .../freestyle/intern/scene_graph/SceneVisitor.h | 100 +- .../freestyle/intern/scene_graph/TriangleRep.cpp | 60 +- .../freestyle/intern/scene_graph/TriangleRep.h | 217 +- .../freestyle/intern/scene_graph/VertexRep.cpp | 4 +- .../freestyle/intern/scene_graph/VertexRep.h | 201 +- .../intern/stroke/AdvancedFunctions0D.cpp | 126 +- .../freestyle/intern/stroke/AdvancedFunctions0D.h | 292 +- .../intern/stroke/AdvancedFunctions1D.cpp | 163 +- .../freestyle/intern/stroke/AdvancedFunctions1D.h | 415 +- .../freestyle/intern/stroke/AdvancedPredicates1D.h | 67 +- .../intern/stroke/AdvancedStrokeShaders.cpp | 483 +-- .../intern/stroke/AdvancedStrokeShaders.h | 325 +- .../freestyle/intern/stroke/BasicStrokeShaders.cpp | 1023 ++--- .../freestyle/intern/stroke/BasicStrokeShaders.h | 974 +++-- source/blender/freestyle/intern/stroke/Canvas.cpp | 625 +-- source/blender/freestyle/intern/stroke/Canvas.h | 363 +- source/blender/freestyle/intern/stroke/Chain.cpp | 214 +- source/blender/freestyle/intern/stroke/Chain.h | 143 +- .../freestyle/intern/stroke/ChainingIterators.cpp | 274 +- .../freestyle/intern/stroke/ChainingIterators.h | 614 +-- .../freestyle/intern/stroke/ContextFunctions.cpp | 26 +- .../freestyle/intern/stroke/ContextFunctions.h | 9 +- source/blender/freestyle/intern/stroke/Curve.cpp | 1158 +++--- source/blender/freestyle/intern/stroke/Curve.h | 967 ++--- .../intern/stroke/CurveAdvancedIterators.h | 634 +-- .../freestyle/intern/stroke/CurveIterators.h | 511 +-- source/blender/freestyle/intern/stroke/Modifiers.h | 44 +- source/blender/freestyle/intern/stroke/Module.h | 71 +- .../blender/freestyle/intern/stroke/Operators.cpp | 2260 +++++----- source/blender/freestyle/intern/stroke/Operators.h | 442 +- .../freestyle/intern/stroke/PSStrokeRenderer.cpp | 93 +- .../freestyle/intern/stroke/PSStrokeRenderer.h | 25 +- .../freestyle/intern/stroke/Predicates0D.cpp | 8 +- .../blender/freestyle/intern/stroke/Predicates0D.h | 202 +- .../freestyle/intern/stroke/Predicates1D.cpp | 8 +- .../blender/freestyle/intern/stroke/Predicates1D.h | 866 ++-- .../freestyle/intern/stroke/QInformationMap.h | 59 +- source/blender/freestyle/intern/stroke/Stroke.cpp | 1309 +++--- source/blender/freestyle/intern/stroke/Stroke.h | 1567 +++---- .../intern/stroke/StrokeAdvancedIterators.h | 283 +- .../blender/freestyle/intern/stroke/StrokeIO.cpp | 61 +- source/blender/freestyle/intern/stroke/StrokeIO.h | 8 +- .../freestyle/intern/stroke/StrokeIterators.h | 361 +- .../freestyle/intern/stroke/StrokeLayer.cpp | 32 +- .../blender/freestyle/intern/stroke/StrokeLayer.h | 131 +- .../freestyle/intern/stroke/StrokeRenderer.cpp | 72 +- .../freestyle/intern/stroke/StrokeRenderer.h | 146 +- .../blender/freestyle/intern/stroke/StrokeRep.cpp | 1347 +++--- source/blender/freestyle/intern/stroke/StrokeRep.h | 431 +- .../freestyle/intern/stroke/StrokeShader.cpp | 4 +- .../blender/freestyle/intern/stroke/StrokeShader.h | 63 +- .../freestyle/intern/stroke/StrokeTesselator.cpp | 76 +- .../freestyle/intern/stroke/StrokeTesselator.h | 74 +- .../blender/freestyle/intern/stroke/StyleModule.h | 270 +- .../freestyle/intern/stroke/TextStrokeRenderer.cpp | 67 +- .../freestyle/intern/stroke/TextStrokeRenderer.h | 25 +- .../blender/freestyle/intern/system/BaseIterator.h | 95 +- .../blender/freestyle/intern/system/BaseObject.h | 65 +- source/blender/freestyle/intern/system/Cast.h | 18 +- source/blender/freestyle/intern/system/Exception.h | 53 +- .../freestyle/intern/system/FreestyleConfig.h | 14 +- source/blender/freestyle/intern/system/Id.h | 195 +- .../blender/freestyle/intern/system/Interpreter.h | 39 +- source/blender/freestyle/intern/system/Iterator.h | 63 +- .../freestyle/intern/system/PointerSequence.h | 42 +- source/blender/freestyle/intern/system/Precision.h | 6 +- .../blender/freestyle/intern/system/ProgressBar.h | 111 +- .../freestyle/intern/system/PseudoNoise.cpp | 112 +- .../blender/freestyle/intern/system/PseudoNoise.h | 33 +- .../freestyle/intern/system/PythonInterpreter.h | 157 +- source/blender/freestyle/intern/system/RandGen.cpp | 132 +- source/blender/freestyle/intern/system/RandGen.h | 19 +- .../freestyle/intern/system/RenderMonitor.h | 61 +- .../freestyle/intern/system/StringUtils.cpp | 40 +- .../blender/freestyle/intern/system/StringUtils.h | 17 +- source/blender/freestyle/intern/system/TimeStamp.h | 63 +- source/blender/freestyle/intern/system/TimeUtils.h | 43 +- .../view_map/ArbitraryGridDensityProvider.cpp | 123 +- .../intern/view_map/ArbitraryGridDensityProvider.h | 58 +- .../freestyle/intern/view_map/AutoPtrHelper.h | 44 +- .../view_map/AverageAreaGridDensityProvider.cpp | 165 +- .../view_map/AverageAreaGridDensityProvider.h | 58 +- .../blender/freestyle/intern/view_map/BoxGrid.cpp | 300 +- source/blender/freestyle/intern/view_map/BoxGrid.h | 553 ++- .../intern/view_map/CulledOccluderSource.cpp | 422 +- .../intern/view_map/CulledOccluderSource.h | 41 +- .../freestyle/intern/view_map/FEdgeXDetector.cpp | 1218 +++--- .../freestyle/intern/view_map/FEdgeXDetector.h | 381 +- .../freestyle/intern/view_map/Functions0D.cpp | 548 +-- .../freestyle/intern/view_map/Functions0D.h | 577 ++- .../freestyle/intern/view_map/Functions1D.cpp | 340 +- .../freestyle/intern/view_map/Functions1D.h | 905 ++-- .../intern/view_map/GridDensityProvider.h | 218 +- .../HeuristicGridDensityProviderFactory.cpp | 80 +- .../view_map/HeuristicGridDensityProviderFactory.h | 31 +- .../freestyle/intern/view_map/Interface0D.cpp | 62 +- .../freestyle/intern/view_map/Interface0D.h | 459 ++- .../freestyle/intern/view_map/Interface1D.cpp | 28 +- .../freestyle/intern/view_map/Interface1D.h | 245 +- .../freestyle/intern/view_map/OccluderSource.cpp | 149 +- .../freestyle/intern/view_map/OccluderSource.h | 53 +- .../intern/view_map/Pow23GridDensityProvider.cpp | 122 +- .../intern/view_map/Pow23GridDensityProvider.h | 56 +- .../freestyle/intern/view_map/Silhouette.cpp | 331 +- .../blender/freestyle/intern/view_map/Silhouette.h | 3466 ++++++++-------- .../intern/view_map/SilhouetteGeomEngine.cpp | 372 +- .../intern/view_map/SilhouetteGeomEngine.h | 181 +- .../freestyle/intern/view_map/SphericalGrid.cpp | 303 +- .../freestyle/intern/view_map/SphericalGrid.h | 571 +-- .../freestyle/intern/view_map/SteerableViewMap.cpp | 384 +- .../freestyle/intern/view_map/SteerableViewMap.h | 201 +- .../freestyle/intern/view_map/ViewEdgeXBuilder.cpp | 1311 +++--- .../freestyle/intern/view_map/ViewEdgeXBuilder.h | 403 +- .../blender/freestyle/intern/view_map/ViewMap.cpp | 952 ++--- source/blender/freestyle/intern/view_map/ViewMap.h | 3102 +++++++------- .../intern/view_map/ViewMapAdvancedIterators.h | 1383 ++++--- .../freestyle/intern/view_map/ViewMapBuilder.cpp | 4316 ++++++++++---------- .../freestyle/intern/view_map/ViewMapBuilder.h | 424 +- .../freestyle/intern/view_map/ViewMapIO.cpp | 2161 +++++----- .../blender/freestyle/intern/view_map/ViewMapIO.h | 50 +- .../freestyle/intern/view_map/ViewMapIterators.h | 969 ++--- .../intern/view_map/ViewMapTesselator.cpp | 10 +- .../freestyle/intern/view_map/ViewMapTesselator.h | 279 +- .../freestyle/intern/winged_edge/Curvature.cpp | 880 ++-- .../freestyle/intern/winged_edge/Curvature.h | 134 +- .../blender/freestyle/intern/winged_edge/Nature.h | 34 +- .../blender/freestyle/intern/winged_edge/WEdge.cpp | 1010 +++-- .../blender/freestyle/intern/winged_edge/WEdge.h | 2335 +++++------ .../freestyle/intern/winged_edge/WFillGrid.cpp | 54 +- .../freestyle/intern/winged_edge/WFillGrid.h | 91 +- .../freestyle/intern/winged_edge/WSFillGrid.cpp | 54 +- .../freestyle/intern/winged_edge/WSFillGrid.h | 90 +- .../freestyle/intern/winged_edge/WXEdge.cpp | 427 +- .../blender/freestyle/intern/winged_edge/WXEdge.h | 1399 ++++--- .../freestyle/intern/winged_edge/WXEdgeBuilder.cpp | 38 +- .../freestyle/intern/winged_edge/WXEdgeBuilder.h | 26 +- .../intern/winged_edge/WingedEdgeBuilder.cpp | 668 +-- .../intern/winged_edge/WingedEdgeBuilder.h | 235 +- 516 files changed, 58798 insertions(+), 56757 deletions(-) (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/application/AppCanvas.cpp b/source/blender/freestyle/intern/application/AppCanvas.cpp index 7097dd80128..8248266bbf5 100644 --- a/source/blender/freestyle/intern/application/AppCanvas.cpp +++ b/source/blender/freestyle/intern/application/AppCanvas.cpp @@ -31,176 +31,174 @@ namespace Freestyle { -AppCanvas::AppCanvas() -:Canvas() +AppCanvas::AppCanvas() : Canvas() { - _pViewer = 0; - _MapsPath = Config::Path::getInstance()->getMapsDir().c_str(); + _pViewer = 0; + _MapsPath = Config::Path::getInstance()->getMapsDir().c_str(); } -AppCanvas::AppCanvas(AppView *iViewer) -:Canvas() +AppCanvas::AppCanvas(AppView *iViewer) : Canvas() { - _pViewer = iViewer; + _pViewer = iViewer; } -AppCanvas::AppCanvas(const AppCanvas& iBrother) -:Canvas(iBrother) +AppCanvas::AppCanvas(const AppCanvas &iBrother) : Canvas(iBrother) { - _pViewer = iBrother._pViewer; + _pViewer = iBrother._pViewer; } AppCanvas::~AppCanvas() { - _pViewer = 0; + _pViewer = 0; } void AppCanvas::setViewer(AppView *iViewer) { - _pViewer = iViewer; + _pViewer = iViewer; } int AppCanvas::width() const { - return _pViewer->width(); + return _pViewer->width(); } int AppCanvas::height() const { - return _pViewer->height(); + return _pViewer->height(); } BBox AppCanvas::border() const { - return _pViewer->border(); + return _pViewer->border(); } float AppCanvas::thickness() const { - return _pViewer->thickness(); + return _pViewer->thickness(); } BBox AppCanvas::scene3DBBox() const { - return _pViewer->scene3DBBox(); + return _pViewer->scene3DBBox(); } void AppCanvas::preDraw() { - Canvas::preDraw(); + Canvas::preDraw(); } void AppCanvas::init() { #if 0 - static bool firsttime = true; - if (firsttime) { - _Renderer = new BlenderStrokeRenderer; - if (!StrokeRenderer::loadTextures()) { - cerr << "unable to load stroke textures" << endl; - return; - } - } + static bool firsttime = true; + if (firsttime) { + _Renderer = new BlenderStrokeRenderer; + if (!StrokeRenderer::loadTextures()) { + cerr << "unable to load stroke textures" << endl; + return; + } + } #endif } void AppCanvas::postDraw() { - for (unsigned int i = 0; i < _StyleModules.size(); i++) { - if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) - continue; - _Layers[i]->ScaleThickness(thickness()); - } - Canvas::postDraw(); + for (unsigned int i = 0; i < _StyleModules.size(); i++) { + if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) + continue; + _Layers[i]->ScaleThickness(thickness()); + } + Canvas::postDraw(); } void AppCanvas::Erase() { - Canvas::Erase(); + Canvas::Erase(); } // Abstract -void AppCanvas::readColorPixels(int x, int y, int w, int h, RGBImage& oImage) const -{ - float *rgb = new float[3 * w * h]; - memset(rgb, 0, sizeof(float) * 3 * w * h); - int xsch = width(); - int ysch = height(); - if (_pass_diffuse.buf) { - int xmin = border().getMin().x(); - int ymin = border().getMin().y(); - int xmax = border().getMax().x(); - int ymax = border().getMax().y(); - int rectx = _pass_diffuse.width; - int recty = _pass_diffuse.height; - float xfac = ((float)rectx) / ((float)(xmax - xmin)); - float yfac = ((float)recty) / ((float)(ymax - ymin)); +void AppCanvas::readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const +{ + float *rgb = new float[3 * w * h]; + memset(rgb, 0, sizeof(float) * 3 * w * h); + int xsch = width(); + int ysch = height(); + if (_pass_diffuse.buf) { + int xmin = border().getMin().x(); + int ymin = border().getMin().y(); + int xmax = border().getMax().x(); + int ymax = border().getMax().y(); + int rectx = _pass_diffuse.width; + int recty = _pass_diffuse.height; + float xfac = ((float)rectx) / ((float)(xmax - xmin)); + float yfac = ((float)recty) / ((float)(ymax - ymin)); #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, - xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f)); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, + xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f)); + } #endif - int ii, jj; - for (int j = 0; j < h; j++) { - jj = (int)((y - ymin + j) * yfac); - if (jj < 0 || jj >= recty) - continue; - for (int i = 0; i < w; i++) { - ii = (int)((x - xmin + i) * xfac); - if (ii < 0 || ii >= rectx) - continue; - memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float) * 3); - } - } - } - oImage.setArray(rgb, xsch, ysch, w, h, x, y, false); -} - -void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage& oImage) const -{ - float *z = new float[w * h]; - memset(z, 0, sizeof(float) * w * h); - int xsch = width(); - int ysch = height(); - if (_pass_z.buf) { - int xmin = border().getMin().x(); - int ymin = border().getMin().y(); - int xmax = border().getMax().x(); - int ymax = border().getMax().y(); - int rectx = _pass_z.width; - int recty = _pass_z.height; - float xfac = ((float)rectx) / ((float)(xmax - xmin)); - float yfac = ((float)recty) / ((float)(ymax - ymin)); + int ii, jj; + for (int j = 0; j < h; j++) { + jj = (int)((y - ymin + j) * yfac); + if (jj < 0 || jj >= recty) + continue; + for (int i = 0; i < w; i++) { + ii = (int)((x - xmin + i) * xfac); + if (ii < 0 || ii >= rectx) + continue; + memcpy( + rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float) * 3); + } + } + } + oImage.setArray(rgb, xsch, ysch, w, h, x, y, false); +} + +void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const +{ + float *z = new float[w * h]; + memset(z, 0, sizeof(float) * w * h); + int xsch = width(); + int ysch = height(); + if (_pass_z.buf) { + int xmin = border().getMin().x(); + int ymin = border().getMin().y(); + int xmax = border().getMax().x(); + int ymax = border().getMax().y(); + int rectx = _pass_z.width; + int recty = _pass_z.height; + float xfac = ((float)rectx) / ((float)(xmax - xmin)); + float yfac = ((float)recty) / ((float)(ymax - ymin)); #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, - xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f)); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y, + xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f)); + } #endif - int ii, jj; - for (int j = 0; j < h; j++) { - jj = (int)((y - ymin + j) * yfac); - if (jj < 0 || jj >= recty) - continue; - for (int i = 0; i < w; i++) { - ii = (int)((x - xmin + i) * xfac); - if (ii < 0 || ii >= rectx) - continue; - z[w * j + i] = _pass_z.buf[rectx * jj + ii]; - } - } - } - oImage.setArray(z, xsch, ysch, w, h, x, y, false); + int ii, jj; + for (int j = 0; j < h; j++) { + jj = (int)((y - ymin + j) * yfac); + if (jj < 0 || jj >= recty) + continue; + for (int i = 0; i < w; i++) { + ii = (int)((x - xmin + i) * xfac); + if (ii < 0 || ii >= rectx) + continue; + z[w * j + i] = _pass_z.buf[rectx * jj + ii]; + } + } + } + oImage.setArray(z, xsch, ysch, w, h, x, y, false); } void AppCanvas::RenderStroke(Stroke *iStroke) { - if (_basic) - iStroke->RenderBasic(_Renderer); - else - iStroke->Render(_Renderer); + if (_basic) + iStroke->RenderBasic(_Renderer); + else + iStroke->Render(_Renderer); } void AppCanvas::update() diff --git a/source/blender/freestyle/intern/application/AppCanvas.h b/source/blender/freestyle/intern/application/AppCanvas.h index e891a661606..9d1e2458564 100644 --- a/source/blender/freestyle/intern/application/AppCanvas.h +++ b/source/blender/freestyle/intern/application/AppCanvas.h @@ -26,69 +26,72 @@ namespace Freestyle { -class AppCanvas : public Canvas -{ -public: - AppCanvas(); - AppCanvas(AppView *iViewer); - AppCanvas(const AppCanvas& iBrother); - virtual ~AppCanvas(); - - /*! operations that need to be done before a draw */ - virtual void preDraw(); - - /*! operations that need to be done after a draw */ - virtual void postDraw(); - - /*! Erases the layers and clears the canvas */ - virtual void Erase(); - - /* init the canvas */ - virtual void init(); - - /*! Reads a pixel area from the canvas */ - virtual void readColorPixels(int x, int y, int w, int h, RGBImage& oImage) const; - /*! Reads a depth pixel area from the canvas */ - virtual void readDepthPixels(int x, int y, int w, int h, GrayImage& oImage) const; - - virtual BBox scene3DBBox() const; - - /* abstract */ - virtual void RenderStroke(Stroke *); - virtual void update(); - - - /*! accessors */ - virtual int width() const; - virtual int height() const; - virtual BBox border() const; - virtual float thickness() const; - - AppView *_pViewer; - inline const AppView *viewer() const {return _pViewer;} - - /*! modifiers */ - void setViewer(AppView *iViewer); - - /* soc */ - void setPassDiffuse(float *buf, int width, int height) { - _pass_diffuse.buf = buf; - _pass_diffuse.width = width; - _pass_diffuse.height = height; - } - void setPassZ(float *buf, int width, int height) { - _pass_z.buf = buf; - _pass_z.width = width; - _pass_z.height = height; - } - -private: - struct { - float *buf; - int width, height; - } _pass_diffuse, _pass_z; +class AppCanvas : public Canvas { + public: + AppCanvas(); + AppCanvas(AppView *iViewer); + AppCanvas(const AppCanvas &iBrother); + virtual ~AppCanvas(); + + /*! operations that need to be done before a draw */ + virtual void preDraw(); + + /*! operations that need to be done after a draw */ + virtual void postDraw(); + + /*! Erases the layers and clears the canvas */ + virtual void Erase(); + + /* init the canvas */ + virtual void init(); + + /*! Reads a pixel area from the canvas */ + virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const; + /*! Reads a depth pixel area from the canvas */ + virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const; + + virtual BBox scene3DBBox() const; + + /* abstract */ + virtual void RenderStroke(Stroke *); + virtual void update(); + + /*! accessors */ + virtual int width() const; + virtual int height() const; + virtual BBox border() const; + virtual float thickness() const; + + AppView *_pViewer; + inline const AppView *viewer() const + { + return _pViewer; + } + + /*! modifiers */ + void setViewer(AppView *iViewer); + + /* soc */ + void setPassDiffuse(float *buf, int width, int height) + { + _pass_diffuse.buf = buf; + _pass_diffuse.width = width; + _pass_diffuse.height = height; + } + void setPassZ(float *buf, int width, int height) + { + _pass_z.buf = buf; + _pass_z.width = width; + _pass_z.height = height; + } + + private: + struct { + float *buf; + int width, height; + } _pass_diffuse, _pass_z; }; } /* namespace Freestyle */ -#endif // __APPCANVAS_H__ +#endif // __APPCANVAS_H__ diff --git a/source/blender/freestyle/intern/application/AppConfig.cpp b/source/blender/freestyle/intern/application/AppConfig.cpp index 20d8c68ef0e..3e3a939a8fe 100644 --- a/source/blender/freestyle/intern/application/AppConfig.cpp +++ b/source/blender/freestyle/intern/application/AppConfig.cpp @@ -37,61 +37,62 @@ namespace Config { Path *Path::_pInstance = 0; Path::Path() { - // get the root directory - // soc - setRootDir(BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, NULL)); + // get the root directory + // soc + setRootDir(BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, NULL)); - _pInstance = this; + _pInstance = this; } -void Path::setRootDir(const string& iRootDir) +void Path::setRootDir(const string &iRootDir) { - _ProjectDir = iRootDir + string(DIR_SEP.c_str()) + "freestyle"; - _ModelsPath = ""; - _PatternsPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "textures" + - string(DIR_SEP.c_str()) + "variation_patterns" + string(DIR_SEP.c_str()); - _BrushesPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "textures" + - string(DIR_SEP.c_str()) + "brushes" + string(DIR_SEP.c_str()); - _PythonPath = _ProjectDir + string(DIR_SEP.c_str()) + "modules" + string(DIR_SEP.c_str()); - if (getenv("PYTHONPATH")) { - _PythonPath += string(PATH_SEP.c_str()) + string(getenv("PYTHONPATH")); - } - _EnvMapDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "env_map" + - string(DIR_SEP.c_str()); - _MapsDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "maps" + - string(DIR_SEP.c_str()); + _ProjectDir = iRootDir + string(DIR_SEP.c_str()) + "freestyle"; + _ModelsPath = ""; + _PatternsPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + + "textures" + string(DIR_SEP.c_str()) + "variation_patterns" + + string(DIR_SEP.c_str()); + _BrushesPath = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + + "textures" + string(DIR_SEP.c_str()) + "brushes" + string(DIR_SEP.c_str()); + _PythonPath = _ProjectDir + string(DIR_SEP.c_str()) + "modules" + string(DIR_SEP.c_str()); + if (getenv("PYTHONPATH")) { + _PythonPath += string(PATH_SEP.c_str()) + string(getenv("PYTHONPATH")); + } + _EnvMapDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + + "env_map" + string(DIR_SEP.c_str()); + _MapsDir = _ProjectDir + string(DIR_SEP.c_str()) + "data" + string(DIR_SEP.c_str()) + "maps" + + string(DIR_SEP.c_str()); } -void Path::setHomeDir(const string& iHomeDir) +void Path::setHomeDir(const string &iHomeDir) { - _HomeDir = iHomeDir; + _HomeDir = iHomeDir; } Path::~Path() { - _pInstance = 0; + _pInstance = 0; } Path *Path::getInstance() { - return _pInstance; + return _pInstance; } -string Path::getEnvVar(const string& iEnvVarName) +string Path::getEnvVar(const string &iEnvVarName) { - string value; - if (!getenv(iEnvVarName.c_str())) { - cerr << "Warning: You may want to set the $" << iEnvVarName << - " environment variable to use Freestyle." << endl << - " Otherwise, the current directory will be used instead." << endl; - value = "."; - } - else { - value = getenv(iEnvVarName.c_str()); - } - return value; + string value; + if (!getenv(iEnvVarName.c_str())) { + cerr << "Warning: You may want to set the $" << iEnvVarName + << " environment variable to use Freestyle." << endl + << " Otherwise, the current directory will be used instead." << endl; + value = "."; + } + else { + value = getenv(iEnvVarName.c_str()); + } + return value; } -} // End of namepace Config +} // namespace Config } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/application/AppConfig.h b/source/blender/freestyle/intern/application/AppConfig.h index c9eeca457eb..cc2a3962ecd 100644 --- a/source/blender/freestyle/intern/application/AppConfig.h +++ b/source/blender/freestyle/intern/application/AppConfig.h @@ -27,7 +27,7 @@ #include "../system/Precision.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -37,38 +37,62 @@ namespace Freestyle { namespace Config { class Path { -protected: - static Path *_pInstance; - string _ProjectDir; - string _ModelsPath; - string _PatternsPath; - string _BrushesPath; - string _PythonPath; - string _EnvMapDir; - string _MapsDir; - string _HomeDir; - -public: - Path(); - virtual ~Path(); - static Path *getInstance(); - - void setRootDir(const string& iRootDir); - void setHomeDir(const string& iHomeDir); - - const string& getProjectDir() const {return _ProjectDir;} - const string& getModelsPath() const {return _ModelsPath;} - const string& getPatternsPath() const {return _PatternsPath;} - const string& getBrushesPath() const {return _BrushesPath;} - const string& getPythonPath() const {return _PythonPath;} - const string& getEnvMapDir() const {return _EnvMapDir;} - const string& getMapsDir() const {return _MapsDir;} - const string& getHomeDir() const {return _HomeDir;} - - static string getEnvVar(const string& iEnvVarName); + protected: + static Path *_pInstance; + string _ProjectDir; + string _ModelsPath; + string _PatternsPath; + string _BrushesPath; + string _PythonPath; + string _EnvMapDir; + string _MapsDir; + string _HomeDir; + + public: + Path(); + virtual ~Path(); + static Path *getInstance(); + + void setRootDir(const string &iRootDir); + void setHomeDir(const string &iHomeDir); + + const string &getProjectDir() const + { + return _ProjectDir; + } + const string &getModelsPath() const + { + return _ModelsPath; + } + const string &getPatternsPath() const + { + return _PatternsPath; + } + const string &getBrushesPath() const + { + return _BrushesPath; + } + const string &getPythonPath() const + { + return _PythonPath; + } + const string &getEnvMapDir() const + { + return _EnvMapDir; + } + const string &getMapsDir() const + { + return _MapsDir; + } + const string &getHomeDir() const + { + return _HomeDir; + } + + static string getEnvVar(const string &iEnvVarName); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Config:Path") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Config:Path") #endif }; @@ -100,8 +124,8 @@ static const string OPTIONS_QGLVIEWER_FILE("qglviewer.xml"); static const real DEFAULT_SPHERE_RADIUS = 1.0; static const real DEFAULT_DKR_EPSILON = 0.0; -} // End of namepace Config +} // namespace Config } /* namespace Freestyle */ -#endif // __APP_CONFIG_H__ +#endif // __APP_CONFIG_H__ diff --git a/source/blender/freestyle/intern/application/AppView.cpp b/source/blender/freestyle/intern/application/AppView.cpp index 12b4f3db93a..e352e77f7ea 100644 --- a/source/blender/freestyle/intern/application/AppView.cpp +++ b/source/blender/freestyle/intern/application/AppView.cpp @@ -38,7 +38,7 @@ extern "C" { #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#if 1 // FRS_antialiasing +#if 1 // FRS_antialiasing # include "BKE_global.h" # include "DNA_scene_types.h" #endif @@ -50,136 +50,126 @@ namespace Freestyle { AppView::AppView(const char * /*iName*/) { - _Fovy = DEG2RADF(30.0f); - _ModelRootNode = new NodeDrawingStyle; - _SilhouetteRootNode = new NodeDrawingStyle; - _DebugRootNode = new NodeDrawingStyle; + _Fovy = DEG2RADF(30.0f); + _ModelRootNode = new NodeDrawingStyle; + _SilhouetteRootNode = new NodeDrawingStyle; + _DebugRootNode = new NodeDrawingStyle; - _RootNode.AddChild(_ModelRootNode); - _SilhouetteRootNode->setStyle(DrawingStyle::LINES); - _SilhouetteRootNode->setLightingEnabled(false); - _SilhouetteRootNode->setLineWidth(2.0f); - _SilhouetteRootNode->setPointSize(3.0f); + _RootNode.AddChild(_ModelRootNode); + _SilhouetteRootNode->setStyle(DrawingStyle::LINES); + _SilhouetteRootNode->setLightingEnabled(false); + _SilhouetteRootNode->setLineWidth(2.0f); + _SilhouetteRootNode->setPointSize(3.0f); - _RootNode.AddChild(_SilhouetteRootNode); + _RootNode.AddChild(_SilhouetteRootNode); - _DebugRootNode->setStyle(DrawingStyle::LINES); - _DebugRootNode->setLightingEnabled(false); - _DebugRootNode->setLineWidth(1.0f); + _DebugRootNode->setStyle(DrawingStyle::LINES); + _DebugRootNode->setLightingEnabled(false); + _DebugRootNode->setLineWidth(1.0f); - _RootNode.AddChild(_DebugRootNode); + _RootNode.AddChild(_DebugRootNode); - _minBBox = std::min(std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), - _ModelRootNode->bbox().getMin()[2]); - _maxBBox = std::max(std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), - _ModelRootNode->bbox().getMax()[2]); + _minBBox = std::min( + std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), + _ModelRootNode->bbox().getMin()[2]); + _maxBBox = std::max( + std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), + _ModelRootNode->bbox().getMax()[2]); - _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); - _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); + _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); + _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); - _p2DSelectionNode = new NodeDrawingStyle; - _p2DSelectionNode->setLightingEnabled(false); - _p2DSelectionNode->setStyle(DrawingStyle::LINES); - _p2DSelectionNode->setLineWidth(5.0f); + _p2DSelectionNode = new NodeDrawingStyle; + _p2DSelectionNode->setLightingEnabled(false); + _p2DSelectionNode->setStyle(DrawingStyle::LINES); + _p2DSelectionNode->setLineWidth(5.0f); - _p2DNode.AddChild(_p2DSelectionNode); + _p2DNode.AddChild(_p2DSelectionNode); - NodeLight *light = new NodeLight; - _Light.AddChild(light); + NodeLight *light = new NodeLight; + _Light.AddChild(light); } AppView::~AppView() { - /*int ref =*/ /* UNUSED */ _RootNode.destroy(); + /*int ref =*//* UNUSED */ _RootNode.destroy(); - _Light.destroy(); - /*ref =*/ /* UNUSED */ _p2DNode.destroy(); + _Light.destroy(); + /*ref =*//* UNUSED */ _p2DNode.destroy(); } real AppView::distanceToSceneCenter() { - BBox bbox = _ModelRootNode->bbox(); + BBox bbox = _ModelRootNode->bbox(); - Vec3r v(UNPACK3(g_freestyle.viewpoint)); - v -= 0.5 * (bbox.getMin() + bbox.getMax()); + Vec3r v(UNPACK3(g_freestyle.viewpoint)); + v -= 0.5 * (bbox.getMin() + bbox.getMax()); - return v.norm(); + return v.norm(); } real AppView::znear() { - BBox bbox = _ModelRootNode->bbox(); - Vec3r u = bbox.getMin(); - Vec3r v = bbox.getMax(); - Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); - - Vec3r w1(u[0], u[1], u[2]); - Vec3r w2(v[0], u[1], u[2]); - Vec3r w3(u[0], v[1], u[2]); - Vec3r w4(v[0], v[1], u[2]); - Vec3r w5(u[0], u[1], v[2]); - Vec3r w6(v[0], u[1], v[2]); - Vec3r w7(u[0], v[1], v[2]); - Vec3r w8(v[0], v[1], v[2]); - - real _znear = std::min((w1 - cameraCenter).norm(), - std::min((w2 - cameraCenter).norm(), - std::min((w3 - cameraCenter).norm(), - std::min((w4 - cameraCenter).norm(), - std::min((w5 - cameraCenter).norm(), - std::min((w6 - cameraCenter).norm(), - std::min((w7 - cameraCenter).norm(), - (w8 - cameraCenter).norm() - ) - ) - ) - ) - ) - ) - ); - - return std::max(_znear, 0.001); + BBox bbox = _ModelRootNode->bbox(); + Vec3r u = bbox.getMin(); + Vec3r v = bbox.getMax(); + Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); + + Vec3r w1(u[0], u[1], u[2]); + Vec3r w2(v[0], u[1], u[2]); + Vec3r w3(u[0], v[1], u[2]); + Vec3r w4(v[0], v[1], u[2]); + Vec3r w5(u[0], u[1], v[2]); + Vec3r w6(v[0], u[1], v[2]); + Vec3r w7(u[0], v[1], v[2]); + Vec3r w8(v[0], v[1], v[2]); + + real _znear = std::min( + (w1 - cameraCenter).norm(), + std::min((w2 - cameraCenter).norm(), + std::min((w3 - cameraCenter).norm(), + std::min((w4 - cameraCenter).norm(), + std::min((w5 - cameraCenter).norm(), + std::min((w6 - cameraCenter).norm(), + std::min((w7 - cameraCenter).norm(), + (w8 - cameraCenter).norm()))))))); + + return std::max(_znear, 0.001); } real AppView::zfar() { - BBox bbox = _ModelRootNode->bbox(); - Vec3r u = bbox.getMin(); - Vec3r v = bbox.getMax(); - Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); - - Vec3r w1(u[0], u[1], u[2]); - Vec3r w2(v[0], u[1], u[2]); - Vec3r w3(u[0], v[1], u[2]); - Vec3r w4(v[0], v[1], u[2]); - Vec3r w5(u[0], u[1], v[2]); - Vec3r w6(v[0], u[1], v[2]); - Vec3r w7(u[0], v[1], v[2]); - Vec3r w8(v[0], v[1], v[2]); - - real _zfar = std::max((w1 - cameraCenter).norm(), - std::max((w2 - cameraCenter).norm(), - std::max((w3 - cameraCenter).norm(), - std::max((w4 - cameraCenter).norm(), - std::max((w5 - cameraCenter).norm(), - std::max((w6 - cameraCenter).norm(), - std::max((w7 - cameraCenter).norm(), - (w8 - cameraCenter).norm() - ) - ) - ) - ) - ) - ) - ); - - return _zfar; + BBox bbox = _ModelRootNode->bbox(); + Vec3r u = bbox.getMin(); + Vec3r v = bbox.getMax(); + Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint)); + + Vec3r w1(u[0], u[1], u[2]); + Vec3r w2(v[0], u[1], u[2]); + Vec3r w3(u[0], v[1], u[2]); + Vec3r w4(v[0], v[1], u[2]); + Vec3r w5(u[0], u[1], v[2]); + Vec3r w6(v[0], u[1], v[2]); + Vec3r w7(u[0], v[1], v[2]); + Vec3r w8(v[0], v[1], v[2]); + + real _zfar = std::max( + (w1 - cameraCenter).norm(), + std::max((w2 - cameraCenter).norm(), + std::max((w3 - cameraCenter).norm(), + std::max((w4 - cameraCenter).norm(), + std::max((w5 - cameraCenter).norm(), + std::max((w6 - cameraCenter).norm(), + std::max((w7 - cameraCenter).norm(), + (w8 - cameraCenter).norm()))))))); + + return _zfar; } real AppView::GetFocalLength() { - real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter())); - return Near; + real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter())); + return Near; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/application/AppView.h b/source/blender/freestyle/intern/application/AppView.h index 3939d96cf16..0b029895b8c 100644 --- a/source/blender/freestyle/intern/application/AppView.h +++ b/source/blender/freestyle/intern/application/AppView.h @@ -30,212 +30,246 @@ #include "BLI_math.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { using namespace Geometry; -class AppView -{ -public: - AppView(const char *iName = 0); - virtual ~AppView(); - -public: - //inherited - inline unsigned int width() {return _width;} - inline unsigned int height() {return _height;} - inline BBox border() {return _border;} - inline float thickness() {return _thickness;} - inline void setWidth(unsigned int width) {_width = width;} - inline void setHeight(unsigned int height) {_height = height;} - inline void setBorder(int xmin, int ymin, int xmax, int ymax) { - _border = BBox(Vec2i(xmin, ymin), Vec2i(xmax, ymax)); - } - inline void setThickness(float thickness) {_thickness = thickness;} - -protected: - unsigned int _width, _height; - BBox _border; - float _thickness; - -public: - /*! Sets the model to draw in the viewer - * iModel - * The Root Node of the model - */ - inline void setModel(NodeGroup *iModel) - { - if (0 != _ModelRootNode->numberOfChildren()) { - _ModelRootNode->DetachChildren(); - _ModelRootNode->clearBBox(); - } - - AddModel(iModel); - } - - /*! Adds a model for displaying in the viewer */ - inline void AddModel(NodeGroup *iModel) - { - _ModelRootNode->AddChild(iModel); - _ModelRootNode->UpdateBBox(); - - _minBBox = std::min(std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), - _ModelRootNode->bbox().getMin()[2]); - _maxBBox = std::max(std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), - _ModelRootNode->bbox().getMax()[2]); - - _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); - _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); - } - - inline void AddSilhouette(NodeGroup *iSilhouette) - { - _SilhouetteRootNode->AddChild(iSilhouette); - } - - inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/) - { - //_pFENode->AddChild(iSilhouette); - } - - inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/) - { - //_pVisibleSilhouetteNode->AddChild(iVSilhouette); - } - - inline void setDebug(NodeGroup *iDebug) - { - if (0 != _DebugRootNode->numberOfChildren()) { - _DebugRootNode->DetachChildren(); - _DebugRootNode->clearBBox(); - } - - AddDebug(iDebug); - } - - inline void AddDebug(NodeGroup *iDebug) - { - _DebugRootNode->AddChild(iDebug); - } - - inline void DetachModel(Node *iModel) - { - _ModelRootNode->DetachChild(iModel); - _ModelRootNode->UpdateBBox(); - - _minBBox = std::min(std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), - _ModelRootNode->bbox().getMin()[2]); - _maxBBox = std::max(std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), - _ModelRootNode->bbox().getMax()[2]); - - _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); - _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); - } - - inline void DetachModel() - { - _ModelRootNode->DetachChildren(); - _ModelRootNode->clearBBox(); +class AppView { + public: + AppView(const char *iName = 0); + virtual ~AppView(); + + public: + //inherited + inline unsigned int width() + { + return _width; + } + inline unsigned int height() + { + return _height; + } + inline BBox border() + { + return _border; + } + inline float thickness() + { + return _thickness; + } + inline void setWidth(unsigned int width) + { + _width = width; + } + inline void setHeight(unsigned int height) + { + _height = height; + } + inline void setBorder(int xmin, int ymin, int xmax, int ymax) + { + _border = BBox(Vec2i(xmin, ymin), Vec2i(xmax, ymax)); + } + inline void setThickness(float thickness) + { + _thickness = thickness; + } + + protected: + unsigned int _width, _height; + BBox _border; + float _thickness; + + public: + /*! Sets the model to draw in the viewer + * iModel + * The Root Node of the model + */ + inline void setModel(NodeGroup *iModel) + { + if (0 != _ModelRootNode->numberOfChildren()) { + _ModelRootNode->DetachChildren(); + _ModelRootNode->clearBBox(); + } + + AddModel(iModel); + } + + /*! Adds a model for displaying in the viewer */ + inline void AddModel(NodeGroup *iModel) + { + _ModelRootNode->AddChild(iModel); + _ModelRootNode->UpdateBBox(); + + _minBBox = std::min( + std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), + _ModelRootNode->bbox().getMin()[2]); + _maxBBox = std::max( + std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), + _ModelRootNode->bbox().getMax()[2]); + + _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); + _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); + } + + inline void AddSilhouette(NodeGroup *iSilhouette) + { + _SilhouetteRootNode->AddChild(iSilhouette); + } + + inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/) + { + //_pFENode->AddChild(iSilhouette); + } + + inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/) + { + //_pVisibleSilhouetteNode->AddChild(iVSilhouette); + } + + inline void setDebug(NodeGroup *iDebug) + { + if (0 != _DebugRootNode->numberOfChildren()) { + _DebugRootNode->DetachChildren(); + _DebugRootNode->clearBBox(); + } + + AddDebug(iDebug); + } + + inline void AddDebug(NodeGroup *iDebug) + { + _DebugRootNode->AddChild(iDebug); + } + + inline void DetachModel(Node *iModel) + { + _ModelRootNode->DetachChild(iModel); + _ModelRootNode->UpdateBBox(); + + _minBBox = std::min( + std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]), + _ModelRootNode->bbox().getMin()[2]); + _maxBBox = std::max( + std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]), + _ModelRootNode->bbox().getMax()[2]); + + _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox)); + _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox)); + } + + inline void DetachModel() + { + _ModelRootNode->DetachChildren(); + _ModelRootNode->clearBBox(); #if 0 - // 2D Scene - _p2DNode.DetachChildren(); - _pFENode->DetachChildren(); - _pVisibleSilhouetteNode->DetachChildren(); + // 2D Scene + _p2DNode.DetachChildren(); + _pFENode->DetachChildren(); + _pVisibleSilhouetteNode->DetachChildren(); #endif - } + } - inline void DetachSilhouette() - { - _SilhouetteRootNode->DetachChildren(); + inline void DetachSilhouette() + { + _SilhouetteRootNode->DetachChildren(); #if 0 - _pFENode->DetachChildren(); - _pVisibleSilhouetteNode->DetachChildren(); + _pFENode->DetachChildren(); + _pVisibleSilhouetteNode->DetachChildren(); #endif - _p2DSelectionNode->destroy(); - } - - inline void DetachVisibleSilhouette() - { - //_pVisibleSilhouetteNode->DetachChildren(); - _p2DSelectionNode->destroy(); - } - - inline void DetachDebug() - { - _DebugRootNode->DetachChildren(); - } - - real distanceToSceneCenter(); - real GetFocalLength(); - - inline real GetAspect() const - { - return ((real)_width / (real)_height); - } - - void setHorizontalFov(float hfov) - { - _Fovy = 2.0 * atan (tan(hfov / 2.0) / GetAspect()); - } - - inline real GetFovyRadian() const - { - return _Fovy; - } - - inline real GetFovyDegrees() const - { - return _Fovy * 180.0 / M_PI; // TODO Use RAD2DEG here too? - } - - BBox scene3DBBox() const {return _ModelRootNode->bbox();} - - real znear(); - real zfar(); - -public: - /*! Core scene drawing */ - void DrawScene(SceneVisitor *iRenderer); - - /*! 2D Scene Drawing */ - void Draw2DScene(SceneVisitor *iRenderer); - -protected: - /*! fabs or abs */ - inline int rabs(int x) {return abs(x);} - inline real rabs(real x) {return fabs(x);} - -protected: - float _Fovy; - - //The root node container - NodeGroup _RootNode; - NodeDrawingStyle *_ModelRootNode; - NodeDrawingStyle *_SilhouetteRootNode; - NodeDrawingStyle *_DebugRootNode; - - NodeGroup _Light; - - real _minBBox; - real _maxBBox; - real _maxAbs; - real _minAbs; - - // 2D Scene - bool _Draw2DScene; - bool _Draw3DScene; - NodeGroup _p2DNode; - NodeDrawingStyle *_p2DSelectionNode; + _p2DSelectionNode->destroy(); + } + + inline void DetachVisibleSilhouette() + { + //_pVisibleSilhouetteNode->DetachChildren(); + _p2DSelectionNode->destroy(); + } + + inline void DetachDebug() + { + _DebugRootNode->DetachChildren(); + } + + real distanceToSceneCenter(); + real GetFocalLength(); + + inline real GetAspect() const + { + return ((real)_width / (real)_height); + } + + void setHorizontalFov(float hfov) + { + _Fovy = 2.0 * atan(tan(hfov / 2.0) / GetAspect()); + } + + inline real GetFovyRadian() const + { + return _Fovy; + } + + inline real GetFovyDegrees() const + { + return _Fovy * 180.0 / M_PI; // TODO Use RAD2DEG here too? + } + + BBox scene3DBBox() const + { + return _ModelRootNode->bbox(); + } + + real znear(); + real zfar(); + + public: + /*! Core scene drawing */ + void DrawScene(SceneVisitor *iRenderer); + + /*! 2D Scene Drawing */ + void Draw2DScene(SceneVisitor *iRenderer); + + protected: + /*! fabs or abs */ + inline int rabs(int x) + { + return abs(x); + } + inline real rabs(real x) + { + return fabs(x); + } + + protected: + float _Fovy; + + //The root node container + NodeGroup _RootNode; + NodeDrawingStyle *_ModelRootNode; + NodeDrawingStyle *_SilhouetteRootNode; + NodeDrawingStyle *_DebugRootNode; + + NodeGroup _Light; + + real _minBBox; + real _maxBBox; + real _maxAbs; + real _minAbs; + + // 2D Scene + bool _Draw2DScene; + bool _Draw3DScene; + NodeGroup _p2DNode; + NodeDrawingStyle *_p2DSelectionNode; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView") #endif }; } /* namespace Freestyle */ -#endif // __APPVIEW_H__ +#endif // __APPVIEW_H__ diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index bd02b3378d1..e6066123a33 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -74,1045 +74,1051 @@ namespace Freestyle { Controller::Controller() { - const string sep(Config::DIR_SEP.c_str()); + const string sep(Config::DIR_SEP.c_str()); #if 0 - const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR + sep + - Config::OPTIONS_CURRENT_DIRS_FILE; - _current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true); + const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR + sep + + Config::OPTIONS_CURRENT_DIRS_FILE; + _current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true); #endif - _RootNode = new NodeGroup; - _RootNode->addRef(); + _RootNode = new NodeGroup; + _RootNode->addRef(); #if 0 - _SilhouetteNode = NULL; - _ProjectedSilhouette = NULL; - _VisibleProjectedSilhouette = NULL; + _SilhouetteNode = NULL; + _ProjectedSilhouette = NULL; + _VisibleProjectedSilhouette = NULL; - _DebugNode = new NodeGroup; - _DebugNode->addRef(); + _DebugNode = new NodeGroup; + _DebugNode->addRef(); #endif - _winged_edge = NULL; + _winged_edge = NULL; - _pView = NULL; - _pRenderMonitor = NULL; + _pView = NULL; + _pRenderMonitor = NULL; - _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE); + _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE); - _ProgressBar = new ProgressBar; - _SceneNumFaces = 0; + _ProgressBar = new ProgressBar; + _SceneNumFaces = 0; #if 0 - _minEdgeSize = DBL_MAX; + _minEdgeSize = DBL_MAX; #endif - _EPSILON = 1.0e-6; - _bboxDiag = 0; + _EPSILON = 1.0e-6; + _bboxDiag = 0; - _ViewMap = 0; + _ViewMap = 0; - _Canvas = 0; + _Canvas = 0; - _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional; - //_VisibilityAlgo = ViewMapBuilder::ray_casting; + _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional; + //_VisibilityAlgo = ViewMapBuilder::ray_casting; - _Canvas = new AppCanvas; + _Canvas = new AppCanvas; - _inter = new PythonInterpreter(); - _EnableViewMapCache = false; - _EnableQI = true; - _EnableFaceSmoothness = false; - _ComputeRidges = true; - _ComputeSteerableViewMap = false; - _ComputeSuggestive = true; - _ComputeMaterialBoundaries = true; - _sphereRadius = 1.0; - _creaseAngle = 134.43; - prevSceneHash = -1.0; + _inter = new PythonInterpreter(); + _EnableViewMapCache = false; + _EnableQI = true; + _EnableFaceSmoothness = false; + _ComputeRidges = true; + _ComputeSteerableViewMap = false; + _ComputeSuggestive = true; + _ComputeMaterialBoundaries = true; + _sphereRadius = 1.0; + _creaseAngle = 134.43; + prevSceneHash = -1.0; - init_options(); + init_options(); } Controller::~Controller() { - if (NULL != _RootNode) { - int ref = _RootNode->destroy(); - if (0 == ref) - delete _RootNode; - } + if (NULL != _RootNode) { + int ref = _RootNode->destroy(); + if (0 == ref) + delete _RootNode; + } #if 0 - if (NULL != _SilhouetteNode) { - int ref = _SilhouetteNode->destroy(); - if (0 == ref) - delete _SilhouetteNode; - } - - if (NULL != _DebugNode) { - int ref = _DebugNode->destroy(); - if (0 == ref) - delete _DebugNode; - } + if (NULL != _SilhouetteNode) { + int ref = _SilhouetteNode->destroy(); + if (0 == ref) + delete _SilhouetteNode; + } + + if (NULL != _DebugNode) { + int ref = _DebugNode->destroy(); + if (0 == ref) + delete _DebugNode; + } #endif - if (_winged_edge) { - delete _winged_edge; - _winged_edge = NULL; - } + if (_winged_edge) { + delete _winged_edge; + _winged_edge = NULL; + } - if (0 != _ViewMap) { - delete _ViewMap; - _ViewMap = 0; - } + if (0 != _ViewMap) { + delete _ViewMap; + _ViewMap = 0; + } - if (0 != _Canvas) { - delete _Canvas; - _Canvas = 0; - } + if (0 != _Canvas) { + delete _Canvas; + _Canvas = 0; + } - if (_inter) { - delete _inter; - _inter = NULL; - } + if (_inter) { + delete _inter; + _inter = NULL; + } - if (_ProgressBar) { - delete _ProgressBar; - _ProgressBar = NULL; - } + if (_ProgressBar) { + delete _ProgressBar; + _ProgressBar = NULL; + } - //delete _current_dirs; + //delete _current_dirs; } void Controller::setView(AppView *iView) { - if (NULL == iView) - return; + if (NULL == iView) + return; - _pView = iView; - _Canvas->setViewer(_pView); + _pView = iView; + _Canvas->setViewer(_pView); } void Controller::setRenderMonitor(RenderMonitor *iRenderMonitor) { - _pRenderMonitor = iRenderMonitor; + _pRenderMonitor = iRenderMonitor; } void Controller::setPassDiffuse(float *buf, int width, int height) { - AppCanvas *app_canvas = dynamic_cast(_Canvas); - BLI_assert(app_canvas != 0); - app_canvas->setPassDiffuse(buf, width, height); + AppCanvas *app_canvas = dynamic_cast(_Canvas); + BLI_assert(app_canvas != 0); + app_canvas->setPassDiffuse(buf, width, height); } void Controller::setPassZ(float *buf, int width, int height) { - AppCanvas *app_canvas = dynamic_cast(_Canvas); - BLI_assert(app_canvas != 0); - app_canvas->setPassZ(buf, width, height); + AppCanvas *app_canvas = dynamic_cast(_Canvas); + BLI_assert(app_canvas != 0); + app_canvas->setPassZ(buf, width, height); } void Controller::setContext(bContext *C) { - PythonInterpreter *py_inter = dynamic_cast(_inter); - py_inter->setContext(C); + PythonInterpreter *py_inter = dynamic_cast(_inter); + py_inter->setContext(C); } bool Controller::hitViewMapCache() { - if (!_EnableViewMapCache) { - return false; - } - if (sceneHashFunc.match()) { - return (NULL != _ViewMap); - } - sceneHashFunc.store(); - return false; + if (!_EnableViewMapCache) { + return false; + } + if (sceneHashFunc.match()) { + return (NULL != _ViewMap); + } + sceneHashFunc.store(); + return false; } int Controller::LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { - BlenderFileLoader loader(re, view_layer, depsgraph); - - loader.setRenderMonitor(_pRenderMonitor); - - _Chrono.start(); - - NodeGroup *blenderScene = loader.Load(); - - if (blenderScene == NULL) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Cannot load scene" << endl; - } - return 1; - } - - if (blenderScene->numberOfChildren() < 1) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Empty scene" << endl; - } - blenderScene->destroy(); - delete blenderScene; - return 1; - } - - real duration = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Scene loaded" << endl; - printf("Mesh cleaning : %lf\n", duration); - printf("View map cache : %s\n", _EnableViewMapCache ? "enabled" : "disabled"); - } - _SceneNumFaces += loader.numFacesRead(); + BlenderFileLoader loader(re, view_layer, depsgraph); + + loader.setRenderMonitor(_pRenderMonitor); + + _Chrono.start(); + + NodeGroup *blenderScene = loader.Load(); + + if (blenderScene == NULL) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Cannot load scene" << endl; + } + return 1; + } + + if (blenderScene->numberOfChildren() < 1) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Empty scene" << endl; + } + blenderScene->destroy(); + delete blenderScene; + return 1; + } + + real duration = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Scene loaded" << endl; + printf("Mesh cleaning : %lf\n", duration); + printf("View map cache : %s\n", _EnableViewMapCache ? "enabled" : "disabled"); + } + _SceneNumFaces += loader.numFacesRead(); #if 0 - if (loader.minEdgeSize() < _minEdgeSize) { - _minEdgeSize = loader.minEdgeSize(); - } + if (loader.minEdgeSize() < _minEdgeSize) { + _minEdgeSize = loader.minEdgeSize(); + } #endif #if 0 // DEBUG - ScenePrettyPrinter spp; - blenderScene->accept(spp); + ScenePrettyPrinter spp; + blenderScene->accept(spp); #endif - _RootNode->AddChild(blenderScene); - _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox - - _pView->setModel(_RootNode); - //_pView->FitBBox(); - - if (_pRenderMonitor->testBreak()) - return 0; - - if (_EnableViewMapCache) { - - NodeCamera *cam; - if (g_freestyle.proj[3][3] != 0.0) - cam = new NodeOrthographicCamera; - else - cam = new NodePerspectiveCamera; - double proj[16]; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - proj[i * 4 + j] = g_freestyle.proj[i][j]; - } - } - cam->setProjectionMatrix(proj); - _RootNode->AddChild(cam); - _RootNode->AddChild(new NodeViewLayer(*re->scene, *view_layer)); - - sceneHashFunc.reset(); - //blenderScene->accept(sceneHashFunc); - _RootNode->accept(sceneHashFunc); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Scene hash : " << sceneHashFunc.toString() << endl; - } - if (hitViewMapCache()) { - ClearRootNode(); - return 0; - } - else { - delete _ViewMap; - _ViewMap = NULL; - } - } - - _Chrono.start(); - - WXEdgeBuilder wx_builder; - wx_builder.setRenderMonitor(_pRenderMonitor); - blenderScene->accept(wx_builder); - _winged_edge = wx_builder.getWingedEdge(); - - duration = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("WEdge building : %lf\n", duration); - } + _RootNode->AddChild(blenderScene); + _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox + + _pView->setModel(_RootNode); + //_pView->FitBBox(); + + if (_pRenderMonitor->testBreak()) + return 0; + + if (_EnableViewMapCache) { + + NodeCamera *cam; + if (g_freestyle.proj[3][3] != 0.0) + cam = new NodeOrthographicCamera; + else + cam = new NodePerspectiveCamera; + double proj[16]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + proj[i * 4 + j] = g_freestyle.proj[i][j]; + } + } + cam->setProjectionMatrix(proj); + _RootNode->AddChild(cam); + _RootNode->AddChild(new NodeViewLayer(*re->scene, *view_layer)); + + sceneHashFunc.reset(); + //blenderScene->accept(sceneHashFunc); + _RootNode->accept(sceneHashFunc); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Scene hash : " << sceneHashFunc.toString() << endl; + } + if (hitViewMapCache()) { + ClearRootNode(); + return 0; + } + else { + delete _ViewMap; + _ViewMap = NULL; + } + } + + _Chrono.start(); + + WXEdgeBuilder wx_builder; + wx_builder.setRenderMonitor(_pRenderMonitor); + blenderScene->accept(wx_builder); + _winged_edge = wx_builder.getWingedEdge(); + + duration = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + printf("WEdge building : %lf\n", duration); + } #if 0 - _pView->setDebug(_DebugNode); - - // delete stuff - if (0 != ws_builder) { - delete ws_builder; - ws_builder = 0; - } - - soc QFileInfo qfi(iFileName); - soc string basename((const char*)qfi.fileName().toAscii().data()); - char cleaned[FILE_MAX]; - BLI_strncpy(cleaned, iFileName, FILE_MAX); - BLI_cleanup_file(NULL, cleaned); - string basename = string(cleaned); + _pView->setDebug(_DebugNode); + + // delete stuff + if (0 != ws_builder) { + delete ws_builder; + ws_builder = 0; + } + + soc QFileInfo qfi(iFileName); + soc string basename((const char*)qfi.fileName().toAscii().data()); + char cleaned[FILE_MAX]; + BLI_strncpy(cleaned, iFileName, FILE_MAX); + BLI_cleanup_file(NULL, cleaned); + string basename = string(cleaned); #endif - _ListOfModels.push_back("Blender_models"); + _ListOfModels.push_back("Blender_models"); - _Scene3dBBox = _RootNode->bbox(); + _Scene3dBBox = _RootNode->bbox(); - _bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Triangles nb : " << _SceneNumFaces << " imported, " << - _winged_edge->getNumFaces() << " retained" << endl; - cout << "Bounding Box : " << _bboxDiag << endl; - } + _bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Triangles nb : " << _SceneNumFaces << " imported, " << _winged_edge->getNumFaces() + << " retained" << endl; + cout << "Bounding Box : " << _bboxDiag << endl; + } - ClearRootNode(); + ClearRootNode(); - _SceneNumFaces = _winged_edge->getNumFaces(); - if (_SceneNumFaces == 0) { - DeleteWingedEdge(); - return 1; - } + _SceneNumFaces = _winged_edge->getNumFaces(); + if (_SceneNumFaces == 0) { + DeleteWingedEdge(); + return 1; + } - return 0; + return 0; } void Controller::CloseFile() { - WShape::setCurrentId(0); - _ListOfModels.clear(); + WShape::setCurrentId(0); + _ListOfModels.clear(); - // We deallocate the memory: - ClearRootNode(); - DeleteWingedEdge(); - DeleteViewMap(); + // We deallocate the memory: + ClearRootNode(); + DeleteWingedEdge(); + DeleteViewMap(); - // clears the canvas - _Canvas->Clear(); + // clears the canvas + _Canvas->Clear(); - // soc: reset passes - setPassDiffuse(NULL, 0, 0); - setPassZ(NULL, 0, 0); + // soc: reset passes + setPassDiffuse(NULL, 0, 0); + setPassZ(NULL, 0, 0); } void Controller::ClearRootNode() { - _pView->DetachModel(); - if (NULL != _RootNode) { - int ref = _RootNode->destroy(); - if (0 == ref) - _RootNode->addRef(); - _RootNode->clearBBox(); - } + _pView->DetachModel(); + if (NULL != _RootNode) { + int ref = _RootNode->destroy(); + if (0 == ref) + _RootNode->addRef(); + _RootNode->clearBBox(); + } } void Controller::DeleteWingedEdge() { - if (_winged_edge) { - delete _winged_edge; - _winged_edge = NULL; - } - - // clears the grid - _Grid.clear(); - _Scene3dBBox.clear(); - _SceneNumFaces = 0; + if (_winged_edge) { + delete _winged_edge; + _winged_edge = NULL; + } + + // clears the grid + _Grid.clear(); + _Scene3dBBox.clear(); + _SceneNumFaces = 0; #if 0 - _minEdgeSize = DBL_MAX; + _minEdgeSize = DBL_MAX; #endif } void Controller::DeleteViewMap(bool freeCache) { #if 0 - _pView->DetachSilhouette(); - if (NULL != _SilhouetteNode) { - int ref = _SilhouetteNode->destroy(); - if (0 == ref) { - delete _SilhouetteNode; - _SilhouetteNode = NULL; - } - } - - if (NULL != _ProjectedSilhouette) { - int ref = _ProjectedSilhouette->destroy(); - if (0 == ref) { - delete _ProjectedSilhouette; - _ProjectedSilhouette = NULL; - } - } - if (NULL != _VisibleProjectedSilhouette) { - int ref = _VisibleProjectedSilhouette->destroy(); - if (0 == ref) { - delete _VisibleProjectedSilhouette; - _VisibleProjectedSilhouette = NULL; - } - } - - _pView->DetachDebug(); - if (NULL != _DebugNode) { - int ref = _DebugNode->destroy(); - if (0 == ref) - _DebugNode->addRef(); - } + _pView->DetachSilhouette(); + if (NULL != _SilhouetteNode) { + int ref = _SilhouetteNode->destroy(); + if (0 == ref) { + delete _SilhouetteNode; + _SilhouetteNode = NULL; + } + } + + if (NULL != _ProjectedSilhouette) { + int ref = _ProjectedSilhouette->destroy(); + if (0 == ref) { + delete _ProjectedSilhouette; + _ProjectedSilhouette = NULL; + } + } + if (NULL != _VisibleProjectedSilhouette) { + int ref = _VisibleProjectedSilhouette->destroy(); + if (0 == ref) { + delete _VisibleProjectedSilhouette; + _VisibleProjectedSilhouette = NULL; + } + } + + _pView->DetachDebug(); + if (NULL != _DebugNode) { + int ref = _DebugNode->destroy(); + if (0 == ref) + _DebugNode->addRef(); + } #endif - if (NULL != _ViewMap) { - if (freeCache || !_EnableViewMapCache) { - delete _ViewMap; - _ViewMap = NULL; - prevSceneHash = -1.0; - } - else { - _ViewMap->Clean(); - } - } + if (NULL != _ViewMap) { + if (freeCache || !_EnableViewMapCache) { + delete _ViewMap; + _ViewMap = NULL; + prevSceneHash = -1.0; + } + else { + _ViewMap->Clean(); + } + } } void Controller::ComputeViewMap() { - if (!_ListOfModels.size()) - return; + if (!_ListOfModels.size()) + return; - DeleteViewMap(true); + DeleteViewMap(true); - // retrieve the 3D viewpoint and transformations information - //---------------------------------------------------------- - // Save the viewpoint context at the view level in order - // to be able to restore it later: + // retrieve the 3D viewpoint and transformations information + //---------------------------------------------------------- + // Save the viewpoint context at the view level in order + // to be able to restore it later: - // Restore the context of view: - // we need to perform all these operations while the - // 3D context is on. - Vec3f vp(UNPACK3(g_freestyle.viewpoint)); + // Restore the context of view: + // we need to perform all these operations while the + // 3D context is on. + Vec3f vp(UNPACK3(g_freestyle.viewpoint)); #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "mv" << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "mv" << endl; + } #endif - real mv[4][4]; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mv[i][j] = g_freestyle.mv[i][j]; + real mv[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + mv[i][j] = g_freestyle.mv[i][j]; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << mv[i][j] << " "; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << mv[i][j] << " "; + } #endif - } + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << endl; + } #endif - } + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\nproj" << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\nproj" << endl; + } #endif - real proj[4][4]; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - proj[i][j] = g_freestyle.proj[i][j]; + real proj[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + proj[i][j] = g_freestyle.proj[i][j]; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << proj[i][j] << " "; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << proj[i][j] << " "; + } #endif - } + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << endl; + } #endif - } + } - int viewport[4]; - for (int i = 0; i < 4; i++) - viewport[i] = g_freestyle.viewport[i]; + int viewport[4]; + for (int i = 0; i < 4; i++) + viewport[i] = g_freestyle.viewport[i]; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl; + } #endif - // Flag the WXEdge structure for silhouette edge detection: - //---------------------------------------------------------- - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Detecting silhouette edges ===" << endl; - } - _Chrono.start(); - - edgeDetector.setViewpoint(vp); - edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0); - edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges); - edgeDetector.enableSuggestiveContours(_ComputeSuggestive); - edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries); - edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness); - edgeDetector.setCreaseAngle(_creaseAngle); - edgeDetector.setSphereRadius(_sphereRadius); - edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon); - edgeDetector.setRenderMonitor(_pRenderMonitor); - edgeDetector.processShapes(*_winged_edge); - - real duration = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("Feature lines : %lf\n", duration); - } - - if (_pRenderMonitor->testBreak()) - return; - - // Builds the view map structure from the flagged WSEdge structure: - //---------------------------------------------------------- - ViewMapBuilder vmBuilder; - vmBuilder.setEnableQI(_EnableQI); - vmBuilder.setViewpoint(vp); - vmBuilder.setTransform(mv, proj, viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian()); - vmBuilder.setFrustum(_pView->znear(), _pView->zfar()); - vmBuilder.setGrid(&_Grid); - vmBuilder.setRenderMonitor(_pRenderMonitor); + // Flag the WXEdge structure for silhouette edge detection: + //---------------------------------------------------------- + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Detecting silhouette edges ===" << endl; + } + _Chrono.start(); + + edgeDetector.setViewpoint(vp); + edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0); + edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges); + edgeDetector.enableSuggestiveContours(_ComputeSuggestive); + edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries); + edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness); + edgeDetector.setCreaseAngle(_creaseAngle); + edgeDetector.setSphereRadius(_sphereRadius); + edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon); + edgeDetector.setRenderMonitor(_pRenderMonitor); + edgeDetector.processShapes(*_winged_edge); + + real duration = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + printf("Feature lines : %lf\n", duration); + } + + if (_pRenderMonitor->testBreak()) + return; + + // Builds the view map structure from the flagged WSEdge structure: + //---------------------------------------------------------- + ViewMapBuilder vmBuilder; + vmBuilder.setEnableQI(_EnableQI); + vmBuilder.setViewpoint(vp); + vmBuilder.setTransform( + mv, proj, viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian()); + vmBuilder.setFrustum(_pView->znear(), _pView->zfar()); + vmBuilder.setGrid(&_Grid); + vmBuilder.setRenderMonitor(_pRenderMonitor); #if 0 - // Builds a tesselated form of the silhouette for display purpose: - //--------------------------------------------------------------- - ViewMapTesselator3D sTesselator3d; - ViewMapTesselator2D sTesselator2d; - sTesselator2d.setNature(_edgeTesselationNature); - sTesselator3d.setNature(_edgeTesselationNature); + // Builds a tesselated form of the silhouette for display purpose: + //--------------------------------------------------------------- + ViewMapTesselator3D sTesselator3d; + ViewMapTesselator2D sTesselator2d; + sTesselator2d.setNature(_edgeTesselationNature); + sTesselator3d.setNature(_edgeTesselationNature); #endif - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Building the view map ===" << endl; - } - _Chrono.start(); - // Build View Map - _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces); - _ViewMap->setScene3dBBox(_Scene3dBBox); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Building the view map ===" << endl; + } + _Chrono.start(); + // Build View Map + _ViewMap = vmBuilder.BuildViewMap( + *_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces); + _ViewMap->setScene3dBBox(_Scene3dBBox); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size()); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size()); + } #if 0 - // Tesselate the 3D edges: - _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap); - _SilhouetteNode->addRef(); + // Tesselate the 3D edges: + _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap); + _SilhouetteNode->addRef(); - // Tesselate 2D edges - _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap); - _ProjectedSilhouette->addRef(); + // Tesselate 2D edges + _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap); + _ProjectedSilhouette->addRef(); #endif - duration = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("ViewMap building : %lf\n", duration); - } + duration = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + printf("ViewMap building : %lf\n", duration); + } #if 0 - _pView->AddSilhouette(_SilhouetteNode); - _pView->AddSilhouette(_WRoot); - _pView->Add2DSilhouette(_ProjectedSilhouette); - _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette); - _pView->AddDebug(_DebugNode); + _pView->AddSilhouette(_SilhouetteNode); + _pView->AddSilhouette(_WRoot); + _pView->Add2DSilhouette(_ProjectedSilhouette); + _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette); + _pView->AddDebug(_DebugNode); #endif - // Draw the steerable density map: - //-------------------------------- - if (_ComputeSteerableViewMap) { - ComputeSteerableViewMap(); - } - // Reset Style modules modification flags - resetModified(true); + // Draw the steerable density map: + //-------------------------------- + if (_ComputeSteerableViewMap) { + ComputeSteerableViewMap(); + } + // Reset Style modules modification flags + resetModified(true); - DeleteWingedEdge(); + DeleteWingedEdge(); } void Controller::ComputeSteerableViewMap() { #if 0 //soc - if ((!_Canvas) || (!_ViewMap)) - return; - - // Build 4 nodes containing the edges in the 4 directions - NodeGroup *ng[Canvas::NB_STEERABLE_VIEWMAP]; - unsigned i; - real c = 32.0f/255.0f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32. - for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) { - ng[i] = new NodeGroup; - } - NodeShape *completeNS = new NodeShape; - completeNS->material().setDiffuse(c,c,c,1); - ng[Canvas::NB_STEERABLE_VIEWMAP-1]->AddChild(completeNS); - SteerableViewMap *svm = _Canvas->getSteerableViewMap(); - svm->Reset(); - - ViewMap::fedges_container& fedges = _ViewMap->FEdges(); - LineRep *fRep; - NodeShape *ns; - for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); - f != fend; - ++f) - { - if ((*f)->viewedge()->qi() != 0) - continue; - fRep = new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d()); - completeNS->AddRep(fRep); // add to the complete map anyway - double *oweights = svm->AddFEdge(*f); - for (i = 0; i < (Canvas::NB_STEERABLE_VIEWMAP - 1); ++i) { - ns = new NodeShape; - double wc = oweights[i]*c; - if (oweights[i] == 0) - continue; - ns->material().setDiffuse(wc, wc, wc, 1); - ns->AddRep(fRep); - ng[i]->AddChild(ns); - } - } - - GrayImage *img[Canvas::NB_STEERABLE_VIEWMAP]; - //#ifdef WIN32 - QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height()); - QPixmap pm; - QImage qimg; - for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) { - offscreenBuffer.AddNode(ng[i]); -#if 0 - img[i] = new GrayImage(_pView->width(), _pView->height()); - offscreenBuffer.readPixels(0,0,_pView->width(), _pView->height(), img[i]->getArray()); -#endif - pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height()); - - if (pm.isNull()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl; - } - } - //pm.save(QString("steerable") + QString::number(i) + QString(".bmp"), "BMP"); - // FIXME!! Lost of time ! - qimg = pm.toImage(); - // FIXME !! again! - img[i] = new GrayImage(_pView->width(), _pView->height()); - for (unsigned int y = 0; y < img[i]->height(); ++y) { - for (unsigned int x = 0; x < img[i]->width(); ++x) { - //img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)) / 255.0f); - img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y))); - //float c = qGray(qimg.pixel(x, y)); - //img[i]->setPixel(x, y, qGray(qimg.pixel(x, y))); - } - } - offscreenBuffer.DetachNode(ng[i]); - ng[i]->destroy(); - delete ng[i]; - // check -#if 0 - qimg = QImage(_pView->width(), _pView->height(), 32); - for (unsigned int y = 0; y < img[i]->height(); ++y) { - for (unsigned int x = 0; x < img[i]->width(); ++x) { - float v = img[i]->pixel(x, y); - qimg.setPixel(x, y, qRgb(v, v, v)); - } - } - qimg.save(QString("newsteerable") + QString::number(i) + QString(".bmp"), "BMP"); -#endif - } - - - svm->buildImagesPyramids(img, false, 0, 1.0f); + if ((!_Canvas) || (!_ViewMap)) + return; + + // Build 4 nodes containing the edges in the 4 directions + NodeGroup *ng[Canvas::NB_STEERABLE_VIEWMAP]; + unsigned i; + real c = 32.0f/255.0f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32. + for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) { + ng[i] = new NodeGroup; + } + NodeShape *completeNS = new NodeShape; + completeNS->material().setDiffuse(c,c,c,1); + ng[Canvas::NB_STEERABLE_VIEWMAP-1]->AddChild(completeNS); + SteerableViewMap *svm = _Canvas->getSteerableViewMap(); + svm->Reset(); + + ViewMap::fedges_container& fedges = _ViewMap->FEdges(); + LineRep *fRep; + NodeShape *ns; + for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); + f != fend; + ++f) + { + if ((*f)->viewedge()->qi() != 0) + continue; + fRep = new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d()); + completeNS->AddRep(fRep); // add to the complete map anyway + double *oweights = svm->AddFEdge(*f); + for (i = 0; i < (Canvas::NB_STEERABLE_VIEWMAP - 1); ++i) { + ns = new NodeShape; + double wc = oweights[i]*c; + if (oweights[i] == 0) + continue; + ns->material().setDiffuse(wc, wc, wc, 1); + ns->AddRep(fRep); + ng[i]->AddChild(ns); + } + } + + GrayImage *img[Canvas::NB_STEERABLE_VIEWMAP]; + //#ifdef WIN32 + QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height()); + QPixmap pm; + QImage qimg; + for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) { + offscreenBuffer.AddNode(ng[i]); +# if 0 + img[i] = new GrayImage(_pView->width(), _pView->height()); + offscreenBuffer.readPixels(0,0,_pView->width(), _pView->height(), img[i]->getArray()); +# endif + pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height()); + + if (pm.isNull()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl; + } + } + //pm.save(QString("steerable") + QString::number(i) + QString(".bmp"), "BMP"); + // FIXME!! Lost of time ! + qimg = pm.toImage(); + // FIXME !! again! + img[i] = new GrayImage(_pView->width(), _pView->height()); + for (unsigned int y = 0; y < img[i]->height(); ++y) { + for (unsigned int x = 0; x < img[i]->width(); ++x) { + //img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)) / 255.0f); + img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y))); + //float c = qGray(qimg.pixel(x, y)); + //img[i]->setPixel(x, y, qGray(qimg.pixel(x, y))); + } + } + offscreenBuffer.DetachNode(ng[i]); + ng[i]->destroy(); + delete ng[i]; + // check +# if 0 + qimg = QImage(_pView->width(), _pView->height(), 32); + for (unsigned int y = 0; y < img[i]->height(); ++y) { + for (unsigned int x = 0; x < img[i]->width(); ++x) { + float v = img[i]->pixel(x, y); + qimg.setPixel(x, y, qRgb(v, v, v)); + } + } + qimg.save(QString("newsteerable") + QString::number(i) + QString(".bmp"), "BMP"); +# endif + } + + + svm->buildImagesPyramids(img, false, 0, 1.0f); #endif } void Controller::saveSteerableViewMapImages() { - SteerableViewMap *svm = _Canvas->getSteerableViewMap(); - if (!svm) { - cerr << "the Steerable ViewMap has not been computed yet" << endl; - return; - } - svm->saveSteerableViewMap(); + SteerableViewMap *svm = _Canvas->getSteerableViewMap(); + if (!svm) { + cerr << "the Steerable ViewMap has not been computed yet" << endl; + return; + } + svm->saveSteerableViewMap(); } void Controller::toggleVisibilityAlgo() { - if (_VisibilityAlgo == ViewMapBuilder::ray_casting) { - _VisibilityAlgo = ViewMapBuilder::ray_casting_fast; - } - else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) { - _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast; - } - else { - _VisibilityAlgo = ViewMapBuilder::ray_casting; - } + if (_VisibilityAlgo == ViewMapBuilder::ray_casting) { + _VisibilityAlgo = ViewMapBuilder::ray_casting_fast; + } + else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) { + _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast; + } + else { + _VisibilityAlgo = ViewMapBuilder::ray_casting; + } } void Controller::setVisibilityAlgo(int algo) { - switch (algo) { - case FREESTYLE_ALGO_REGULAR: - _VisibilityAlgo = ViewMapBuilder::ray_casting; - break; - case FREESTYLE_ALGO_FAST: - _VisibilityAlgo = ViewMapBuilder::ray_casting_fast; - break; - case FREESTYLE_ALGO_VERYFAST: - _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast; - break; - case FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL: - _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_traditional; - break; - case FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL: - _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional; - break; - case FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE: - _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_cumulative; - break; - case FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE: - _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_cumulative; - break; - } + switch (algo) { + case FREESTYLE_ALGO_REGULAR: + _VisibilityAlgo = ViewMapBuilder::ray_casting; + break; + case FREESTYLE_ALGO_FAST: + _VisibilityAlgo = ViewMapBuilder::ray_casting_fast; + break; + case FREESTYLE_ALGO_VERYFAST: + _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast; + break; + case FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL: + _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_traditional; + break; + case FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL: + _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional; + break; + case FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE: + _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_cumulative; + break; + case FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE: + _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_cumulative; + break; + } } int Controller::getVisibilityAlgo() { - switch (_VisibilityAlgo) { - case ViewMapBuilder::ray_casting: - return FREESTYLE_ALGO_REGULAR; - case ViewMapBuilder::ray_casting_fast: - return FREESTYLE_ALGO_FAST; - case ViewMapBuilder::ray_casting_very_fast: - return FREESTYLE_ALGO_VERYFAST; - case ViewMapBuilder::ray_casting_culled_adaptive_traditional: - return FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL; - case ViewMapBuilder::ray_casting_adaptive_traditional: - return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL; - case ViewMapBuilder::ray_casting_culled_adaptive_cumulative: - return FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE; - case ViewMapBuilder::ray_casting_adaptive_cumulative: - return FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE; - } - - // ray_casting_adaptive_traditional is the most exact replacement - // for legacy code - return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL; + switch (_VisibilityAlgo) { + case ViewMapBuilder::ray_casting: + return FREESTYLE_ALGO_REGULAR; + case ViewMapBuilder::ray_casting_fast: + return FREESTYLE_ALGO_FAST; + case ViewMapBuilder::ray_casting_very_fast: + return FREESTYLE_ALGO_VERYFAST; + case ViewMapBuilder::ray_casting_culled_adaptive_traditional: + return FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL; + case ViewMapBuilder::ray_casting_adaptive_traditional: + return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL; + case ViewMapBuilder::ray_casting_culled_adaptive_cumulative: + return FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE; + case ViewMapBuilder::ray_casting_adaptive_cumulative: + return FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE; + } + + // ray_casting_adaptive_traditional is the most exact replacement + // for legacy code + return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL; } void Controller::setViewMapCache(bool iBool) { - _EnableViewMapCache = iBool; + _EnableViewMapCache = iBool; } bool Controller::getViewMapCache() const { - return _EnableViewMapCache; + return _EnableViewMapCache; } void Controller::setQuantitativeInvisibility(bool iBool) { - _EnableQI = iBool; + _EnableQI = iBool; } bool Controller::getQuantitativeInvisibility() const { - return _EnableQI; + return _EnableQI; } void Controller::setFaceSmoothness(bool iBool) { - _EnableFaceSmoothness = iBool; + _EnableFaceSmoothness = iBool; } bool Controller::getFaceSmoothness() const { - return _EnableFaceSmoothness; + return _EnableFaceSmoothness; } void Controller::setComputeRidgesAndValleysFlag(bool iBool) { - _ComputeRidges = iBool; + _ComputeRidges = iBool; } bool Controller::getComputeRidgesAndValleysFlag() const { - return _ComputeRidges; + return _ComputeRidges; } void Controller::setComputeSuggestiveContoursFlag(bool b) { - _ComputeSuggestive = b; + _ComputeSuggestive = b; } bool Controller::getComputeSuggestiveContoursFlag() const { - return _ComputeSuggestive; + return _ComputeSuggestive; } void Controller::setComputeMaterialBoundariesFlag(bool b) { - _ComputeMaterialBoundaries = b; + _ComputeMaterialBoundaries = b; } bool Controller::getComputeMaterialBoundariesFlag() const { - return _ComputeMaterialBoundaries; + return _ComputeMaterialBoundaries; } void Controller::setComputeSteerableViewMapFlag(bool iBool) { - _ComputeSteerableViewMap = iBool; + _ComputeSteerableViewMap = iBool; } bool Controller::getComputeSteerableViewMapFlag() const { - return _ComputeSteerableViewMap; + return _ComputeSteerableViewMap; } int Controller::DrawStrokes() { - if (_ViewMap == 0) - return 0; - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Stroke drawing ===" << endl; - } - _Chrono.start(); - _Canvas->Draw(); - real d = _Chrono.stop(); - int strokeCount = _Canvas->getStrokeCount(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Strokes generation : " << d << endl; - cout << "Stroke count : " << strokeCount << endl; - } - resetModified(); - DeleteViewMap(); - return strokeCount; + if (_ViewMap == 0) + return 0; + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Stroke drawing ===" << endl; + } + _Chrono.start(); + _Canvas->Draw(); + real d = _Chrono.stop(); + int strokeCount = _Canvas->getStrokeCount(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Strokes generation : " << d << endl; + cout << "Stroke count : " << strokeCount << endl; + } + resetModified(); + DeleteViewMap(); + return strokeCount; } void Controller::ResetRenderCount() { - _render_count = 0; + _render_count = 0; } Render *Controller::RenderStrokes(Render *re, bool render) { - int totmesh = 0; - _Chrono.start(); - BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count); - if (render) { - _Canvas->Render(blenderRenderer); - totmesh = blenderRenderer->GenerateScene(); - } - real d = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Temporary scene generation: " << d << endl; - } - _Chrono.start(); - Render *freestyle_render = blenderRenderer->RenderScene(re, render); - d = _Chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Stroke rendering : " << d << endl; - - uintptr_t mem_in_use = MEM_get_memory_in_use(); - uintptr_t mmap_in_use = MEM_get_mapped_memory_in_use(); - uintptr_t peak_memory = MEM_get_peak_memory(); - - float megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); - float mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); - float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); - - printf("%d objs, %d verts, %d faces, mem %.2fM (%.2fM, peak %.2fM)\n", - totmesh, freestyle_render->i.totvert, freestyle_render->i.totface, - megs_used_memory, mmap_used_memory, megs_peak_memory); - } - delete blenderRenderer; - - return freestyle_render; + int totmesh = 0; + _Chrono.start(); + BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count); + if (render) { + _Canvas->Render(blenderRenderer); + totmesh = blenderRenderer->GenerateScene(); + } + real d = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Temporary scene generation: " << d << endl; + } + _Chrono.start(); + Render *freestyle_render = blenderRenderer->RenderScene(re, render); + d = _Chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Stroke rendering : " << d << endl; + + uintptr_t mem_in_use = MEM_get_memory_in_use(); + uintptr_t mmap_in_use = MEM_get_mapped_memory_in_use(); + uintptr_t peak_memory = MEM_get_peak_memory(); + + float megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); + float mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); + float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); + + printf("%d objs, %d verts, %d faces, mem %.2fM (%.2fM, peak %.2fM)\n", + totmesh, + freestyle_render->i.totvert, + freestyle_render->i.totface, + megs_used_memory, + mmap_used_memory, + megs_peak_memory); + } + delete blenderRenderer; + + return freestyle_render; } void Controller::InsertStyleModule(unsigned index, const char *iFileName) { - if (!BLI_path_extension_check(iFileName, ".py")) { - cerr << "Error: Cannot load \"" << string(iFileName) << "\", unknown extension" << endl; - return; - } + if (!BLI_path_extension_check(iFileName, ".py")) { + cerr << "Error: Cannot load \"" << string(iFileName) << "\", unknown extension" << endl; + return; + } - StyleModule *sm = new StyleModule(iFileName, _inter); - _Canvas->InsertStyleModule(index, sm); + StyleModule *sm = new StyleModule(iFileName, _inter); + _Canvas->InsertStyleModule(index, sm); } void Controller::InsertStyleModule(unsigned index, const char *iName, const char *iBuffer) { - StyleModule *sm = new BufferedStyleModule(iBuffer, iName, _inter); - _Canvas->InsertStyleModule(index, sm); + StyleModule *sm = new BufferedStyleModule(iBuffer, iName, _inter); + _Canvas->InsertStyleModule(index, sm); } void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText) { - StyleModule *sm = new BlenderStyleModule(iText, iName, _inter); - _Canvas->InsertStyleModule(index, sm); + StyleModule *sm = new BlenderStyleModule(iText, iName, _inter); + _Canvas->InsertStyleModule(index, sm); } void Controller::AddStyleModule(const char * /*iFileName*/) { - //_pStyleWindow->Add(iFileName); + //_pStyleWindow->Add(iFileName); } void Controller::RemoveStyleModule(unsigned index) { - _Canvas->RemoveStyleModule(index); + _Canvas->RemoveStyleModule(index); } void Controller::Clear() { - _Canvas->Clear(); + _Canvas->Clear(); } -void Controller::ReloadStyleModule(unsigned index, const char * iFileName) +void Controller::ReloadStyleModule(unsigned index, const char *iFileName) { - StyleModule *sm = new StyleModule(iFileName, _inter); - _Canvas->ReplaceStyleModule(index, sm); + StyleModule *sm = new StyleModule(iFileName, _inter); + _Canvas->ReplaceStyleModule(index, sm); } void Controller::SwapStyleModules(unsigned i1, unsigned i2) { - _Canvas->SwapStyleModules(i1, i2); + _Canvas->SwapStyleModules(i1, i2); } void Controller::toggleLayer(unsigned index, bool iDisplay) { - _Canvas->setVisible(index, iDisplay); + _Canvas->setVisible(index, iDisplay); } void Controller::setModified(unsigned index, bool iMod) { - //_pStyleWindow->setModified(index, iMod); - _Canvas->setModified(index, iMod); - updateCausalStyleModules(index + 1); + //_pStyleWindow->setModified(index, iMod); + _Canvas->setModified(index, iMod); + updateCausalStyleModules(index + 1); } void Controller::updateCausalStyleModules(unsigned index) { - vector vec; - _Canvas->causalStyleModules(vec, index); - for (vector::const_iterator it = vec.begin(); it != vec.end(); it++) { - //_pStyleWindow->setModified(*it, true); - _Canvas->setModified(*it, true); - } + vector vec; + _Canvas->causalStyleModules(vec, index); + for (vector::const_iterator it = vec.begin(); it != vec.end(); it++) { + //_pStyleWindow->setModified(*it, true); + _Canvas->setModified(*it, true); + } } void Controller::resetModified(bool iMod) { - //_pStyleWindow->resetModified(iMod); - _Canvas->resetModified(iMod); + //_pStyleWindow->resetModified(iMod); + _Canvas->resetModified(iMod); } -NodeGroup *Controller::BuildRep(vector::iterator vedges_begin, vector::iterator vedges_end) +NodeGroup *Controller::BuildRep(vector::iterator vedges_begin, + vector::iterator vedges_end) { - ViewMapTesselator2D tesselator2D; - FrsMaterial mat; - mat.setDiffuse(1, 1, 0.3, 1); - tesselator2D.setFrsMaterial(mat); + ViewMapTesselator2D tesselator2D; + FrsMaterial mat; + mat.setDiffuse(1, 1, 0.3, 1); + tesselator2D.setFrsMaterial(mat); - return (tesselator2D.Tesselate(vedges_begin, vedges_end)); + return (tesselator2D.Tesselate(vedges_begin, vedges_end)); } void Controller::toggleEdgeTesselationNature(Nature::EdgeNature iNature) { - _edgeTesselationNature ^= (iNature); - ComputeViewMap(); + _edgeTesselationNature ^= (iNature); + ComputeViewMap(); } -void Controller::setModelsDir(const string& /*dir*/) +void Controller::setModelsDir(const string & /*dir*/) { - //_current_dirs->setValue("models/dir", dir); + //_current_dirs->setValue("models/dir", dir); } string Controller::getModelsDir() const { - string dir = "."; - //_current_dirs->getValue("models/dir", dir); - return dir; + string dir = "."; + //_current_dirs->getValue("models/dir", dir); + return dir; } -void Controller::setModulesDir(const string& /*dir*/) +void Controller::setModulesDir(const string & /*dir*/) { - //_current_dirs->setValue("modules/dir", dir); + //_current_dirs->setValue("modules/dir", dir); } string Controller::getModulesDir() const { - string dir = "."; - //_current_dirs->getValue("modules/dir", dir); - return dir; + string dir = "."; + //_current_dirs->getValue("modules/dir", dir); + return dir; } void Controller::resetInterpreter() { - if (_inter) - _inter->reset(); + if (_inter) + _inter->reset(); } - void Controller::displayDensityCurves(int x, int y) { - SteerableViewMap *svm = _Canvas->getSteerableViewMap(); - if (!svm) - return; - - unsigned int i, j; - typedef vector densityCurve; - vector curves(svm->getNumberOfOrientations() + 1); - vector curvesDirection(svm->getNumberOfPyramidLevels()); - - // collect the curves values - unsigned nbCurves = svm->getNumberOfOrientations() + 1; - unsigned nbPoints = svm->getNumberOfPyramidLevels(); - if (!nbPoints) - return; - - // build the density/nbLevels curves for each orientation - for (i = 0; i < nbCurves; ++i) { - for (j = 0; j < nbPoints; ++j) { - curves[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(i, j, x, y), 0)); - } - } - // build the density/nbOrientations curves for each level - for (i = 0; i < nbPoints; ++i) { - for (j = 0; j < nbCurves; ++j) { - curvesDirection[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(j, i, x, y), 0)); - } - } - - // display the curves + SteerableViewMap *svm = _Canvas->getSteerableViewMap(); + if (!svm) + return; + + unsigned int i, j; + typedef vector densityCurve; + vector curves(svm->getNumberOfOrientations() + 1); + vector curvesDirection(svm->getNumberOfPyramidLevels()); + + // collect the curves values + unsigned nbCurves = svm->getNumberOfOrientations() + 1; + unsigned nbPoints = svm->getNumberOfPyramidLevels(); + if (!nbPoints) + return; + + // build the density/nbLevels curves for each orientation + for (i = 0; i < nbCurves; ++i) { + for (j = 0; j < nbPoints; ++j) { + curves[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(i, j, x, y), 0)); + } + } + // build the density/nbOrientations curves for each level + for (i = 0; i < nbPoints; ++i) { + for (j = 0; j < nbCurves; ++j) { + curvesDirection[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(j, i, x, y), 0)); + } + } + + // display the curves #if 0 - for (i = 0; i < nbCurves; ++i) - _pDensityCurvesWindow->setOrientationCurve(i, Vec2d(0, 0), Vec2d(nbPoints, 1), curves[i], "scale", "density"); - for (i = 1; i <= 8; ++i) - _pDensityCurvesWindow->setLevelCurve(i, Vec2d(0, 0), Vec2d(nbCurves, 1), curvesDirection[i], - "orientation", "density"); - _pDensityCurvesWindow->show(); + for (i = 0; i < nbCurves; ++i) + _pDensityCurvesWindow->setOrientationCurve(i, Vec2d(0, 0), Vec2d(nbPoints, 1), curves[i], "scale", "density"); + for (i = 1; i <= 8; ++i) + _pDensityCurvesWindow->setLevelCurve(i, Vec2d(0, 0), Vec2d(nbCurves, 1), curvesDirection[i], + "orientation", "density"); + _pDensityCurvesWindow->show(); #endif } void Controller::init_options() { - // from AppOptionsWindow.cpp - // Default init options + // from AppOptionsWindow.cpp + // Default init options - Config::Path * cpath = Config::Path::getInstance(); + Config::Path *cpath = Config::Path::getInstance(); - // Directories - ViewMapIO::Options::setModelsPath(cpath->getModelsPath()); - TextureManager::Options::setPatternsPath(cpath->getPatternsPath()); - TextureManager::Options::setBrushesPath(cpath->getModelsPath()); + // Directories + ViewMapIO::Options::setModelsPath(cpath->getModelsPath()); + TextureManager::Options::setPatternsPath(cpath->getPatternsPath()); + TextureManager::Options::setBrushesPath(cpath->getModelsPath()); - // ViewMap Format - ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS); - ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS); - setComputeSteerableViewMapFlag(false); + // ViewMap Format + ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS); + ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS); + setComputeSteerableViewMapFlag(false); - // Visibility - setQuantitativeInvisibility(true); + // Visibility + setQuantitativeInvisibility(true); - // soc: initialize canvas - _Canvas->init(); + // soc: initialize canvas + _Canvas->init(); - // soc: initialize passes - setPassDiffuse(NULL, 0, 0); - setPassZ(NULL, 0, 0); + // soc: initialize passes + setPassDiffuse(NULL, 0, 0); + setPassZ(NULL, 0, 0); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index 765ea418f5e..be8553c73e1 100644 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -32,7 +32,7 @@ #include "../view_map/ViewMapBuilder.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -47,201 +47,219 @@ class SShape; class ViewEdge; class ViewMap; -class Controller -{ -public: - Controller(); - ~Controller(); - - void setView(AppView *iView); - void setRenderMonitor(RenderMonitor *iRenderMonitor); - void setPassDiffuse(float *buf, int width, int height); - void setPassZ(float *buf, int width, int height); - void setContext(bContext *C); - - //soc - void init_options(); - - int LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); - int Load3DSFile(const char *iFileName); - void CloseFile(); - void ComputeViewMap(); - void ComputeSteerableViewMap(); - void saveSteerableViewMapImages(); - void toggleEdgeTesselationNature(Nature::EdgeNature iNature); - int DrawStrokes(); - void ResetRenderCount(); - Render *RenderStrokes(Render *re, bool render); - void SwapStyleModules(unsigned i1, unsigned i2); - void InsertStyleModule(unsigned index, const char *iFileName); - void InsertStyleModule(unsigned index, const char *iName, const char *iBuffer); - void InsertStyleModule(unsigned index, const char *iName, struct Text *iText); - void AddStyleModule(const char *iFileName); - void RemoveStyleModule(unsigned index); - void ReloadStyleModule(unsigned index, const char * iFileName); - void Clear(); - void ClearRootNode(); - void DeleteWingedEdge(); - void DeleteViewMap(bool freeCache = false); - void toggleLayer(unsigned index, bool iDisplay); - void setModified(unsigned index, bool iMod); - void resetModified(bool iMod=false); - void updateCausalStyleModules(unsigned index); - void displayDensityCurves(int x, int y); - - ViewEdge *SelectViewEdge(real x, real y); - FEdge *SelectFEdge(real x, real y); - NodeGroup *BuildRep(vector::iterator vedges_begin, vector::iterator vedges_end) ; +class Controller { + public: + Controller(); + ~Controller(); + + void setView(AppView *iView); + void setRenderMonitor(RenderMonitor *iRenderMonitor); + void setPassDiffuse(float *buf, int width, int height); + void setPassZ(float *buf, int width, int height); + void setContext(bContext *C); + + //soc + void init_options(); + + int LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); + int Load3DSFile(const char *iFileName); + void CloseFile(); + void ComputeViewMap(); + void ComputeSteerableViewMap(); + void saveSteerableViewMapImages(); + void toggleEdgeTesselationNature(Nature::EdgeNature iNature); + int DrawStrokes(); + void ResetRenderCount(); + Render *RenderStrokes(Render *re, bool render); + void SwapStyleModules(unsigned i1, unsigned i2); + void InsertStyleModule(unsigned index, const char *iFileName); + void InsertStyleModule(unsigned index, const char *iName, const char *iBuffer); + void InsertStyleModule(unsigned index, const char *iName, struct Text *iText); + void AddStyleModule(const char *iFileName); + void RemoveStyleModule(unsigned index); + void ReloadStyleModule(unsigned index, const char *iFileName); + void Clear(); + void ClearRootNode(); + void DeleteWingedEdge(); + void DeleteViewMap(bool freeCache = false); + void toggleLayer(unsigned index, bool iDisplay); + void setModified(unsigned index, bool iMod); + void resetModified(bool iMod = false); + void updateCausalStyleModules(unsigned index); + void displayDensityCurves(int x, int y); + + ViewEdge *SelectViewEdge(real x, real y); + FEdge *SelectFEdge(real x, real y); + NodeGroup *BuildRep(vector::iterator vedges_begin, + vector::iterator vedges_end); #if 0 - NodeGroup *debugNode() {return _DebugNode;} - AppView *view() {return _pView;} - NodeGroup *debugScene() {return _DebugNode;} - Grid& grid() {return _Grid;} + NodeGroup *debugNode() {return _DebugNode;} + AppView *view() {return _pView;} + NodeGroup *debugScene() {return _DebugNode;} + Grid& grid() {return _Grid;} #endif - void toggleVisibilityAlgo(); - void setVisibilityAlgo(int algo); - int getVisibilityAlgo(); - - void setViewMapCache(bool iBool); - bool getViewMapCache() const; - void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility - bool getQuantitativeInvisibility() const; - void setFaceSmoothness(bool iBool); - bool getFaceSmoothness() const; - - void setComputeRidgesAndValleysFlag(bool b); - bool getComputeRidgesAndValleysFlag() const; - void setComputeSuggestiveContoursFlag(bool b); - bool getComputeSuggestiveContoursFlag() const; - void setComputeMaterialBoundariesFlag(bool b); - bool getComputeMaterialBoundariesFlag() const; - - void setComputeSteerableViewMapFlag(bool iBool); - bool getComputeSteerableViewMapFlag() const; - void setCreaseAngle(float angle) {_creaseAngle = angle;} - float getCreaseAngle() const {return _creaseAngle;} - void setSphereRadius(float s) {_sphereRadius = s;} - float getSphereRadius() const {return _sphereRadius;} - void setSuggestiveContourKrDerivativeEpsilon(float dkr) {_suggestiveContourKrDerivativeEpsilon = dkr;} - float getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;} - - void setModelsDir(const string& dir); - string getModelsDir() const; - void setModulesDir(const string& dir); - string getModulesDir() const; - - bool hitViewMapCache(); - - void resetInterpreter(); - -public: - // Viewmap data structure - ViewMap *_ViewMap; - - // Canvas - AppCanvas *_Canvas; - -private: - // Main Window: - //AppMainWindow *_pMainWindow; - - // List of models currently loaded - vector _ListOfModels; - - // Current directories - //ConfigIO* _current_dirs; - - //View - // 3D - AppView *_pView; - - // 2D + void toggleVisibilityAlgo(); + void setVisibilityAlgo(int algo); + int getVisibilityAlgo(); + + void setViewMapCache(bool iBool); + bool getViewMapCache() const; + void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility + bool getQuantitativeInvisibility() const; + void setFaceSmoothness(bool iBool); + bool getFaceSmoothness() const; + + void setComputeRidgesAndValleysFlag(bool b); + bool getComputeRidgesAndValleysFlag() const; + void setComputeSuggestiveContoursFlag(bool b); + bool getComputeSuggestiveContoursFlag() const; + void setComputeMaterialBoundariesFlag(bool b); + bool getComputeMaterialBoundariesFlag() const; + + void setComputeSteerableViewMapFlag(bool iBool); + bool getComputeSteerableViewMapFlag() const; + void setCreaseAngle(float angle) + { + _creaseAngle = angle; + } + float getCreaseAngle() const + { + return _creaseAngle; + } + void setSphereRadius(float s) + { + _sphereRadius = s; + } + float getSphereRadius() const + { + return _sphereRadius; + } + void setSuggestiveContourKrDerivativeEpsilon(float dkr) + { + _suggestiveContourKrDerivativeEpsilon = dkr; + } + float getSuggestiveContourKrDerivativeEpsilon() const + { + return _suggestiveContourKrDerivativeEpsilon; + } + + void setModelsDir(const string &dir); + string getModelsDir() const; + void setModulesDir(const string &dir); + string getModulesDir() const; + + bool hitViewMapCache(); + + void resetInterpreter(); + + public: + // Viewmap data structure + ViewMap *_ViewMap; + + // Canvas + AppCanvas *_Canvas; + + private: + // Main Window: + //AppMainWindow *_pMainWindow; + + // List of models currently loaded + vector _ListOfModels; + + // Current directories + //ConfigIO* _current_dirs; + + //View + // 3D + AppView *_pView; + + // 2D #if 0 - Viewer2DWindow *_pView2DWindow; - Viewer2D *_pView2D; + Viewer2DWindow *_pView2DWindow; + Viewer2D *_pView2D; #endif - RenderMonitor *_pRenderMonitor; + RenderMonitor *_pRenderMonitor; - //Model - // Drawing Structure - NodeGroup *_RootNode; + //Model + // Drawing Structure + NodeGroup *_RootNode; - // Winged-Edge structure - WingedEdge *_winged_edge; + // Winged-Edge structure + WingedEdge *_winged_edge; #if 0 - // Silhouette structure: - std::vector _SShapes; - NodeGroup *_SRoot; + // Silhouette structure: + std::vector _SShapes; + NodeGroup *_SRoot; - // Silhouette - NodeGroup *_SilhouetteNode; - NodeGroup *_ProjectedSilhouette; - NodeGroup *_VisibleProjectedSilhouette; + // Silhouette + NodeGroup *_SilhouetteNode; + NodeGroup *_ProjectedSilhouette; + NodeGroup *_VisibleProjectedSilhouette; - // more Debug info - NodeGroup *_DebugNode; + // more Debug info + NodeGroup *_DebugNode; #endif - // debug - //NodeUser *_ViewMapNode; // FIXME + // debug + //NodeUser *_ViewMapNode; // FIXME - // Chronometer: - Chronometer _Chrono; + // Chronometer: + Chronometer _Chrono; - // Progress Bar - ProgressBar *_ProgressBar; + // Progress Bar + ProgressBar *_ProgressBar; - // edges tesselation nature - int _edgeTesselationNature; + // edges tesselation nature + int _edgeTesselationNature; - FastGrid _Grid; - //HashGrid _Grid; + FastGrid _Grid; + //HashGrid _Grid; - BBox _Scene3dBBox; - unsigned int _SceneNumFaces; + BBox _Scene3dBBox; + unsigned int _SceneNumFaces; #if 0 - real _minEdgeSize; + real _minEdgeSize; #endif - real _EPSILON; - real _bboxDiag; + real _EPSILON; + real _bboxDiag; - int _render_count; + int _render_count; - //AppStyleWindow *_pStyleWindow; - //AppOptionsWindow *_pOptionsWindow; - //AppDensityCurvesWindow *_pDensityCurvesWindow; + //AppStyleWindow *_pStyleWindow; + //AppOptionsWindow *_pOptionsWindow; + //AppDensityCurvesWindow *_pDensityCurvesWindow; - ViewMapBuilder::visibility_algo _VisibilityAlgo; + ViewMapBuilder::visibility_algo _VisibilityAlgo; - // Script Interpreter - Interpreter *_inter; + // Script Interpreter + Interpreter *_inter; - string _help_index; - string _browser_cmd; + string _help_index; + string _browser_cmd; - bool _EnableViewMapCache; - bool _EnableQI; - bool _EnableFaceSmoothness; - bool _ComputeRidges; - bool _ComputeSuggestive; - bool _ComputeMaterialBoundaries; - float _creaseAngle; - float _sphereRadius; - float _suggestiveContourKrDerivativeEpsilon; + bool _EnableViewMapCache; + bool _EnableQI; + bool _EnableFaceSmoothness; + bool _ComputeRidges; + bool _ComputeSuggestive; + bool _ComputeMaterialBoundaries; + float _creaseAngle; + float _sphereRadius; + float _suggestiveContourKrDerivativeEpsilon; - bool _ComputeSteerableViewMap; + bool _ComputeSteerableViewMap; - FEdgeXDetector edgeDetector; + FEdgeXDetector edgeDetector; - SceneHash sceneHashFunc; - real prevSceneHash; + SceneHash sceneHashFunc; + real prevSceneHash; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller") #endif }; @@ -249,4 +267,4 @@ extern Controller *g_pController; } /* namespace Freestyle */ -#endif // __CONTROLLER_H__ +#endif // __CONTROLLER_H__ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index 1e2bfecff6a..6b14c9ec70f 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -30,151 +30,145 @@ namespace Freestyle { BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { - _re = re; - _depsgraph = depsgraph; - _Scene = NULL; - _numFacesRead = 0; + _re = re; + _depsgraph = depsgraph; + _Scene = NULL; + _numFacesRead = 0; #if 0 - _minEdgeSize = DBL_MAX; + _minEdgeSize = DBL_MAX; #endif - _smooth = (view_layer->freestyle_config.flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) != 0; - _pRenderMonitor = NULL; + _smooth = (view_layer->freestyle_config.flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) != 0; + _pRenderMonitor = NULL; } BlenderFileLoader::~BlenderFileLoader() { - _Scene = NULL; + _Scene = NULL; } NodeGroup *BlenderFileLoader::Load() { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Importing triangular meshes into Blender ===" << endl; - } - - // creation of the scene root node - _Scene = new NodeGroup; - - _viewplane_left = _re->viewplane.xmin; - _viewplane_right = _re->viewplane.xmax; - _viewplane_bottom = _re->viewplane.ymin; - _viewplane_top = _re->viewplane.ymax; - - if (_re->clip_start < 0.f) { - // Adjust clipping start/end and set up a Z offset when the viewport preview - // is used with the orthographic view. In this case, _re->clip_start is negative, - // while Freestyle assumes that imported mesh data are in the camera coordinate - // system with the view point located at origin [bug #36009]. - _z_near = -0.001f; - _z_offset = _re->clip_start + _z_near; - _z_far = -_re->clip_end + _z_offset; - } - else { - _z_near = -_re->clip_start; - _z_far = -_re->clip_end; - _z_offset = 0.f; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Importing triangular meshes into Blender ===" << endl; + } + + // creation of the scene root node + _Scene = new NodeGroup; + + _viewplane_left = _re->viewplane.xmin; + _viewplane_right = _re->viewplane.xmax; + _viewplane_bottom = _re->viewplane.ymin; + _viewplane_top = _re->viewplane.ymax; + + if (_re->clip_start < 0.f) { + // Adjust clipping start/end and set up a Z offset when the viewport preview + // is used with the orthographic view. In this case, _re->clip_start is negative, + // while Freestyle assumes that imported mesh data are in the camera coordinate + // system with the view point located at origin [bug #36009]. + _z_near = -0.001f; + _z_offset = _re->clip_start + _z_near; + _z_far = -_re->clip_end + _z_offset; + } + else { + _z_near = -_re->clip_start; + _z_far = -_re->clip_end; + _z_offset = 0.f; + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right - << " b " << _viewplane_bottom << " t " << _viewplane_top - << " n " << _z_near << " f " << _z_far << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right + << " b " << _viewplane_bottom << " t " << _viewplane_top + << " n " << _z_near << " f " << _z_far << endl; + } #endif - int id = 0; - - DEG_OBJECT_ITER_BEGIN( - _depsgraph, ob, - DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | - DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | - DEG_ITER_OBJECT_FLAG_VISIBLE | - DEG_ITER_OBJECT_FLAG_DUPLI) - { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) { - break; - } - - if (ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) { - continue; - } - - bool apply_modifiers = false; - bool calc_undeformed = false; - Mesh *mesh = BKE_mesh_new_from_object(_depsgraph, - _re->main, - _re->scene, - ob, - apply_modifiers, - calc_undeformed); - - if (mesh) { - insertShapeNode(ob, mesh, ++id); - BKE_id_free_ex(_re->main, &mesh->id, LIB_ID_FREE_NO_UI_USER, true); - } - } - DEG_OBJECT_ITER_END; - - // Return the built scene. - return _Scene; + int id = 0; + + DEG_OBJECT_ITER_BEGIN (_depsgraph, + ob, + DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | + DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | DEG_ITER_OBJECT_FLAG_VISIBLE | + DEG_ITER_OBJECT_FLAG_DUPLI) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) { + break; + } + + if (ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) { + continue; + } + + bool apply_modifiers = false; + bool calc_undeformed = false; + Mesh *mesh = BKE_mesh_new_from_object( + _depsgraph, _re->main, _re->scene, ob, apply_modifiers, calc_undeformed); + + if (mesh) { + insertShapeNode(ob, mesh, ++id); + BKE_id_free_ex(_re->main, &mesh->id, LIB_ID_FREE_NO_UI_USER, true); + } + } + DEG_OBJECT_ITER_END; + + // Return the built scene. + return _Scene; } #define CLIPPED_BY_NEAR -1 -#define NOT_CLIPPED 0 -#define CLIPPED_BY_FAR 1 +#define NOT_CLIPPED 0 +#define CLIPPED_BY_FAR 1 // check if each vertex of a triangle (V1, V2, V3) is clipped by the near/far plane // and calculate the number of triangles to be generated by clipping int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]) { - float *v[3]; - int numClipped, sum, numTris = 0; - - v[0] = v1; - v[1] = v2; - v[2] = v3; - numClipped = sum = 0; - for (int i = 0; i < 3; i++) { - if (v[i][2] > _z_near) { - clip[i] = CLIPPED_BY_NEAR; - numClipped++; - } - else if (v[i][2] < _z_far) { - clip[i] = CLIPPED_BY_FAR; - numClipped++; - } - else { - clip[i] = NOT_CLIPPED; - } + float *v[3]; + int numClipped, sum, numTris = 0; + + v[0] = v1; + v[1] = v2; + v[2] = v3; + numClipped = sum = 0; + for (int i = 0; i < 3; i++) { + if (v[i][2] > _z_near) { + clip[i] = CLIPPED_BY_NEAR; + numClipped++; + } + else if (v[i][2] < _z_far) { + clip[i] = CLIPPED_BY_FAR; + numClipped++; + } + else { + clip[i] = NOT_CLIPPED; + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far"); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far"); + } #endif - sum += clip[i]; - } - switch (numClipped) { - case 0: - numTris = 1; // triangle - break; - case 1: - numTris = 2; // tetragon - break; - case 2: - if (sum == 0) - numTris = 3; // pentagon - else - numTris = 1; // triangle - break; - case 3: - if (sum == 3 || sum == -3) - numTris = 0; - else - numTris = 2; // tetragon - break; - } - return numTris; + sum += clip[i]; + } + switch (numClipped) { + case 0: + numTris = 1; // triangle + break; + case 1: + numTris = 2; // tetragon + break; + case 2: + if (sum == 0) + numTris = 3; // pentagon + else + numTris = 1; // triangle + break; + case 3: + if (sum == 3 || sum == -3) + numTris = 0; + else + numTris = 2; // tetragon + break; + } + return numTris; } // find the intersection point C between the line segment from V1 to V2 and @@ -182,143 +176,168 @@ int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3], // the X and Y components are unknown). void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z) { - // Order v1 and v2 by Z values to make sure that clipLine(P, Q, c, z) - // and clipLine(Q, P, c, z) gives exactly the same numerical result. - float *p, *q; - if (v1[2] < v2[2]) { - p = v1; - q = v2; - } - else { - p = v2; - q = v1; - } - double d[3]; - for (int i = 0; i < 3; i++) - d[i] = q[i] - p[i]; - double t = (z - p[2]) / d[2]; - c[0] = p[0] + t * d[0]; - c[1] = p[1] + t * d[1]; - c[2] = z; + // Order v1 and v2 by Z values to make sure that clipLine(P, Q, c, z) + // and clipLine(Q, P, c, z) gives exactly the same numerical result. + float *p, *q; + if (v1[2] < v2[2]) { + p = v1; + q = v2; + } + else { + p = v2; + q = v1; + } + double d[3]; + for (int i = 0; i < 3; i++) + d[i] = q[i] - p[i]; + double t = (z - p[2]) / d[2]; + c[0] = p[0] + t * d[0]; + c[1] = p[1] + t * d[1]; + c[2] = z; } // clip the triangle (V1, V2, V3) by the near and far clipping plane and // obtain a set of vertices after the clipping. The number of vertices // is at most 5. -void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], - float triNormals[][3], float n1[3], float n2[3], float n3[3], - bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3]) +void BlenderFileLoader::clipTriangle(int numTris, + float triCoords[][3], + float v1[3], + float v2[3], + float v3[3], + float triNormals[][3], + float n1[3], + float n2[3], + float n3[3], + bool edgeMarks[], + bool em1, + bool em2, + bool em3, + int clip[3]) { - float *v[3], *n[3]; - bool em[3]; - int i, j, k; - - v[0] = v1; n[0] = n1; - v[1] = v2; n[1] = n2; - v[2] = v3; n[2] = n3; - em[0] = em1; /* edge mark of the edge between v1 and v2 */ - em[1] = em2; /* edge mark of the edge between v2 and v3 */ - em[2] = em3; /* edge mark of the edge between v3 and v1 */ - k = 0; - for (i = 0; i < 3; i++) { - j = (i + 1) % 3; - if (clip[i] == NOT_CLIPPED) { - copy_v3_v3(triCoords[k], v[i]); - copy_v3_v3(triNormals[k], n[i]); - edgeMarks[k] = em[i]; - k++; - if (clip[j] != NOT_CLIPPED) { - clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far); - copy_v3_v3(triNormals[k], n[j]); - edgeMarks[k] = false; - k++; - } - } - else if (clip[i] != clip[j]) { - if (clip[j] == NOT_CLIPPED) { - clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far); - copy_v3_v3(triNormals[k], n[i]); - edgeMarks[k] = em[i]; - k++; - } - else { - clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far); - copy_v3_v3(triNormals[k], n[i]); - edgeMarks[k] = em[i]; - k++; - clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far); - copy_v3_v3(triNormals[k], n[j]); - edgeMarks[k] = false; - k++; - } - } - } - BLI_assert(k == 2 + numTris); - (void)numTris; /* Ignored in release builds. */ + float *v[3], *n[3]; + bool em[3]; + int i, j, k; + + v[0] = v1; + n[0] = n1; + v[1] = v2; + n[1] = n2; + v[2] = v3; + n[2] = n3; + em[0] = em1; /* edge mark of the edge between v1 and v2 */ + em[1] = em2; /* edge mark of the edge between v2 and v3 */ + em[2] = em3; /* edge mark of the edge between v3 and v1 */ + k = 0; + for (i = 0; i < 3; i++) { + j = (i + 1) % 3; + if (clip[i] == NOT_CLIPPED) { + copy_v3_v3(triCoords[k], v[i]); + copy_v3_v3(triNormals[k], n[i]); + edgeMarks[k] = em[i]; + k++; + if (clip[j] != NOT_CLIPPED) { + clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far); + copy_v3_v3(triNormals[k], n[j]); + edgeMarks[k] = false; + k++; + } + } + else if (clip[i] != clip[j]) { + if (clip[j] == NOT_CLIPPED) { + clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far); + copy_v3_v3(triNormals[k], n[i]); + edgeMarks[k] = em[i]; + k++; + } + else { + clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far); + copy_v3_v3(triNormals[k], n[i]); + edgeMarks[k] = em[i]; + k++; + clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far); + copy_v3_v3(triNormals[k], n[j]); + edgeMarks[k] = false; + k++; + } + } + } + BLI_assert(k == 2 + numTris); + (void)numTris; /* Ignored in release builds. */ } -void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3], - float n1[3], float n2[3], float n3[3], - bool fm, bool em1, bool em2, bool em3) +void BlenderFileLoader::addTriangle(struct LoaderState *ls, + float v1[3], + float v2[3], + float v3[3], + float n1[3], + float n2[3], + float n3[3], + bool fm, + bool em1, + bool em2, + bool em3) { - float *fv[3], *fn[3]; + float *fv[3], *fn[3]; #if 0 - float len; + float len; #endif - unsigned int i, j; - IndexedFaceSet::FaceEdgeMark marks = 0; - - // initialize the bounding box by the first vertex - if (ls->currentIndex == 0) { - copy_v3_v3(ls->minBBox, v1); - copy_v3_v3(ls->maxBBox, v1); - } - - fv[0] = v1; fn[0] = n1; - fv[1] = v2; fn[1] = n2; - fv[2] = v3; fn[2] = n3; - for (i = 0; i < 3; i++) { - - copy_v3_v3(ls->pv, fv[i]); - copy_v3_v3(ls->pn, fn[i]); - - // update the bounding box - for (j = 0; j < 3; j++) { - if (ls->minBBox[j] > ls->pv[j]) - ls->minBBox[j] = ls->pv[j]; - - if (ls->maxBBox[j] < ls->pv[j]) - ls->maxBBox[j] = ls->pv[j]; - } + unsigned int i, j; + IndexedFaceSet::FaceEdgeMark marks = 0; + + // initialize the bounding box by the first vertex + if (ls->currentIndex == 0) { + copy_v3_v3(ls->minBBox, v1); + copy_v3_v3(ls->maxBBox, v1); + } + + fv[0] = v1; + fn[0] = n1; + fv[1] = v2; + fn[1] = n2; + fv[2] = v3; + fn[2] = n3; + for (i = 0; i < 3; i++) { + + copy_v3_v3(ls->pv, fv[i]); + copy_v3_v3(ls->pn, fn[i]); + + // update the bounding box + for (j = 0; j < 3; j++) { + if (ls->minBBox[j] > ls->pv[j]) + ls->minBBox[j] = ls->pv[j]; + + if (ls->maxBBox[j] < ls->pv[j]) + ls->maxBBox[j] = ls->pv[j]; + } #if 0 - len = len_v3v3(fv[i], fv[(i + 1) % 3]); - if (_minEdgeSize > len) - _minEdgeSize = len; + len = len_v3v3(fv[i], fv[(i + 1) % 3]); + if (_minEdgeSize > len) + _minEdgeSize = len; #endif - *ls->pvi = ls->currentIndex; - *ls->pni = ls->currentIndex; - *ls->pmi = ls->currentMIndex; - - ls->currentIndex += 3; - ls->pv += 3; - ls->pn += 3; - - ls->pvi++; - ls->pni++; - ls->pmi++; - } - - if (fm) - marks |= IndexedFaceSet::FACE_MARK; - if (em1) - marks |= IndexedFaceSet::EDGE_MARK_V1V2; - if (em2) - marks |= IndexedFaceSet::EDGE_MARK_V2V3; - if (em3) - marks |= IndexedFaceSet::EDGE_MARK_V3V1; - *(ls->pm++) = marks; + *ls->pvi = ls->currentIndex; + *ls->pni = ls->currentIndex; + *ls->pmi = ls->currentMIndex; + + ls->currentIndex += 3; + ls->pv += 3; + ls->pn += 3; + + ls->pvi++; + ls->pni++; + ls->pmi++; + } + + if (fm) + marks |= IndexedFaceSet::FACE_MARK; + if (em1) + marks |= IndexedFaceSet::EDGE_MARK_V1V2; + if (em2) + marks |= IndexedFaceSet::EDGE_MARK_V2V3; + if (em3) + marks |= IndexedFaceSet::EDGE_MARK_V3V1; + *(ls->pm++) = marks; } // With A, B and P indicating the three vertices of a given triangle, returns: @@ -327,420 +346,445 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v // zero otherwise. int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3[3]) { - const float eps = 1.0e-6; - const float eps_sq = eps * eps; + const float eps = 1.0e-6; + const float eps_sq = eps * eps; #if 0 - float area = area_tri_v3(v1, v2, v3); - bool verbose = (area < 1.0e-6); + float area = area_tri_v3(v1, v2, v3); + bool verbose = (area < 1.0e-6); #endif - if (equals_v3v3(v1, v2) || equals_v3v3(v2, v3) || equals_v3v3(v1, v3)) { + if (equals_v3v3(v1, v2) || equals_v3v3(v2, v3) || equals_v3v3(v1, v3)) { #if 0 - if (verbose && G.debug & G_DEBUG_FREESTYLE) { - printf("BlenderFileLoader::testDegenerateTriangle = 1\n"); - } + if (verbose && G.debug & G_DEBUG_FREESTYLE) { + printf("BlenderFileLoader::testDegenerateTriangle = 1\n"); + } #endif - return 1; - } - if (dist_squared_to_line_segment_v3(v1, v2, v3) < eps_sq || - dist_squared_to_line_segment_v3(v2, v1, v3) < eps_sq || - dist_squared_to_line_segment_v3(v3, v1, v2) < eps_sq) - { + return 1; + } + if (dist_squared_to_line_segment_v3(v1, v2, v3) < eps_sq || + dist_squared_to_line_segment_v3(v2, v1, v3) < eps_sq || + dist_squared_to_line_segment_v3(v3, v1, v2) < eps_sq) { #if 0 - if (verbose && G.debug & G_DEBUG_FREESTYLE) { - printf("BlenderFileLoader::testDegenerateTriangle = 2\n"); - } + if (verbose && G.debug & G_DEBUG_FREESTYLE) { + printf("BlenderFileLoader::testDegenerateTriangle = 2\n"); + } #endif - return 2; - } + return 2; + } #if 0 - if (verbose && G.debug & G_DEBUG_FREESTYLE) { - printf("BlenderFileLoader::testDegenerateTriangle = 0\n"); - } + if (verbose && G.debug & G_DEBUG_FREESTYLE) { + printf("BlenderFileLoader::testDegenerateTriangle = 0\n"); + } #endif - return 0; + return 0; } static bool testEdgeMark(Mesh *me, FreestyleEdge *fed, const MLoopTri *lt, int i) { - MLoop *mloop = &me->mloop[lt->tri[i]]; - MLoop *mloop_next = &me->mloop[lt->tri[(i+1)%3]]; - MEdge *medge = &me->medge[mloop->e]; + MLoop *mloop = &me->mloop[lt->tri[i]]; + MLoop *mloop_next = &me->mloop[lt->tri[(i + 1) % 3]]; + MEdge *medge = &me->medge[mloop->e]; - if (!ELEM(mloop_next->v, medge->v1, medge->v2)) { - /* Not an edge in the original mesh before triangulation. */ - return false; - } + if (!ELEM(mloop_next->v, medge->v1, medge->v2)) { + /* Not an edge in the original mesh before triangulation. */ + return false; + } - return (fed[mloop->e].flag & FREESTYLE_EDGE_MARK) != 0; + return (fed[mloop->e].flag & FREESTYLE_EDGE_MARK) != 0; } void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) { - char *name = ob->id.name + 2; - - // Compute loop triangles - int tottri = poly_to_tri_count(me->totpoly, me->totloop); - MLoopTri *mlooptri = (MLoopTri*)MEM_malloc_arrayN(tottri, sizeof(*mlooptri), __func__); - BKE_mesh_recalc_looptri( - me->mloop, me->mpoly, - me->mvert, - me->totloop, me->totpoly, - mlooptri); - - // Compute loop normals - BKE_mesh_calc_normals_split(me); - float (*lnors)[3] = NULL; - - if (CustomData_has_layer(&me->ldata, CD_NORMAL)) { - lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL); - } - - // Get other mesh data - MVert *mvert = me->mvert; - MLoop *mloop = me->mloop; - MPoly *mpoly = me->mpoly; - FreestyleEdge *fed = (FreestyleEdge*)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE); - FreestyleFace *ffa = (FreestyleFace*)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE); - - // Compute view matrix - Object *ob_camera_eval = DEG_get_evaluated_object(_depsgraph, RE_GetCamera(_re)); - float viewinv[4][4], viewmat[4][4]; - RE_GetCameraModelMatrix(_re, ob_camera_eval, viewinv); - invert_m4_m4(viewmat, viewinv); - - // Compute matrix including camera transform - float obmat[4][4], nmat[4][4]; - mul_m4_m4m4(obmat, viewmat, ob->obmat); - invert_m4_m4(nmat, obmat); - transpose_m4(nmat); - - // We count the number of triangles after the clipping by the near and far view - // planes is applied (Note: mesh vertices are in the camera coordinate system). - unsigned numFaces = 0; - float v1[3], v2[3], v3[3]; - float n1[3], n2[3], n3[3], facenormal[3]; - int clip[3]; - for (int a = 0; a < tottri; a++) { - const MLoopTri *lt = &mlooptri[a]; - - copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); - copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); - copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); - - mul_m4_v3(obmat, v1); - mul_m4_v3(obmat, v2); - mul_m4_v3(obmat, v3); - - v1[2] += _z_offset; - v2[2] += _z_offset; - v3[2] += _z_offset; - - numFaces += countClippedFaces(v1, v2, v3, clip); - } + char *name = ob->id.name + 2; + + // Compute loop triangles + int tottri = poly_to_tri_count(me->totpoly, me->totloop); + MLoopTri *mlooptri = (MLoopTri *)MEM_malloc_arrayN(tottri, sizeof(*mlooptri), __func__); + BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, mlooptri); + + // Compute loop normals + BKE_mesh_calc_normals_split(me); + float(*lnors)[3] = NULL; + + if (CustomData_has_layer(&me->ldata, CD_NORMAL)) { + lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL); + } + + // Get other mesh data + MVert *mvert = me->mvert; + MLoop *mloop = me->mloop; + MPoly *mpoly = me->mpoly; + FreestyleEdge *fed = (FreestyleEdge *)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE); + FreestyleFace *ffa = (FreestyleFace *)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE); + + // Compute view matrix + Object *ob_camera_eval = DEG_get_evaluated_object(_depsgraph, RE_GetCamera(_re)); + float viewinv[4][4], viewmat[4][4]; + RE_GetCameraModelMatrix(_re, ob_camera_eval, viewinv); + invert_m4_m4(viewmat, viewinv); + + // Compute matrix including camera transform + float obmat[4][4], nmat[4][4]; + mul_m4_m4m4(obmat, viewmat, ob->obmat); + invert_m4_m4(nmat, obmat); + transpose_m4(nmat); + + // We count the number of triangles after the clipping by the near and far view + // planes is applied (Note: mesh vertices are in the camera coordinate system). + unsigned numFaces = 0; + float v1[3], v2[3], v3[3]; + float n1[3], n2[3], n3[3], facenormal[3]; + int clip[3]; + for (int a = 0; a < tottri; a++) { + const MLoopTri *lt = &mlooptri[a]; + + copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); + copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); + copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); + + mul_m4_v3(obmat, v1); + mul_m4_v3(obmat, v2); + mul_m4_v3(obmat, v3); + + v1[2] += _z_offset; + v2[2] += _z_offset; + v3[2] += _z_offset; + + numFaces += countClippedFaces(v1, v2, v3, clip); + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "numFaces " << numFaces << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "numFaces " << numFaces << endl; + } #endif - if (numFaces == 0) { - MEM_freeN(mlooptri); - return; - } - - // We allocate memory for the meshes to be imported - NodeGroup *currentMesh = new NodeGroup; - NodeShape *shape = new NodeShape; - - unsigned vSize = 3 * 3 * numFaces; - float *vertices = new float[vSize]; - unsigned nSize = vSize; - float *normals = new float[nSize]; - unsigned *numVertexPerFaces = new unsigned[numFaces]; - vector meshMaterials; - vector meshFrsMaterials; - - IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces]; - unsigned i; - for (i = 0; i poly]; - Material *mat = give_current_material(ob, mp->mat_nr + 1); - - copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); - copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); - copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); - - mul_m4_v3(obmat, v1); - mul_m4_v3(obmat, v2); - mul_m4_v3(obmat, v3); - - v1[2] += _z_offset; - v2[2] += _z_offset; - v3[2] += _z_offset; - - if (_smooth && (mp->flag & ME_SMOOTH) && lnors) { - copy_v3_v3(n1, lnors[lt->tri[0]]); - copy_v3_v3(n2, lnors[lt->tri[1]]); - copy_v3_v3(n3, lnors[lt->tri[2]]); - - mul_mat3_m4_v3(nmat, n1); - mul_mat3_m4_v3(nmat, n2); - mul_mat3_m4_v3(nmat, n3); - - normalize_v3(n1); - normalize_v3(n2); - normalize_v3(n3); - } - else { - normal_tri_v3(facenormal, v3, v2, v1); - - copy_v3_v3(n1, facenormal); - copy_v3_v3(n2, facenormal); - copy_v3_v3(n3, facenormal); - } - - unsigned int numTris = countClippedFaces(v1, v2, v3, clip); - if (numTris == 0) - continue; - - bool fm = (ffa) ? (ffa[lt->poly].flag & FREESTYLE_FACE_MARK) != 0 : false; - bool em1 = false, em2 = false, em3 = false; - - if (fed) { - em1 = testEdgeMark(me, fed, lt, 0); - em2 = testEdgeMark(me, fed, lt, 1); - em3 = testEdgeMark(me, fed, lt, 2); - } - - if (mat) { - tmpMat.setLine(mat->line_col[0], mat->line_col[1], mat->line_col[2], mat->line_col[3]); - tmpMat.setDiffuse(mat->r, mat->g, mat->b, 1.0f); - tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, 1.0f); - tmpMat.setShininess(128.f); - tmpMat.setPriority(mat->line_priority); - } - - if (meshMaterials.empty()) { - meshMaterials.push_back(mat); - meshFrsMaterials.push_back(tmpMat); - shape->setFrsMaterial(tmpMat); - } - else { - // find if the Blender material is already in the list - unsigned int i = 0; - bool found = false; - - for (vector::iterator it = meshMaterials.begin(), itend = meshMaterials.end(); - it != itend; - it++, i++) - { - if (*it == mat) { - ls.currentMIndex = i; - found = true; - break; - } - } - - if (!found) { - meshMaterials.push_back(mat); - meshFrsMaterials.push_back(tmpMat); - ls.currentMIndex = meshFrsMaterials.size() - 1; - } - } - - float triCoords[5][3], triNormals[5][3]; - bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices - - clipTriangle(numTris, triCoords, v1, v2, v3, triNormals, n1, n2, n3, - edgeMarks, em1, em2, em3, clip); - for (i = 0; i < numTris; i++) { - addTriangle(&ls, triCoords[0], triCoords[i + 1], triCoords[i + 2], - triNormals[0], triNormals[i + 1], triNormals[i + 2], - fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i + 1], - (i == numTris - 1) ? edgeMarks[i + 2] : false); - _numFacesRead++; - } - } - - MEM_freeN(mlooptri); - - // We might have several times the same vertex. We want a clean - // shape with no real-vertex. Here, we are making a cleaning pass. - float *cleanVertices = NULL; - unsigned int cvSize; - unsigned int *cleanVIndices = NULL; - - GeomCleaner::CleanIndexedVertexArray(vertices, vSize, VIndices, viSize, &cleanVertices, &cvSize, &cleanVIndices); - - float *cleanNormals = NULL; - unsigned int cnSize; - unsigned int *cleanNIndices = NULL; - - GeomCleaner::CleanIndexedVertexArray(normals, nSize, NIndices, niSize, &cleanNormals, &cnSize, &cleanNIndices); - - // format materials array - FrsMaterial **marray = new FrsMaterial *[meshFrsMaterials.size()]; - unsigned int mindex = 0; - for (vector::iterator m = meshFrsMaterials.begin(), mend = meshFrsMaterials.end(); m != mend; ++m) { - marray[mindex] = new FrsMaterial(*m); - ++mindex; - } - - // deallocates memory: - delete [] vertices; - delete [] normals; - delete [] VIndices; - delete [] NIndices; - - // Fix for degenerated triangles - // A degenerate triangle is a triangle such that - // 1) A and B are in the same position in the 3D space; or - // 2) the distance between point P and line segment AB is zero. - // Only those degenerate triangles in the second form are resolved here - // by adding a small offset to P, whereas those in the first form are - // addressed later in WShape::MakeFace(). - vector detriList; - Vec3r zero(0.0, 0.0, 0.0); - unsigned vi0, vi1, vi2; - for (i = 0; i < viSize; i += 3) { - detri_t detri; - vi0 = cleanVIndices[i]; - vi1 = cleanVIndices[i + 1]; - vi2 = cleanVIndices[i + 2]; - Vec3r v0(cleanVertices[vi0], cleanVertices[vi0 + 1], cleanVertices[vi0 + 2]); - Vec3r v1(cleanVertices[vi1], cleanVertices[vi1 + 1], cleanVertices[vi1 + 2]); - Vec3r v2(cleanVertices[vi2], cleanVertices[vi2 + 1], cleanVertices[vi2 + 2]); - if (v0 == v1 || v0 == v2 || v1 == v2) { - continue; // do nothing for now - } - else if (GeomUtils::distPointSegment(v0, v1, v2) < 1.0e-6) { - detri.viP = vi0; - detri.viA = vi1; - detri.viB = vi2; - } - else if (GeomUtils::distPointSegment(v1, v0, v2) < 1.0e-6) { - detri.viP = vi1; - detri.viA = vi0; - detri.viB = vi2; - } - else if (GeomUtils::distPointSegment(v2, v0, v1) < 1.0e-6) { - detri.viP = vi2; - detri.viA = vi0; - detri.viB = vi1; - } - else { - continue; - } - - detri.v = zero; - detri.n = 0; - for (unsigned int j = 0; j < viSize; j += 3) { - if (i == j) - continue; - vi0 = cleanVIndices[j]; - vi1 = cleanVIndices[j + 1]; - vi2 = cleanVIndices[j + 2]; - Vec3r v0(cleanVertices[vi0], cleanVertices[vi0 + 1], cleanVertices[vi0 + 2]); - Vec3r v1(cleanVertices[vi1], cleanVertices[vi1 + 1], cleanVertices[vi1 + 2]); - Vec3r v2(cleanVertices[vi2], cleanVertices[vi2 + 1], cleanVertices[vi2 + 2]); - if (detri.viP == vi0 && (detri.viA == vi1 || detri.viB == vi1)) { - detri.v += (v2 - v0); - detri.n++; - } - else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) { - detri.v += (v1 - v0); - detri.n++; - } - else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) { - detri.v += (v2 - v1); - detri.n++; - } - else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) { - detri.v += (v0 - v1); - detri.n++; - } - else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) { - detri.v += (v1 - v2); - detri.n++; - } - else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) { - detri.v += (v0 - v2); - detri.n++; - } - } - if (detri.n > 0) { - detri.v.normalizeSafe(); - } - detriList.push_back(detri); - } - - if (detriList.size() > 0) { - vector::iterator v; - for (v = detriList.begin(); v != detriList.end(); v++) { - detri_t detri = (*v); - if (detri.n == 0) { - cleanVertices[detri.viP] = cleanVertices[detri.viA]; - cleanVertices[detri.viP + 1] = cleanVertices[detri.viA + 1]; - cleanVertices[detri.viP + 2] = cleanVertices[detri.viA + 2]; - } - else if (detri.v.norm() > 0.0) { - cleanVertices[detri.viP] += 1.0e-5 * detri.v.x(); - cleanVertices[detri.viP + 1] += 1.0e-5 * detri.v.y(); - cleanVertices[detri.viP + 2] += 1.0e-5 * detri.v.z(); - } - } - if (G.debug & G_DEBUG_FREESTYLE) { - printf("Warning: Object %s contains %lu degenerated triangle%s (strokes may be incorrect)\n", - name, (long unsigned int)detriList.size(), (detriList.size() > 1) ? "s" : ""); - } - } - - // Create the IndexedFaceSet with the retrieved attributes - IndexedFaceSet *rep; - rep = new IndexedFaceSet(cleanVertices, cvSize, cleanNormals, cnSize, marray, meshFrsMaterials.size(), 0, 0, - numFaces, numVertexPerFaces, faceStyle, faceEdgeMarks, cleanVIndices, viSize, - cleanNIndices, niSize, MIndices, viSize, 0, 0, 0); - // sets the id of the rep - rep->setId(Id(id, 0)); - rep->setName(ob->id.name + 2); - rep->setLibraryPath(ob->id.lib ? ob->id.lib->name : ""); - - const BBox bbox = BBox(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]), - Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2])); - rep->setBBox(bbox); - shape->AddRep(rep); - - currentMesh->AddChild(shape); - _Scene->AddChild(currentMesh); + if (numFaces == 0) { + MEM_freeN(mlooptri); + return; + } + + // We allocate memory for the meshes to be imported + NodeGroup *currentMesh = new NodeGroup; + NodeShape *shape = new NodeShape; + + unsigned vSize = 3 * 3 * numFaces; + float *vertices = new float[vSize]; + unsigned nSize = vSize; + float *normals = new float[nSize]; + unsigned *numVertexPerFaces = new unsigned[numFaces]; + vector meshMaterials; + vector meshFrsMaterials; + + IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces]; + unsigned i; + for (i = 0; i < numFaces; i++) { + faceStyle[i] = IndexedFaceSet::TRIANGLES; + numVertexPerFaces[i] = 3; + } + + IndexedFaceSet::FaceEdgeMark *faceEdgeMarks = new IndexedFaceSet::FaceEdgeMark[numFaces]; + + unsigned viSize = 3 * numFaces; + unsigned *VIndices = new unsigned[viSize]; + unsigned niSize = viSize; + unsigned *NIndices = new unsigned[niSize]; + unsigned *MIndices = new unsigned[viSize]; // Material Indices + + struct LoaderState ls; + ls.pv = vertices; + ls.pn = normals; + ls.pm = faceEdgeMarks; + ls.pvi = VIndices; + ls.pni = NIndices; + ls.pmi = MIndices; + ls.currentIndex = 0; + ls.currentMIndex = 0; + + FrsMaterial tmpMat; + + // We parse the vlak nodes again and import meshes while applying the clipping + // by the near and far view planes. + for (int a = 0; a < tottri; a++) { + const MLoopTri *lt = &mlooptri[a]; + const MPoly *mp = &mpoly[lt->poly]; + Material *mat = give_current_material(ob, mp->mat_nr + 1); + + copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); + copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); + copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); + + mul_m4_v3(obmat, v1); + mul_m4_v3(obmat, v2); + mul_m4_v3(obmat, v3); + + v1[2] += _z_offset; + v2[2] += _z_offset; + v3[2] += _z_offset; + + if (_smooth && (mp->flag & ME_SMOOTH) && lnors) { + copy_v3_v3(n1, lnors[lt->tri[0]]); + copy_v3_v3(n2, lnors[lt->tri[1]]); + copy_v3_v3(n3, lnors[lt->tri[2]]); + + mul_mat3_m4_v3(nmat, n1); + mul_mat3_m4_v3(nmat, n2); + mul_mat3_m4_v3(nmat, n3); + + normalize_v3(n1); + normalize_v3(n2); + normalize_v3(n3); + } + else { + normal_tri_v3(facenormal, v3, v2, v1); + + copy_v3_v3(n1, facenormal); + copy_v3_v3(n2, facenormal); + copy_v3_v3(n3, facenormal); + } + + unsigned int numTris = countClippedFaces(v1, v2, v3, clip); + if (numTris == 0) + continue; + + bool fm = (ffa) ? (ffa[lt->poly].flag & FREESTYLE_FACE_MARK) != 0 : false; + bool em1 = false, em2 = false, em3 = false; + + if (fed) { + em1 = testEdgeMark(me, fed, lt, 0); + em2 = testEdgeMark(me, fed, lt, 1); + em3 = testEdgeMark(me, fed, lt, 2); + } + + if (mat) { + tmpMat.setLine(mat->line_col[0], mat->line_col[1], mat->line_col[2], mat->line_col[3]); + tmpMat.setDiffuse(mat->r, mat->g, mat->b, 1.0f); + tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, 1.0f); + tmpMat.setShininess(128.f); + tmpMat.setPriority(mat->line_priority); + } + + if (meshMaterials.empty()) { + meshMaterials.push_back(mat); + meshFrsMaterials.push_back(tmpMat); + shape->setFrsMaterial(tmpMat); + } + else { + // find if the Blender material is already in the list + unsigned int i = 0; + bool found = false; + + for (vector::iterator it = meshMaterials.begin(), itend = meshMaterials.end(); + it != itend; + it++, i++) { + if (*it == mat) { + ls.currentMIndex = i; + found = true; + break; + } + } + + if (!found) { + meshMaterials.push_back(mat); + meshFrsMaterials.push_back(tmpMat); + ls.currentMIndex = meshFrsMaterials.size() - 1; + } + } + + float triCoords[5][3], triNormals[5][3]; + bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices + + clipTriangle( + numTris, triCoords, v1, v2, v3, triNormals, n1, n2, n3, edgeMarks, em1, em2, em3, clip); + for (i = 0; i < numTris; i++) { + addTriangle(&ls, + triCoords[0], + triCoords[i + 1], + triCoords[i + 2], + triNormals[0], + triNormals[i + 1], + triNormals[i + 2], + fm, + (i == 0) ? edgeMarks[0] : false, + edgeMarks[i + 1], + (i == numTris - 1) ? edgeMarks[i + 2] : false); + _numFacesRead++; + } + } + + MEM_freeN(mlooptri); + + // We might have several times the same vertex. We want a clean + // shape with no real-vertex. Here, we are making a cleaning pass. + float *cleanVertices = NULL; + unsigned int cvSize; + unsigned int *cleanVIndices = NULL; + + GeomCleaner::CleanIndexedVertexArray( + vertices, vSize, VIndices, viSize, &cleanVertices, &cvSize, &cleanVIndices); + + float *cleanNormals = NULL; + unsigned int cnSize; + unsigned int *cleanNIndices = NULL; + + GeomCleaner::CleanIndexedVertexArray( + normals, nSize, NIndices, niSize, &cleanNormals, &cnSize, &cleanNIndices); + + // format materials array + FrsMaterial **marray = new FrsMaterial *[meshFrsMaterials.size()]; + unsigned int mindex = 0; + for (vector::iterator m = meshFrsMaterials.begin(), mend = meshFrsMaterials.end(); + m != mend; + ++m) { + marray[mindex] = new FrsMaterial(*m); + ++mindex; + } + + // deallocates memory: + delete[] vertices; + delete[] normals; + delete[] VIndices; + delete[] NIndices; + + // Fix for degenerated triangles + // A degenerate triangle is a triangle such that + // 1) A and B are in the same position in the 3D space; or + // 2) the distance between point P and line segment AB is zero. + // Only those degenerate triangles in the second form are resolved here + // by adding a small offset to P, whereas those in the first form are + // addressed later in WShape::MakeFace(). + vector detriList; + Vec3r zero(0.0, 0.0, 0.0); + unsigned vi0, vi1, vi2; + for (i = 0; i < viSize; i += 3) { + detri_t detri; + vi0 = cleanVIndices[i]; + vi1 = cleanVIndices[i + 1]; + vi2 = cleanVIndices[i + 2]; + Vec3r v0(cleanVertices[vi0], cleanVertices[vi0 + 1], cleanVertices[vi0 + 2]); + Vec3r v1(cleanVertices[vi1], cleanVertices[vi1 + 1], cleanVertices[vi1 + 2]); + Vec3r v2(cleanVertices[vi2], cleanVertices[vi2 + 1], cleanVertices[vi2 + 2]); + if (v0 == v1 || v0 == v2 || v1 == v2) { + continue; // do nothing for now + } + else if (GeomUtils::distPointSegment(v0, v1, v2) < 1.0e-6) { + detri.viP = vi0; + detri.viA = vi1; + detri.viB = vi2; + } + else if (GeomUtils::distPointSegment(v1, v0, v2) < 1.0e-6) { + detri.viP = vi1; + detri.viA = vi0; + detri.viB = vi2; + } + else if (GeomUtils::distPointSegment(v2, v0, v1) < 1.0e-6) { + detri.viP = vi2; + detri.viA = vi0; + detri.viB = vi1; + } + else { + continue; + } + + detri.v = zero; + detri.n = 0; + for (unsigned int j = 0; j < viSize; j += 3) { + if (i == j) + continue; + vi0 = cleanVIndices[j]; + vi1 = cleanVIndices[j + 1]; + vi2 = cleanVIndices[j + 2]; + Vec3r v0(cleanVertices[vi0], cleanVertices[vi0 + 1], cleanVertices[vi0 + 2]); + Vec3r v1(cleanVertices[vi1], cleanVertices[vi1 + 1], cleanVertices[vi1 + 2]); + Vec3r v2(cleanVertices[vi2], cleanVertices[vi2 + 1], cleanVertices[vi2 + 2]); + if (detri.viP == vi0 && (detri.viA == vi1 || detri.viB == vi1)) { + detri.v += (v2 - v0); + detri.n++; + } + else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) { + detri.v += (v1 - v0); + detri.n++; + } + else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) { + detri.v += (v2 - v1); + detri.n++; + } + else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) { + detri.v += (v0 - v1); + detri.n++; + } + else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) { + detri.v += (v1 - v2); + detri.n++; + } + else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) { + detri.v += (v0 - v2); + detri.n++; + } + } + if (detri.n > 0) { + detri.v.normalizeSafe(); + } + detriList.push_back(detri); + } + + if (detriList.size() > 0) { + vector::iterator v; + for (v = detriList.begin(); v != detriList.end(); v++) { + detri_t detri = (*v); + if (detri.n == 0) { + cleanVertices[detri.viP] = cleanVertices[detri.viA]; + cleanVertices[detri.viP + 1] = cleanVertices[detri.viA + 1]; + cleanVertices[detri.viP + 2] = cleanVertices[detri.viA + 2]; + } + else if (detri.v.norm() > 0.0) { + cleanVertices[detri.viP] += 1.0e-5 * detri.v.x(); + cleanVertices[detri.viP + 1] += 1.0e-5 * detri.v.y(); + cleanVertices[detri.viP + 2] += 1.0e-5 * detri.v.z(); + } + } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("Warning: Object %s contains %lu degenerated triangle%s (strokes may be incorrect)\n", + name, + (long unsigned int)detriList.size(), + (detriList.size() > 1) ? "s" : ""); + } + } + + // Create the IndexedFaceSet with the retrieved attributes + IndexedFaceSet *rep; + rep = new IndexedFaceSet(cleanVertices, + cvSize, + cleanNormals, + cnSize, + marray, + meshFrsMaterials.size(), + 0, + 0, + numFaces, + numVertexPerFaces, + faceStyle, + faceEdgeMarks, + cleanVIndices, + viSize, + cleanNIndices, + niSize, + MIndices, + viSize, + 0, + 0, + 0); + // sets the id of the rep + rep->setId(Id(id, 0)); + rep->setName(ob->id.name + 2); + rep->setLibraryPath(ob->id.lib ? ob->id.lib->name : ""); + + const BBox bbox = BBox(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]), + Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2])); + rep->setBBox(bbox); + shape->AddRep(rep); + + currentMesh->AddChild(shape); + _Scene->AddChild(currentMesh); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h index 251e9329128..5fe98fba0d0 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h @@ -61,7 +61,7 @@ extern "C" { #include "DEG_depsgraph_query.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -69,78 +69,103 @@ namespace Freestyle { class NodeGroup; struct LoaderState { - float *pv; - float *pn; - IndexedFaceSet::FaceEdgeMark *pm; - unsigned *pvi; - unsigned *pni; - unsigned *pmi; - unsigned currentIndex; - unsigned currentMIndex; - float minBBox[3]; - float maxBBox[3]; + float *pv; + float *pn; + IndexedFaceSet::FaceEdgeMark *pm; + unsigned *pvi; + unsigned *pni; + unsigned *pmi; + unsigned currentIndex; + unsigned currentMIndex; + float minBBox[3]; + float maxBBox[3]; }; -class BlenderFileLoader -{ -public: - /*! Builds a MaxFileLoader */ - BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); - virtual ~BlenderFileLoader(); +class BlenderFileLoader { + public: + /*! Builds a MaxFileLoader */ + BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); + virtual ~BlenderFileLoader(); - /*! Loads the 3D scene and returns a pointer to the scene root node */ - NodeGroup *Load(); + /*! Loads the 3D scene and returns a pointer to the scene root node */ + NodeGroup *Load(); - /*! Gets the number of read faces */ - inline unsigned int numFacesRead() {return _numFacesRead;} + /*! Gets the number of read faces */ + inline unsigned int numFacesRead() + { + return _numFacesRead; + } #if 0 - /*! Gets the smallest edge size read */ - inline real minEdgeSize() {return _minEdgeSize;} + /*! Gets the smallest edge size read */ + inline real minEdgeSize() {return _minEdgeSize;} #endif - /*! Modifiers */ - inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;} - -protected: - void insertShapeNode(Object *ob, Mesh *mesh, int id); - int testDegenerateTriangle(float v1[3], float v2[3], float v3[3]); - int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]); - void clipLine(float v1[3], float v2[3], float c[3], float z); - void clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], - float triNormals[][3], float n1[3], float n2[3], float n3[3], - bool edgeMarks[5], bool em1, bool em2, bool em3, int clip[3]); - void addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3], - float n1[3], float n2[3], float n3[3], bool fm, bool em1, bool em2, bool em3); - -protected: - struct detri_t { - unsigned viA, viB, viP; // 0 <= viA, viB, viP < viSize - Vec3r v; - unsigned n; - }; - Render *_re; - Depsgraph *_depsgraph; - NodeGroup *_Scene; - unsigned _numFacesRead; + /*! Modifiers */ + inline void setRenderMonitor(RenderMonitor *iRenderMonitor) + { + _pRenderMonitor = iRenderMonitor; + } + + protected: + void insertShapeNode(Object *ob, Mesh *mesh, int id); + int testDegenerateTriangle(float v1[3], float v2[3], float v3[3]); + int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]); + void clipLine(float v1[3], float v2[3], float c[3], float z); + void clipTriangle(int numTris, + float triCoords[][3], + float v1[3], + float v2[3], + float v3[3], + float triNormals[][3], + float n1[3], + float n2[3], + float n3[3], + bool edgeMarks[5], + bool em1, + bool em2, + bool em3, + int clip[3]); + void addTriangle(struct LoaderState *ls, + float v1[3], + float v2[3], + float v3[3], + float n1[3], + float n2[3], + float n3[3], + bool fm, + bool em1, + bool em2, + bool em3); + + protected: + struct detri_t { + unsigned viA, viB, viP; // 0 <= viA, viB, viP < viSize + Vec3r v; + unsigned n; + }; + Render *_re; + Depsgraph *_depsgraph; + NodeGroup *_Scene; + unsigned _numFacesRead; #if 0 - real _minEdgeSize; + real _minEdgeSize; #endif - bool _smooth; /* if true, face smoothness is taken into account */ - float _viewplane_left; - float _viewplane_right; - float _viewplane_bottom; - float _viewplane_top; - float _z_near, _z_far; - float _z_offset; + bool _smooth; /* if true, face smoothness is taken into account */ + float _viewplane_left; + float _viewplane_right; + float _viewplane_bottom; + float _viewplane_top; + float _z_near, _z_far; + float _z_offset; - RenderMonitor *_pRenderMonitor; + RenderMonitor *_pRenderMonitor; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderFileLoader") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderFileLoader") #endif }; } /* namespace Freestyle */ -#endif // __BLENDER_FILE_LOADER_H__ +#endif // __BLENDER_FILE_LOADER_H__ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index e7fc162ee1c..47e2fef33e3 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -74,821 +74,822 @@ const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_ti BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : StrokeRenderer() { - freestyle_bmain = re->freestyle_bmain; - - // for stroke mesh generation - _width = re->winx; - _height = re->winy; - - old_scene = re->scene; - - char name[MAX_ID_NAME - 2]; - BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2); - freestyle_scene = BKE_scene_add(freestyle_bmain, name); - freestyle_scene->r.cfra = old_scene->r.cfra; - freestyle_scene->r.mode = old_scene->r.mode & - ~(R_EDGE_FRS | R_BORDER); - freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch - freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch - freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp; - freestyle_scene->r.yasp = 1.0f; // old_scene->r.yasp; - freestyle_scene->r.tilex = old_scene->r.tilex; - freestyle_scene->r.tiley = old_scene->r.tiley; - freestyle_scene->r.size = 100; // old_scene->r.size - freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag; - freestyle_scene->r.scemode = (old_scene->r.scemode & ~(R_SINGLE_LAYER | R_NO_FRAME_UPDATE | R_MULTIVIEW)) & - (re->r.scemode | ~R_FULL_SAMPLE); - freestyle_scene->r.flag = old_scene->r.flag; - freestyle_scene->r.threads = old_scene->r.threads; - freestyle_scene->r.border.xmin = old_scene->r.border.xmin; - freestyle_scene->r.border.ymin = old_scene->r.border.ymin; - freestyle_scene->r.border.xmax = old_scene->r.border.xmax; - freestyle_scene->r.border.ymax = old_scene->r.border.ymax; - strcpy(freestyle_scene->r.pic, old_scene->r.pic); - freestyle_scene->r.safety.xmin = old_scene->r.safety.xmin; - freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin; - freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax; - freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax; - freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity; - STRNCPY(freestyle_scene->r.engine, old_scene->r.engine); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Stroke rendering engine : " << freestyle_scene->r.engine << endl; - } - freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA; - freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG; - - // Copy ID properties, including Cycles render properties - if (old_scene->id.properties) { - freestyle_scene->id.properties = IDP_CopyProperty_ex(old_scene->id.properties, 0); - } - - /* Render with transparent background. */ - freestyle_scene->r.alphamode = R_ALPHAPREMUL; - - if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) { - PointerRNA freestyle_scene_ptr; - RNA_id_pointer_create(&freestyle_scene->id, &freestyle_scene_ptr); - PointerRNA freestyle_cycles_ptr = RNA_pointer_get(&freestyle_scene_ptr, "cycles"); - RNA_boolean_set(&freestyle_cycles_ptr, "film_transparent", 1); - } - - if (G.debug & G_DEBUG_FREESTYLE) { - printf("%s: %d thread(s)\n", __func__, BKE_render_num_threads(&freestyle_scene->r)); - } - - BKE_scene_set_background(freestyle_bmain, freestyle_scene); - - // Scene layer. - ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; - view_layer->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA; - - // Camera - Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, NULL); - - Camera *camera = (Camera *)object_camera->data; - camera->type = CAM_ORTHO; - camera->ortho_scale = max(re->rectx, re->recty); - camera->clip_start = 0.1f; - camera->clip_end = 100.0f; - - _z_delta = 0.00001f; - _z = camera->clip_start + _z_delta; - - object_camera->loc[0] = re->disprect.xmin + 0.5f * re->rectx; - object_camera->loc[1] = re->disprect.ymin + 0.5f * re->recty; - object_camera->loc[2] = 1.0f; - - freestyle_scene->camera = object_camera; - - // Reset serial mesh ID (used for BlenderStrokeRenderer::NewMesh()) - _mesh_id = 0xffffffff; - - // Create a bNodeTree-to-Material hash table - _nodetree_hash = BLI_ghash_ptr_new("BlenderStrokeRenderer::_nodetree_hash"); - - // Depsgraph - freestyle_depsgraph = DEG_graph_new(freestyle_scene, view_layer, DAG_EVAL_RENDER); - DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0); - DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0); - DEG_graph_tag_relations_update(freestyle_depsgraph); + freestyle_bmain = re->freestyle_bmain; + + // for stroke mesh generation + _width = re->winx; + _height = re->winy; + + old_scene = re->scene; + + char name[MAX_ID_NAME - 2]; + BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2); + freestyle_scene = BKE_scene_add(freestyle_bmain, name); + freestyle_scene->r.cfra = old_scene->r.cfra; + freestyle_scene->r.mode = old_scene->r.mode & ~(R_EDGE_FRS | R_BORDER); + freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch + freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch + freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp; + freestyle_scene->r.yasp = 1.0f; // old_scene->r.yasp; + freestyle_scene->r.tilex = old_scene->r.tilex; + freestyle_scene->r.tiley = old_scene->r.tiley; + freestyle_scene->r.size = 100; // old_scene->r.size + freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag; + freestyle_scene->r.scemode = (old_scene->r.scemode & + ~(R_SINGLE_LAYER | R_NO_FRAME_UPDATE | R_MULTIVIEW)) & + (re->r.scemode | ~R_FULL_SAMPLE); + freestyle_scene->r.flag = old_scene->r.flag; + freestyle_scene->r.threads = old_scene->r.threads; + freestyle_scene->r.border.xmin = old_scene->r.border.xmin; + freestyle_scene->r.border.ymin = old_scene->r.border.ymin; + freestyle_scene->r.border.xmax = old_scene->r.border.xmax; + freestyle_scene->r.border.ymax = old_scene->r.border.ymax; + strcpy(freestyle_scene->r.pic, old_scene->r.pic); + freestyle_scene->r.safety.xmin = old_scene->r.safety.xmin; + freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin; + freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax; + freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax; + freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity; + STRNCPY(freestyle_scene->r.engine, old_scene->r.engine); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Stroke rendering engine : " << freestyle_scene->r.engine << endl; + } + freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA; + freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG; + + // Copy ID properties, including Cycles render properties + if (old_scene->id.properties) { + freestyle_scene->id.properties = IDP_CopyProperty_ex(old_scene->id.properties, 0); + } + + /* Render with transparent background. */ + freestyle_scene->r.alphamode = R_ALPHAPREMUL; + + if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) { + PointerRNA freestyle_scene_ptr; + RNA_id_pointer_create(&freestyle_scene->id, &freestyle_scene_ptr); + PointerRNA freestyle_cycles_ptr = RNA_pointer_get(&freestyle_scene_ptr, "cycles"); + RNA_boolean_set(&freestyle_cycles_ptr, "film_transparent", 1); + } + + if (G.debug & G_DEBUG_FREESTYLE) { + printf("%s: %d thread(s)\n", __func__, BKE_render_num_threads(&freestyle_scene->r)); + } + + BKE_scene_set_background(freestyle_bmain, freestyle_scene); + + // Scene layer. + ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; + view_layer->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA; + + // Camera + Object *object_camera = BKE_object_add( + freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, NULL); + + Camera *camera = (Camera *)object_camera->data; + camera->type = CAM_ORTHO; + camera->ortho_scale = max(re->rectx, re->recty); + camera->clip_start = 0.1f; + camera->clip_end = 100.0f; + + _z_delta = 0.00001f; + _z = camera->clip_start + _z_delta; + + object_camera->loc[0] = re->disprect.xmin + 0.5f * re->rectx; + object_camera->loc[1] = re->disprect.ymin + 0.5f * re->recty; + object_camera->loc[2] = 1.0f; + + freestyle_scene->camera = object_camera; + + // Reset serial mesh ID (used for BlenderStrokeRenderer::NewMesh()) + _mesh_id = 0xffffffff; + + // Create a bNodeTree-to-Material hash table + _nodetree_hash = BLI_ghash_ptr_new("BlenderStrokeRenderer::_nodetree_hash"); + + // Depsgraph + freestyle_depsgraph = DEG_graph_new(freestyle_scene, view_layer, DAG_EVAL_RENDER); + DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0); + DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0); + DEG_graph_tag_relations_update(freestyle_depsgraph); } BlenderStrokeRenderer::~BlenderStrokeRenderer() { - // The freestyle_scene object is not released here. Instead, - // the scene is released in free_all_freestyle_renders() in - // source/blender/render/intern/source/pipeline.c, after the - // compositor has finished. - - // release objects and data blocks - Base *base_next = NULL; - ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; - for (Base *b = (Base *)view_layer->object_bases.first; b; b = base_next) { - base_next = b->next; - Object *ob = b->object; - char *name = ob->id.name; + // The freestyle_scene object is not released here. Instead, + // the scene is released in free_all_freestyle_renders() in + // source/blender/render/intern/source/pipeline.c, after the + // compositor has finished. + + // release objects and data blocks + Base *base_next = NULL; + ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; + for (Base *b = (Base *)view_layer->object_bases.first; b; b = base_next) { + base_next = b->next; + Object *ob = b->object; + char *name = ob->id.name; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl; + } #endif - switch (ob->type) { - case OB_CAMERA: - freestyle_scene->camera = NULL; - ATTR_FALLTHROUGH; - case OB_MESH: - BKE_scene_collections_object_remove(freestyle_bmain, - freestyle_scene, - ob, - true); - break; - default: - cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name + 2) << endl; - } - } - - // release materials - Link *lnk = (Link *)freestyle_bmain->materials.first; - - while (lnk) - { - Material *ma = (Material*)lnk; - lnk = lnk->next; - BKE_id_free(freestyle_bmain, ma); - } - - BLI_ghash_free(_nodetree_hash, NULL, NULL); - - DEG_graph_free(freestyle_depsgraph); - - FreeStrokeGroups(); + switch (ob->type) { + case OB_CAMERA: + freestyle_scene->camera = NULL; + ATTR_FALLTHROUGH; + case OB_MESH: + BKE_scene_collections_object_remove(freestyle_bmain, freestyle_scene, ob, true); + break; + default: + cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" + << (name + 2) << endl; + } + } + + // release materials + Link *lnk = (Link *)freestyle_bmain->materials.first; + + while (lnk) { + Material *ma = (Material *)lnk; + lnk = lnk->next; + BKE_id_free(freestyle_bmain, ma); + } + + BLI_ghash_free(_nodetree_hash, NULL, NULL); + + DEG_graph_free(freestyle_depsgraph); + + FreeStrokeGroups(); } float BlenderStrokeRenderer::get_stroke_vertex_z(void) const { - float z = _z; - BlenderStrokeRenderer *self = const_cast(this); - if (!(_z < _z_delta * 100000.0f)) - self->_z_delta *= 10.0f; - self->_z += _z_delta; - return -z; + float z = _z; + BlenderStrokeRenderer *self = const_cast(this); + if (!(_z < _z_delta * 100000.0f)) + self->_z_delta *= 10.0f; + self->_z += _z_delta; + return -z; } unsigned int BlenderStrokeRenderer::get_stroke_mesh_id(void) const { - unsigned mesh_id = _mesh_id; - BlenderStrokeRenderer *self = const_cast(this); - self->_mesh_id--; - return mesh_id; + unsigned mesh_id = _mesh_id; + BlenderStrokeRenderer *self = const_cast(this); + self->_mesh_id--; + return mesh_id; } -Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, bNodeTree *iNodeTree, bool do_id_user) +Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, + bNodeTree *iNodeTree, + bool do_id_user) { - Material *ma = BKE_material_add(bmain, "stroke_shader"); - bNodeTree *ntree; - bNode *output_linestyle = NULL; - bNodeSocket *fromsock, *tosock; - PointerRNA fromptr, toptr; - NodeShaderAttribute *storage; - - id_us_min(&ma->id); - - if (iNodeTree) { - // make a copy of linestyle->nodetree - ntree = ntreeCopyTree_ex(iNodeTree, bmain, do_id_user); - - // find the active Output Line Style node - for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { - if (node->type == SH_NODE_OUTPUT_LINESTYLE && (node->flag & NODE_DO_OUTPUT)) { - output_linestyle = node; - break; - } - } - } - else { - ntree = ntreeAddTree(NULL, "stroke_shader", "ShaderNodeTree"); - } - ma->nodetree = ntree; - ma->use_nodes = 1; - - bNode *input_attr_color = nodeAddStaticNode(NULL, ntree, SH_NODE_ATTRIBUTE); - input_attr_color->locx = 0.0f; - input_attr_color->locy = -200.0f; - storage = (NodeShaderAttribute *)input_attr_color->storage; - BLI_strncpy(storage->name, "Color", sizeof(storage->name)); - - bNode *mix_rgb_color = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_RGB); - mix_rgb_color->custom1 = MA_RAMP_BLEND; // Mix - mix_rgb_color->locx = 200.0f; - mix_rgb_color->locy = -200.0f; - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 0); // Fac - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - RNA_float_set(&toptr, "default_value", 0.0f); - - bNode *input_attr_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_ATTRIBUTE); - input_attr_alpha->locx = 400.0f; - input_attr_alpha->locy = 300.0f; - storage = (NodeShaderAttribute *)input_attr_alpha->storage; - BLI_strncpy(storage->name, "Alpha", sizeof(storage->name)); - - bNode *mix_rgb_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_RGB); - mix_rgb_alpha->custom1 = MA_RAMP_BLEND; // Mix - mix_rgb_alpha->locx = 600.0f; - mix_rgb_alpha->locy = 300.0f; - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 0); // Fac - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - RNA_float_set(&toptr, "default_value", 0.0f); - - bNode *shader_emission = nodeAddStaticNode(NULL, ntree, SH_NODE_EMISSION); - shader_emission->locx = 400.0f; - shader_emission->locy = -200.0f; - - bNode *input_light_path = nodeAddStaticNode(NULL, ntree, SH_NODE_LIGHT_PATH); - input_light_path->locx = 400.0f; - input_light_path->locy = 100.0f; - - bNode *mix_shader_color = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_SHADER); - mix_shader_color->locx = 600.0f; - mix_shader_color->locy = -100.0f; - - bNode *shader_transparent = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_TRANSPARENT); - shader_transparent->locx = 600.0f; - shader_transparent->locy = 100.0f; - - bNode *mix_shader_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_SHADER); - mix_shader_alpha->locx = 800.0f; - mix_shader_alpha->locy = 100.0f; - - bNode *output_material = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL); - output_material->locx = 1000.0f; - output_material->locy = 100.0f; - - fromsock = (bNodeSocket *)BLI_findlink(&input_attr_color->outputs, 0); // Color - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 1); // Color1 - nodeAddLink(ntree, input_attr_color, fromsock, mix_rgb_color, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->outputs, 0); // Color - tosock = (bNodeSocket *)BLI_findlink(&shader_emission->inputs, 0); // Color - nodeAddLink(ntree, mix_rgb_color, fromsock, shader_emission, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&shader_emission->outputs, 0); // Emission - tosock = (bNodeSocket *)BLI_findlink(&mix_shader_color->inputs, 2); // Shader (second) - nodeAddLink(ntree, shader_emission, fromsock, mix_shader_color, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&input_light_path->outputs, 0); // In Camera Ray - tosock = (bNodeSocket *)BLI_findlink(&mix_shader_color->inputs, 0); // Fac - nodeAddLink(ntree, input_light_path, fromsock, mix_shader_color, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->outputs, 0); // Color - tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 0); // Fac - nodeAddLink(ntree, mix_rgb_alpha, fromsock, mix_shader_alpha, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&input_attr_alpha->outputs, 0); // Color - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 1); // Color1 - nodeAddLink(ntree, input_attr_alpha, fromsock, mix_rgb_alpha, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&shader_transparent->outputs, 0); // BSDF - tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 1); // Shader (first) - nodeAddLink(ntree, shader_transparent, fromsock, mix_shader_alpha, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&mix_shader_color->outputs, 0); // Shader - tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 2); // Shader (second) - nodeAddLink(ntree, mix_shader_color, fromsock, mix_shader_alpha, tosock); - - fromsock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->outputs, 0); // Shader - tosock = (bNodeSocket *)BLI_findlink(&output_material->inputs, 0); // Surface - nodeAddLink(ntree, mix_shader_alpha, fromsock, output_material, tosock); - - if (output_linestyle) { - bNodeSocket *outsock; - bNodeLink *link; - - mix_rgb_color->custom1 = output_linestyle->custom1; // blend_type - mix_rgb_color->custom2 = output_linestyle->custom2; // use_clamp - - outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 0); // Color - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 2); // Color2 - link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); - if (link) { - nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_color, tosock); - } - else { - float color[4]; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - RNA_float_get_array(&fromptr, "default_value", color); - RNA_float_set_array(&toptr, "default_value", color); - } - - outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 1); // Color Fac - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 0); // Fac - link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); - if (link) { - nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_color, tosock); - } - else { - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - RNA_float_set(&toptr, "default_value", RNA_float_get(&fromptr, "default_value")); - } - - outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 2); // Alpha - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 2); // Color2 - link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); - if (link) { - nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_alpha, tosock); - } - else { - float color[4]; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - color[0] = color[1] = color[2] = RNA_float_get(&fromptr, "default_value"); - color[3] = 1.0f; - RNA_float_set_array(&toptr, "default_value", color); - } - - outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 3); // Alpha Fac - tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 0); // Fac - link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); - if (link) { - nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_alpha, tosock); - } - else { - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); - RNA_float_set(&toptr, "default_value", RNA_float_get(&fromptr, "default_value")); - } - - for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { - if (node->type == SH_NODE_UVALONGSTROKE) { - // UV output of the UV Along Stroke node - bNodeSocket *sock = (bNodeSocket *)BLI_findlink(&node->outputs, 0); - - // add new UV Map node - bNode *input_uvmap = nodeAddStaticNode(NULL, ntree, SH_NODE_UVMAP); - input_uvmap->locx = node->locx - 200.0f; - input_uvmap->locy = node->locy; - NodeShaderUVMap *storage = (NodeShaderUVMap *)input_uvmap->storage; - if (node->custom1 & 1) { // use_tips - BLI_strncpy(storage->uv_map, uvNames[1], sizeof(storage->uv_map)); - } - else { - BLI_strncpy(storage->uv_map, uvNames[0], sizeof(storage->uv_map)); - } - fromsock = (bNodeSocket *)BLI_findlink(&input_uvmap->outputs, 0); // UV - - // replace links from the UV Along Stroke node by links from the UV Map node - for (bNodeLink *link = (bNodeLink *)ntree->links.first; link; link = link->next) { - if (link->fromnode == node && link->fromsock == sock) { - nodeAddLink(ntree, input_uvmap, fromsock, link->tonode, link->tosock); - } - } - nodeRemSocketLinks(ntree, sock); - } - } - } - - nodeSetActive(ntree, output_material); - ntreeUpdateTree(bmain, ntree); - - return ma; + Material *ma = BKE_material_add(bmain, "stroke_shader"); + bNodeTree *ntree; + bNode *output_linestyle = NULL; + bNodeSocket *fromsock, *tosock; + PointerRNA fromptr, toptr; + NodeShaderAttribute *storage; + + id_us_min(&ma->id); + + if (iNodeTree) { + // make a copy of linestyle->nodetree + ntree = ntreeCopyTree_ex(iNodeTree, bmain, do_id_user); + + // find the active Output Line Style node + for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { + if (node->type == SH_NODE_OUTPUT_LINESTYLE && (node->flag & NODE_DO_OUTPUT)) { + output_linestyle = node; + break; + } + } + } + else { + ntree = ntreeAddTree(NULL, "stroke_shader", "ShaderNodeTree"); + } + ma->nodetree = ntree; + ma->use_nodes = 1; + + bNode *input_attr_color = nodeAddStaticNode(NULL, ntree, SH_NODE_ATTRIBUTE); + input_attr_color->locx = 0.0f; + input_attr_color->locy = -200.0f; + storage = (NodeShaderAttribute *)input_attr_color->storage; + BLI_strncpy(storage->name, "Color", sizeof(storage->name)); + + bNode *mix_rgb_color = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_RGB); + mix_rgb_color->custom1 = MA_RAMP_BLEND; // Mix + mix_rgb_color->locx = 200.0f; + mix_rgb_color->locy = -200.0f; + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 0); // Fac + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + RNA_float_set(&toptr, "default_value", 0.0f); + + bNode *input_attr_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_ATTRIBUTE); + input_attr_alpha->locx = 400.0f; + input_attr_alpha->locy = 300.0f; + storage = (NodeShaderAttribute *)input_attr_alpha->storage; + BLI_strncpy(storage->name, "Alpha", sizeof(storage->name)); + + bNode *mix_rgb_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_RGB); + mix_rgb_alpha->custom1 = MA_RAMP_BLEND; // Mix + mix_rgb_alpha->locx = 600.0f; + mix_rgb_alpha->locy = 300.0f; + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 0); // Fac + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + RNA_float_set(&toptr, "default_value", 0.0f); + + bNode *shader_emission = nodeAddStaticNode(NULL, ntree, SH_NODE_EMISSION); + shader_emission->locx = 400.0f; + shader_emission->locy = -200.0f; + + bNode *input_light_path = nodeAddStaticNode(NULL, ntree, SH_NODE_LIGHT_PATH); + input_light_path->locx = 400.0f; + input_light_path->locy = 100.0f; + + bNode *mix_shader_color = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_SHADER); + mix_shader_color->locx = 600.0f; + mix_shader_color->locy = -100.0f; + + bNode *shader_transparent = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_TRANSPARENT); + shader_transparent->locx = 600.0f; + shader_transparent->locy = 100.0f; + + bNode *mix_shader_alpha = nodeAddStaticNode(NULL, ntree, SH_NODE_MIX_SHADER); + mix_shader_alpha->locx = 800.0f; + mix_shader_alpha->locy = 100.0f; + + bNode *output_material = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL); + output_material->locx = 1000.0f; + output_material->locy = 100.0f; + + fromsock = (bNodeSocket *)BLI_findlink(&input_attr_color->outputs, 0); // Color + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 1); // Color1 + nodeAddLink(ntree, input_attr_color, fromsock, mix_rgb_color, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->outputs, 0); // Color + tosock = (bNodeSocket *)BLI_findlink(&shader_emission->inputs, 0); // Color + nodeAddLink(ntree, mix_rgb_color, fromsock, shader_emission, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&shader_emission->outputs, 0); // Emission + tosock = (bNodeSocket *)BLI_findlink(&mix_shader_color->inputs, 2); // Shader (second) + nodeAddLink(ntree, shader_emission, fromsock, mix_shader_color, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&input_light_path->outputs, 0); // In Camera Ray + tosock = (bNodeSocket *)BLI_findlink(&mix_shader_color->inputs, 0); // Fac + nodeAddLink(ntree, input_light_path, fromsock, mix_shader_color, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->outputs, 0); // Color + tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 0); // Fac + nodeAddLink(ntree, mix_rgb_alpha, fromsock, mix_shader_alpha, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&input_attr_alpha->outputs, 0); // Color + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 1); // Color1 + nodeAddLink(ntree, input_attr_alpha, fromsock, mix_rgb_alpha, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&shader_transparent->outputs, 0); // BSDF + tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 1); // Shader (first) + nodeAddLink(ntree, shader_transparent, fromsock, mix_shader_alpha, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&mix_shader_color->outputs, 0); // Shader + tosock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->inputs, 2); // Shader (second) + nodeAddLink(ntree, mix_shader_color, fromsock, mix_shader_alpha, tosock); + + fromsock = (bNodeSocket *)BLI_findlink(&mix_shader_alpha->outputs, 0); // Shader + tosock = (bNodeSocket *)BLI_findlink(&output_material->inputs, 0); // Surface + nodeAddLink(ntree, mix_shader_alpha, fromsock, output_material, tosock); + + if (output_linestyle) { + bNodeSocket *outsock; + bNodeLink *link; + + mix_rgb_color->custom1 = output_linestyle->custom1; // blend_type + mix_rgb_color->custom2 = output_linestyle->custom2; // use_clamp + + outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 0); // Color + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 2); // Color2 + link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); + if (link) { + nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_color, tosock); + } + else { + float color[4]; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + RNA_float_get_array(&fromptr, "default_value", color); + RNA_float_set_array(&toptr, "default_value", color); + } + + outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 1); // Color Fac + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 0); // Fac + link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); + if (link) { + nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_color, tosock); + } + else { + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + RNA_float_set(&toptr, "default_value", RNA_float_get(&fromptr, "default_value")); + } + + outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 2); // Alpha + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 2); // Color2 + link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); + if (link) { + nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_alpha, tosock); + } + else { + float color[4]; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + color[0] = color[1] = color[2] = RNA_float_get(&fromptr, "default_value"); + color[3] = 1.0f; + RNA_float_set_array(&toptr, "default_value", color); + } + + outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 3); // Alpha Fac + tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 0); // Fac + link = (bNodeLink *)BLI_findptr(&ntree->links, outsock, offsetof(bNodeLink, tosock)); + if (link) { + nodeAddLink(ntree, link->fromnode, link->fromsock, mix_rgb_alpha, tosock); + } + else { + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, outsock, &fromptr); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock, &toptr); + RNA_float_set(&toptr, "default_value", RNA_float_get(&fromptr, "default_value")); + } + + for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { + if (node->type == SH_NODE_UVALONGSTROKE) { + // UV output of the UV Along Stroke node + bNodeSocket *sock = (bNodeSocket *)BLI_findlink(&node->outputs, 0); + + // add new UV Map node + bNode *input_uvmap = nodeAddStaticNode(NULL, ntree, SH_NODE_UVMAP); + input_uvmap->locx = node->locx - 200.0f; + input_uvmap->locy = node->locy; + NodeShaderUVMap *storage = (NodeShaderUVMap *)input_uvmap->storage; + if (node->custom1 & 1) { // use_tips + BLI_strncpy(storage->uv_map, uvNames[1], sizeof(storage->uv_map)); + } + else { + BLI_strncpy(storage->uv_map, uvNames[0], sizeof(storage->uv_map)); + } + fromsock = (bNodeSocket *)BLI_findlink(&input_uvmap->outputs, 0); // UV + + // replace links from the UV Along Stroke node by links from the UV Map node + for (bNodeLink *link = (bNodeLink *)ntree->links.first; link; link = link->next) { + if (link->fromnode == node && link->fromsock == sock) { + nodeAddLink(ntree, input_uvmap, fromsock, link->tonode, link->tosock); + } + } + nodeRemSocketLinks(ntree, sock); + } + } + } + + nodeSetActive(ntree, output_material); + ntreeUpdateTree(bmain, ntree); + + return ma; } void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { - RenderStrokeRepBasic(iStrokeRep); + RenderStrokeRepBasic(iStrokeRep); } void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const { - bNodeTree *nt = iStrokeRep->getNodeTree(); - Material *ma = (Material *)BLI_ghash_lookup(_nodetree_hash, nt); - if (!ma) { - ma = BlenderStrokeRenderer::GetStrokeShader(freestyle_bmain, nt, false); - BLI_ghash_insert(_nodetree_hash, nt, ma); - } - iStrokeRep->setMaterial(ma); - - const vector& strips = iStrokeRep->getStrips(); - const bool hasTex = iStrokeRep->hasTex(); - int totvert = 0, totedge = 0, totpoly = 0, totloop = 0; - int visible_faces, visible_segments; - for (vector::const_iterator s = strips.begin(), send = strips.end(); s != send; ++s) { - Strip::vertex_container& strip_vertices = (*s)->vertices(); - - // count visible faces and strip segments - test_strip_visibility(strip_vertices, &visible_faces, &visible_segments); - if (visible_faces == 0) - continue; - - totvert += visible_faces + visible_segments * 2; - totedge += visible_faces * 2 + visible_segments; - totpoly += visible_faces; - totloop += visible_faces * 3; - } - - BlenderStrokeRenderer *self = const_cast(this); // FIXME - vector *groups = hasTex ? &self->texturedStrokeGroups : &self->strokeGroups; - StrokeGroup *group; - if (groups->empty() || !(groups->back()->totvert + totvert < MESH_MAX_VERTS && - groups->back()->totcol + 1 < MAXMAT)) - { - group = new StrokeGroup; - groups->push_back(group); - } - else { - group = groups->back(); - } - group->strokes.push_back(iStrokeRep); - group->totvert += totvert; - group->totedge += totedge; - group->totpoly += totpoly; - group->totloop += totloop; - group->totcol++; + bNodeTree *nt = iStrokeRep->getNodeTree(); + Material *ma = (Material *)BLI_ghash_lookup(_nodetree_hash, nt); + if (!ma) { + ma = BlenderStrokeRenderer::GetStrokeShader(freestyle_bmain, nt, false); + BLI_ghash_insert(_nodetree_hash, nt, ma); + } + iStrokeRep->setMaterial(ma); + + const vector &strips = iStrokeRep->getStrips(); + const bool hasTex = iStrokeRep->hasTex(); + int totvert = 0, totedge = 0, totpoly = 0, totloop = 0; + int visible_faces, visible_segments; + for (vector::const_iterator s = strips.begin(), send = strips.end(); s != send; ++s) { + Strip::vertex_container &strip_vertices = (*s)->vertices(); + + // count visible faces and strip segments + test_strip_visibility(strip_vertices, &visible_faces, &visible_segments); + if (visible_faces == 0) + continue; + + totvert += visible_faces + visible_segments * 2; + totedge += visible_faces * 2 + visible_segments; + totpoly += visible_faces; + totloop += visible_faces * 3; + } + + BlenderStrokeRenderer *self = const_cast(this); // FIXME + vector *groups = hasTex ? &self->texturedStrokeGroups : &self->strokeGroups; + StrokeGroup *group; + if (groups->empty() || !(groups->back()->totvert + totvert < MESH_MAX_VERTS && + groups->back()->totcol + 1 < MAXMAT)) { + group = new StrokeGroup; + groups->push_back(group); + } + else { + group = groups->back(); + } + group->strokes.push_back(iStrokeRep); + group->totvert += totvert; + group->totedge += totedge; + group->totpoly += totpoly; + group->totloop += totloop; + group->totcol++; } // Check if the triangle is visible (i.e., within the render image boundary) bool BlenderStrokeRenderer::test_triangle_visibility(StrokeVertexRep *svRep[3]) const { - int xl, xu, yl, yu; - Vec2r p; - - xl = xu = yl = yu = 0; - for (int i = 0; i < 3; i++) { - p = svRep[i]->point2d(); - if (p[0] < 0.0) - xl++; - else if (p[0] > _width) - xu++; - if (p[1] < 0.0) - yl++; - else if (p[1] > _height) - yu++; - } - return !(xl == 3 || xu == 3 || yl == 3 || yu == 3); + int xl, xu, yl, yu; + Vec2r p; + + xl = xu = yl = yu = 0; + for (int i = 0; i < 3; i++) { + p = svRep[i]->point2d(); + if (p[0] < 0.0) + xl++; + else if (p[0] > _width) + xu++; + if (p[1] < 0.0) + yl++; + else if (p[1] > _height) + yu++; + } + return !(xl == 3 || xu == 3 || yl == 3 || yu == 3); } // Check the visibility of faces and strip segments. -void BlenderStrokeRenderer::test_strip_visibility(Strip::vertex_container& strip_vertices, - int *visible_faces, int *visible_segments) const +void BlenderStrokeRenderer::test_strip_visibility(Strip::vertex_container &strip_vertices, + int *visible_faces, + int *visible_segments) const { - const int strip_vertex_count = strip_vertices.size(); - Strip::vertex_container::iterator v[3]; - StrokeVertexRep *svRep[3]; - bool visible; - - // iterate over all vertices and count visible faces and strip segments - // (note: a strip segment is a series of visible faces, while two strip - // segments are separated by one or more invisible faces) - v[0] = strip_vertices.begin(); - v[1] = v[0] + 1; - v[2] = v[0] + 2; - *visible_faces = *visible_segments = 0; - visible = false; - for (int n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) { - svRep[0] = *(v[0]); - svRep[1] = *(v[1]); - svRep[2] = *(v[2]); - if (test_triangle_visibility(svRep)) { - (*visible_faces)++; - if (!visible) - (*visible_segments)++; - visible = true; - } - else { - visible = false; - } - } + const int strip_vertex_count = strip_vertices.size(); + Strip::vertex_container::iterator v[3]; + StrokeVertexRep *svRep[3]; + bool visible; + + // iterate over all vertices and count visible faces and strip segments + // (note: a strip segment is a series of visible faces, while two strip + // segments are separated by one or more invisible faces) + v[0] = strip_vertices.begin(); + v[1] = v[0] + 1; + v[2] = v[0] + 2; + *visible_faces = *visible_segments = 0; + visible = false; + for (int n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) { + svRep[0] = *(v[0]); + svRep[1] = *(v[1]); + svRep[2] = *(v[2]); + if (test_triangle_visibility(svRep)) { + (*visible_faces)++; + if (!visible) + (*visible_segments)++; + visible = true; + } + else { + visible = false; + } + } } // Release allocated memory for stroke groups void BlenderStrokeRenderer::FreeStrokeGroups() { - vector::const_iterator it, itend; - - for (it = strokeGroups.begin(), itend = strokeGroups.end(); - it != itend; ++it) - { - delete (*it); - } - for (it = texturedStrokeGroups.begin(), itend = texturedStrokeGroups.end(); - it != itend; ++it) - { - delete (*it); - } + vector::const_iterator it, itend; + + for (it = strokeGroups.begin(), itend = strokeGroups.end(); it != itend; ++it) { + delete (*it); + } + for (it = texturedStrokeGroups.begin(), itend = texturedStrokeGroups.end(); it != itend; ++it) { + delete (*it); + } } // Build a scene populated by mesh objects representing stylized strokes int BlenderStrokeRenderer::GenerateScene() { - vector::const_iterator it, itend; - - for (it = strokeGroups.begin(), itend = strokeGroups.end(); - it != itend; ++it) - { - GenerateStrokeMesh(*it, false); - } - for (it = texturedStrokeGroups.begin(), itend = texturedStrokeGroups.end(); - it != itend; ++it) - { - GenerateStrokeMesh(*it, true); - } - return get_stroke_count(); + vector::const_iterator it, itend; + + for (it = strokeGroups.begin(), itend = strokeGroups.end(); it != itend; ++it) { + GenerateStrokeMesh(*it, false); + } + for (it = texturedStrokeGroups.begin(), itend = texturedStrokeGroups.end(); it != itend; ++it) { + GenerateStrokeMesh(*it, true); + } + return get_stroke_count(); } // Return the number of strokes int BlenderStrokeRenderer::get_stroke_count() const { - return strokeGroups.size() + texturedStrokeGroups.size(); + return strokeGroups.size() + texturedStrokeGroups.size(); } // Build a mesh object representing a group of stylized strokes void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) { #if 0 - Object *object_mesh = BKE_object_add(freestyle_bmain, freestyle_scene, (ViewLayer *)freestyle_scene->view_layers.first, OB_MESH); - DEG_relations_tag_update(freestyle_bmain); + Object *object_mesh = BKE_object_add(freestyle_bmain, freestyle_scene, (ViewLayer *)freestyle_scene->view_layers.first, OB_MESH); + DEG_relations_tag_update(freestyle_bmain); #else - Object *object_mesh = NewMesh(); + Object *object_mesh = NewMesh(); #endif - Mesh *mesh = (Mesh *)object_mesh->data; - - mesh->totvert = group->totvert; - mesh->totedge = group->totedge; - mesh->totpoly = group->totpoly; - mesh->totloop = group->totloop; - mesh->totcol = group->totcol; - - mesh->mvert = (MVert *)CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert); - mesh->medge = (MEdge *)CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge); - mesh->mpoly = (MPoly *)CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly); - mesh->mloop = (MLoop *)CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop); - - MVert *vertices = mesh->mvert; - MEdge *edges = mesh->medge; - MPoly *polys = mesh->mpoly; - MLoop *loops = mesh->mloop; - MLoopUV *loopsuv[2] = { NULL }; - - if (hasTex) { - // First UV layer - CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[0]); - CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0); - BKE_mesh_update_customdata_pointers(mesh, true); - loopsuv[0] = mesh->mloopuv; - - // Second UV layer - CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[1]); - CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1); - BKE_mesh_update_customdata_pointers(mesh, true); - loopsuv[1] = mesh->mloopuv; - } - - // colors and transparency (the latter represented by grayscale colors) - MLoopCol *colors = (MLoopCol *)CustomData_add_layer_named(&mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop, "Color"); - MLoopCol *transp = (MLoopCol *)CustomData_add_layer_named(&mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop, "Alpha"); - mesh->mloopcol = colors; - - mesh->mat = (Material **)MEM_mallocN(sizeof(Material *) * mesh->totcol, "MaterialList"); - - //////////////////// - // Data copy - //////////////////// - - int vertex_index = 0, edge_index = 0, loop_index = 0, material_index = 0; - int visible_faces, visible_segments; - bool visible; - Strip::vertex_container::iterator v[3]; - StrokeVertexRep *svRep[3]; - Vec2r p; - - for (vector::const_iterator it = group->strokes.begin(), itend = group->strokes.end(); - it != itend; ++it) - { - mesh->mat[material_index] = (*it)->getMaterial(); - id_us_plus(&mesh->mat[material_index]->id); - - vector& strips = (*it)->getStrips(); - for (vector::const_iterator s = strips.begin(), send = strips.end(); s != send; ++s) { - Strip::vertex_container& strip_vertices = (*s)->vertices(); - int strip_vertex_count = strip_vertices.size(); - - // count visible faces and strip segments - test_strip_visibility(strip_vertices, &visible_faces, &visible_segments); - if (visible_faces == 0) - continue; - - v[0] = strip_vertices.begin(); - v[1] = v[0] + 1; - v[2] = v[0] + 2; - - visible = false; - - // Note: Mesh generation in the following loop assumes stroke strips - // to be triangle strips. - for (int n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) { - svRep[0] = *(v[0]); - svRep[1] = *(v[1]); - svRep[2] = *(v[2]); - if (!test_triangle_visibility(svRep)) { - visible = false; - } - else { - if (!visible) { - // first vertex - vertices->co[0] = svRep[0]->point2d()[0]; - vertices->co[1] = svRep[0]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); - vertices->no[0] = 0; - vertices->no[1] = 0; - vertices->no[2] = SHRT_MAX; - ++vertices; - ++vertex_index; - - // second vertex - vertices->co[0] = svRep[1]->point2d()[0]; - vertices->co[1] = svRep[1]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); - vertices->no[0] = 0; - vertices->no[1] = 0; - vertices->no[2] = SHRT_MAX; - ++vertices; - ++vertex_index; - - // first edge - edges->v1 = vertex_index - 2; - edges->v2 = vertex_index - 1; - ++edges; - ++edge_index; - } - visible = true; - - // vertex - vertices->co[0] = svRep[2]->point2d()[0]; - vertices->co[1] = svRep[2]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); - vertices->no[0] = 0; - vertices->no[1] = 0; - vertices->no[2] = SHRT_MAX; - ++vertices; - ++vertex_index; - - // edges - edges->v1 = vertex_index - 1; - edges->v2 = vertex_index - 3; - ++edges; - ++edge_index; - - edges->v1 = vertex_index - 1; - edges->v2 = vertex_index - 2; - ++edges; - ++edge_index; - - // poly - polys->loopstart = loop_index; - polys->totloop = 3; - polys->mat_nr = material_index; - ++polys; - - // Even and odd loops connect triangles vertices differently - bool is_odd = n % 2; - // loops - if (is_odd) { - loops[0].v = vertex_index - 1; - loops[0].e = edge_index - 2; - - loops[1].v = vertex_index - 3; - loops[1].e = edge_index - 3; - - loops[2].v = vertex_index - 2; - loops[2].e = edge_index - 1; - } - else { - loops[0].v = vertex_index - 1; - loops[0].e = edge_index - 1; - - loops[1].v = vertex_index - 2; - loops[1].e = edge_index - 3; - - loops[2].v = vertex_index - 3; - loops[2].e = edge_index - 2; - } - loops += 3; - loop_index += 3; - - // UV - if (hasTex) { - // First UV layer (loopsuv[0]) has no tips (texCoord(0)). - // Second UV layer (loopsuv[1]) has tips: (texCoord(1)). - for (int L = 0; L < 2; L++) { - if (is_odd) { - loopsuv[L][0].uv[0] = svRep[2]->texCoord(L).x(); - loopsuv[L][0].uv[1] = svRep[2]->texCoord(L).y(); - - loopsuv[L][1].uv[0] = svRep[0]->texCoord(L).x(); - loopsuv[L][1].uv[1] = svRep[0]->texCoord(L).y(); - - loopsuv[L][2].uv[0] = svRep[1]->texCoord(L).x(); - loopsuv[L][2].uv[1] = svRep[1]->texCoord(L).y(); - } - else { - loopsuv[L][0].uv[0] = svRep[2]->texCoord(L).x(); - loopsuv[L][0].uv[1] = svRep[2]->texCoord(L).y(); - - loopsuv[L][1].uv[0] = svRep[1]->texCoord(L).x(); - loopsuv[L][1].uv[1] = svRep[1]->texCoord(L).y(); - - loopsuv[L][2].uv[0] = svRep[0]->texCoord(L).x(); - loopsuv[L][2].uv[1] = svRep[0]->texCoord(L).y(); - } - loopsuv[L] += 3; - } - } - - // colors and alpha transparency. vertex colors are in sRGB - // space by convention, so convert from linear - float rgba[3][4]; - - for (int i = 0; i < 3; i++) { - copy_v3fl_v3db(rgba[i], &svRep[i]->color()[0]); - rgba[i][3] = svRep[i]->alpha(); - } - - if (is_odd) { - linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]); - linearrgb_to_srgb_uchar4(&colors[1].r, rgba[0]); - linearrgb_to_srgb_uchar4(&colors[2].r, rgba[1]); - } - else { - linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]); - linearrgb_to_srgb_uchar4(&colors[1].r, rgba[1]); - linearrgb_to_srgb_uchar4(&colors[2].r, rgba[0]); - } - transp[0].r = transp[0].g = transp[0].b = colors[0].a; - transp[1].r = transp[1].g = transp[1].b = colors[1].a; - transp[2].r = transp[2].g = transp[2].b = colors[2].a; - colors += 3; - transp += 3; - } - } // loop over strip vertices - } // loop over strips - material_index++; - } // loop over strokes - - test_object_materials(freestyle_bmain, object_mesh, (ID *)mesh); - -#if 0 // XXX - BLI_assert(mesh->totvert == vertex_index); - BLI_assert(mesh->totedge == edge_index); - BLI_assert(mesh->totloop == loop_index); - BLI_assert(mesh->totcol == material_index); - BKE_mesh_validate(mesh, true, true); + Mesh *mesh = (Mesh *)object_mesh->data; + + mesh->totvert = group->totvert; + mesh->totedge = group->totedge; + mesh->totpoly = group->totpoly; + mesh->totloop = group->totloop; + mesh->totcol = group->totcol; + + mesh->mvert = (MVert *)CustomData_add_layer( + &mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert); + mesh->medge = (MEdge *)CustomData_add_layer( + &mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge); + mesh->mpoly = (MPoly *)CustomData_add_layer( + &mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly); + mesh->mloop = (MLoop *)CustomData_add_layer( + &mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop); + + MVert *vertices = mesh->mvert; + MEdge *edges = mesh->medge; + MPoly *polys = mesh->mpoly; + MLoop *loops = mesh->mloop; + MLoopUV *loopsuv[2] = {NULL}; + + if (hasTex) { + // First UV layer + CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[0]); + CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0); + BKE_mesh_update_customdata_pointers(mesh, true); + loopsuv[0] = mesh->mloopuv; + + // Second UV layer + CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[1]); + CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1); + BKE_mesh_update_customdata_pointers(mesh, true); + loopsuv[1] = mesh->mloopuv; + } + + // colors and transparency (the latter represented by grayscale colors) + MLoopCol *colors = (MLoopCol *)CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop, "Color"); + MLoopCol *transp = (MLoopCol *)CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop, "Alpha"); + mesh->mloopcol = colors; + + mesh->mat = (Material **)MEM_mallocN(sizeof(Material *) * mesh->totcol, "MaterialList"); + + //////////////////// + // Data copy + //////////////////// + + int vertex_index = 0, edge_index = 0, loop_index = 0, material_index = 0; + int visible_faces, visible_segments; + bool visible; + Strip::vertex_container::iterator v[3]; + StrokeVertexRep *svRep[3]; + Vec2r p; + + for (vector::const_iterator it = group->strokes.begin(), + itend = group->strokes.end(); + it != itend; + ++it) { + mesh->mat[material_index] = (*it)->getMaterial(); + id_us_plus(&mesh->mat[material_index]->id); + + vector &strips = (*it)->getStrips(); + for (vector::const_iterator s = strips.begin(), send = strips.end(); s != send; ++s) { + Strip::vertex_container &strip_vertices = (*s)->vertices(); + int strip_vertex_count = strip_vertices.size(); + + // count visible faces and strip segments + test_strip_visibility(strip_vertices, &visible_faces, &visible_segments); + if (visible_faces == 0) + continue; + + v[0] = strip_vertices.begin(); + v[1] = v[0] + 1; + v[2] = v[0] + 2; + + visible = false; + + // Note: Mesh generation in the following loop assumes stroke strips + // to be triangle strips. + for (int n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) { + svRep[0] = *(v[0]); + svRep[1] = *(v[1]); + svRep[2] = *(v[2]); + if (!test_triangle_visibility(svRep)) { + visible = false; + } + else { + if (!visible) { + // first vertex + vertices->co[0] = svRep[0]->point2d()[0]; + vertices->co[1] = svRep[0]->point2d()[1]; + vertices->co[2] = get_stroke_vertex_z(); + vertices->no[0] = 0; + vertices->no[1] = 0; + vertices->no[2] = SHRT_MAX; + ++vertices; + ++vertex_index; + + // second vertex + vertices->co[0] = svRep[1]->point2d()[0]; + vertices->co[1] = svRep[1]->point2d()[1]; + vertices->co[2] = get_stroke_vertex_z(); + vertices->no[0] = 0; + vertices->no[1] = 0; + vertices->no[2] = SHRT_MAX; + ++vertices; + ++vertex_index; + + // first edge + edges->v1 = vertex_index - 2; + edges->v2 = vertex_index - 1; + ++edges; + ++edge_index; + } + visible = true; + + // vertex + vertices->co[0] = svRep[2]->point2d()[0]; + vertices->co[1] = svRep[2]->point2d()[1]; + vertices->co[2] = get_stroke_vertex_z(); + vertices->no[0] = 0; + vertices->no[1] = 0; + vertices->no[2] = SHRT_MAX; + ++vertices; + ++vertex_index; + + // edges + edges->v1 = vertex_index - 1; + edges->v2 = vertex_index - 3; + ++edges; + ++edge_index; + + edges->v1 = vertex_index - 1; + edges->v2 = vertex_index - 2; + ++edges; + ++edge_index; + + // poly + polys->loopstart = loop_index; + polys->totloop = 3; + polys->mat_nr = material_index; + ++polys; + + // Even and odd loops connect triangles vertices differently + bool is_odd = n % 2; + // loops + if (is_odd) { + loops[0].v = vertex_index - 1; + loops[0].e = edge_index - 2; + + loops[1].v = vertex_index - 3; + loops[1].e = edge_index - 3; + + loops[2].v = vertex_index - 2; + loops[2].e = edge_index - 1; + } + else { + loops[0].v = vertex_index - 1; + loops[0].e = edge_index - 1; + + loops[1].v = vertex_index - 2; + loops[1].e = edge_index - 3; + + loops[2].v = vertex_index - 3; + loops[2].e = edge_index - 2; + } + loops += 3; + loop_index += 3; + + // UV + if (hasTex) { + // First UV layer (loopsuv[0]) has no tips (texCoord(0)). + // Second UV layer (loopsuv[1]) has tips: (texCoord(1)). + for (int L = 0; L < 2; L++) { + if (is_odd) { + loopsuv[L][0].uv[0] = svRep[2]->texCoord(L).x(); + loopsuv[L][0].uv[1] = svRep[2]->texCoord(L).y(); + + loopsuv[L][1].uv[0] = svRep[0]->texCoord(L).x(); + loopsuv[L][1].uv[1] = svRep[0]->texCoord(L).y(); + + loopsuv[L][2].uv[0] = svRep[1]->texCoord(L).x(); + loopsuv[L][2].uv[1] = svRep[1]->texCoord(L).y(); + } + else { + loopsuv[L][0].uv[0] = svRep[2]->texCoord(L).x(); + loopsuv[L][0].uv[1] = svRep[2]->texCoord(L).y(); + + loopsuv[L][1].uv[0] = svRep[1]->texCoord(L).x(); + loopsuv[L][1].uv[1] = svRep[1]->texCoord(L).y(); + + loopsuv[L][2].uv[0] = svRep[0]->texCoord(L).x(); + loopsuv[L][2].uv[1] = svRep[0]->texCoord(L).y(); + } + loopsuv[L] += 3; + } + } + + // colors and alpha transparency. vertex colors are in sRGB + // space by convention, so convert from linear + float rgba[3][4]; + + for (int i = 0; i < 3; i++) { + copy_v3fl_v3db(rgba[i], &svRep[i]->color()[0]); + rgba[i][3] = svRep[i]->alpha(); + } + + if (is_odd) { + linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]); + linearrgb_to_srgb_uchar4(&colors[1].r, rgba[0]); + linearrgb_to_srgb_uchar4(&colors[2].r, rgba[1]); + } + else { + linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]); + linearrgb_to_srgb_uchar4(&colors[1].r, rgba[1]); + linearrgb_to_srgb_uchar4(&colors[2].r, rgba[0]); + } + transp[0].r = transp[0].g = transp[0].b = colors[0].a; + transp[1].r = transp[1].g = transp[1].b = colors[1].a; + transp[2].r = transp[2].g = transp[2].b = colors[2].a; + colors += 3; + transp += 3; + } + } // loop over strip vertices + } // loop over strips + material_index++; + } // loop over strokes + + test_object_materials(freestyle_bmain, object_mesh, (ID *)mesh); + +#if 0 // XXX + BLI_assert(mesh->totvert == vertex_index); + BLI_assert(mesh->totedge == edge_index); + BLI_assert(mesh->totloop == loop_index); + BLI_assert(mesh->totcol == material_index); + BKE_mesh_validate(mesh, true, true); #endif } // A replacement of BKE_object_add() for better performance. Object *BlenderStrokeRenderer::NewMesh() const { - Object *ob; - char name[MAX_ID_NAME]; - unsigned int mesh_id = get_stroke_mesh_id(); + Object *ob; + char name[MAX_ID_NAME]; + unsigned int mesh_id = get_stroke_mesh_id(); - BLI_snprintf(name, MAX_ID_NAME, "0%08xOB", mesh_id); - ob = BKE_object_add_only_object(freestyle_bmain, OB_MESH, name); - BLI_snprintf(name, MAX_ID_NAME, "0%08xME", mesh_id); - ob->data = BKE_mesh_add(freestyle_bmain, name); + BLI_snprintf(name, MAX_ID_NAME, "0%08xOB", mesh_id); + ob = BKE_object_add_only_object(freestyle_bmain, OB_MESH, name); + BLI_snprintf(name, MAX_ID_NAME, "0%08xME", mesh_id); + ob->data = BKE_mesh_add(freestyle_bmain, name); - Collection *collection_master = BKE_collection_master(freestyle_scene); - BKE_collection_object_add(freestyle_bmain, collection_master, ob); - DEG_graph_tag_relations_update(freestyle_depsgraph); + Collection *collection_master = BKE_collection_master(freestyle_scene); + BKE_collection_object_add(freestyle_bmain, collection_master, ob); + DEG_graph_tag_relations_update(freestyle_depsgraph); - DEG_graph_id_tag_update(freestyle_bmain, - freestyle_depsgraph, - &ob->id, - ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); + DEG_graph_id_tag_update(freestyle_bmain, + freestyle_depsgraph, + &ob->id, + ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); - return ob; + return ob; } Render *BlenderStrokeRenderer::RenderScene(Render * /*re*/, bool render) { - Camera *camera = (Camera *)freestyle_scene->camera->data; - if (camera->clip_end < _z) - camera->clip_end = _z + _z_delta * 100.0f; + Camera *camera = (Camera *)freestyle_scene->camera->data; + if (camera->clip_end < _z) + camera->clip_end = _z + _z_delta * 100.0f; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "clip_start " << camera->clip_start << ", clip_end " << camera->clip_end << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "clip_start " << camera->clip_start << ", clip_end " << camera->clip_end << endl; + } #endif - Render *freestyle_render = RE_NewSceneRender(freestyle_scene); - ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; - DEG_graph_relations_update(freestyle_depsgraph, freestyle_bmain, freestyle_scene, view_layer); + Render *freestyle_render = RE_NewSceneRender(freestyle_scene); + ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; + DEG_graph_relations_update(freestyle_depsgraph, freestyle_bmain, freestyle_scene, view_layer); - RE_RenderFreestyleStrokes(freestyle_render, freestyle_bmain, freestyle_scene, - render && get_stroke_count() > 0); + RE_RenderFreestyleStrokes( + freestyle_render, freestyle_bmain, freestyle_scene, render && get_stroke_count() > 0); - return freestyle_render; + return freestyle_render; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h index 686e7272cc8..c333319ada1 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h @@ -38,66 +38,67 @@ struct bNodeTree; namespace Freestyle { -class BlenderStrokeRenderer : public StrokeRenderer -{ -public: - BlenderStrokeRenderer(Render *re, int render_count); - virtual ~BlenderStrokeRenderer(); - - /*! Renders a stroke rep */ - virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; - virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; - - Object *NewMesh() const; - - struct StrokeGroup { - explicit StrokeGroup() : totvert(0), totedge(0), totpoly(0), totloop(0), totcol(0) {} - vector strokes; - int totvert; - int totedge; - int totpoly; - int totloop; - int totcol; - }; - vector strokeGroups, texturedStrokeGroups; - - int GenerateScene(); - void GenerateStrokeMesh(StrokeGroup *group, bool hasTex); - void FreeStrokeGroups(); - - Render *RenderScene(Render *re, bool render); - - static Material *GetStrokeShader(Main *bmain, bNodeTree *iNodeTree, bool do_id_user); - -protected: - Main *freestyle_bmain; - Scene *old_scene; - Scene *freestyle_scene; - Depsgraph *freestyle_depsgraph; - bContext *_context; - float _width, _height; - float _z, _z_delta; - unsigned int _mesh_id; - bool _use_shading_nodes; - struct GHash *_nodetree_hash; - - static const char *uvNames[]; - - int get_stroke_count() const; - float get_stroke_vertex_z(void) const; - unsigned int get_stroke_mesh_id(void) const; - bool test_triangle_visibility(StrokeVertexRep *svRep[3]) const; - void test_strip_visibility( - Strip::vertex_container& strip_vertices, - int *visible_faces, int *visible_segments) const; - - vector _strokeReps; +class BlenderStrokeRenderer : public StrokeRenderer { + public: + BlenderStrokeRenderer(Render *re, int render_count); + virtual ~BlenderStrokeRenderer(); + + /*! Renders a stroke rep */ + virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; + virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; + + Object *NewMesh() const; + + struct StrokeGroup { + explicit StrokeGroup() : totvert(0), totedge(0), totpoly(0), totloop(0), totcol(0) + { + } + vector strokes; + int totvert; + int totedge; + int totpoly; + int totloop; + int totcol; + }; + vector strokeGroups, texturedStrokeGroups; + + int GenerateScene(); + void GenerateStrokeMesh(StrokeGroup *group, bool hasTex); + void FreeStrokeGroups(); + + Render *RenderScene(Render *re, bool render); + + static Material *GetStrokeShader(Main *bmain, bNodeTree *iNodeTree, bool do_id_user); + + protected: + Main *freestyle_bmain; + Scene *old_scene; + Scene *freestyle_scene; + Depsgraph *freestyle_depsgraph; + bContext *_context; + float _width, _height; + float _z, _z_delta; + unsigned int _mesh_id; + bool _use_shading_nodes; + struct GHash *_nodetree_hash; + + static const char *uvNames[]; + + int get_stroke_count() const; + float get_stroke_vertex_z(void) const; + unsigned int get_stroke_mesh_id(void) const; + bool test_triangle_visibility(StrokeVertexRep *svRep[3]) const; + void test_strip_visibility(Strip::vertex_container &strip_vertices, + int *visible_faces, + int *visible_segments) const; + + vector _strokeReps; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStrokeRenderer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStrokeRenderer") #endif }; } /* namespace Freestyle */ -#endif // __BLENDER_STROKE_RENDERER_H__ +#endif // __BLENDER_STROKE_RENDERER_H__ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h index 166f9243f63..a4beb1c119c 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h @@ -25,69 +25,69 @@ #include "../system/PythonInterpreter.h" extern "C" { -#include "BLI_utildefines.h" // BLI_assert() +#include "BLI_utildefines.h" // BLI_assert() struct Text; } namespace Freestyle { -class BufferedStyleModule : public StyleModule -{ -public: - BufferedStyleModule(const string& buffer, const string& file_name, Interpreter *inter) : StyleModule(file_name, inter) - { - _buffer = buffer; - } - - virtual ~BufferedStyleModule() - { - } - -protected: - virtual int interpret() - { - PythonInterpreter *py_inter = dynamic_cast(_inter); - BLI_assert(py_inter != 0); - return py_inter->interpretString(_buffer, getFileName()); - } - -private: - string _buffer; +class BufferedStyleModule : public StyleModule { + public: + BufferedStyleModule(const string &buffer, const string &file_name, Interpreter *inter) + : StyleModule(file_name, inter) + { + _buffer = buffer; + } + + virtual ~BufferedStyleModule() + { + } + + protected: + virtual int interpret() + { + PythonInterpreter *py_inter = dynamic_cast(_inter); + BLI_assert(py_inter != 0); + return py_inter->interpretString(_buffer, getFileName()); + } + + private: + string _buffer; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BufferedStyleModule") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BufferedStyleModule") #endif }; -class BlenderStyleModule : public StyleModule -{ -public: - BlenderStyleModule(struct Text *text, const string &name, Interpreter *inter) : StyleModule(name, inter) - { - _text = text; - } - - virtual ~BlenderStyleModule() - { - } - -protected: - virtual int interpret() - { - PythonInterpreter *py_inter = dynamic_cast(_inter); - BLI_assert(py_inter != 0); - return py_inter->interpretText(_text, getFileName()); - } - -private: - struct Text *_text; +class BlenderStyleModule : public StyleModule { + public: + BlenderStyleModule(struct Text *text, const string &name, Interpreter *inter) + : StyleModule(name, inter) + { + _text = text; + } + + virtual ~BlenderStyleModule() + { + } + + protected: + virtual int interpret() + { + PythonInterpreter *py_inter = dynamic_cast(_inter); + BLI_assert(py_inter != 0); + return py_inter->interpretText(_text, getFileName()); + } + + private: + struct Text *_text; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStyleModule") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStyleModule") #endif }; } /* namespace Freestyle */ -#endif // __BLENDERSTYLEMODULE_H__ +#endif // __BLENDERSTYLEMODULE_H__ diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 785f291d8c3..63ff4cc5457 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -66,7 +66,7 @@ extern "C" { #include "FRS_freestyle.h" #define DEFAULT_SPHERE_RADIUS 1.0f -#define DEFAULT_DKR_EPSILON 0.0f +#define DEFAULT_DKR_EPSILON 0.0f struct FreestyleGlobals g_freestyle; @@ -80,17 +80,17 @@ static AppView *view = NULL; static FreestyleLineSet lineset_buffer; static bool lineset_copied = false; - static void load_post_callback(struct Main * /*main*/, struct ID * /*id*/, void * /*arg*/) { - lineset_copied = false; + lineset_copied = false; } static bCallbackFuncStore load_post_callback_funcstore = { - NULL, NULL, /* next, prev */ - load_post_callback, /* func */ - NULL, /* arg */ - 0 /* alloc */ + NULL, + NULL, /* next, prev */ + load_post_callback, /* func */ + NULL, /* arg */ + 0 /* alloc */ }; //======================================================= @@ -99,35 +99,35 @@ static bCallbackFuncStore load_post_callback_funcstore = { void FRS_initialize() { - if (freestyle_is_initialized) - return; + if (freestyle_is_initialized) + return; - pathconfig = new Config::Path; - controller = new Controller(); - view = new AppView; - controller->setView(view); - controller->Clear(); - g_freestyle.scene = NULL; - lineset_copied = false; + pathconfig = new Config::Path; + controller = new Controller(); + view = new AppView; + controller->setView(view); + controller->Clear(); + g_freestyle.scene = NULL; + lineset_copied = false; - BLI_callback_add(&load_post_callback_funcstore, BLI_CB_EVT_LOAD_POST); + BLI_callback_add(&load_post_callback_funcstore, BLI_CB_EVT_LOAD_POST); - freestyle_is_initialized = 1; + freestyle_is_initialized = 1; } void FRS_set_context(bContext *C) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl; - } - controller->setContext(C); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl; + } + controller->setContext(C); } void FRS_exit() { - delete pathconfig; - delete controller; - delete view; + delete pathconfig; + delete controller; + delete view; } //======================================================= @@ -136,536 +136,545 @@ void FRS_exit() static void init_view(Render *re) { - int width = re->winx; - int height = re->winy; - int xmin = re->disprect.xmin; - int ymin = re->disprect.ymin; - int xmax = re->disprect.xmax; - int ymax = re->disprect.ymax; - - float thickness = 1.0f; - switch (re->r.line_thickness_mode) { - case R_LINE_THICKNESS_ABSOLUTE: - thickness = re->r.unit_line_thickness * (re->r.size / 100.f); - break; - case R_LINE_THICKNESS_RELATIVE: - thickness = height / 480.f; - break; - } - - g_freestyle.viewport[0] = g_freestyle.viewport[1] = 0; - g_freestyle.viewport[2] = width; - g_freestyle.viewport[3] = height; - - view->setWidth(width); - view->setHeight(height); - view->setBorder(xmin, ymin, xmax, ymax); - view->setThickness(thickness); - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Dimensions of the 2D image coordinate system ===" << endl; - cout << "Width : " << width << endl; - cout << "Height : " << height << endl; - if (re->r.mode & R_BORDER) - cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl; - cout << "Unit line thickness : " << thickness << " pixel(s)" << endl; - } + int width = re->winx; + int height = re->winy; + int xmin = re->disprect.xmin; + int ymin = re->disprect.ymin; + int xmax = re->disprect.xmax; + int ymax = re->disprect.ymax; + + float thickness = 1.0f; + switch (re->r.line_thickness_mode) { + case R_LINE_THICKNESS_ABSOLUTE: + thickness = re->r.unit_line_thickness * (re->r.size / 100.f); + break; + case R_LINE_THICKNESS_RELATIVE: + thickness = height / 480.f; + break; + } + + g_freestyle.viewport[0] = g_freestyle.viewport[1] = 0; + g_freestyle.viewport[2] = width; + g_freestyle.viewport[3] = height; + + view->setWidth(width); + view->setHeight(height); + view->setBorder(xmin, ymin, xmax, ymax); + view->setThickness(thickness); + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Dimensions of the 2D image coordinate system ===" << endl; + cout << "Width : " << width << endl; + cout << "Height : " << height << endl; + if (re->r.mode & R_BORDER) + cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" + << endl; + cout << "Unit line thickness : " << thickness << " pixel(s)" << endl; + } } static void init_camera(Render *re) { - // It is assumed that imported meshes are in the camera coordinate system. - // Therefore, the view point (i.e., camera position) is at the origin, and - // the model-view matrix is simply the identity matrix. + // It is assumed that imported meshes are in the camera coordinate system. + // Therefore, the view point (i.e., camera position) is at the origin, and + // the model-view matrix is simply the identity matrix. - zero_v3(g_freestyle.viewpoint); + zero_v3(g_freestyle.viewpoint); - unit_m4(g_freestyle.mv); + unit_m4(g_freestyle.mv); - copy_m4_m4(g_freestyle.proj, re->winmat); + copy_m4_m4(g_freestyle.proj, re->winmat); #if 0 - print_m4("mv", g_freestyle.mv); - print_m4("proj", g_freestyle.proj); + print_m4("mv", g_freestyle.mv); + print_m4("proj", g_freestyle.proj); #endif } static char *escape_quotes(char *name) { - char *s = (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes"); - char *p = s; - while (*name) { - if (*name == '\'') - *(p++) = '\\'; - *(p++) = *(name++); - } - *p = '\0'; - return s; + char *s = (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes"); + char *p = s; + while (*name) { + if (*name == '\'') + *(p++) = '\\'; + *(p++) = *(name++); + } + *p = '\0'; + return s; } -static char * create_lineset_handler(char *layer_name, char *lineset_name) +static char *create_lineset_handler(char *layer_name, char *lineset_name) { - const char *fmt = "__import__('parameter_editor').process('%s', '%s')\n"; - char *s1 = escape_quotes(layer_name); - char *s2 = escape_quotes(lineset_name); - char *text = BLI_sprintfN(fmt, s1, s2); - MEM_freeN(s1); - MEM_freeN(s2); - return text; + const char *fmt = "__import__('parameter_editor').process('%s', '%s')\n"; + char *s1 = escape_quotes(layer_name); + char *s2 = escape_quotes(lineset_name); + char *text = BLI_sprintfN(fmt, s1, s2); + MEM_freeN(s1); + MEM_freeN(s2); + return text; } -struct edge_type_condition -{ - int edge_type, value; +struct edge_type_condition { + int edge_type, value; }; // examines the conditions and returns true if the target edge type needs to be computed static bool test_edge_type_conditions(struct edge_type_condition *conditions, - int num_edge_types, bool logical_and, int target, bool distinct) + int num_edge_types, + bool logical_and, + int target, + bool distinct) { - int target_condition = 0; - int num_non_target_positive_conditions = 0; - int num_non_target_negative_conditions = 0; - - for (int i = 0; i < num_edge_types; i++) { - if (conditions[i].edge_type == target) - target_condition = conditions[i].value; - else if (conditions[i].value > 0) - ++num_non_target_positive_conditions; - else if (conditions[i].value < 0) - ++num_non_target_negative_conditions; - } - if (distinct) { - // In this case, the 'target' edge type is assumed to appear on distinct edge - // of its own and never together with other edge types. - if (logical_and) { - if (num_non_target_positive_conditions > 0) - return false; - if (target_condition > 0) - return true; - if (target_condition < 0) - return false; - if (num_non_target_negative_conditions > 0) - return true; - } - else { - if (target_condition > 0) - return true; - if (num_non_target_negative_conditions > 0) - return true; - if (target_condition < 0) - return false; - if (num_non_target_positive_conditions > 0) - return false; - } - } - else { - // In this case, the 'target' edge type may appear together with other edge types. - if (target_condition > 0) - return true; - if (target_condition < 0) - return true; - if (logical_and) { - if (num_non_target_positive_conditions > 0) - return false; - if (num_non_target_negative_conditions > 0) - return true; - } - else { - if (num_non_target_negative_conditions > 0) - return true; - if (num_non_target_positive_conditions > 0) - return false; - } - } - return true; + int target_condition = 0; + int num_non_target_positive_conditions = 0; + int num_non_target_negative_conditions = 0; + + for (int i = 0; i < num_edge_types; i++) { + if (conditions[i].edge_type == target) + target_condition = conditions[i].value; + else if (conditions[i].value > 0) + ++num_non_target_positive_conditions; + else if (conditions[i].value < 0) + ++num_non_target_negative_conditions; + } + if (distinct) { + // In this case, the 'target' edge type is assumed to appear on distinct edge + // of its own and never together with other edge types. + if (logical_and) { + if (num_non_target_positive_conditions > 0) + return false; + if (target_condition > 0) + return true; + if (target_condition < 0) + return false; + if (num_non_target_negative_conditions > 0) + return true; + } + else { + if (target_condition > 0) + return true; + if (num_non_target_negative_conditions > 0) + return true; + if (target_condition < 0) + return false; + if (num_non_target_positive_conditions > 0) + return false; + } + } + else { + // In this case, the 'target' edge type may appear together with other edge types. + if (target_condition > 0) + return true; + if (target_condition < 0) + return true; + if (logical_and) { + if (num_non_target_positive_conditions > 0) + return false; + if (num_non_target_negative_conditions > 0) + return true; + } + else { + if (num_non_target_negative_conditions > 0) + return true; + if (num_non_target_positive_conditions > 0) + return false; + } + } + return true; } static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { - // load mesh - re->i.infostr = IFACE_("Freestyle: Mesh loading"); - re->stats_draw(re->sdh, &re->i); - re->i.infostr = NULL; - if (controller->LoadMesh(re, view_layer, depsgraph)) // returns if scene cannot be loaded or if empty - return; - if (re->test_break(re->tbh)) - return; - - // add style modules - FreestyleConfig *config = &view_layer->freestyle_config; - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "\n=== Rendering options ===" << endl; - } - int layer_count = 0; - - switch (config->mode) { - case FREESTYLE_CONTROL_SCRIPT_MODE: - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Modules :" << endl; - } - for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig *)config->modules.first; - module_conf; - module_conf = module_conf->next) - { - if (module_conf->script && module_conf->is_displayed) { - const char *id_name = module_conf->script->id.name + 2; - if (G.debug & G_DEBUG_FREESTYLE) { - cout << " " << layer_count + 1 << ": " << id_name; - if (module_conf->script->name) - cout << " (" << module_conf->script->name << ")"; - cout << endl; - } - controller->InsertStyleModule(layer_count, id_name, module_conf->script); - controller->toggleLayer(layer_count, true); - layer_count++; - } - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << endl; - } - controller->setComputeRidgesAndValleysFlag((config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false); - controller->setComputeSuggestiveContoursFlag((config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false); - controller->setComputeMaterialBoundariesFlag((config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false); - break; - case FREESTYLE_CONTROL_EDITOR_MODE: - int use_ridges_and_valleys = 0; - int use_suggestive_contours = 0; - int use_material_boundaries = 0; - struct edge_type_condition conditions[] = { - {FREESTYLE_FE_SILHOUETTE, 0}, - {FREESTYLE_FE_BORDER, 0}, - {FREESTYLE_FE_CREASE, 0}, - {FREESTYLE_FE_RIDGE_VALLEY, 0}, - {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0}, - {FREESTYLE_FE_MATERIAL_BOUNDARY, 0}, - {FREESTYLE_FE_CONTOUR, 0}, - {FREESTYLE_FE_EXTERNAL_CONTOUR, 0}, - {FREESTYLE_FE_EDGE_MARK, 0}, - }; - int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Linesets:" << endl; - } - for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; - lineset; - lineset = lineset->next) - { - if (lineset->flags & FREESTYLE_LINESET_ENABLED) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << " " << layer_count+1 << ": " << lineset->name << " - " << - (lineset->linestyle ? (lineset->linestyle->id.name + 2) : "") << endl; - } - char *buffer = create_lineset_handler(view_layer->name, lineset->name); - controller->InsertStyleModule(layer_count, lineset->name, buffer); - controller->toggleLayer(layer_count, true); - MEM_freeN(buffer); - if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) { - ++use_ridges_and_valleys; - ++use_suggestive_contours; - ++use_material_boundaries; - } - else { - // conditions for feature edge selection by edge types - for (int i = 0; i < num_edge_types; i++) { - if (!(lineset->edge_types & conditions[i].edge_type)) - conditions[i].value = 0; // no condition specified - else if (!(lineset->exclude_edge_types & conditions[i].edge_type)) - conditions[i].value = 1; // condition: X - else - conditions[i].value = -1; // condition: NOT X - } - // logical operator for the selection conditions - bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0); - // negation operator - if (lineset->flags & FREESTYLE_LINESET_FE_NOT) { - // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws: - // NOT (X OR Y) --> (NOT X) AND (NOT Y) - // NOT (X AND Y) --> (NOT X) OR (NOT Y) - for (int i = 0; i < num_edge_types; i++) - conditions[i].value *= -1; - logical_and = !logical_and; - } - if (test_edge_type_conditions(conditions, num_edge_types, logical_and, - FREESTYLE_FE_RIDGE_VALLEY, true)) - { - ++use_ridges_and_valleys; - } - if (test_edge_type_conditions(conditions, num_edge_types, logical_and, - FREESTYLE_FE_SUGGESTIVE_CONTOUR, true)) - { - ++use_suggestive_contours; - } - if (test_edge_type_conditions(conditions, num_edge_types, logical_and, - FREESTYLE_FE_MATERIAL_BOUNDARY, true)) - { - ++use_material_boundaries; - } - } - layer_count++; - } - } - controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0); - controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0); - controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0); - break; - } - - // set parameters - if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) { - controller->setSphereRadius(config->sphere_radius); - controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon); - } - else { - controller->setSphereRadius(DEFAULT_SPHERE_RADIUS); - controller->setSuggestiveContourKrDerivativeEpsilon(DEFAULT_DKR_EPSILON); - } - controller->setFaceSmoothness((config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false); - controller->setCreaseAngle(RAD2DEGF(config->crease_angle)); - controller->setVisibilityAlgo((config->flags & FREESTYLE_CULLING) ? - FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE : - FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE); - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Crease angle : " << controller->getCreaseAngle() << endl; - cout << "Sphere radius : " << controller->getSphereRadius() << endl; - cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl; - cout << "Ridges and valleys : " << - (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl; - cout << "Suggestive contours : " << - (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl; - cout << "Suggestive contour Kr derivative epsilon : " << - controller->getSuggestiveContourKrDerivativeEpsilon() << endl; - cout << "Material boundaries : " << - (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl; - cout << endl; - } - - // set diffuse and z depth passes - RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name); - bool diffuse = false, z = false; - for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) { - if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE_COLOR)) { - controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty); - diffuse = true; - } - if (STREQ(rpass->name, RE_PASSNAME_Z)) { - controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty); - z = true; - } - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Passes :" << endl; - cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl; - cout << " Z = " << (z ? "enabled" : "disabled") << endl; - } - - if (controller->hitViewMapCache()) - return; - - // compute view map - re->i.infostr = IFACE_("Freestyle: View map creation"); - re->stats_draw(re->sdh, &re->i); - re->i.infostr = NULL; - controller->ComputeViewMap(); + // load mesh + re->i.infostr = IFACE_("Freestyle: Mesh loading"); + re->stats_draw(re->sdh, &re->i); + re->i.infostr = NULL; + if (controller->LoadMesh( + re, view_layer, depsgraph)) // returns if scene cannot be loaded or if empty + return; + if (re->test_break(re->tbh)) + return; + + // add style modules + FreestyleConfig *config = &view_layer->freestyle_config; + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "\n=== Rendering options ===" << endl; + } + int layer_count = 0; + + switch (config->mode) { + case FREESTYLE_CONTROL_SCRIPT_MODE: + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Modules :" << endl; + } + for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig *)config->modules.first; + module_conf; + module_conf = module_conf->next) { + if (module_conf->script && module_conf->is_displayed) { + const char *id_name = module_conf->script->id.name + 2; + if (G.debug & G_DEBUG_FREESTYLE) { + cout << " " << layer_count + 1 << ": " << id_name; + if (module_conf->script->name) + cout << " (" << module_conf->script->name << ")"; + cout << endl; + } + controller->InsertStyleModule(layer_count, id_name, module_conf->script); + controller->toggleLayer(layer_count, true); + layer_count++; + } + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << endl; + } + controller->setComputeRidgesAndValleysFlag( + (config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false); + controller->setComputeSuggestiveContoursFlag( + (config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false); + controller->setComputeMaterialBoundariesFlag( + (config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false); + break; + case FREESTYLE_CONTROL_EDITOR_MODE: + int use_ridges_and_valleys = 0; + int use_suggestive_contours = 0; + int use_material_boundaries = 0; + struct edge_type_condition conditions[] = { + {FREESTYLE_FE_SILHOUETTE, 0}, + {FREESTYLE_FE_BORDER, 0}, + {FREESTYLE_FE_CREASE, 0}, + {FREESTYLE_FE_RIDGE_VALLEY, 0}, + {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0}, + {FREESTYLE_FE_MATERIAL_BOUNDARY, 0}, + {FREESTYLE_FE_CONTOUR, 0}, + {FREESTYLE_FE_EXTERNAL_CONTOUR, 0}, + {FREESTYLE_FE_EDGE_MARK, 0}, + }; + int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Linesets:" << endl; + } + for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; + lineset = lineset->next) { + if (lineset->flags & FREESTYLE_LINESET_ENABLED) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << " " << layer_count + 1 << ": " << lineset->name << " - " + << (lineset->linestyle ? (lineset->linestyle->id.name + 2) : "") << endl; + } + char *buffer = create_lineset_handler(view_layer->name, lineset->name); + controller->InsertStyleModule(layer_count, lineset->name, buffer); + controller->toggleLayer(layer_count, true); + MEM_freeN(buffer); + if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) { + ++use_ridges_and_valleys; + ++use_suggestive_contours; + ++use_material_boundaries; + } + else { + // conditions for feature edge selection by edge types + for (int i = 0; i < num_edge_types; i++) { + if (!(lineset->edge_types & conditions[i].edge_type)) + conditions[i].value = 0; // no condition specified + else if (!(lineset->exclude_edge_types & conditions[i].edge_type)) + conditions[i].value = 1; // condition: X + else + conditions[i].value = -1; // condition: NOT X + } + // logical operator for the selection conditions + bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0); + // negation operator + if (lineset->flags & FREESTYLE_LINESET_FE_NOT) { + // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws: + // NOT (X OR Y) --> (NOT X) AND (NOT Y) + // NOT (X AND Y) --> (NOT X) OR (NOT Y) + for (int i = 0; i < num_edge_types; i++) + conditions[i].value *= -1; + logical_and = !logical_and; + } + if (test_edge_type_conditions( + conditions, num_edge_types, logical_and, FREESTYLE_FE_RIDGE_VALLEY, true)) { + ++use_ridges_and_valleys; + } + if (test_edge_type_conditions(conditions, + num_edge_types, + logical_and, + FREESTYLE_FE_SUGGESTIVE_CONTOUR, + true)) { + ++use_suggestive_contours; + } + if (test_edge_type_conditions(conditions, + num_edge_types, + logical_and, + FREESTYLE_FE_MATERIAL_BOUNDARY, + true)) { + ++use_material_boundaries; + } + } + layer_count++; + } + } + controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0); + controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0); + controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0); + break; + } + + // set parameters + if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) { + controller->setSphereRadius(config->sphere_radius); + controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon); + } + else { + controller->setSphereRadius(DEFAULT_SPHERE_RADIUS); + controller->setSuggestiveContourKrDerivativeEpsilon(DEFAULT_DKR_EPSILON); + } + controller->setFaceSmoothness((config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false); + controller->setCreaseAngle(RAD2DEGF(config->crease_angle)); + controller->setVisibilityAlgo((config->flags & FREESTYLE_CULLING) ? + FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE : + FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE); + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Crease angle : " << controller->getCreaseAngle() << endl; + cout << "Sphere radius : " << controller->getSphereRadius() << endl; + cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") + << endl; + cout << "Ridges and valleys : " + << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl; + cout << "Suggestive contours : " + << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl; + cout << "Suggestive contour Kr derivative epsilon : " + << controller->getSuggestiveContourKrDerivativeEpsilon() << endl; + cout << "Material boundaries : " + << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl; + cout << endl; + } + + // set diffuse and z depth passes + RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name); + bool diffuse = false, z = false; + for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) { + if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE_COLOR)) { + controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty); + diffuse = true; + } + if (STREQ(rpass->name, RE_PASSNAME_Z)) { + controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty); + z = true; + } + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Passes :" << endl; + cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl; + cout << " Z = " << (z ? "enabled" : "disabled") << endl; + } + + if (controller->hitViewMapCache()) + return; + + // compute view map + re->i.infostr = IFACE_("Freestyle: View map creation"); + re->stats_draw(re->sdh, &re->i); + re->i.infostr = NULL; + controller->ComputeViewMap(); } void FRS_composite_result(Render *re, ViewLayer *view_layer, Render *freestyle_render) { - RenderLayer *rl; - float *src, *dest, *pixSrc, *pixDest; - int x, y, rectx, recty; - - if (freestyle_render == NULL || freestyle_render->result == NULL) - return; - - rl = render_get_active_layer( freestyle_render, freestyle_render->result ); - if (!rl) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "No source render layer to composite" << endl; - } - return; - } - - src = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, freestyle_render->viewname); - if (!src) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "No source result image to composite" << endl; - } - return; - } + RenderLayer *rl; + float *src, *dest, *pixSrc, *pixDest; + int x, y, rectx, recty; + + if (freestyle_render == NULL || freestyle_render->result == NULL) + return; + + rl = render_get_active_layer(freestyle_render, freestyle_render->result); + if (!rl) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No source render layer to composite" << endl; + } + return; + } + + src = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, freestyle_render->viewname); + if (!src) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No source result image to composite" << endl; + } + return; + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "src: " << rl->rectx << " x " << rl->recty << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "src: " << rl->rectx << " x " << rl->recty << endl; + } #endif - rl = RE_GetRenderLayer(re->result, view_layer->name); - if (!rl) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "No destination render layer to composite to" << endl; - } - return; - } - dest = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, re->viewname); - if (!dest) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "No destination result image to composite to" << endl; - } - return; - } + rl = RE_GetRenderLayer(re->result, view_layer->name); + if (!rl) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No destination render layer to composite to" << endl; + } + return; + } + dest = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, re->viewname); + if (!dest) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No destination result image to composite to" << endl; + } + return; + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "dest: " << rl->rectx << " x " << rl->recty << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "dest: " << rl->rectx << " x " << rl->recty << endl; + } #endif - rectx = re->rectx; - recty = re->recty; - for (y = 0; y < recty; y++) { - for (x = 0; x < rectx; x++) { - pixSrc = src + 4 * (rectx * y + x); - if (pixSrc[3] > 0.0) { - pixDest = dest + 4 * (rectx * y + x); - blend_color_mix_float(pixDest, pixDest, pixSrc); - } - } - } + rectx = re->rectx; + recty = re->recty; + for (y = 0; y < recty; y++) { + for (x = 0; x < rectx; x++) { + pixSrc = src + 4 * (rectx * y + x); + if (pixSrc[3] > 0.0) { + pixDest = dest + 4 * (rectx * y + x); + blend_color_mix_float(pixDest, pixDest, pixSrc); + } + } + } } static int displayed_layer_count(ViewLayer *view_layer) { - int count = 0; - - switch (view_layer->freestyle_config.mode) { - case FREESTYLE_CONTROL_SCRIPT_MODE: - for (FreestyleModuleConfig *module = (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first; - module; - module = module->next) - { - if (module->script && module->is_displayed) - count++; - } - break; - case FREESTYLE_CONTROL_EDITOR_MODE: - for (FreestyleLineSet *lineset = (FreestyleLineSet *)view_layer->freestyle_config.linesets.first; - lineset; - lineset = lineset->next) - { - if (lineset->flags & FREESTYLE_LINESET_ENABLED) - count++; - } - break; - } - return count; + int count = 0; + + switch (view_layer->freestyle_config.mode) { + case FREESTYLE_CONTROL_SCRIPT_MODE: + for (FreestyleModuleConfig *module = + (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first; + module; + module = module->next) { + if (module->script && module->is_displayed) + count++; + } + break; + case FREESTYLE_CONTROL_EDITOR_MODE: + for (FreestyleLineSet *lineset = + (FreestyleLineSet *)view_layer->freestyle_config.linesets.first; + lineset; + lineset = lineset->next) { + if (lineset->flags & FREESTYLE_LINESET_ENABLED) + count++; + } + break; + } + return count; } int FRS_is_freestyle_enabled(ViewLayer *view_layer) { - return ((view_layer->flag & VIEW_LAYER_RENDER) && - (view_layer->flag & VIEW_LAYER_FREESTYLE) && - displayed_layer_count(view_layer) > 0); + return ((view_layer->flag & VIEW_LAYER_RENDER) && (view_layer->flag & VIEW_LAYER_FREESTYLE) && + displayed_layer_count(view_layer) > 0); } void FRS_init_stroke_renderer(Render *re) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << endl; - cout << "#===============================================================" << endl; - cout << "# Freestyle" << endl; - cout << "#===============================================================" << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << endl; + cout << "#===============================================================" << endl; + cout << "# Freestyle" << endl; + cout << "#===============================================================" << endl; + } - init_view(re); + init_view(re); - controller->ResetRenderCount(); + controller->ResetRenderCount(); } void FRS_begin_stroke_rendering(Render *re) { - init_camera(re); + init_camera(re); } Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render) { - Render *freestyle_render = NULL; - - if (!render) - return controller->RenderStrokes(re, false); - - RenderMonitor monitor(re); - controller->setRenderMonitor(&monitor); - controller->setViewMapCache((view_layer->freestyle_config.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false); - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << endl; - cout << "----------------------------------------------------------" << endl; - cout << "| " << (re->scene->id.name + 2) << "|" << view_layer->name << endl; - cout << "----------------------------------------------------------" << endl; - } - - /* Create depsgraph and evaluate scene. */ - ViewLayer *scene_view_layer = (ViewLayer*)BLI_findstring(&re->scene->view_layers, view_layer->name, offsetof(ViewLayer, name)); - Depsgraph *depsgraph = DEG_graph_new(re->scene, scene_view_layer, DAG_EVAL_RENDER); - BKE_scene_graph_update_for_newframe(depsgraph, re->main); - - // prepare Freestyle: - // - load mesh - // - add style modules - // - set parameters - // - compute view map - prepare(re, view_layer, depsgraph); - - if (re->test_break(re->tbh)) { - controller->CloseFile(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Break" << endl; - } - } - else { - // render and composite Freestyle result - if (controller->_ViewMap) { - // render strokes - re->i.infostr = IFACE_("Freestyle: Stroke rendering"); - re->stats_draw(re->sdh, &re->i); - re->i.infostr = NULL; - g_freestyle.scene = DEG_get_evaluated_scene(depsgraph); - int strokeCount = controller->DrawStrokes(); - if (strokeCount > 0) { - freestyle_render = controller->RenderStrokes(re, true); - } - controller->CloseFile(); - g_freestyle.scene = NULL; - - // composite result - if (freestyle_render) { - FRS_composite_result(re, view_layer, freestyle_render); - RE_FreeRenderResult(freestyle_render->result); - freestyle_render->result = NULL; - } - } - } - - DEG_graph_free(depsgraph); - - return freestyle_render; + Render *freestyle_render = NULL; + + if (!render) + return controller->RenderStrokes(re, false); + + RenderMonitor monitor(re); + controller->setRenderMonitor(&monitor); + controller->setViewMapCache( + (view_layer->freestyle_config.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false); + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << endl; + cout << "----------------------------------------------------------" << endl; + cout << "| " << (re->scene->id.name + 2) << "|" << view_layer->name << endl; + cout << "----------------------------------------------------------" << endl; + } + + /* Create depsgraph and evaluate scene. */ + ViewLayer *scene_view_layer = (ViewLayer *)BLI_findstring( + &re->scene->view_layers, view_layer->name, offsetof(ViewLayer, name)); + Depsgraph *depsgraph = DEG_graph_new(re->scene, scene_view_layer, DAG_EVAL_RENDER); + BKE_scene_graph_update_for_newframe(depsgraph, re->main); + + // prepare Freestyle: + // - load mesh + // - add style modules + // - set parameters + // - compute view map + prepare(re, view_layer, depsgraph); + + if (re->test_break(re->tbh)) { + controller->CloseFile(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Break" << endl; + } + } + else { + // render and composite Freestyle result + if (controller->_ViewMap) { + // render strokes + re->i.infostr = IFACE_("Freestyle: Stroke rendering"); + re->stats_draw(re->sdh, &re->i); + re->i.infostr = NULL; + g_freestyle.scene = DEG_get_evaluated_scene(depsgraph); + int strokeCount = controller->DrawStrokes(); + if (strokeCount > 0) { + freestyle_render = controller->RenderStrokes(re, true); + } + controller->CloseFile(); + g_freestyle.scene = NULL; + + // composite result + if (freestyle_render) { + FRS_composite_result(re, view_layer, freestyle_render); + RE_FreeRenderResult(freestyle_render->result); + freestyle_render->result = NULL; + } + } + } + + DEG_graph_free(depsgraph); + + return freestyle_render; } void FRS_end_stroke_rendering(Render * /*re*/) { - // clear canvas - controller->Clear(); + // clear canvas + controller->Clear(); } void FRS_free_view_map_cache(void) { - // free cache - controller->DeleteViewMap(true); + // free cache + controller->DeleteViewMap(true); #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - printf("View map cache freed\n"); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("View map cache freed\n"); + } #endif } @@ -675,64 +684,64 @@ void FRS_free_view_map_cache(void) void FRS_copy_active_lineset(FreestyleConfig *config) { - FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - - if (lineset) { - lineset_buffer.linestyle = lineset->linestyle; - lineset_buffer.flags = lineset->flags; - lineset_buffer.selection = lineset->selection; - lineset_buffer.qi = lineset->qi; - lineset_buffer.qi_start = lineset->qi_start; - lineset_buffer.qi_end = lineset->qi_end; - lineset_buffer.edge_types = lineset->edge_types; - lineset_buffer.exclude_edge_types = lineset->exclude_edge_types; - lineset_buffer.group = lineset->group; - strcpy(lineset_buffer.name, lineset->name); - lineset_copied = true; - } + FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); + + if (lineset) { + lineset_buffer.linestyle = lineset->linestyle; + lineset_buffer.flags = lineset->flags; + lineset_buffer.selection = lineset->selection; + lineset_buffer.qi = lineset->qi; + lineset_buffer.qi_start = lineset->qi_start; + lineset_buffer.qi_end = lineset->qi_end; + lineset_buffer.edge_types = lineset->edge_types; + lineset_buffer.exclude_edge_types = lineset->exclude_edge_types; + lineset_buffer.group = lineset->group; + strcpy(lineset_buffer.name, lineset->name); + lineset_copied = true; + } } void FRS_paste_active_lineset(FreestyleConfig *config) { - if (!lineset_copied) - return; - - FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - - if (lineset) { - if (lineset->linestyle) - id_us_min(&lineset->linestyle->id); - lineset->linestyle = lineset_buffer.linestyle; - if (lineset->linestyle) - id_us_plus(&lineset->linestyle->id); - lineset->flags = lineset_buffer.flags; - lineset->selection = lineset_buffer.selection; - lineset->qi = lineset_buffer.qi; - lineset->qi_start = lineset_buffer.qi_start; - lineset->qi_end = lineset_buffer.qi_end; - lineset->edge_types = lineset_buffer.edge_types; - lineset->exclude_edge_types = lineset_buffer.exclude_edge_types; - if (lineset->group) { - id_us_min(&lineset->group->id); - lineset->group = NULL; - } - if (lineset_buffer.group) { - lineset->group = lineset_buffer.group; - id_us_plus(&lineset->group->id); - } - strcpy(lineset->name, lineset_buffer.name); - BKE_freestyle_lineset_unique_name(config, lineset); - lineset->flags |= FREESTYLE_LINESET_CURRENT; - } + if (!lineset_copied) + return; + + FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); + + if (lineset) { + if (lineset->linestyle) + id_us_min(&lineset->linestyle->id); + lineset->linestyle = lineset_buffer.linestyle; + if (lineset->linestyle) + id_us_plus(&lineset->linestyle->id); + lineset->flags = lineset_buffer.flags; + lineset->selection = lineset_buffer.selection; + lineset->qi = lineset_buffer.qi; + lineset->qi_start = lineset_buffer.qi_start; + lineset->qi_end = lineset_buffer.qi_end; + lineset->edge_types = lineset_buffer.edge_types; + lineset->exclude_edge_types = lineset_buffer.exclude_edge_types; + if (lineset->group) { + id_us_min(&lineset->group->id); + lineset->group = NULL; + } + if (lineset_buffer.group) { + lineset->group = lineset_buffer.group; + id_us_plus(&lineset->group->id); + } + strcpy(lineset->name, lineset_buffer.name); + BKE_freestyle_lineset_unique_name(config, lineset); + lineset->flags |= FREESTYLE_LINESET_CURRENT; + } } void FRS_delete_active_lineset(FreestyleConfig *config) { - FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); + FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - if (lineset) { - BKE_freestyle_lineset_delete(config, lineset); - } + if (lineset) { + BKE_freestyle_lineset_delete(config, lineset); + } } /** @@ -741,18 +750,18 @@ void FRS_delete_active_lineset(FreestyleConfig *config) */ bool FRS_move_active_lineset(FreestyleConfig *config, int direction) { - FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); - return (lineset != NULL) && BLI_listbase_link_move(&config->linesets, lineset, direction); + FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); + return (lineset != NULL) && BLI_listbase_link_move(&config->linesets, lineset, direction); } // Testing Material *FRS_create_stroke_material(Main *bmain, struct FreestyleLineStyle *linestyle) { - bNodeTree *nt = (linestyle->use_nodes) ? linestyle->nodetree : NULL; - Material *ma = BlenderStrokeRenderer::GetStrokeShader(bmain, nt, true); - ma->id.us = 0; - return ma; + bNodeTree *nt = (linestyle->use_nodes) ? linestyle->nodetree : NULL; + Material *ma = BlenderStrokeRenderer::GetStrokeShader(bmain, nt, true); + ma->id.us = 0; + return ma; } -} // extern "C" +} // extern "C" diff --git a/source/blender/freestyle/intern/geometry/BBox.h b/source/blender/freestyle/intern/geometry/BBox.h index 741d4e6715e..7350fabbc13 100644 --- a/source/blender/freestyle/intern/geometry/BBox.h +++ b/source/blender/freestyle/intern/geometry/BBox.h @@ -28,133 +28,127 @@ #include "BLI_utildefines.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -template -class BBox -{ -public: - inline BBox() - { - _empty = true; - } - - template - inline BBox(const T& min_in, const T& max_in) : _min(min_in), _max(max_in) - { - _empty = false; - } - - template - inline BBox(const BBox& b) : _min(b.getMin()), _max(b.getMax()) - { - _empty = false; - } - - template - inline void extendToContain(const T& p) - { - if (_empty) { - _min = p; - _max = p; - _empty = false; - return; - } - for (unsigned int i = 0; i < Point::dim(); i++) { - if (p[i] < _min[i]) - _min[i] = p[i]; - else if (p[i] > _max[i]) - _max[i] = p[i]; - } - _empty = false; - } - - inline void clear() - { - _empty = true; - } - - inline bool empty() const - { - return _empty; - } - - inline const Point& getMin() const - { - return _min; - } - - inline const Point& getMax() const - { - return _max; - } - - inline BBox& operator=(const BBox& b) - { - BLI_assert(!b.empty()); - _min = b.getMin(); - _max = b.getMax(); - _empty = false; - return *this; - } - - inline BBox& operator+=(const BBox& b) - { - BLI_assert(!b.empty()); - if (_empty) { - _min = b.getMin(); - _max = b.getMax(); - _empty = false; - } - else { - for (unsigned int i = 0; i < Point::dim(); i++) { - if (b.getMin()[i] < _min[i]) - _min[i] = b.getMin()[i]; - if (b.getMax()[i] > _max[i]) - _max[i] = b.getMax()[i]; - } - } - return *this; - } - - inline bool inside(const Point& p) - { - if (empty()) - return false; - for (unsigned int i = 0; i < Point::dim(); i++) { - if ((_min[i]>p[i]) || (_max[i] class BBox { + public: + inline BBox() + { + _empty = true; + } + + template inline BBox(const T &min_in, const T &max_in) : _min(min_in), _max(max_in) + { + _empty = false; + } + + template inline BBox(const BBox &b) : _min(b.getMin()), _max(b.getMax()) + { + _empty = false; + } + + template inline void extendToContain(const T &p) + { + if (_empty) { + _min = p; + _max = p; + _empty = false; + return; + } + for (unsigned int i = 0; i < Point::dim(); i++) { + if (p[i] < _min[i]) + _min[i] = p[i]; + else if (p[i] > _max[i]) + _max[i] = p[i]; + } + _empty = false; + } + + inline void clear() + { + _empty = true; + } + + inline bool empty() const + { + return _empty; + } + + inline const Point &getMin() const + { + return _min; + } + + inline const Point &getMax() const + { + return _max; + } + + inline BBox &operator=(const BBox &b) + { + BLI_assert(!b.empty()); + _min = b.getMin(); + _max = b.getMax(); + _empty = false; + return *this; + } + + inline BBox &operator+=(const BBox &b) + { + BLI_assert(!b.empty()); + if (_empty) { + _min = b.getMin(); + _max = b.getMax(); + _empty = false; + } + else { + for (unsigned int i = 0; i < Point::dim(); i++) { + if (b.getMin()[i] < _min[i]) + _min[i] = b.getMin()[i]; + if (b.getMax()[i] > _max[i]) + _max[i] = b.getMax()[i]; + } + } + return *this; + } + + inline bool inside(const Point &p) + { + if (empty()) + return false; + for (unsigned int i = 0; i < Point::dim(); i++) { + if ((_min[i] > p[i]) || (_max[i] < p[i])) + return false; + } + return true; + } + + private: + Point _min; + Point _max; + bool _empty; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BBox") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BBox") #endif }; -template -BBox& operator+(const BBox &b1, const BBox &b2) +template BBox &operator+(const BBox &b1, const BBox &b2) { - Point new_min; - Point new_max; + Point new_min; + Point new_max; - for (unsigned int i = 0; i < Point::dim(); i++) { - new_min[i] = b1.getMin()[i] < b2.getMin()[i] ? b1.getMin()[i] : b2.getMin()[i]; - new_max[i] = b1.getMax()[i] > b2.getMax()[i] ? b1.getMax()[i] : b2.getMax()[i]; - } + for (unsigned int i = 0; i < Point::dim(); i++) { + new_min[i] = b1.getMin()[i] < b2.getMin()[i] ? b1.getMin()[i] : b2.getMin()[i]; + new_max[i] = b1.getMax()[i] > b2.getMax()[i] ? b1.getMax()[i] : b2.getMax()[i]; + } - return BBox(new_min, new_max); + return BBox(new_min, new_max); } } /* namespace Freestyle */ -#endif // __BBOX_H__ +#endif // __BBOX_H__ diff --git a/source/blender/freestyle/intern/geometry/Bezier.cpp b/source/blender/freestyle/intern/geometry/Bezier.cpp index aeac71fca11..3f6b6b25f76 100644 --- a/source/blender/freestyle/intern/geometry/Bezier.cpp +++ b/source/blender/freestyle/intern/geometry/Bezier.cpp @@ -34,90 +34,90 @@ BezierCurveSegment::~BezierCurveSegment() { } -void BezierCurveSegment::AddControlPoint(const Vec2d& iPoint) +void BezierCurveSegment::AddControlPoint(const Vec2d &iPoint) { - _ControlPolygon.push_back(iPoint); - if (_ControlPolygon.size() == 4) - Build(); + _ControlPolygon.push_back(iPoint); + if (_ControlPolygon.size() == 4) + Build(); } void BezierCurveSegment::Build() { - if (_ControlPolygon.size() != 4) - return; - - // Compute the rightmost part of the matrix: - vector::const_iterator p0, p1, p2, p3; - p0 = _ControlPolygon.begin(); - p1 = p0; - ++p1; - p2 = p1; - ++p2; - p3 = p2; - ++p3; - float x[4], y[4]; - - x[0] = -p0->x() + 3 * p1->x() - 3 * p2->x() + p3->x(); - x[1] = 3 * p0->x() - 6 * p1->x() + 3 * p2->x(); - x[2] = -3 * p0->x() + 3 * p1->x(); - x[3] = p0->x(); - - y[0] = -p0->y() + 3 * p1->y() - 3 * p2->y() + p3->y(); - y[1] = 3 * p0->y() - 6 * p1->y() + 3 * p2->y(); - y[2] = -3 * p0->y() + 3 * p1->y(); - y[3] = p0->y(); - - int nvertices = 12; - float increment = 1.0 / (float)nvertices; - float t = 0.0f; - for (int i = 0; i <= nvertices; ++i) { - _Vertices.push_back(Vec2d((x[3] + t * (x[2] + t * (x[1] + t * x[0]))), - (y[3] + t * (y[2] + t * (y[1] + t * y[0]))))); - t += increment; - } + if (_ControlPolygon.size() != 4) + return; + + // Compute the rightmost part of the matrix: + vector::const_iterator p0, p1, p2, p3; + p0 = _ControlPolygon.begin(); + p1 = p0; + ++p1; + p2 = p1; + ++p2; + p3 = p2; + ++p3; + float x[4], y[4]; + + x[0] = -p0->x() + 3 * p1->x() - 3 * p2->x() + p3->x(); + x[1] = 3 * p0->x() - 6 * p1->x() + 3 * p2->x(); + x[2] = -3 * p0->x() + 3 * p1->x(); + x[3] = p0->x(); + + y[0] = -p0->y() + 3 * p1->y() - 3 * p2->y() + p3->y(); + y[1] = 3 * p0->y() - 6 * p1->y() + 3 * p2->y(); + y[2] = -3 * p0->y() + 3 * p1->y(); + y[3] = p0->y(); + + int nvertices = 12; + float increment = 1.0 / (float)nvertices; + float t = 0.0f; + for (int i = 0; i <= nvertices; ++i) { + _Vertices.push_back(Vec2d((x[3] + t * (x[2] + t * (x[1] + t * x[0]))), + (y[3] + t * (y[2] + t * (y[1] + t * y[0]))))); + t += increment; + } } BezierCurve::BezierCurve() { - _currentSegment = new BezierCurveSegment; + _currentSegment = new BezierCurveSegment; } -BezierCurve::BezierCurve(vector& iPoints, double error) +BezierCurve::BezierCurve(vector &iPoints, double error) { - FitCurveWrapper fitcurve; - _currentSegment = new BezierCurveSegment; - vector curve; - - fitcurve.FitCurve(iPoints, curve, error); - int i = 0; - vector::iterator v, vend; - for (v = curve.begin(), vend = curve.end(); v != vend; ++v) { - if ((i == 0) || (i % 4 != 0)) - AddControlPoint(*v); - ++i; - } + FitCurveWrapper fitcurve; + _currentSegment = new BezierCurveSegment; + vector curve; + + fitcurve.FitCurve(iPoints, curve, error); + int i = 0; + vector::iterator v, vend; + for (v = curve.begin(), vend = curve.end(); v != vend; ++v) { + if ((i == 0) || (i % 4 != 0)) + AddControlPoint(*v); + ++i; + } } BezierCurve::~BezierCurve() { - if (!_Segments.empty()) { - vector::iterator v, vend; - for (v = _Segments.begin(), vend = _Segments.end(); v != vend; ++v) - delete *v; - } - if (_currentSegment) - delete _currentSegment; + if (!_Segments.empty()) { + vector::iterator v, vend; + for (v = _Segments.begin(), vend = _Segments.end(); v != vend; ++v) + delete *v; + } + if (_currentSegment) + delete _currentSegment; } -void BezierCurve::AddControlPoint(const Vec2d& iPoint) +void BezierCurve::AddControlPoint(const Vec2d &iPoint) { - _ControlPolygon.push_back(iPoint); - _currentSegment->AddControlPoint(iPoint); - if (_currentSegment->size() == 4) { - _Segments.push_back(_currentSegment); - _currentSegment = new BezierCurveSegment; - _currentSegment->AddControlPoint(iPoint); - } + _ControlPolygon.push_back(iPoint); + _currentSegment->AddControlPoint(iPoint); + if (_currentSegment->size() == 4) { + _Segments.push_back(_currentSegment); + _currentSegment = new BezierCurveSegment; + _currentSegment->AddControlPoint(iPoint); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/Bezier.h b/source/blender/freestyle/intern/geometry/Bezier.h index babeb3e9e57..adcd6e3a652 100644 --- a/source/blender/freestyle/intern/geometry/Bezier.h +++ b/source/blender/freestyle/intern/geometry/Bezier.h @@ -29,70 +29,68 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { using namespace Geometry; -class BezierCurveSegment -{ -private: - std::vector _ControlPolygon; - std::vector _Vertices; +class BezierCurveSegment { + private: + std::vector _ControlPolygon; + std::vector _Vertices; -public: - BezierCurveSegment(); - virtual ~BezierCurveSegment(); + public: + BezierCurveSegment(); + virtual ~BezierCurveSegment(); - void AddControlPoint(const Vec2d& iPoint); - void Build(); + void AddControlPoint(const Vec2d &iPoint); + void Build(); - inline int size() const - { - return _ControlPolygon.size(); - } + inline int size() const + { + return _ControlPolygon.size(); + } - inline std::vector& vertices() - { - return _Vertices; - } + inline std::vector &vertices() + { + return _Vertices; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BezierCurveSegment") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BezierCurveSegment") #endif }; -class BezierCurve -{ -private: - std::vector _ControlPolygon; - std::vector _Segments; - BezierCurveSegment *_currentSegment; +class BezierCurve { + private: + std::vector _ControlPolygon; + std::vector _Segments; + BezierCurveSegment *_currentSegment; -public: - BezierCurve(); - BezierCurve(std::vector& iPoints, double error=4.0); - virtual ~BezierCurve(); + public: + BezierCurve(); + BezierCurve(std::vector &iPoints, double error = 4.0); + virtual ~BezierCurve(); - void AddControlPoint(const Vec2d& iPoint); + void AddControlPoint(const Vec2d &iPoint); - std::vector& controlPolygon() - { - return _ControlPolygon; - } + std::vector &controlPolygon() + { + return _ControlPolygon; + } - std::vector& segments() - { - return _Segments; - } + std::vector &segments() + { + return _Segments; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BezierCurve") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BezierCurve") #endif }; } /* namespace Freestyle */ -#endif // __BEZIER_H__ +#endif // __BEZIER_H__ diff --git a/source/blender/freestyle/intern/geometry/FastGrid.cpp b/source/blender/freestyle/intern/geometry/FastGrid.cpp index dec22e67acb..e0d36bece6e 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.cpp +++ b/source/blender/freestyle/intern/geometry/FastGrid.cpp @@ -30,52 +30,52 @@ namespace Freestyle { void FastGrid::clear() { - if (!_cells) - return; + if (!_cells) + return; - for (unsigned int i = 0; i < _cells_size; i++) { - if (_cells[i]) - delete _cells[i]; - } - delete[] _cells; - _cells = NULL; - _cells_size = 0; + for (unsigned int i = 0; i < _cells_size; i++) { + if (_cells[i]) + delete _cells[i]; + } + delete[] _cells; + _cells = NULL; + _cells_size = 0; - Grid::clear(); + Grid::clear(); } -void FastGrid::configure(const Vec3r& orig, const Vec3r& size, unsigned nb) +void FastGrid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) { - Grid::configure(orig, size, nb); - _cells_size = _cells_nb[0] * _cells_nb[1] * _cells_nb[2]; - _cells = new Cell *[_cells_size]; - memset(_cells, 0, _cells_size * sizeof(*_cells)); + Grid::configure(orig, size, nb); + _cells_size = _cells_nb[0] * _cells_nb[1] * _cells_nb[2]; + _cells = new Cell *[_cells_size]; + memset(_cells, 0, _cells_size * sizeof(*_cells)); } -Cell *FastGrid::getCell(const Vec3u& p) +Cell *FastGrid::getCell(const Vec3u &p) { #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cells << " " << p << " " << _cells_nb[0] << "-" << _cells_nb[1] << "-" << _cells_nb[2] - << " " << _cells_size << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cells << " " << p << " " << _cells_nb[0] << "-" << _cells_nb[1] << "-" << _cells_nb[2] + << " " << _cells_size << endl; + } #endif - BLI_assert(_cells || ("_cells is a null pointer")); - BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size); - BLI_assert(p[0] < _cells_nb[0]); - BLI_assert(p[1] < _cells_nb[1]); - BLI_assert(p[2] < _cells_nb[2]); - return _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]]; + BLI_assert(_cells || ("_cells is a null pointer")); + BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size); + BLI_assert(p[0] < _cells_nb[0]); + BLI_assert(p[1] < _cells_nb[1]); + BLI_assert(p[2] < _cells_nb[2]); + return _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]]; } -void FastGrid::fillCell(const Vec3u& p, Cell& cell) +void FastGrid::fillCell(const Vec3u &p, Cell &cell) { - BLI_assert(_cells || ("_cells is a null pointer")); - BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size); - BLI_assert(p[0] < _cells_nb[0]); - BLI_assert(p[1] < _cells_nb[1]); - BLI_assert(p[2] < _cells_nb[2]); - _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]] = &cell; + BLI_assert(_cells || ("_cells is a null pointer")); + BLI_assert((_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]) < _cells_size); + BLI_assert(p[0] < _cells_nb[0]); + BLI_assert(p[1] < _cells_nb[1]); + BLI_assert(p[2] < _cells_nb[2]); + _cells[_cells_nb[0] * (p[2] * _cells_nb[1] + p[1]) + p[0]] = &cell; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/FastGrid.h b/source/blender/freestyle/intern/geometry/FastGrid.h index 8c22703a68c..e2345d4831c 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.h +++ b/source/blender/freestyle/intern/geometry/FastGrid.h @@ -30,51 +30,49 @@ namespace Freestyle { * We don't use a hashtable here. The grid is explicitly stored for faster computations. * However, this might result in significant increase in memory usage (compared to the regular grid) */ -class FastGrid : public Grid -{ -public: - FastGrid() : Grid() - { - _cells = NULL; - _cells_size = 0; - } +class FastGrid : public Grid { + public: + FastGrid() : Grid() + { + _cells = NULL; + _cells_size = 0; + } - virtual ~FastGrid() - { - clear(); - } + virtual ~FastGrid() + { + clear(); + } - /*! clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. - */ - virtual void clear(); + /*! clears the grid + * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + */ + virtual void clear(); - /*! Sets the different parameters of the grid - * orig - * The grid origin - * size - * The grid's dimensions - * nb - * The number of cells of the grid - */ - virtual void configure(const Vec3r& orig, const Vec3r& size, unsigned nb); + /*! Sets the different parameters of the grid + * orig + * The grid origin + * size + * The grid's dimensions + * nb + * The number of cells of the grid + */ + virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb); - /*! returns the cell whose coordinates are pased as argument */ - Cell *getCell(const Vec3u& p); + /*! returns the cell whose coordinates are pased as argument */ + Cell *getCell(const Vec3u &p); - /*! Fills the case p with the cell iCell */ - virtual void fillCell(const Vec3u& p, Cell& cell); + /*! Fills the case p with the cell iCell */ + virtual void fillCell(const Vec3u &p, Cell &cell); -protected: - Cell **_cells; - unsigned _cells_size; + protected: + Cell **_cells; + unsigned _cells_size; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FastGrid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FastGrid") #endif - }; } /* namespace Freestyle */ -#endif // __FASTGRID_H__ +#endif // __FASTGRID_H__ diff --git a/source/blender/freestyle/intern/geometry/FitCurve.cpp b/source/blender/freestyle/intern/geometry/FitCurve.cpp index 9e12507b896..b0408826763 100644 --- a/source/blender/freestyle/intern/geometry/FitCurve.cpp +++ b/source/blender/freestyle/intern/geometry/FitCurve.cpp @@ -20,7 +20,7 @@ * \brief from "Graphics Gems", Academic Press, 1990 */ -#include // for malloc and free +#include // for malloc and free #include #include @@ -41,9 +41,11 @@ static double B1(double u); static double B2(double u); static double B3(double u); static Vector2 ComputeLeftTangent(Vector2 *d, int end); -static double ComputeMaxError(Vector2 *d, int first, int last, BezierCurve bezCurve, double *u, int *splitPoint); +static double ComputeMaxError( + Vector2 *d, int first, int last, BezierCurve bezCurve, double *u, int *splitPoint); static double *ChordLengthParameterize(Vector2 *d, int first, int last); -static BezierCurve GenerateBezier(Vector2 *d, int first, int last, double *uPrime, Vector2 tHat1, Vector2 tHat2); +static BezierCurve GenerateBezier( + Vector2 *d, int first, int last, double *uPrime, Vector2 tHat1, Vector2 tHat2); static Vector2 V2AddII(Vector2 a, Vector2 b); static Vector2 V2ScaleIII(Vector2 v, double s); static Vector2 V2SubII(Vector2 a, Vector2 b); @@ -51,64 +53,64 @@ static Vector2 V2SubII(Vector2 a, Vector2 b); /* returns squared length of input vector */ static double V2SquaredLength(Vector2 *a) { - return (((*a)[0] * (*a)[0]) + ((*a)[1] * (*a)[1])); + return (((*a)[0] * (*a)[0]) + ((*a)[1] * (*a)[1])); } /* returns length of input vector */ static double V2Length(Vector2 *a) { - return (sqrt(V2SquaredLength(a))); + return (sqrt(V2SquaredLength(a))); } static Vector2 *V2Scale(Vector2 *v, double newlen) { - double len = V2Length(v); - if (len != 0.0) { - (*v)[0] *= newlen / len; - (*v)[1] *= newlen / len; - } - return v; + double len = V2Length(v); + if (len != 0.0) { + (*v)[0] *= newlen / len; + (*v)[1] *= newlen / len; + } + return v; } /* return the dot product of vectors a and b */ static double V2Dot(Vector2 *a, Vector2 *b) { - return (((*a)[0] * (*b)[0]) + ((*a)[1] * (*b)[1])); + return (((*a)[0] * (*b)[0]) + ((*a)[1] * (*b)[1])); } /* return the distance between two points */ static double V2DistanceBetween2Points(Vector2 *a, Vector2 *b) { - double dx = (*a)[0] - (*b)[0]; - double dy = (*a)[1] - (*b)[1]; - return (sqrt((dx * dx) + (dy * dy))); + double dx = (*a)[0] - (*b)[0]; + double dy = (*a)[1] - (*b)[1]; + return (sqrt((dx * dx) + (dy * dy))); } /* return vector sum c = a+b */ static Vector2 *V2Add(Vector2 *a, Vector2 *b, Vector2 *c) { - (*c)[0] = (*a)[0] + (*b)[0]; - (*c)[1] = (*a)[1] + (*b)[1]; - return c; + (*c)[0] = (*a)[0] + (*b)[0]; + (*c)[1] = (*a)[1] + (*b)[1]; + return c; } /* normalizes the input vector and returns it */ static Vector2 *V2Normalize(Vector2 *v) { - double len = V2Length(v); - if (len != 0.0) { - (*v)[0] /= len; - (*v)[1] /= len; - } - return v; + double len = V2Length(v); + if (len != 0.0) { + (*v)[0] /= len; + (*v)[1] /= len; + } + return v; } /* negates the input vector and returns it */ static Vector2 *V2Negate(Vector2 *v) { - (*v)[0] = -(*v)[0]; - (*v)[1] = -(*v)[1]; - return v; + (*v)[0] = -(*v)[0]; + (*v)[1] = -(*v)[1]; + return v; } /* GenerateBezier: @@ -118,92 +120,88 @@ static Vector2 *V2Negate(Vector2 *v) * double *uPrime; Parameter values for region * Vector2 tHat1, tHat2; Unit tangents at endpoints */ -static BezierCurve GenerateBezier(Vector2 *d, int first, int last, double *uPrime, Vector2 tHat1, Vector2 tHat2) +static BezierCurve GenerateBezier( + Vector2 *d, int first, int last, double *uPrime, Vector2 tHat1, Vector2 tHat2) { - int i; - Vector2 A[2]; /* rhs for eqn */ - int nPts; /* Number of pts in sub-curve */ - double C[2][2]; /* Matrix C */ - double X[2]; /* Matrix X */ - double det_C0_C1; /* Determinants of matrices */ - double det_C0_X; - double det_X_C1; - double alpha_l; /* Alpha values, left and right */ - double alpha_r; - Vector2 tmp; /* Utility variable */ - BezierCurve bezCurve; /* RETURN bezier curve ctl pts */ - - bezCurve = (Vector2 *)malloc(4 * sizeof(Vector2)); - nPts = last - first + 1; - - /* Create the C and X matrices */ - C[0][0] = 0.0; - C[0][1] = 0.0; - C[1][0] = 0.0; - C[1][1] = 0.0; - X[0] = 0.0; - X[1] = 0.0; - for (i = 0; i < nPts; i++) { - /* Compute the A's */ - A[0] = tHat1; - A[1] = tHat2; - V2Scale(&A[0], B1(uPrime[i])); - V2Scale(&A[1], B2(uPrime[i])); - - C[0][0] += V2Dot(&A[0], &A[0]); - C[0][1] += V2Dot(&A[0], &A[1]); -// C[1][0] += V2Dot(&A[0], &A[1]); - C[1][0] = C[0][1]; - C[1][1] += V2Dot(&A[1], &A[1]); - - tmp = V2SubII(d[first + i], - V2AddII(V2ScaleIII(d[first], B0(uPrime[i])), - V2AddII(V2ScaleIII(d[first], B1(uPrime[i])), - V2AddII(V2ScaleIII(d[last], B2(uPrime[i])), - V2ScaleIII(d[last], B3(uPrime[i])) - ) - ) - ) - ); - - X[0] += V2Dot(&A[0], &tmp); - X[1] += V2Dot(&A[1], &tmp); - } - - /* Compute the determinants of C and X */ - det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1]; - det_C0_X = C[0][0] * X[1] - C[0][1] * X[0]; - det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1]; - - /* Finally, derive alpha values */ - if (det_C0_C1 == 0.0) { - det_C0_C1 = (C[0][0] * C[1][1]) * 10.0e-12; - } - alpha_l = det_X_C1 / det_C0_C1; - alpha_r = det_C0_X / det_C0_C1; - - - /* If alpha negative, use the Wu/Barsky heuristic (see text) (if alpha is 0, you get coincident control points - * that lead to divide by zero in any subsequent NewtonRaphsonRootFind() call). - */ - if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) { - double dist = V2DistanceBetween2Points(&d[last], &d[first]) / 3.0; - - bezCurve[0] = d[first]; - bezCurve[3] = d[last]; - V2Add(&(bezCurve[0]), V2Scale(&(tHat1), dist), &(bezCurve[1])); - V2Add(&(bezCurve[3]), V2Scale(&(tHat2), dist), &(bezCurve[2])); - return bezCurve; - } - - /* First and last control points of the Bezier curve are positioned exactly at the first and last data points - * Control points 1 and 2 are positioned an alpha distance out on the tangent vectors, left and right, respectively - */ - bezCurve[0] = d[first]; - bezCurve[3] = d[last]; - V2Add(&bezCurve[0], V2Scale(&tHat1, alpha_l), &bezCurve[1]); - V2Add(&bezCurve[3], V2Scale(&tHat2, alpha_r), &bezCurve[2]); - return (bezCurve); + int i; + Vector2 A[2]; /* rhs for eqn */ + int nPts; /* Number of pts in sub-curve */ + double C[2][2]; /* Matrix C */ + double X[2]; /* Matrix X */ + double det_C0_C1; /* Determinants of matrices */ + double det_C0_X; + double det_X_C1; + double alpha_l; /* Alpha values, left and right */ + double alpha_r; + Vector2 tmp; /* Utility variable */ + BezierCurve bezCurve; /* RETURN bezier curve ctl pts */ + + bezCurve = (Vector2 *)malloc(4 * sizeof(Vector2)); + nPts = last - first + 1; + + /* Create the C and X matrices */ + C[0][0] = 0.0; + C[0][1] = 0.0; + C[1][0] = 0.0; + C[1][1] = 0.0; + X[0] = 0.0; + X[1] = 0.0; + for (i = 0; i < nPts; i++) { + /* Compute the A's */ + A[0] = tHat1; + A[1] = tHat2; + V2Scale(&A[0], B1(uPrime[i])); + V2Scale(&A[1], B2(uPrime[i])); + + C[0][0] += V2Dot(&A[0], &A[0]); + C[0][1] += V2Dot(&A[0], &A[1]); + // C[1][0] += V2Dot(&A[0], &A[1]); + C[1][0] = C[0][1]; + C[1][1] += V2Dot(&A[1], &A[1]); + + tmp = V2SubII(d[first + i], + V2AddII(V2ScaleIII(d[first], B0(uPrime[i])), + V2AddII(V2ScaleIII(d[first], B1(uPrime[i])), + V2AddII(V2ScaleIII(d[last], B2(uPrime[i])), + V2ScaleIII(d[last], B3(uPrime[i])))))); + + X[0] += V2Dot(&A[0], &tmp); + X[1] += V2Dot(&A[1], &tmp); + } + + /* Compute the determinants of C and X */ + det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1]; + det_C0_X = C[0][0] * X[1] - C[0][1] * X[0]; + det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1]; + + /* Finally, derive alpha values */ + if (det_C0_C1 == 0.0) { + det_C0_C1 = (C[0][0] * C[1][1]) * 10.0e-12; + } + alpha_l = det_X_C1 / det_C0_C1; + alpha_r = det_C0_X / det_C0_C1; + + /* If alpha negative, use the Wu/Barsky heuristic (see text) (if alpha is 0, you get coincident control points + * that lead to divide by zero in any subsequent NewtonRaphsonRootFind() call). + */ + if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) { + double dist = V2DistanceBetween2Points(&d[last], &d[first]) / 3.0; + + bezCurve[0] = d[first]; + bezCurve[3] = d[last]; + V2Add(&(bezCurve[0]), V2Scale(&(tHat1), dist), &(bezCurve[1])); + V2Add(&(bezCurve[3]), V2Scale(&(tHat2), dist), &(bezCurve[2])); + return bezCurve; + } + + /* First and last control points of the Bezier curve are positioned exactly at the first and last data points + * Control points 1 and 2 are positioned an alpha distance out on the tangent vectors, left and right, respectively + */ + bezCurve[0] = d[first]; + bezCurve[3] = d[last]; + V2Add(&bezCurve[0], V2Scale(&tHat1, alpha_l), &bezCurve[1]); + V2Add(&bezCurve[3], V2Scale(&tHat2, alpha_r), &bezCurve[2]); + return (bezCurve); } /* @@ -216,15 +214,15 @@ static BezierCurve GenerateBezier(Vector2 *d, int first, int last, double *uPri */ static double *Reparameterize(Vector2 *d, int first, int last, double *u, BezierCurve bezCurve) { - int nPts = last - first + 1; - int i; - double *uPrime; /* New parameter values */ - - uPrime = (double *)malloc(nPts * sizeof(double)); - for (i = first; i <= last; i++) { - uPrime[i - first] = NewtonRaphsonRootFind(bezCurve, d[i], u[i - first]); - } - return (uPrime); + int nPts = last - first + 1; + int i; + double *uPrime; /* New parameter values */ + + uPrime = (double *)malloc(nPts * sizeof(double)); + for (i = first; i <= last; i++) { + uPrime[i - first] = NewtonRaphsonRootFind(bezCurve, d[i], u[i - first]); + } + return (uPrime); } /* @@ -236,41 +234,41 @@ static double *Reparameterize(Vector2 *d, int first, int last, double *u, Bezier */ static double NewtonRaphsonRootFind(BezierCurve Q, Vector2 P, double u) { - double numerator, denominator; - Vector2 Q1[3], Q2[2]; /* Q' and Q'' */ - Vector2 Q_u, Q1_u, Q2_u; /* u evaluated at Q, Q', & Q'' */ - double uPrime; /* Improved u */ - int i; - - /* Compute Q(u) */ - Q_u = BezierII(3, Q, u); - - /* Generate control vertices for Q' */ - for (i = 0; i <= 2; i++) { - Q1[i][0] = (Q[i + 1][0] - Q[i][0]) * 3.0; - Q1[i][1] = (Q[i + 1][1] - Q[i][1]) * 3.0; - } - - /* Generate control vertices for Q'' */ - for (i = 0; i <= 1; i++) { - Q2[i][0] = (Q1[i + 1][0] - Q1[i][0]) * 2.0; - Q2[i][1] = (Q1[i + 1][1] - Q1[i][1]) * 2.0; - } - - /* Compute Q'(u) and Q''(u) */ - Q1_u = BezierII(2, Q1, u); - Q2_u = BezierII(1, Q2, u); - - /* Compute f(u)/f'(u) */ - numerator = (Q_u[0] - P[0]) * (Q1_u[0]) + (Q_u[1] - P[1]) * (Q1_u[1]); - denominator = (Q1_u[0]) * (Q1_u[0]) + (Q1_u[1]) * (Q1_u[1]) + - (Q_u[0] - P[0]) * (Q2_u[0]) + (Q_u[1] - P[1]) * (Q2_u[1]); - - /* u = u - f(u)/f'(u) */ - if (denominator == 0) // FIXME - return u; - uPrime = u - (numerator / denominator); - return uPrime; + double numerator, denominator; + Vector2 Q1[3], Q2[2]; /* Q' and Q'' */ + Vector2 Q_u, Q1_u, Q2_u; /* u evaluated at Q, Q', & Q'' */ + double uPrime; /* Improved u */ + int i; + + /* Compute Q(u) */ + Q_u = BezierII(3, Q, u); + + /* Generate control vertices for Q' */ + for (i = 0; i <= 2; i++) { + Q1[i][0] = (Q[i + 1][0] - Q[i][0]) * 3.0; + Q1[i][1] = (Q[i + 1][1] - Q[i][1]) * 3.0; + } + + /* Generate control vertices for Q'' */ + for (i = 0; i <= 1; i++) { + Q2[i][0] = (Q1[i + 1][0] - Q1[i][0]) * 2.0; + Q2[i][1] = (Q1[i + 1][1] - Q1[i][1]) * 2.0; + } + + /* Compute Q'(u) and Q''(u) */ + Q1_u = BezierII(2, Q1, u); + Q2_u = BezierII(1, Q2, u); + + /* Compute f(u)/f'(u) */ + numerator = (Q_u[0] - P[0]) * (Q1_u[0]) + (Q_u[1] - P[1]) * (Q1_u[1]); + denominator = (Q1_u[0]) * (Q1_u[0]) + (Q1_u[1]) * (Q1_u[1]) + (Q_u[0] - P[0]) * (Q2_u[0]) + + (Q_u[1] - P[1]) * (Q2_u[1]); + + /* u = u - f(u)/f'(u) */ + if (denominator == 0) // FIXME + return u; + uPrime = u - (numerator / denominator); + return uPrime; } /* @@ -282,27 +280,27 @@ static double NewtonRaphsonRootFind(BezierCurve Q, Vector2 P, double u) */ static Vector2 BezierII(int degree, Vector2 *V, double t) { - int i, j; - Vector2 Q; /* Point on curve at parameter t */ - Vector2 *Vtemp; /* Local copy of control points */ - - /* Copy array */ - Vtemp = (Vector2 *)malloc((unsigned)((degree + 1) * sizeof(Vector2))); - for (i = 0; i <= degree; i++) { - Vtemp[i] = V[i]; - } - - /* Triangle computation */ - for (i = 1; i <= degree; i++) { - for (j = 0; j <= degree - i; j++) { - Vtemp[j][0] = (1.0 - t) * Vtemp[j][0] + t * Vtemp[j + 1][0]; - Vtemp[j][1] = (1.0 - t) * Vtemp[j][1] + t * Vtemp[j + 1][1]; - } - } - - Q = Vtemp[0]; - free((void *)Vtemp); - return Q; + int i, j; + Vector2 Q; /* Point on curve at parameter t */ + Vector2 *Vtemp; /* Local copy of control points */ + + /* Copy array */ + Vtemp = (Vector2 *)malloc((unsigned)((degree + 1) * sizeof(Vector2))); + for (i = 0; i <= degree; i++) { + Vtemp[i] = V[i]; + } + + /* Triangle computation */ + for (i = 1; i <= degree; i++) { + for (j = 0; j <= degree - i; j++) { + Vtemp[j][0] = (1.0 - t) * Vtemp[j][0] + t * Vtemp[j + 1][0]; + Vtemp[j][1] = (1.0 - t) * Vtemp[j][1] + t * Vtemp[j + 1][1]; + } + } + + Q = Vtemp[0]; + free((void *)Vtemp); + return Q; } /* @@ -311,25 +309,25 @@ static Vector2 BezierII(int degree, Vector2 *V, double t) */ static double B0(double u) { - double tmp = 1.0 - u; - return (tmp * tmp * tmp); + double tmp = 1.0 - u; + return (tmp * tmp * tmp); } static double B1(double u) { - double tmp = 1.0 - u; - return (3 * u * (tmp * tmp)); + double tmp = 1.0 - u; + return (3 * u * (tmp * tmp)); } static double B2(double u) { - double tmp = 1.0 - u; - return (3 * u * u * tmp); + double tmp = 1.0 - u; + return (3 * u * u * tmp); } static double B3(double u) { - return (u * u * u); + return (u * u * u); } /* @@ -341,10 +339,10 @@ static double B3(double u) */ static Vector2 ComputeLeftTangent(Vector2 *d, int end) { - Vector2 tHat1; - tHat1 = V2SubII(d[end + 1], d[end]); - tHat1 = *V2Normalize(&tHat1); - return tHat1; + Vector2 tHat1; + tHat1 = V2SubII(d[end + 1], d[end]); + tHat1 = *V2Normalize(&tHat1); + return tHat1; } /* Vector2 *d; Digitized points @@ -352,10 +350,10 @@ static Vector2 ComputeLeftTangent(Vector2 *d, int end) */ static Vector2 ComputeRightTangent(Vector2 *d, int end) { - Vector2 tHat2; - tHat2 = V2SubII(d[end - 1], d[end]); - tHat2 = *V2Normalize(&tHat2); - return tHat2; + Vector2 tHat2; + tHat2 = V2SubII(d[end - 1], d[end]); + tHat2 = *V2Normalize(&tHat2); + return tHat2; } /* Vector2 *d; Digitized points @@ -363,20 +361,20 @@ static Vector2 ComputeRightTangent(Vector2 *d, int end) */ static Vector2 ComputeCenterTangent(Vector2 *d, int center) { - Vector2 V1, V2, tHatCenter; + Vector2 V1, V2, tHatCenter; - V1 = V2SubII(d[center - 1], d[center]); - V2 = V2SubII(d[center], d[center + 1]); - tHatCenter[0] = (V1[0] + V2[0]) / 2.0; - tHatCenter[1] = (V1[1] + V2[1]) / 2.0; - tHatCenter = *V2Normalize(&tHatCenter); + V1 = V2SubII(d[center - 1], d[center]); + V2 = V2SubII(d[center], d[center + 1]); + tHatCenter[0] = (V1[0] + V2[0]) / 2.0; + tHatCenter[1] = (V1[1] + V2[1]) / 2.0; + tHatCenter = *V2Normalize(&tHatCenter); - /* avoid numerical singularity in the special case when V1 == -V2 */ - if (V2Length(&tHatCenter) < M_EPSILON) { - tHatCenter = *V2Normalize(&V1); - } + /* avoid numerical singularity in the special case when V1 == -V2 */ + if (V2Length(&tHatCenter) < M_EPSILON) { + tHatCenter = *V2Normalize(&V1); + } - return tHatCenter; + return tHatCenter; } /* @@ -387,21 +385,21 @@ static Vector2 ComputeCenterTangent(Vector2 *d, int center) */ static double *ChordLengthParameterize(Vector2 *d, int first, int last) { - int i; - double *u; /* Parameterization */ + int i; + double *u; /* Parameterization */ - u = (double *)malloc((unsigned)(last - first + 1) * sizeof(double)); + u = (double *)malloc((unsigned)(last - first + 1) * sizeof(double)); - u[0] = 0.0; - for (i = first + 1; i <= last; i++) { - u[i - first] = u[i - first - 1] + V2DistanceBetween2Points(&d[i], &d[i - 1]); - } + u[0] = 0.0; + for (i = first + 1; i <= last; i++) { + u[i - first] = u[i - first - 1] + V2DistanceBetween2Points(&d[i], &d[i - 1]); + } - for (i = first + 1; i <= last; i++) { - u[i - first] = u[i - first] / u[last - first]; - } + for (i = first + 1; i <= last; i++) { + u[i - first] = u[i - first] / u[last - first]; + } - return u; + return u; } /* @@ -413,50 +411,51 @@ static double *ChordLengthParameterize(Vector2 *d, int first, int last) * double *u; Parameterization of points * int *splitPoint; Point of maximum error */ -static double ComputeMaxError(Vector2 *d, int first, int last, BezierCurve bezCurve, double *u, int *splitPoint) +static double ComputeMaxError( + Vector2 *d, int first, int last, BezierCurve bezCurve, double *u, int *splitPoint) { - int i; - double maxDist; /* Maximum error */ - double dist; /* Current error */ - Vector2 P; /* Point on curve */ - Vector2 v; /* Vector from point to curve */ - - *splitPoint = (last - first + 1) / 2; - maxDist = 0.0; - for (i = first + 1; i < last; i++) { - P = BezierII(3, bezCurve, u[i - first]); - v = V2SubII(P, d[i]); - dist = V2SquaredLength(&v); - if (dist >= maxDist) { - maxDist = dist; - *splitPoint = i; - } - } - return maxDist; + int i; + double maxDist; /* Maximum error */ + double dist; /* Current error */ + Vector2 P; /* Point on curve */ + Vector2 v; /* Vector from point to curve */ + + *splitPoint = (last - first + 1) / 2; + maxDist = 0.0; + for (i = first + 1; i < last; i++) { + P = BezierII(3, bezCurve, u[i - first]); + v = V2SubII(P, d[i]); + dist = V2SquaredLength(&v); + if (dist >= maxDist) { + maxDist = dist; + *splitPoint = i; + } + } + return maxDist; } static Vector2 V2AddII(Vector2 a, Vector2 b) { - Vector2 c; - c[0] = a[0] + b[0]; - c[1] = a[1] + b[1]; - return c; + Vector2 c; + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + return c; } static Vector2 V2ScaleIII(Vector2 v, double s) { - Vector2 result; - result[0] = v[0] * s; - result[1] = v[1] * s; - return result; + Vector2 result; + result[0] = v[0] * s; + result[1] = v[1] * s; + return result; } static Vector2 V2SubII(Vector2 a, Vector2 b) { - Vector2 c; - c[0] = a[0] - b[0]; - c[1] = a[1] - b[1]; - return c; + Vector2 c; + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + return c; } //------------------------- WRAPPER -----------------------------// @@ -467,114 +466,115 @@ FitCurveWrapper::FitCurveWrapper() FitCurveWrapper::~FitCurveWrapper() { - _vertices.clear(); + _vertices.clear(); } void FitCurveWrapper::DrawBezierCurve(int n, Vector2 *curve) { - for (int i = 0; i <= n; ++i) - _vertices.push_back(curve[i]); + for (int i = 0; i <= n; ++i) + _vertices.push_back(curve[i]); } -void FitCurveWrapper::FitCurve(vector& data, vector& oCurve, double error) +void FitCurveWrapper::FitCurve(vector &data, vector &oCurve, double error) { - int size = data.size(); - Vector2 *d = new Vector2[size]; - for (int i = 0; i < size; ++i) { - d[i][0] = data[i][0]; - d[i][1] = data[i][1]; - } + int size = data.size(); + Vector2 *d = new Vector2[size]; + for (int i = 0; i < size; ++i) { + d[i][0] = data[i][0]; + d[i][1] = data[i][1]; + } - FitCurve(d, size, error); + FitCurve(d, size, error); - delete[] d; + delete[] d; - // copy results - for (vector::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; ++v) { - oCurve.push_back(Vec2d(v->x(), v->y())) ; - } + // copy results + for (vector::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; ++v) { + oCurve.push_back(Vec2d(v->x(), v->y())); + } } void FitCurveWrapper::FitCurve(Vector2 *d, int nPts, double error) { - Vector2 tHat1, tHat2; /* Unit tangent vectors at endpoints */ + Vector2 tHat1, tHat2; /* Unit tangent vectors at endpoints */ - tHat1 = ComputeLeftTangent(d, 0); - tHat2 = ComputeRightTangent(d, nPts - 1); - FitCubic(d, 0, nPts - 1, tHat1, tHat2, error); + tHat1 = ComputeLeftTangent(d, 0); + tHat2 = ComputeRightTangent(d, nPts - 1); + FitCubic(d, 0, nPts - 1, tHat1, tHat2, error); } -void FitCurveWrapper::FitCubic(Vector2 *d, int first, int last, Vector2 tHat1, Vector2 tHat2, double error) +void FitCurveWrapper::FitCubic( + Vector2 *d, int first, int last, Vector2 tHat1, Vector2 tHat2, double error) { - BezierCurve bezCurve; /* Control points of fitted Bezier curve */ - double *u; /* Parameter values for point */ - double *uPrime; /* Improved parameter values */ - double maxError; /* Maximum fitting error */ - int splitPoint; /* Point to split point set at */ - int nPts; /* Number of points in subset */ - double iterationError; /* Error below which you try iterating */ - int maxIterations = 4; /* Max times to try iterating */ - Vector2 tHatCenter; /* Unit tangent vector at splitPoint */ - int i; - - iterationError = error * error; - nPts = last - first + 1; - - /* Use heuristic if region only has two points in it */ - if (nPts == 2) { - double dist = V2DistanceBetween2Points(&d[last], &d[first]) / 3.0; - - bezCurve = (Vector2 *)malloc(4 * sizeof(Vector2)); - bezCurve[0] = d[first]; - bezCurve[3] = d[last]; - V2Add(&bezCurve[0], V2Scale(&tHat1, dist), &bezCurve[1]); - V2Add(&bezCurve[3], V2Scale(&tHat2, dist), &bezCurve[2]); - DrawBezierCurve(3, bezCurve); - free((void *)bezCurve); - return; - } - - /* Parameterize points, and attempt to fit curve */ - u = ChordLengthParameterize(d, first, last); - bezCurve = GenerateBezier(d, first, last, u, tHat1, tHat2); - - /* Find max deviation of points to fitted curve */ - maxError = ComputeMaxError(d, first, last, bezCurve, u, &splitPoint); - if (maxError < error) { - DrawBezierCurve(3, bezCurve); - free((void *)u); - free((void *)bezCurve); - return; - } - - /* If error not too large, try some reparameterization and iteration */ - if (maxError < iterationError) { - for (i = 0; i < maxIterations; i++) { - uPrime = Reparameterize(d, first, last, u, bezCurve); - - free((void *)u); - free((void *)bezCurve); - u = uPrime; - - bezCurve = GenerateBezier(d, first, last, u, tHat1, tHat2); - maxError = ComputeMaxError(d, first, last, bezCurve, u, &splitPoint); - - if (maxError < error) { - DrawBezierCurve(3, bezCurve); - free((void *)u); - free((void *)bezCurve); - return; - } - } - } - - /* Fitting failed -- split at max error point and fit recursively */ - free((void *)u); - free((void *)bezCurve); - tHatCenter = ComputeCenterTangent(d, splitPoint); - FitCubic(d, first, splitPoint, tHat1, tHatCenter, error); - V2Negate(&tHatCenter); - FitCubic(d, splitPoint, last, tHatCenter, tHat2, error); + BezierCurve bezCurve; /* Control points of fitted Bezier curve */ + double *u; /* Parameter values for point */ + double *uPrime; /* Improved parameter values */ + double maxError; /* Maximum fitting error */ + int splitPoint; /* Point to split point set at */ + int nPts; /* Number of points in subset */ + double iterationError; /* Error below which you try iterating */ + int maxIterations = 4; /* Max times to try iterating */ + Vector2 tHatCenter; /* Unit tangent vector at splitPoint */ + int i; + + iterationError = error * error; + nPts = last - first + 1; + + /* Use heuristic if region only has two points in it */ + if (nPts == 2) { + double dist = V2DistanceBetween2Points(&d[last], &d[first]) / 3.0; + + bezCurve = (Vector2 *)malloc(4 * sizeof(Vector2)); + bezCurve[0] = d[first]; + bezCurve[3] = d[last]; + V2Add(&bezCurve[0], V2Scale(&tHat1, dist), &bezCurve[1]); + V2Add(&bezCurve[3], V2Scale(&tHat2, dist), &bezCurve[2]); + DrawBezierCurve(3, bezCurve); + free((void *)bezCurve); + return; + } + + /* Parameterize points, and attempt to fit curve */ + u = ChordLengthParameterize(d, first, last); + bezCurve = GenerateBezier(d, first, last, u, tHat1, tHat2); + + /* Find max deviation of points to fitted curve */ + maxError = ComputeMaxError(d, first, last, bezCurve, u, &splitPoint); + if (maxError < error) { + DrawBezierCurve(3, bezCurve); + free((void *)u); + free((void *)bezCurve); + return; + } + + /* If error not too large, try some reparameterization and iteration */ + if (maxError < iterationError) { + for (i = 0; i < maxIterations; i++) { + uPrime = Reparameterize(d, first, last, u, bezCurve); + + free((void *)u); + free((void *)bezCurve); + u = uPrime; + + bezCurve = GenerateBezier(d, first, last, u, tHat1, tHat2); + maxError = ComputeMaxError(d, first, last, bezCurve, u, &splitPoint); + + if (maxError < error) { + DrawBezierCurve(3, bezCurve); + free((void *)u); + free((void *)bezCurve); + return; + } + } + } + + /* Fitting failed -- split at max error point and fit recursively */ + free((void *)u); + free((void *)bezCurve); + tHatCenter = ComputeCenterTangent(d, splitPoint); + FitCubic(d, first, splitPoint, tHat1, tHatCenter, error); + V2Negate(&tHatCenter); + FitCubic(d, splitPoint, last, tHatCenter, tHat2, error); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/FitCurve.h b/source/blender/freestyle/intern/geometry/FitCurve.h index f32549ed526..92afd685d8f 100644 --- a/source/blender/freestyle/intern/geometry/FitCurve.h +++ b/source/blender/freestyle/intern/geometry/FitCurve.h @@ -34,83 +34,80 @@ namespace Freestyle { using namespace Geometry; /* 2d point */ -typedef struct Point2Struct -{ - double coordinates[2]; - - Point2Struct() - { - coordinates[0] = 0; - coordinates[1] = 0; - } - - inline double operator[](const int i) const - { - return coordinates[i]; - } - - inline double& operator[](const int i) - { - return coordinates[i]; - } - - inline double x() const - { - return coordinates[0]; - } - - inline double y() const - { - return coordinates[1]; - } +typedef struct Point2Struct { + double coordinates[2]; + + Point2Struct() + { + coordinates[0] = 0; + coordinates[1] = 0; + } + + inline double operator[](const int i) const + { + return coordinates[i]; + } + + inline double &operator[](const int i) + { + return coordinates[i]; + } + + inline double x() const + { + return coordinates[0]; + } + + inline double y() const + { + return coordinates[1]; + } } Point2; typedef Point2 Vector2; - -class FitCurveWrapper -{ -private: - std::vector _vertices; - -public: - FitCurveWrapper(); - ~FitCurveWrapper(); - - /*! Fits a set of 2D data points to a set of Bezier Curve segments - * data - * Input data points - * oCurve - * Control points of the sets of bezier curve segments. - * Each segment is made of 4 points (polynomial degree of curve = 3) - * error - * max error tolerance between resulting curve and input data - */ - void FitCurve(std::vector& data, std::vector& oCurve, double error); - -protected: - /* Vec2d *d; Array of digitized points - * int nPts; Number of digitized points - * double error; User-defined error squared - */ - void FitCurve(Vector2 *d, int nPts, double error); - - /*! Draws a Bezier curve segment - * n - * degree of curve (=3) - * curve - * bezier segments control points - */ - void DrawBezierCurve(int n, Vector2 *curve); - - /* Vec2d *d; Array of digitized points - * int first, last; Indices of first and last pts in region - * Vec2d tHat1, tHat2; Unit tangent vectors at endpoints - * double error; User-defined error squared - */ - void FitCubic(Vector2 *d, int first, int last, Vector2 tHat1, Vector2 tHat2, double error); +class FitCurveWrapper { + private: + std::vector _vertices; + + public: + FitCurveWrapper(); + ~FitCurveWrapper(); + + /*! Fits a set of 2D data points to a set of Bezier Curve segments + * data + * Input data points + * oCurve + * Control points of the sets of bezier curve segments. + * Each segment is made of 4 points (polynomial degree of curve = 3) + * error + * max error tolerance between resulting curve and input data + */ + void FitCurve(std::vector &data, std::vector &oCurve, double error); + + protected: + /* Vec2d *d; Array of digitized points + * int nPts; Number of digitized points + * double error; User-defined error squared + */ + void FitCurve(Vector2 *d, int nPts, double error); + + /*! Draws a Bezier curve segment + * n + * degree of curve (=3) + * curve + * bezier segments control points + */ + void DrawBezierCurve(int n, Vector2 *curve); + + /* Vec2d *d; Array of digitized points + * int first, last; Indices of first and last pts in region + * Vec2d tHat1, tHat2; Unit tangent vectors at endpoints + * double error; User-defined error squared + */ + void FitCubic(Vector2 *d, int first, int last, Vector2 tHat1, Vector2 tHat2, double error); }; } /* namespace Freestyle */ -#endif // __FITCURVE_H__ +#endif // __FITCURVE_H__ diff --git a/source/blender/freestyle/intern/geometry/Geom.h b/source/blender/freestyle/intern/geometry/Geom.h index ecd07f88835..63785d56cab 100644 --- a/source/blender/freestyle/intern/geometry/Geom.h +++ b/source/blender/freestyle/intern/geometry/Geom.h @@ -30,44 +30,44 @@ namespace Freestyle { namespace Geometry { -typedef VecMat::Vec2 Vec2u; -typedef VecMat::Vec2 Vec2i; -typedef VecMat::Vec2 Vec2f; -typedef VecMat::Vec2 Vec2d; -typedef VecMat::Vec2 Vec2r; +typedef VecMat::Vec2 Vec2u; +typedef VecMat::Vec2 Vec2i; +typedef VecMat::Vec2 Vec2f; +typedef VecMat::Vec2 Vec2d; +typedef VecMat::Vec2 Vec2r; -typedef VecMat::Vec3 Vec3u; -typedef VecMat::Vec3 Vec3i; -typedef VecMat::Vec3 Vec3f; -typedef VecMat::Vec3 Vec3d; -typedef VecMat::Vec3 Vec3r; +typedef VecMat::Vec3 Vec3u; +typedef VecMat::Vec3 Vec3i; +typedef VecMat::Vec3 Vec3f; +typedef VecMat::Vec3 Vec3d; +typedef VecMat::Vec3 Vec3r; typedef VecMat::HVec3 HVec3u; -typedef VecMat::HVec3 HVec3i; -typedef VecMat::HVec3 HVec3f; -typedef VecMat::HVec3 HVec3d; -typedef VecMat::HVec3 HVec3r; +typedef VecMat::HVec3 HVec3i; +typedef VecMat::HVec3 HVec3f; +typedef VecMat::HVec3 HVec3d; +typedef VecMat::HVec3 HVec3r; -typedef VecMat::SquareMatrix Matrix22u; -typedef VecMat::SquareMatrix Matrix22i; -typedef VecMat::SquareMatrix Matrix22f; -typedef VecMat::SquareMatrix Matrix22d; -typedef VecMat::SquareMatrix Matrix22r; +typedef VecMat::SquareMatrix Matrix22u; +typedef VecMat::SquareMatrix Matrix22i; +typedef VecMat::SquareMatrix Matrix22f; +typedef VecMat::SquareMatrix Matrix22d; +typedef VecMat::SquareMatrix Matrix22r; -typedef VecMat::SquareMatrix Matrix33u; -typedef VecMat::SquareMatrix Matrix33i; -typedef VecMat::SquareMatrix Matrix33f; -typedef VecMat::SquareMatrix Matrix33d; -typedef VecMat::SquareMatrix Matrix33r; +typedef VecMat::SquareMatrix Matrix33u; +typedef VecMat::SquareMatrix Matrix33i; +typedef VecMat::SquareMatrix Matrix33f; +typedef VecMat::SquareMatrix Matrix33d; +typedef VecMat::SquareMatrix Matrix33r; -typedef VecMat::SquareMatrix Matrix44u; -typedef VecMat::SquareMatrix Matrix44i; -typedef VecMat::SquareMatrix Matrix44f; -typedef VecMat::SquareMatrix Matrix44d; -typedef VecMat::SquareMatrix Matrix44r; +typedef VecMat::SquareMatrix Matrix44u; +typedef VecMat::SquareMatrix Matrix44i; +typedef VecMat::SquareMatrix Matrix44f; +typedef VecMat::SquareMatrix Matrix44d; +typedef VecMat::SquareMatrix Matrix44r; -} // end of namespace Geometry +} // end of namespace Geometry } /* namespace Freestyle */ -#endif // __GEOM_H__ +#endif // __GEOM_H__ diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp index 9643593a03d..32d6fc62085 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp @@ -20,13 +20,13 @@ */ #if 0 -#if defined(__GNUC__) && (__GNUC__ >= 3) +# if defined(__GNUC__) && (__GNUC__ >= 3) // hash_map is not part of the C++ standard anymore; // hash_map.h has been kept though for backward compatibility -# include -#else -# include -#endif +# include +# else +# include +# endif #endif #include @@ -43,188 +43,209 @@ using namespace std; namespace Freestyle { -void GeomCleaner::SortIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, float **oVertices, unsigned **oIndices) +void GeomCleaner::SortIndexedVertexArray(const float *iVertices, + unsigned iVSize, + const unsigned *iIndices, + unsigned iISize, + float **oVertices, + unsigned **oIndices) { - // First, we build a list of IndexVertex: - list indexedVertices; - unsigned i; - for (i = 0; i < iVSize; i += 3) { - indexedVertices.push_back(IndexedVertex(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3)); - } - - // q-sort - indexedVertices.sort(); - - // build the indices mapping array: - unsigned *mapIndices = new unsigned[iVSize / 3]; - *oVertices = new float[iVSize]; - list::iterator iv; - unsigned newIndex = 0; - unsigned vIndex = 0; - for (iv = indexedVertices.begin(); iv != indexedVertices.end(); iv++) { - // Build the final results: - (*oVertices)[vIndex] = iv->x(); - (*oVertices)[vIndex + 1] = iv->y(); - (*oVertices)[vIndex + 2] = iv->z(); - - mapIndices[iv->index()] = newIndex; - newIndex++; - vIndex += 3; - } - - // Build the final index array: - *oIndices = new unsigned[iISize]; - for (i = 0; i < iISize; i++) { - (*oIndices)[i] = 3 * mapIndices[iIndices[i] / 3]; - } - - delete [] mapIndices; + // First, we build a list of IndexVertex: + list indexedVertices; + unsigned i; + for (i = 0; i < iVSize; i += 3) { + indexedVertices.push_back( + IndexedVertex(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3)); + } + + // q-sort + indexedVertices.sort(); + + // build the indices mapping array: + unsigned *mapIndices = new unsigned[iVSize / 3]; + *oVertices = new float[iVSize]; + list::iterator iv; + unsigned newIndex = 0; + unsigned vIndex = 0; + for (iv = indexedVertices.begin(); iv != indexedVertices.end(); iv++) { + // Build the final results: + (*oVertices)[vIndex] = iv->x(); + (*oVertices)[vIndex + 1] = iv->y(); + (*oVertices)[vIndex + 2] = iv->z(); + + mapIndices[iv->index()] = newIndex; + newIndex++; + vIndex += 3; + } + + // Build the final index array: + *oIndices = new unsigned[iISize]; + for (i = 0; i < iISize; i++) { + (*oIndices)[i] = 3 * mapIndices[iIndices[i] / 3]; + } + + delete[] mapIndices; } -void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices) +void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, + unsigned iVSize, + const unsigned *iIndices, + unsigned iISize, + float **oVertices, + unsigned *oVSize, + unsigned **oIndices) { - // First, we build a list of IndexVertex: - vector vertices; - unsigned i; - for (i = 0; i < iVSize; i += 3) { - vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); - } - - unsigned *mapVertex = new unsigned[iVSize]; - vector::iterator v = vertices.begin(); - - vector compressedVertices; - Vec3f previous = *v; - mapVertex[0] = 0; - compressedVertices.push_back(vertices.front()); - - v++; - Vec3f current; - i = 1; - for (; v != vertices.end(); v++) { - current = *v; - if (current == previous) - mapVertex[i] = compressedVertices.size() - 1; - else { - compressedVertices.push_back(current); - mapVertex[i] = compressedVertices.size() - 1; - } - previous = current; - i++; - } - - // Builds the resulting vertex array: - *oVSize = 3 * compressedVertices.size(); - *oVertices = new float[*oVSize]; - i = 0; - for (v = compressedVertices.begin(); v != compressedVertices.end(); v++) { - (*oVertices)[i] = (*v)[0]; - (*oVertices)[i + 1] = (*v)[1]; - (*oVertices)[i + 2] = (*v)[2]; - i += 3; - } - - // Map the index array: - *oIndices = new unsigned[iISize]; - for (i = 0; i < iISize; i++) { - (*oIndices)[i] = 3 * mapVertex[iIndices[i] / 3]; - } - - delete [] mapVertex; + // First, we build a list of IndexVertex: + vector vertices; + unsigned i; + for (i = 0; i < iVSize; i += 3) { + vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); + } + + unsigned *mapVertex = new unsigned[iVSize]; + vector::iterator v = vertices.begin(); + + vector compressedVertices; + Vec3f previous = *v; + mapVertex[0] = 0; + compressedVertices.push_back(vertices.front()); + + v++; + Vec3f current; + i = 1; + for (; v != vertices.end(); v++) { + current = *v; + if (current == previous) + mapVertex[i] = compressedVertices.size() - 1; + else { + compressedVertices.push_back(current); + mapVertex[i] = compressedVertices.size() - 1; + } + previous = current; + i++; + } + + // Builds the resulting vertex array: + *oVSize = 3 * compressedVertices.size(); + *oVertices = new float[*oVSize]; + i = 0; + for (v = compressedVertices.begin(); v != compressedVertices.end(); v++) { + (*oVertices)[i] = (*v)[0]; + (*oVertices)[i + 1] = (*v)[1]; + (*oVertices)[i + 2] = (*v)[2]; + i += 3; + } + + // Map the index array: + *oIndices = new unsigned[iISize]; + for (i = 0; i < iISize; i++) { + (*oIndices)[i] = 3 * mapVertex[iIndices[i] / 3]; + } + + delete[] mapVertex; } -void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, float **oVertices, unsigned *oVSize, +void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, + unsigned iVSize, + const unsigned *iIndices, + unsigned iISize, + float **oVertices, + unsigned *oVSize, unsigned **oIndices) { - // tmp arrays used to store the sorted data: - float *tmpVertices; - unsigned *tmpIndices; - - Chronometer chrono; - // Sort data - chrono.start(); - GeomCleaner::SortIndexedVertexArray(iVertices, iVSize, iIndices, iISize, &tmpVertices, &tmpIndices); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("Sorting: %lf sec.\n", chrono.stop()); - } - - // compress data - chrono.start(); - GeomCleaner::CompressIndexedVertexArray(tmpVertices, iVSize, tmpIndices, iISize, oVertices, oVSize, oIndices); - real duration = chrono.stop(); - if (G.debug & G_DEBUG_FREESTYLE) { - printf("Merging: %lf sec.\n", duration); - } - - // deallocates memory: - delete [] tmpVertices; - delete [] tmpIndices; + // tmp arrays used to store the sorted data: + float *tmpVertices; + unsigned *tmpIndices; + + Chronometer chrono; + // Sort data + chrono.start(); + GeomCleaner::SortIndexedVertexArray( + iVertices, iVSize, iIndices, iISize, &tmpVertices, &tmpIndices); + if (G.debug & G_DEBUG_FREESTYLE) { + printf("Sorting: %lf sec.\n", chrono.stop()); + } + + // compress data + chrono.start(); + GeomCleaner::CompressIndexedVertexArray( + tmpVertices, iVSize, tmpIndices, iISize, oVertices, oVSize, oIndices); + real duration = chrono.stop(); + if (G.debug & G_DEBUG_FREESTYLE) { + printf("Merging: %lf sec.\n", duration); + } + + // deallocates memory: + delete[] tmpVertices; + delete[] tmpIndices; } /*! Defines a hash table used for searching the Cells */ struct GeomCleanerHasher { #define _MUL 950706376UL #define _MOD 2147483647UL - inline size_t operator() (const Vec3r& p) const - { - size_t res = ((unsigned long) (p[0] * _MUL)) % _MOD; - res = ((res + (unsigned long) (p[1]) * _MUL)) % _MOD; - return ((res +(unsigned long) (p[2]) * _MUL)) % _MOD; - } + inline size_t operator()(const Vec3r &p) const + { + size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD; + res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD; + return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD; + } #undef _MUL #undef _MOD }; -void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices) +void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, + unsigned iVSize, + const unsigned *iIndices, + unsigned iISize, + float **oVertices, + unsigned *oVSize, + unsigned **oIndices) { - typedef map cleanHashTable; - vector vertices; - unsigned i; - for (i = 0; i < iVSize; i += 3) - vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); - - cleanHashTable ht; - vector newIndices; - vector newVertices; - - // elimination of needless points - unsigned currentIndex = 0; - vector::const_iterator v = vertices.begin(); - vector::const_iterator end = vertices.end(); - cleanHashTable::const_iterator found; - for (; v != end; v++) { - found = ht.find(*v); - if (found != ht.end()) { - // The vertex is already in the new array. - newIndices.push_back((*found).second); - } - else { - newVertices.push_back(*v); - newIndices.push_back(currentIndex); - ht[*v] = currentIndex; - currentIndex++; - } - } - - // creation of oVertices array: - *oVSize = 3 * newVertices.size(); - *oVertices = new float[*oVSize]; - currentIndex = 0; - end = newVertices.end(); - for (v = newVertices.begin(); v != end ; v++) { - (*oVertices)[currentIndex++] = (*v)[0]; - (*oVertices)[currentIndex++] = (*v)[1]; - (*oVertices)[currentIndex++] = (*v)[2]; - } - - // map new indices: - *oIndices = new unsigned[iISize]; - for (i = 0; i < iISize; i++) - (*oIndices)[i] = 3 * newIndices[iIndices[i] / 3]; + typedef map cleanHashTable; + vector vertices; + unsigned i; + for (i = 0; i < iVSize; i += 3) + vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); + + cleanHashTable ht; + vector newIndices; + vector newVertices; + + // elimination of needless points + unsigned currentIndex = 0; + vector::const_iterator v = vertices.begin(); + vector::const_iterator end = vertices.end(); + cleanHashTable::const_iterator found; + for (; v != end; v++) { + found = ht.find(*v); + if (found != ht.end()) { + // The vertex is already in the new array. + newIndices.push_back((*found).second); + } + else { + newVertices.push_back(*v); + newIndices.push_back(currentIndex); + ht[*v] = currentIndex; + currentIndex++; + } + } + + // creation of oVertices array: + *oVSize = 3 * newVertices.size(); + *oVertices = new float[*oVSize]; + currentIndex = 0; + end = newVertices.end(); + for (v = newVertices.begin(); v != end; v++) { + (*oVertices)[currentIndex++] = (*v)[0]; + (*oVertices)[currentIndex++] = (*v)[1]; + (*oVertices)[currentIndex++] = (*v)[2]; + } + + // map new indices: + *oIndices = new unsigned[iISize]; + for (i = 0; i < iISize; i++) + (*oIndices)[i] = 3 * newIndices[iIndices[i] / 3]; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.h b/source/blender/freestyle/intern/geometry/GeomCleaner.h index 32bcc244f69..b34828f87a9 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.h +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.h @@ -27,204 +27,225 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { using namespace Geometry; -class GeomCleaner -{ -public: - inline GeomCleaner() {} - inline ~GeomCleaner() {} - - /*! Sorts an array of Indexed vertices - * iVertices - * Array of vertices to sort. It is organized as a float series of vertex coordinates: XYZXYZXYZ... - * iVSize - * The size of iVertices array. - * iIndices - * The array containing the vertex indices (used to refer to the vertex coordinates in an indexed face). Each - * element is an unsignedeger multiple of 3. - * iISize - * The size of iIndices array - * oVertices - * Output of sorted vertices. A vertex v1 precedes another one v2 in this array if v1.x A[0]) && (A[0] > min[0])) && ((max[0] > B[0]) && (B[0] > min[0]))) && - (((max[1] > A[1]) && (A[1] > min[1])) && ((max[1] > B[1]) && (B[1] > min[1])))) - { - return true; - } - return false; + if ((((max[0] > A[0]) && (A[0] > min[0])) && ((max[0] > B[0]) && (B[0] > min[0]))) && + (((max[1] > A[1]) && (A[1] > min[1])) && ((max[1] > B[1]) && (B[1] > min[1])))) { + return true; + } + return false; } -intersection_test intersect2dSeg2dSeg(const Vec2r& p1, const Vec2r& p2, const Vec2r& p3, const Vec2r& p4, Vec2r& res) +intersection_test intersect2dSeg2dSeg( + const Vec2r &p1, const Vec2r &p2, const Vec2r &p3, const Vec2r &p4, Vec2r &res) { - real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns - real r1, r2, r3, r4; // 'Sign' values - real denom, num; // Intermediate values - - // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". - a1 = p2[1] - p1[1]; - b1 = p1[0] - p2[0]; - c1 = p2[0] * p1[1] - p1[0] * p2[1]; - - // Compute r3 and r4. - r3 = a1 * p3[0] + b1 * p3[1] + c1; - r4 = a1 * p4[0] + b1 * p4[1] + c1; - - // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, - // the line segments do not intersect. - if ( r3 != 0 && r4 != 0 && r3 * r4 > 0.0) - return (DONT_INTERSECT); - - // Compute a2, b2, c2 - a2 = p4[1] - p3[1]; - b2 = p3[0] - p4[0]; - c2 = p4[0] * p3[1] - p3[0] * p4[1]; - - // Compute r1 and r2 - r1 = a2 * p1[0] + b2 * p1[1] + c2; - r2 = a2 * p2[0] + b2 * p2[1] + c2; - - // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line segment, - // the line segments do not intersect. - if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) - return (DONT_INTERSECT); - - // Line segments intersect: compute intersection point. - denom = a1 * b2 - a2 * b1; - if (fabs(denom) < M_EPSILON) - return (COLINEAR); - - num = b1 * c2 - b2 * c1; - res[0] = num / denom; - - num = a2 * c1 - a1 * c2; - res[1] = num / denom; - - return (DO_INTERSECT); + real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns + real r1, r2, r3, r4; // 'Sign' values + real denom, num; // Intermediate values + + // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". + a1 = p2[1] - p1[1]; + b1 = p1[0] - p2[0]; + c1 = p2[0] * p1[1] - p1[0] * p2[1]; + + // Compute r3 and r4. + r3 = a1 * p3[0] + b1 * p3[1] + c1; + r4 = a1 * p4[0] + b1 * p4[1] + c1; + + // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, + // the line segments do not intersect. + if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) + return (DONT_INTERSECT); + + // Compute a2, b2, c2 + a2 = p4[1] - p3[1]; + b2 = p3[0] - p4[0]; + c2 = p4[0] * p3[1] - p3[0] * p4[1]; + + // Compute r1 and r2 + r1 = a2 * p1[0] + b2 * p1[1] + c2; + r2 = a2 * p2[0] + b2 * p2[1] + c2; + + // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line segment, + // the line segments do not intersect. + if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) + return (DONT_INTERSECT); + + // Line segments intersect: compute intersection point. + denom = a1 * b2 - a2 * b1; + if (fabs(denom) < M_EPSILON) + return (COLINEAR); + + num = b1 * c2 - b2 * c1; + res[0] = num / denom; + + num = a2 * c1 - a1 * c2; + res[1] = num / denom; + + return (DO_INTERSECT); } -intersection_test intersect2dLine2dLine(const Vec2r& p1, const Vec2r& p2, const Vec2r& p3, const Vec2r& p4, Vec2r& res) +intersection_test intersect2dLine2dLine( + const Vec2r &p1, const Vec2r &p2, const Vec2r &p3, const Vec2r &p4, Vec2r &res) { - real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns - real denom, num; // Intermediate values + real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns + real denom, num; // Intermediate values - // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". - a1 = p2[1] - p1[1]; - b1 = p1[0] - p2[0]; - c1 = p2[0] * p1[1] - p1[0] * p2[1]; + // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". + a1 = p2[1] - p1[1]; + b1 = p1[0] - p2[0]; + c1 = p2[0] * p1[1] - p1[0] * p2[1]; - // Compute a2, b2, c2 - a2 = p4[1] - p3[1]; - b2 = p3[0] - p4[0]; - c2 = p4[0] * p3[1] - p3[0] * p4[1]; + // Compute a2, b2, c2 + a2 = p4[1] - p3[1]; + b2 = p3[0] - p4[0]; + c2 = p4[0] * p3[1] - p3[0] * p4[1]; - // Line segments intersect: compute intersection point. - denom = a1 * b2 - a2 * b1; - if (fabs(denom) < M_EPSILON) - return (COLINEAR); + // Line segments intersect: compute intersection point. + denom = a1 * b2 - a2 * b1; + if (fabs(denom) < M_EPSILON) + return (COLINEAR); - num = b1 * c2 - b2 * c1; - res[0] = num / denom; + num = b1 * c2 - b2 * c1; + res[0] = num / denom; - num = a2 * c1 - a1 * c2; - res[1] = num / denom; + num = a2 * c1 - a1 * c2; + res[1] = num / denom; - return (DO_INTERSECT); + return (DO_INTERSECT); } -intersection_test intersect2dSeg2dSegParametric(const Vec2r& p1, const Vec2r& p2, const Vec2r& p3, const Vec2r& p4, - real& t, real& u, real epsilon) +intersection_test intersect2dSeg2dSegParametric(const Vec2r &p1, + const Vec2r &p2, + const Vec2r &p3, + const Vec2r &p4, + real &t, + real &u, + real epsilon) { - real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns - real r1, r2, r3, r4; // 'Sign' values - real denom, num; // Intermediate values + real a1, a2, b1, b2, c1, c2; // Coefficients of line eqns + real r1, r2, r3, r4; // 'Sign' values + real denom, num; // Intermediate values - // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". - a1 = p2[1] - p1[1]; - b1 = p1[0] - p2[0]; - c1 = p2[0] * p1[1] - p1[0] * p2[1]; + // Compute a1, b1, c1, where line joining points p1 and p2 is "a1 x + b1 y + c1 = 0". + a1 = p2[1] - p1[1]; + b1 = p1[0] - p2[0]; + c1 = p2[0] * p1[1] - p1[0] * p2[1]; - // Compute r3 and r4. - r3 = a1 * p3[0] + b1 * p3[1] + c1; - r4 = a1 * p4[0] + b1 * p4[1] + c1; + // Compute r3 and r4. + r3 = a1 * p3[0] + b1 * p3[1] + c1; + r4 = a1 * p4[0] + b1 * p4[1] + c1; - // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, - // the line segments do not intersect. - if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) - return (DONT_INTERSECT); + // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, + // the line segments do not intersect. + if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) + return (DONT_INTERSECT); - // Compute a2, b2, c2 - a2 = p4[1] - p3[1]; - b2 = p3[0] - p4[0]; - c2 = p4[0] * p3[1] - p3[0] * p4[1]; + // Compute a2, b2, c2 + a2 = p4[1] - p3[1]; + b2 = p3[0] - p4[0]; + c2 = p4[0] * p3[1] - p3[0] * p4[1]; - // Compute r1 and r2 - r1 = a2 * p1[0] + b2 * p1[1] + c2; - r2 = a2 * p2[0] + b2 * p2[1] + c2; + // Compute r1 and r2 + r1 = a2 * p1[0] + b2 * p1[1] + c2; + r2 = a2 * p2[0] + b2 * p2[1] + c2; - // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line segment, - // the line segments do not intersect. - if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) - return (DONT_INTERSECT); + // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line segment, + // the line segments do not intersect. + if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) + return (DONT_INTERSECT); - // Line segments intersect: compute intersection point. - denom = a1 * b2 - a2 * b1; - if (fabs(denom) < epsilon) - return (COLINEAR); + // Line segments intersect: compute intersection point. + denom = a1 * b2 - a2 * b1; + if (fabs(denom) < epsilon) + return (COLINEAR); - real d1, e1; + real d1, e1; - d1 = p1[1] - p3[1]; - e1 = p1[0] - p3[0]; + d1 = p1[1] - p3[1]; + e1 = p1[0] - p3[0]; - num = -b2 * d1 - a2 * e1; - t = num / denom; + num = -b2 * d1 - a2 * e1; + t = num / denom; - num = -b1 * d1 - a1 * e1; - u = num / denom; + num = -b1 * d1 - a1 * e1; + u = num / denom; - return (DO_INTERSECT); + return (DO_INTERSECT); } // AABB-triangle overlap test code by Tomas Akenine-Möller @@ -204,198 +210,205 @@ intersection_test intersect2dSeg2dSegParametric(const Vec2r& p1, const Vec2r& p2 #define Z 2 #define FINDMINMAX(x0, x1, x2, min, max) \ - { \ - min = max = x0; \ - if (x1 < min) \ - min = x1; \ - if (x1 > max) \ - max = x1; \ - if (x2 < min) \ - min = x2; \ - if (x2 > max) \ - max = x2; \ - } (void)0 + { \ + min = max = x0; \ + if (x1 < min) \ + min = x1; \ + if (x1 > max) \ + max = x1; \ + if (x2 < min) \ + min = x2; \ + if (x2 > max) \ + max = x2; \ + } \ + (void)0 //======================== X-tests ========================// -#define AXISTEST_X01(a, b, fa, fb) \ - { \ - p0 = a * v0[Y] - b * v0[Z]; \ - p2 = a * v2[Y] - b * v2[Z]; \ - if (p0 < p2) { \ - min = p0; \ - max = p2; \ - } \ - else { \ - min = p2; \ - max = p0; \ - } \ - rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 - -#define AXISTEST_X2(a, b, fa, fb) \ - { \ - p0 = a * v0[Y] - b * v0[Z]; \ - p1 = a * v1[Y] - b * v1[Z]; \ - if (p0 < p1) { \ - min = p0; \ - max = p1; \ - } \ - else { \ - min = p1; \ - max = p0; \ - } \ - rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 +#define AXISTEST_X01(a, b, fa, fb) \ + { \ + p0 = a * v0[Y] - b * v0[Z]; \ + p2 = a * v2[Y] - b * v2[Z]; \ + if (p0 < p2) { \ + min = p0; \ + max = p2; \ + } \ + else { \ + min = p2; \ + max = p0; \ + } \ + rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 + +#define AXISTEST_X2(a, b, fa, fb) \ + { \ + p0 = a * v0[Y] - b * v0[Z]; \ + p1 = a * v1[Y] - b * v1[Z]; \ + if (p0 < p1) { \ + min = p0; \ + max = p1; \ + } \ + else { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 //======================== Y-tests ========================// -#define AXISTEST_Y02(a, b, fa, fb) \ - { \ - p0 = -a * v0[X] + b * v0[Z]; \ - p2 = -a * v2[X] + b * v2[Z]; \ - if (p0 < p2) { \ - min = p0; \ - max = p2; \ - } \ - else { \ - min = p2; \ - max = p0; \ - } \ - rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 - -#define AXISTEST_Y1(a, b, fa, fb) \ - { \ - p0 = -a * v0[X] + b * v0[Z]; \ - p1 = -a * v1[X] + b * v1[Z]; \ - if (p0 < p1) { \ - min = p0; \ - max = p1; \ - } \ - else { \ - min = p1; \ - max = p0; \ - } \ - rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 +#define AXISTEST_Y02(a, b, fa, fb) \ + { \ + p0 = -a * v0[X] + b * v0[Z]; \ + p2 = -a * v2[X] + b * v2[Z]; \ + if (p0 < p2) { \ + min = p0; \ + max = p2; \ + } \ + else { \ + min = p2; \ + max = p0; \ + } \ + rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 + +#define AXISTEST_Y1(a, b, fa, fb) \ + { \ + p0 = -a * v0[X] + b * v0[Z]; \ + p1 = -a * v1[X] + b * v1[Z]; \ + if (p0 < p1) { \ + min = p0; \ + max = p1; \ + } \ + else { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 //======================== Z-tests ========================// -#define AXISTEST_Z12(a, b, fa, fb) \ - { \ - p1 = a * v1[X] - b * v1[Y]; \ - p2 = a * v2[X] - b * v2[Y]; \ - if (p2 < p1) { \ - min = p2; \ - max = p1; \ - } \ - else { \ - min = p1; \ - max = p2; \ - } \ - rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 - -#define AXISTEST_Z0(a, b, fa, fb) \ - { \ - p0 = a * v0[X] - b * v0[Y]; \ - p1 = a * v1[X] - b * v1[Y]; \ - if (p0 < p1) { \ - min = p0; \ - max = p1; \ - } \ - else { \ - min = p1; \ - max = p0; \ - } \ - rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \ - if (min > rad || max < -rad) \ - return 0; \ - } (void)0 +#define AXISTEST_Z12(a, b, fa, fb) \ + { \ + p1 = a * v1[X] - b * v1[Y]; \ + p2 = a * v2[X] - b * v2[Y]; \ + if (p2 < p1) { \ + min = p2; \ + max = p1; \ + } \ + else { \ + min = p1; \ + max = p2; \ + } \ + rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 + +#define AXISTEST_Z0(a, b, fa, fb) \ + { \ + p0 = a * v0[X] - b * v0[Y]; \ + p1 = a * v1[X] - b * v1[Y]; \ + if (p0 < p1) { \ + min = p0; \ + max = p1; \ + } \ + else { \ + min = p1; \ + max = p0; \ + } \ + rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \ + if (min > rad || max < -rad) \ + return 0; \ + } \ + (void)0 // This internal procedure is defined below. -bool overlapPlaneBox(Vec3r& normal, real d, Vec3r& maxbox); +bool overlapPlaneBox(Vec3r &normal, real d, Vec3r &maxbox); // Use separating axis theorem to test overlap between triangle and box need to test for overlap in these directions: // 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle we do not even need to test these) // 2) normal of the triangle // 3) crossproduct(edge from tri, {x,y,z}-directin) this gives 3x3=9 more tests -bool overlapTriangleBox(Vec3r& boxcenter, Vec3r& boxhalfsize, Vec3r triverts[3]) +bool overlapTriangleBox(Vec3r &boxcenter, Vec3r &boxhalfsize, Vec3r triverts[3]) { - Vec3r v0, v1, v2, normal, e0, e1, e2; - real min, max, d, p0, p1, p2, rad, fex, fey, fez; - - // This is the fastest branch on Sun - // move everything so that the boxcenter is in (0, 0, 0) - v0 = triverts[0] - boxcenter; - v1 = triverts[1] - boxcenter; - v2 = triverts[2] - boxcenter; - - // compute triangle edges - e0 = v1 - v0; - e1 = v2 - v1; - e2 = v0 - v2; - - // Bullet 3: - // Do the 9 tests first (this was faster) - fex = fabs(e0[X]); - fey = fabs(e0[Y]); - fez = fabs(e0[Z]); - AXISTEST_X01(e0[Z], e0[Y], fez, fey); - AXISTEST_Y02(e0[Z], e0[X], fez, fex); - AXISTEST_Z12(e0[Y], e0[X], fey, fex); - - fex = fabs(e1[X]); - fey = fabs(e1[Y]); - fez = fabs(e1[Z]); - AXISTEST_X01(e1[Z], e1[Y], fez, fey); - AXISTEST_Y02(e1[Z], e1[X], fez, fex); - AXISTEST_Z0(e1[Y], e1[X], fey, fex); - - fex = fabs(e2[X]); - fey = fabs(e2[Y]); - fez = fabs(e2[Z]); - AXISTEST_X2(e2[Z], e2[Y], fez, fey); - AXISTEST_Y1(e2[Z], e2[X], fez, fex); - AXISTEST_Z12(e2[Y], e2[X], fey, fex); - - // Bullet 1: - // first test overlap in the {x,y,z}-directions - // find min, max of the triangle each direction, and test for overlap in that direction -- this is equivalent - // to testing a minimal AABB around the triangle against the AABB - - // test in X-direction - FINDMINMAX(v0[X], v1[X], v2[X], min, max); - if (min > boxhalfsize[X] || max < -boxhalfsize[X]) - return false; - - // test in Y-direction - FINDMINMAX(v0[Y], v1[Y], v2[Y], min, max); - if (min > boxhalfsize[Y] || max < -boxhalfsize[Y]) - return false; - - // test in Z-direction - FINDMINMAX(v0[Z], v1[Z], v2[Z], min, max); - if (min > boxhalfsize[Z] || max < -boxhalfsize[Z]) - return false; - - // Bullet 2: - // test if the box intersects the plane of the triangle - // compute plane equation of triangle: normal * x + d = 0 - normal = e0 ^ e1; - d = -(normal * v0); // plane eq: normal.x + d = 0 - if (!overlapPlaneBox(normal, d, boxhalfsize)) - return false; - - return true; // box and triangle overlaps + Vec3r v0, v1, v2, normal, e0, e1, e2; + real min, max, d, p0, p1, p2, rad, fex, fey, fez; + + // This is the fastest branch on Sun + // move everything so that the boxcenter is in (0, 0, 0) + v0 = triverts[0] - boxcenter; + v1 = triverts[1] - boxcenter; + v2 = triverts[2] - boxcenter; + + // compute triangle edges + e0 = v1 - v0; + e1 = v2 - v1; + e2 = v0 - v2; + + // Bullet 3: + // Do the 9 tests first (this was faster) + fex = fabs(e0[X]); + fey = fabs(e0[Y]); + fez = fabs(e0[Z]); + AXISTEST_X01(e0[Z], e0[Y], fez, fey); + AXISTEST_Y02(e0[Z], e0[X], fez, fex); + AXISTEST_Z12(e0[Y], e0[X], fey, fex); + + fex = fabs(e1[X]); + fey = fabs(e1[Y]); + fez = fabs(e1[Z]); + AXISTEST_X01(e1[Z], e1[Y], fez, fey); + AXISTEST_Y02(e1[Z], e1[X], fez, fex); + AXISTEST_Z0(e1[Y], e1[X], fey, fex); + + fex = fabs(e2[X]); + fey = fabs(e2[Y]); + fez = fabs(e2[Z]); + AXISTEST_X2(e2[Z], e2[Y], fez, fey); + AXISTEST_Y1(e2[Z], e2[X], fez, fex); + AXISTEST_Z12(e2[Y], e2[X], fey, fex); + + // Bullet 1: + // first test overlap in the {x,y,z}-directions + // find min, max of the triangle each direction, and test for overlap in that direction -- this is equivalent + // to testing a minimal AABB around the triangle against the AABB + + // test in X-direction + FINDMINMAX(v0[X], v1[X], v2[X], min, max); + if (min > boxhalfsize[X] || max < -boxhalfsize[X]) + return false; + + // test in Y-direction + FINDMINMAX(v0[Y], v1[Y], v2[Y], min, max); + if (min > boxhalfsize[Y] || max < -boxhalfsize[Y]) + return false; + + // test in Z-direction + FINDMINMAX(v0[Z], v1[Z], v2[Z], min, max); + if (min > boxhalfsize[Z] || max < -boxhalfsize[Z]) + return false; + + // Bullet 2: + // test if the box intersects the plane of the triangle + // compute plane equation of triangle: normal * x + d = 0 + normal = e0 ^ e1; + d = -(normal * v0); // plane eq: normal.x + d = 0 + if (!overlapPlaneBox(normal, d, boxhalfsize)) + return false; + + return true; // box and triangle overlaps } // Fast, Minimum Storage Ray-Triangle Intersection @@ -409,271 +422,287 @@ bool overlapTriangleBox(Vec3r& boxcenter, Vec3r& boxhalfsize, Vec3r triverts[3]) // Cornell University // Ithaca, New York // wbt@graphics.cornell.edu -bool intersectRayTriangle(const Vec3r& orig, const Vec3r& dir, const Vec3r& v0, const Vec3r& v1, const Vec3r& v2, - real& t, real& u, real& v, const real epsilon) +bool intersectRayTriangle(const Vec3r &orig, + const Vec3r &dir, + const Vec3r &v0, + const Vec3r &v1, + const Vec3r &v2, + real &t, + real &u, + real &v, + const real epsilon) { - Vec3r edge1, edge2, tvec, pvec, qvec; - real det, inv_det; - - // find vectors for two edges sharing v0 - edge1 = v1 - v0; - edge2 = v2 - v0; - - // begin calculating determinant - also used to calculate U parameter - pvec = dir ^ edge2; - - // if determinant is near zero, ray lies in plane of triangle - det = edge1 * pvec; - - // calculate distance from v0 to ray origin - tvec = orig - v0; - inv_det = 1.0 / det; - - qvec = tvec ^ edge1; - - if (det > epsilon) { - u = tvec * pvec; - if (u < 0.0 || u > det) - return false; - - // calculate V parameter and test bounds - v = dir * qvec; - if (v < 0.0 || u + v > det) - return false; - } - else if (det < -epsilon) { - // calculate U parameter and test bounds - u = tvec * pvec; - if (u > 0.0 || u < det) - return false; - - // calculate V parameter and test bounds - v = dir * qvec; - if (v > 0.0 || u + v < det) - return false; - } - else { - return false; // ray is parallell to the plane of the triangle - } - - u *= inv_det; - v *= inv_det; - t = (edge2 * qvec) * inv_det; - - return true; + Vec3r edge1, edge2, tvec, pvec, qvec; + real det, inv_det; + + // find vectors for two edges sharing v0 + edge1 = v1 - v0; + edge2 = v2 - v0; + + // begin calculating determinant - also used to calculate U parameter + pvec = dir ^ edge2; + + // if determinant is near zero, ray lies in plane of triangle + det = edge1 * pvec; + + // calculate distance from v0 to ray origin + tvec = orig - v0; + inv_det = 1.0 / det; + + qvec = tvec ^ edge1; + + if (det > epsilon) { + u = tvec * pvec; + if (u < 0.0 || u > det) + return false; + + // calculate V parameter and test bounds + v = dir * qvec; + if (v < 0.0 || u + v > det) + return false; + } + else if (det < -epsilon) { + // calculate U parameter and test bounds + u = tvec * pvec; + if (u > 0.0 || u < det) + return false; + + // calculate V parameter and test bounds + v = dir * qvec; + if (v > 0.0 || u + v < det) + return false; + } + else { + return false; // ray is parallell to the plane of the triangle + } + + u *= inv_det; + v *= inv_det; + t = (edge2 * qvec) * inv_det; + + return true; } // Intersection between plane and ray, adapted from Graphics Gems, Didier Badouel // The plane is represented by a set of points P implicitly defined as dot(norm, P) + d = 0. // The ray is represented as r(t) = orig + dir * t. -intersection_test intersectRayPlane(const Vec3r& orig, const Vec3r& dir, const Vec3r& norm, const real d, - real& t, const real epsilon) +intersection_test intersectRayPlane(const Vec3r &orig, + const Vec3r &dir, + const Vec3r &norm, + const real d, + real &t, + const real epsilon) { - real denom = norm * dir; + real denom = norm * dir; - if (fabs(denom) <= epsilon) { // plane and ray are parallel - if (fabs((norm * orig) + d) <= epsilon) - return COINCIDENT; // plane and ray are coincident - else - return COLINEAR; - } + if (fabs(denom) <= epsilon) { // plane and ray are parallel + if (fabs((norm * orig) + d) <= epsilon) + return COINCIDENT; // plane and ray are coincident + else + return COLINEAR; + } - t = -(d + (norm * orig)) / denom; + t = -(d + (norm * orig)) / denom; - if (t < 0.0f) - return DONT_INTERSECT; + if (t < 0.0f) + return DONT_INTERSECT; - return DO_INTERSECT; + return DO_INTERSECT; } -bool intersectRayBBox(const Vec3r& orig, const Vec3r& dir, // ray origin and direction - const Vec3r& boxMin, const Vec3r& boxMax, // the bbox - real t0, real t1, - real& tmin, // I0 = orig + tmin * dir is the first intersection - real& tmax, // I1 = orig + tmax * dir is the second intersection +bool intersectRayBBox(const Vec3r &orig, + const Vec3r &dir, // ray origin and direction + const Vec3r &boxMin, + const Vec3r &boxMax, // the bbox + real t0, + real t1, + real &tmin, // I0 = orig + tmin * dir is the first intersection + real &tmax, // I1 = orig + tmax * dir is the second intersection real /*epsilon*/) { - float tymin, tymax, tzmin, tzmax; - Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]); - int sign[3]; - sign[0] = (inv_direction.x() < 0); - sign[1] = (inv_direction.y() < 0); - sign[2] = (inv_direction.z() < 0); - - Vec3r bounds[2]; - bounds[0] = boxMin; - bounds[1] = boxMax; - - tmin = (bounds[sign[0]].x() - orig.x()) * inv_direction.x(); - tmax = (bounds[1 - sign[0]].x() - orig.x()) * inv_direction.x(); - tymin = (bounds[sign[1]].y() - orig.y()) * inv_direction.y(); - tymax = (bounds[1 - sign[1]].y() - orig.y()) * inv_direction.y(); - if ((tmin > tymax) || (tymin > tmax)) - return false; - if (tymin > tmin) - tmin = tymin; - if (tymax < tmax) - tmax = tymax; - tzmin = (bounds[sign[2]].z() - orig.z()) * inv_direction.z(); - tzmax = (bounds[1 - sign[2]].z() - orig.z()) * inv_direction.z(); - if ((tmin > tzmax) || (tzmin > tmax)) - return false; - if (tzmin > tmin) - tmin = tzmin; - if (tzmax < tmax) - tmax = tzmax; - return ((tmin < t1) && (tmax > t0)); + float tymin, tymax, tzmin, tzmax; + Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]); + int sign[3]; + sign[0] = (inv_direction.x() < 0); + sign[1] = (inv_direction.y() < 0); + sign[2] = (inv_direction.z() < 0); + + Vec3r bounds[2]; + bounds[0] = boxMin; + bounds[1] = boxMax; + + tmin = (bounds[sign[0]].x() - orig.x()) * inv_direction.x(); + tmax = (bounds[1 - sign[0]].x() - orig.x()) * inv_direction.x(); + tymin = (bounds[sign[1]].y() - orig.y()) * inv_direction.y(); + tymax = (bounds[1 - sign[1]].y() - orig.y()) * inv_direction.y(); + if ((tmin > tymax) || (tymin > tmax)) + return false; + if (tymin > tmin) + tmin = tymin; + if (tymax < tmax) + tmax = tymax; + tzmin = (bounds[sign[2]].z() - orig.z()) * inv_direction.z(); + tzmax = (bounds[1 - sign[2]].z() - orig.z()) * inv_direction.z(); + if ((tmin > tzmax) || (tzmin > tmax)) + return false; + if (tzmin > tmin) + tmin = tzmin; + if (tzmax < tmax) + tmax = tzmax; + return ((tmin < t1) && (tmax > t0)); } // Checks whether 3D points p lies inside or outside of the triangle ABC -bool includePointTriangle(const Vec3r& P, const Vec3r& A, const Vec3r& B, const Vec3r& C) +bool includePointTriangle(const Vec3r &P, const Vec3r &A, const Vec3r &B, const Vec3r &C) { - Vec3r AB(B - A); - Vec3r BC(C - B); - Vec3r CA(A - C); - Vec3r AP(P - A); - Vec3r BP(P - B); - Vec3r CP(P - C); + Vec3r AB(B - A); + Vec3r BC(C - B); + Vec3r CA(A - C); + Vec3r AP(P - A); + Vec3r BP(P - B); + Vec3r CP(P - C); - Vec3r N(AB ^ BC); // triangle's normal + Vec3r N(AB ^ BC); // triangle's normal - N.normalize(); + N.normalize(); - Vec3r J(AB ^ AP), K(BC ^ BP), L(CA ^ CP); - J.normalize(); - K.normalize(); - L.normalize(); + Vec3r J(AB ^ AP), K(BC ^ BP), L(CA ^ CP); + J.normalize(); + K.normalize(); + L.normalize(); - if (J * N < 0) - return false; // on the right of AB + if (J * N < 0) + return false; // on the right of AB - if (K * N < 0) - return false; // on the right of BC + if (K * N < 0) + return false; // on the right of BC - if (L * N < 0) - return false; // on the right of CA + if (L * N < 0) + return false; // on the right of CA - return true; + return true; } -void transformVertex(const Vec3r& vert, const Matrix44r& matrix, Vec3r& res) +void transformVertex(const Vec3r &vert, const Matrix44r &matrix, Vec3r &res) { - HVec3r hvert(vert), res_tmp; - real scale; - for (unsigned int j = 0; j < 4; j++) { - scale = hvert[j]; - for (unsigned int i = 0; i < 4; i++) - res_tmp[i] += matrix(i, j) * scale; - } - - res[0] = res_tmp.x(); - res[1] = res_tmp.y(); - res[2] = res_tmp.z(); + HVec3r hvert(vert), res_tmp; + real scale; + for (unsigned int j = 0; j < 4; j++) { + scale = hvert[j]; + for (unsigned int i = 0; i < 4; i++) + res_tmp[i] += matrix(i, j) * scale; + } + + res[0] = res_tmp.x(); + res[1] = res_tmp.y(); + res[2] = res_tmp.z(); } -void transformVertices(const vector& vertices, const Matrix44r& trans, vector& res) +void transformVertices(const vector &vertices, const Matrix44r &trans, vector &res) { - size_t i; - res.resize(vertices.size()); - for (i = 0; i < vertices.size(); i++) { - transformVertex(vertices[i], trans, res[i]); - } + size_t i; + res.resize(vertices.size()); + for (i = 0; i < vertices.size(); i++) { + transformVertex(vertices[i], trans, res[i]); + } } -Vec3r rotateVector(const Matrix44r& mat, const Vec3r& v) +Vec3r rotateVector(const Matrix44r &mat, const Vec3r &v) { - Vec3r res; - for (unsigned int i = 0; i < 3; i++) { - res[i] = 0; - for (unsigned int j = 0; j < 3; j++) - res[i] += mat(i, j) * v[j]; - } - res.normalize(); - return res; + Vec3r res; + for (unsigned int i = 0; i < 3; i++) { + res[i] = 0; + for (unsigned int j = 0; j < 3; j++) + res[i] += mat(i, j) * v[j]; + } + res.normalize(); + return res; } // This internal procedure is defined below. -void fromCoordAToCoordB(const Vec3r& p, Vec3r& q, const real transform[4][4]); +void fromCoordAToCoordB(const Vec3r &p, Vec3r &q, const real transform[4][4]); -void fromWorldToCamera(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4]) +void fromWorldToCamera(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4]) { - fromCoordAToCoordB(p, q, model_view_matrix); + fromCoordAToCoordB(p, q, model_view_matrix); } -void fromCameraToRetina(const Vec3r& p, Vec3r& q, const real projection_matrix[4][4]) +void fromCameraToRetina(const Vec3r &p, Vec3r &q, const real projection_matrix[4][4]) { - fromCoordAToCoordB(p, q, projection_matrix); + fromCoordAToCoordB(p, q, projection_matrix); } -void fromRetinaToImage(const Vec3r& p, Vec3r& q, const int viewport[4]) +void fromRetinaToImage(const Vec3r &p, Vec3r &q, const int viewport[4]) { - // winX: - q[0] = viewport[0] + viewport[2] * (p[0] + 1.0) / 2.0; + // winX: + q[0] = viewport[0] + viewport[2] * (p[0] + 1.0) / 2.0; - // winY: - q[1] = viewport[1] + viewport[3] * (p[1] + 1.0) / 2.0; + // winY: + q[1] = viewport[1] + viewport[3] * (p[1] + 1.0) / 2.0; - // winZ: - q[2] = (p[2] + 1.0) / 2.0; + // winZ: + q[2] = (p[2] + 1.0) / 2.0; } -void fromWorldToImage(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4], - const real projection_matrix[4][4], const int viewport[4]) +void fromWorldToImage(const Vec3r &p, + Vec3r &q, + const real model_view_matrix[4][4], + const real projection_matrix[4][4], + const int viewport[4]) { - Vec3r p1, p2; - fromWorldToCamera(p, p1, model_view_matrix); - fromCameraToRetina(p1, p2, projection_matrix); - fromRetinaToImage(p2, q, viewport); - q[2] = p1[2]; + Vec3r p1, p2; + fromWorldToCamera(p, p1, model_view_matrix); + fromCameraToRetina(p1, p2, projection_matrix); + fromRetinaToImage(p2, q, viewport); + q[2] = p1[2]; } -void fromWorldToImage(const Vec3r& p, Vec3r& q, const real transform[4][4], const int viewport[4]) +void fromWorldToImage(const Vec3r &p, Vec3r &q, const real transform[4][4], const int viewport[4]) { - fromCoordAToCoordB(p, q, transform); + fromCoordAToCoordB(p, q, transform); - // winX: - q[0] = viewport[0] + viewport[2] * (q[0] + 1.0) / 2.0; + // winX: + q[0] = viewport[0] + viewport[2] * (q[0] + 1.0) / 2.0; - //winY: - q[1] = viewport[1] + viewport[3] * (q[1] + 1.0) / 2.0; + //winY: + q[1] = viewport[1] + viewport[3] * (q[1] + 1.0) / 2.0; } -void fromImageToRetina(const Vec3r& p, Vec3r& q, const int viewport[4]) +void fromImageToRetina(const Vec3r &p, Vec3r &q, const int viewport[4]) { - q = p; - q[0] = 2.0 * (q[0] - viewport[0]) / viewport[2] - 1.0; - q[1] = 2.0 * (q[1] - viewport[1]) / viewport[3] - 1.0; + q = p; + q[0] = 2.0 * (q[0] - viewport[0]) / viewport[2] - 1.0; + q[1] = 2.0 * (q[1] - viewport[1]) / viewport[3] - 1.0; } -void fromRetinaToCamera(const Vec3r& p, Vec3r& q, real focal, const real projection_matrix[4][4]) +void fromRetinaToCamera(const Vec3r &p, Vec3r &q, real focal, const real projection_matrix[4][4]) { - if (projection_matrix[3][3] == 0.0) { // perspective - q[0] = (-p[0] * focal) / projection_matrix[0][0]; - q[1] = (-p[1] * focal) / projection_matrix[1][1]; - q[2] = focal; - } - else { // orthogonal - q[0] = p[0] / projection_matrix[0][0]; - q[1] = p[1] / projection_matrix[1][1]; - q[2] = focal; - } + if (projection_matrix[3][3] == 0.0) { // perspective + q[0] = (-p[0] * focal) / projection_matrix[0][0]; + q[1] = (-p[1] * focal) / projection_matrix[1][1]; + q[2] = focal; + } + else { // orthogonal + q[0] = p[0] / projection_matrix[0][0]; + q[1] = p[1] / projection_matrix[1][1]; + q[2] = focal; + } } -void fromCameraToWorld(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4]) +void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4]) { - real translation[3] = { - model_view_matrix[0][3], - model_view_matrix[1][3], - model_view_matrix[2][3], - }; - for (unsigned short i = 0; i < 3; i++) { - q[i] = 0.0; - for (unsigned short j = 0; j < 3; j++) - q[i] += model_view_matrix[j][i] * (p[j] - translation[j]); - } + real translation[3] = { + model_view_matrix[0][3], + model_view_matrix[1][3], + model_view_matrix[2][3], + }; + for (unsigned short i = 0; i < 3; i++) { + q[i] = 0.0; + for (unsigned short j = 0; j < 3; j++) + q[i] += model_view_matrix[j][i] * (p[j] - translation[j]); + } } - // // Internal code // @@ -685,92 +714,92 @@ void fromCameraToWorld(const Vec3r& p, Vec3r& q, const real model_view_matrix[4] // from its use. // Users of this code must verify correctness for their application. -#define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0]) // 2D perp product +#define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0]) // 2D perp product inline bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n) { - if (seg[0] == seg[1]) - return false; - - real tE = 0; // the maximum entering segment parameter - real tL = 1; // the minimum leaving segment parameter - real t, N, D; // intersect parameter t = N / D - Vec2r dseg = seg[1] - seg[0]; // the segment direction vector - Vec2r e; // edge vector - - for (unsigned int i = 0; i < n; i++) { // process polygon edge poly[i]poly[i+1] - e = poly[i + 1] - poly[i]; - N = PERP(e, seg[0] - poly[i]); - D = -PERP(e, dseg); - if (fabs(D) < M_EPSILON) { - if (N < 0) - return false; - else - continue; - } - - t = N / D; - if (D < 0) { // segment seg is entering across this edge - if (t > tE) { // new max tE - tE = t; - if (tE > tL) // seg enters after leaving polygon - return false; - } - } - else { // segment seg is leaving across this edge - if (t < tL) { // new min tL - tL = t; - if (tL < tE) // seg leaves before entering polygon - return false; - } - } - } - - // tE <= tL implies that there is a valid intersection subsegment - return true; + if (seg[0] == seg[1]) + return false; + + real tE = 0; // the maximum entering segment parameter + real tL = 1; // the minimum leaving segment parameter + real t, N, D; // intersect parameter t = N / D + Vec2r dseg = seg[1] - seg[0]; // the segment direction vector + Vec2r e; // edge vector + + for (unsigned int i = 0; i < n; i++) { // process polygon edge poly[i]poly[i+1] + e = poly[i + 1] - poly[i]; + N = PERP(e, seg[0] - poly[i]); + D = -PERP(e, dseg); + if (fabs(D) < M_EPSILON) { + if (N < 0) + return false; + else + continue; + } + + t = N / D; + if (D < 0) { // segment seg is entering across this edge + if (t > tE) { // new max tE + tE = t; + if (tE > tL) // seg enters after leaving polygon + return false; + } + } + else { // segment seg is leaving across this edge + if (t < tL) { // new min tL + tL = t; + if (tL < tE) // seg leaves before entering polygon + return false; + } + } + } + + // tE <= tL implies that there is a valid intersection subsegment + return true; } -inline bool overlapPlaneBox(Vec3r& normal, real d, Vec3r& maxbox) +inline bool overlapPlaneBox(Vec3r &normal, real d, Vec3r &maxbox) { - Vec3r vmin, vmax; - - for (unsigned int q = X; q <= Z; q++) { - if (normal[q] > 0.0f) { - vmin[q] = -maxbox[q]; - vmax[q] = maxbox[q]; - } - else { - vmin[q] = maxbox[q]; - vmax[q] = -maxbox[q]; - } - } - if ((normal * vmin) + d > 0.0f) - return false; - if ((normal * vmax) + d >= 0.0f) - return true; - return false; + Vec3r vmin, vmax; + + for (unsigned int q = X; q <= Z; q++) { + if (normal[q] > 0.0f) { + vmin[q] = -maxbox[q]; + vmax[q] = maxbox[q]; + } + else { + vmin[q] = maxbox[q]; + vmax[q] = -maxbox[q]; + } + } + if ((normal * vmin) + d > 0.0f) + return false; + if ((normal * vmax) + d >= 0.0f) + return true; + return false; } -inline void fromCoordAToCoordB(const Vec3r&p, Vec3r& q, const real transform[4][4]) +inline void fromCoordAToCoordB(const Vec3r &p, Vec3r &q, const real transform[4][4]) { - HVec3r hp(p); - HVec3r hq(0, 0, 0, 0); - - for (unsigned int i = 0; i < 4; i++) { - for (unsigned int j = 0; j < 4; j++) { - hq[i] += transform[i][j] * hp[j]; - } - } - - if (hq[3] == 0) { - q = p; - return; - } - - for (unsigned int k = 0; k < 3; k++) - q[k] = hq[k] / hq[3]; + HVec3r hp(p); + HVec3r hq(0, 0, 0, 0); + + for (unsigned int i = 0; i < 4; i++) { + for (unsigned int j = 0; j < 4; j++) { + hq[i] += transform[i][j] * hp[j]; + } + } + + if (hq[3] == 0) { + q = p; + return; + } + + for (unsigned int k = 0; k < 3; k++) + q[k] = hq[k] / hq[3]; } -} // end of namespace GeomUtils +} // end of namespace GeomUtils } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.h b/source/blender/freestyle/intern/geometry/GeomUtils.h index 94904b72ff1..42ef9612074 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.h +++ b/source/blender/freestyle/intern/geometry/GeomUtils.h @@ -42,28 +42,27 @@ namespace GeomUtils { ///////////////////////////////////////////////////////////////////////////// /*! Computes the distance from a point P to a segment AB */ -template -real distPointSegment(const T& P, const T& A, const T& B) +template real distPointSegment(const T &P, const T &A, const T &B) { - T AB, AP, BP; - AB = B - A; - AP = P - A; - BP = P - B; + T AB, AP, BP; + AB = B - A; + AP = P - A; + BP = P - B; - real c1(AB * AP); - if (c1 <= 0) - return AP.norm(); + real c1(AB * AP); + if (c1 <= 0) + return AP.norm(); - real c2(AB * AB); - if (c2 <= c1) - return BP.norm(); + real c2(AB * AB); + if (c2 <= c1) + return BP.norm(); - real b = c1 / c2; - T Pb, PPb; - Pb = A + b * AB; - PPb = P - Pb; + real b = c1 / c2; + T Pb, PPb; + Pb = A + b * AB; + PPb = P - Pb; - return PPb.norm(); + return PPb.norm(); } // @@ -71,67 +70,83 @@ real distPointSegment(const T& P, const T& A, const T& B) // ///////////////////////////////////////////////////////////////////////////// typedef enum { - DONT_INTERSECT, - DO_INTERSECT, - COLINEAR, - COINCIDENT, + DONT_INTERSECT, + DO_INTERSECT, + COLINEAR, + COINCIDENT, } intersection_test; -intersection_test intersect2dSeg2dSeg(const Vec2r& p1, const Vec2r& p2, // first segment - const Vec2r& p3, const Vec2r& p4, // second segment - Vec2r& res); // found intersection point - -intersection_test intersect2dLine2dLine(const Vec2r& p1, const Vec2r& p2, // first segment - const Vec2r& p3, const Vec2r& p4, // second segment - Vec2r& res); // found intersection point - -intersection_test intersect2dSeg2dSegParametric(const Vec2r& p1, const Vec2r& p2, // first segment - const Vec2r& p3, const Vec2r& p4, // second segment - real& t, // I = P1 + t * P1P2) - real& u, // I = P3 + u * P3P4 +intersection_test intersect2dSeg2dSeg(const Vec2r &p1, + const Vec2r &p2, // first segment + const Vec2r &p3, + const Vec2r &p4, // second segment + Vec2r &res); // found intersection point + +intersection_test intersect2dLine2dLine(const Vec2r &p1, + const Vec2r &p2, // first segment + const Vec2r &p3, + const Vec2r &p4, // second segment + Vec2r &res); // found intersection point + +intersection_test intersect2dSeg2dSegParametric(const Vec2r &p1, + const Vec2r &p2, // first segment + const Vec2r &p3, + const Vec2r &p4, // second segment + real &t, // I = P1 + t * P1P2) + real &u, // I = P3 + u * P3P4 real epsilon = M_EPSILON); /*! check whether a 2D segment intersect a 2D region or not */ -bool intersect2dSeg2dArea(const Vec2r& min, const Vec2r& max, const Vec2r& A, const Vec2r& B); +bool intersect2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B); /*! check whether a 2D segment is included in a 2D region or not */ -bool include2dSeg2dArea(const Vec2r& min, const Vec2r& max, const Vec2r& A, const Vec2r& B); +bool include2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B); /*! Box-triangle overlap test, adapted from Tomas Akenine-Möller code */ -bool overlapTriangleBox(Vec3r& boxcenter, Vec3r& boxhalfsize, Vec3r triverts[3]); +bool overlapTriangleBox(Vec3r &boxcenter, Vec3r &boxhalfsize, Vec3r triverts[3]); /*! Fast, Minimum Storage Ray-Triangle Intersection, adapted from Tomas Möller and Ben Trumbore code. */ -bool intersectRayTriangle(const Vec3r& orig, const Vec3r& dir, const Vec3r& v0, const Vec3r& v1, const Vec3r& v2, - real& t, // I = orig + t * dir - real& u, real& v, // I = (1 - u - v) * v0 + u * v1 + v * v2 - const real epsilon = M_EPSILON); // the epsilon to use +bool intersectRayTriangle(const Vec3r &orig, + const Vec3r &dir, + const Vec3r &v0, + const Vec3r &v1, + const Vec3r &v2, + real &t, // I = orig + t * dir + real &u, + real &v, // I = (1 - u - v) * v0 + u * v1 + v * v2 + const real epsilon = M_EPSILON); // the epsilon to use /*! Intersection between plane and ray adapted from Graphics Gems, Didier Badouel */ -intersection_test intersectRayPlane(const Vec3r& orig, const Vec3r& dir, // ray origin and direction +intersection_test intersectRayPlane(const Vec3r &orig, + const Vec3r &dir, // ray origin and direction // plane's normal and offset (plane = { P / P.N + d = 0 }) - const Vec3r& norm, const real d, - real& t, // I = orig + t * dir - const real epsilon = M_EPSILON); // the epsilon to use + const Vec3r &norm, + const real d, + real &t, // I = orig + t * dir + const real epsilon = M_EPSILON); // the epsilon to use /*! Intersection Ray-Bounding box (axis aligned). * Adapted from Williams et al, "An Efficient Robust Ray-Box Intersection Algorithm", JGT 10:1 (2005), pp. 49-54. */ -bool intersectRayBBox(const Vec3r& orig, const Vec3r& dir, // ray origin and direction - const Vec3r& boxMin, const Vec3r& boxMax, // the bbox +bool intersectRayBBox(const Vec3r &orig, + const Vec3r &dir, // ray origin and direction + const Vec3r &boxMin, + const Vec3r &boxMax, // the bbox // the interval in which at least on of the intersections must happen - real t0, real t1, - real& tmin, // Imin = orig + tmin * dir is the first intersection - real& tmax, // Imax = orig + tmax * dir is the second intersection - real epsilon = M_EPSILON); // the epsilon to use + real t0, + real t1, + real &tmin, // Imin = orig + tmin * dir is the first intersection + real &tmax, // Imax = orig + tmax * dir is the second intersection + real epsilon = M_EPSILON); // the epsilon to use /*! Checks whether 3D point P lies inside or outside of the triangle ABC */ -bool includePointTriangle(const Vec3r& P, const Vec3r& A, const Vec3r& B, const Vec3r& C); +bool includePointTriangle(const Vec3r &P, const Vec3r &A, const Vec3r &B, const Vec3r &C); -void transformVertex(const Vec3r& vert, const Matrix44r& matrix, Vec3r& res); +void transformVertex(const Vec3r &vert, const Matrix44r &matrix, Vec3r &res); -void transformVertices(const vector& vertices, const Matrix44r& trans, vector& res); +void transformVertices(const vector &vertices, const Matrix44r &trans, vector &res); -Vec3r rotateVector(const Matrix44r& mat, const Vec3r& v); +Vec3r rotateVector(const Matrix44r &mat, const Vec3r &v); // // Coordinates systems changing procedures @@ -152,7 +167,10 @@ Vec3r rotateVector(const Matrix44r& mat, const Vec3r& v); * viewport * The viewport: x,y coordinates followed by width and height (OpenGL like viewport) */ -void fromWorldToImage(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4], const real projection_matrix[4][4], +void fromWorldToImage(const Vec3r &p, + Vec3r &q, + const real model_view_matrix[4][4], + const real projection_matrix[4][4], const int viewport[4]); /*! From world to image @@ -166,7 +184,7 @@ void fromWorldToImage(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][ * viewport * The viewport: x,y coordinates followed by width and height (OpenGL like viewport) */ -void fromWorldToImage(const Vec3r& p, Vec3r& q, const real transform[4][4], const int viewport[4]); +void fromWorldToImage(const Vec3r &p, Vec3r &q, const real transform[4][4], const int viewport[4]); /*! Projects from world coordinates to camera coordinates * Returns the point's coordinates expressed in the camera's @@ -179,7 +197,7 @@ void fromWorldToImage(const Vec3r& p, Vec3r& q, const real transform[4][4], cons * The model view matrix expressed in line major order (OpenGL * matrices are column major ordered) */ -void fromWorldToCamera(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4]); +void fromWorldToCamera(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4]); /*! Projects from World Coordinates to retina coordinates * Returns the point's coordinates expressed in Retina system. @@ -191,7 +209,7 @@ void fromWorldToCamera(const Vec3r& p, Vec3r& q, const real model_view_matrix[4] * The projection matrix expressed in line major order (OpenGL * matrices are column major ordered) */ -void fromCameraToRetina(const Vec3r& p, Vec3r& q, const real projection_matrix[4][4]); +void fromCameraToRetina(const Vec3r &p, Vec3r &q, const real projection_matrix[4][4]); /*! From retina to image. * Returns the coordinates expressed in Image coordinates system. @@ -202,7 +220,7 @@ void fromCameraToRetina(const Vec3r& p, Vec3r& q, const real projection_matrix[4 * viewport * The viewport: x,y coordinates followed by width and height (OpenGL like viewport). */ -void fromRetinaToImage(const Vec3r& p, Vec3r& q, const int viewport[4]); +void fromRetinaToImage(const Vec3r &p, Vec3r &q, const int viewport[4]); /*! From image to retina * p @@ -212,7 +230,7 @@ void fromRetinaToImage(const Vec3r& p, Vec3r& q, const int viewport[4]); * viewport * The viewport: x,y coordinates followed by width and height (OpenGL like viewport). */ -void fromImageToRetina(const Vec3r& p, Vec3r& q, const int viewport[4]); +void fromImageToRetina(const Vec3r &p, Vec3r &q, const int viewport[4]); /*! computes the coordinates of q in the camera coordinates system, * using the known z coordinates of the 3D point. @@ -226,7 +244,7 @@ void fromImageToRetina(const Vec3r& p, Vec3r& q, const int viewport[4]); * The projection matrix expressed in line major order (OpenGL * matrices are column major ordered) */ -void fromRetinaToCamera(const Vec3r& p, Vec3r& q, real z, const real projection_matrix[4][4]); +void fromRetinaToCamera(const Vec3r &p, Vec3r &q, real z, const real projection_matrix[4][4]); /*! Projects from camera coordinates to world coordinates * Returns the point's coordinates expressed in the world's @@ -239,10 +257,10 @@ void fromRetinaToCamera(const Vec3r& p, Vec3r& q, real z, const real projection_ * The model view matrix expressed in line major order (OpenGL * matrices are column major ordered) */ -void fromCameraToWorld(const Vec3r& p, Vec3r& q, const real model_view_matrix[4][4]); +void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4]); -} // end of namespace GeomUtils +} // end of namespace GeomUtils } /* namespace Freestyle */ -#endif // __GEOMUTILS_H__ +#endif // __GEOMUTILS_H__ diff --git a/source/blender/freestyle/intern/geometry/Grid.cpp b/source/blender/freestyle/intern/geometry/Grid.cpp index e7d3cf1a8cc..6a95e540c79 100644 --- a/source/blender/freestyle/intern/geometry/Grid.cpp +++ b/source/blender/freestyle/intern/geometry/Grid.cpp @@ -32,352 +32,356 @@ namespace Freestyle { ///////////////// void allOccludersGridVisitor::examineOccluder(Polygon3r *occ) { - occluders_.push_back(occ); + occluders_.push_back(occ); } -static bool inBox(const Vec3r& inter, const Vec3r& box_min, const Vec3r& box_max) +static bool inBox(const Vec3r &inter, const Vec3r &box_min, const Vec3r &box_max) { - if (((inter.x() >= box_min.x()) && (inter.x() < box_max.x())) && - ((inter.y() >= box_min.y()) && (inter.y() < box_max.y())) && - ((inter.z() >= box_min.z()) && (inter.z() < box_max.z()))) - { - return true; - } - return false; + if (((inter.x() >= box_min.x()) && (inter.x() < box_max.x())) && + ((inter.y() >= box_min.y()) && (inter.y() < box_max.y())) && + ((inter.z() >= box_min.z()) && (inter.z() < box_max.z()))) { + return true; + } + return false; } void firstIntersectionGridVisitor::examineOccluder(Polygon3r *occ) { - // check whether the edge and the polygon plane are coincident: - //------------------------------------------------------------- - //first let us compute the plane equation. - Vec3r v1(((occ)->getVertices())[0]); - Vec3d normal((occ)->getNormal()); - //soc unused - double d = -(v1 * normal); - - double tmp_u, tmp_v, tmp_t; - if ((occ)->rayIntersect(ray_org_, ray_dir_, tmp_t, tmp_u, tmp_v)) { - if (fabs(ray_dir_ * normal) > 0.0001) { - // Check whether the intersection is in the cell: - if (inBox(ray_org_ + tmp_t * ray_dir_ / ray_dir_.norm(), current_cell_->getOrigin(), - current_cell_->getOrigin() + cell_size_)) - { + // check whether the edge and the polygon plane are coincident: + //------------------------------------------------------------- + //first let us compute the plane equation. + Vec3r v1(((occ)->getVertices())[0]); + Vec3d normal((occ)->getNormal()); + //soc unused - double d = -(v1 * normal); + + double tmp_u, tmp_v, tmp_t; + if ((occ)->rayIntersect(ray_org_, ray_dir_, tmp_t, tmp_u, tmp_v)) { + if (fabs(ray_dir_ * normal) > 0.0001) { + // Check whether the intersection is in the cell: + if (inBox(ray_org_ + tmp_t * ray_dir_ / ray_dir_.norm(), + current_cell_->getOrigin(), + current_cell_->getOrigin() + cell_size_)) { #if 0 - Vec3d bboxdiag(_scene3d->bbox().getMax() - _scene3d->bbox().getMin()); - if ((t > 1.0e-06 * (min(min(bboxdiag.x(), bboxdiag.y()), bboxdiag.z()))) && (t < raylength)) { + Vec3d bboxdiag(_scene3d->bbox().getMax() - _scene3d->bbox().getMin()); + if ((t > 1.0e-06 * (min(min(bboxdiag.x(), bboxdiag.y()), bboxdiag.z()))) && (t < raylength)) { #else - if (tmp_t < t_) { + if (tmp_t < t_) { #endif - occluder_ = occ; - u_ = tmp_u; - v_ = tmp_v; - t_ = tmp_t; - } - } - else { - occ->userdata2 = 0; - } - } - } + occluder_ = occ; + u_ = tmp_u; + v_ = tmp_v; + t_ = tmp_t; + } + } + else { + occ->userdata2 = 0; + } + } } +} // namespace Freestyle bool firstIntersectionGridVisitor::stop() { - if (occluder_) - return true; - return false; + if (occluder_) + return true; + return false; } // Grid ///////////////// void Grid::clear() { - if (_occluders.size() != 0) { - for (OccludersSet::iterator it = _occluders.begin(); it != _occluders.end(); it++) { - delete (*it); - } - _occluders.clear(); - } - - _size = Vec3r(0, 0, 0); - _cell_size = Vec3r(0, 0, 0); - _orig = Vec3r(0, 0, 0); - _cells_nb = Vec3u(0, 0, 0); - //_ray_occluders.clear(); + if (_occluders.size() != 0) { + for (OccludersSet::iterator it = _occluders.begin(); it != _occluders.end(); it++) { + delete (*it); + } + _occluders.clear(); + } + + _size = Vec3r(0, 0, 0); + _cell_size = Vec3r(0, 0, 0); + _orig = Vec3r(0, 0, 0); + _cells_nb = Vec3u(0, 0, 0); + //_ray_occluders.clear(); } -void Grid::configure(const Vec3r& orig, const Vec3r& size, unsigned nb) +void Grid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) { - _orig = orig; - Vec3r tmpSize = size; - // Compute the volume of the desired grid - real grid_vol = size[0] * size[1] * size[2]; - - if (grid_vol == 0) { - double min = DBL_MAX; - int index = 0; - int nzeros = 0; - for (int i = 0; i < 3; ++i) { - if (size[i] == 0) { - ++nzeros; - index = i; - } - if ((size[i] != 0) && (min > size[i])) { - min = size[i]; - } - } - if (nzeros > 1) { - throw std::runtime_error("Warning: the 3D grid has more than one null dimension"); - } - tmpSize[index] = min; - _orig[index] = _orig[index] - min / 2; - } - // Compute the desired volume of a single cell - real cell_vol = grid_vol / nb; - // The edge of such a cubic cell is cubic root of cellVolume - real edge = pow(cell_vol, 1.0 / 3.0); - - // We compute the number of cells par edge such as we cover at least the whole box. - unsigned i; - for (i = 0; i < 3; i++) - _cells_nb[i] = (unsigned)floor(tmpSize[i] / edge) + 1; - - _size = tmpSize; - - for (i = 0; i < 3; i++) - _cell_size[i] = _size[i] / _cells_nb[i]; + _orig = orig; + Vec3r tmpSize = size; + // Compute the volume of the desired grid + real grid_vol = size[0] * size[1] * size[2]; + + if (grid_vol == 0) { + double min = DBL_MAX; + int index = 0; + int nzeros = 0; + for (int i = 0; i < 3; ++i) { + if (size[i] == 0) { + ++nzeros; + index = i; + } + if ((size[i] != 0) && (min > size[i])) { + min = size[i]; + } + } + if (nzeros > 1) { + throw std::runtime_error("Warning: the 3D grid has more than one null dimension"); + } + tmpSize[index] = min; + _orig[index] = _orig[index] - min / 2; + } + // Compute the desired volume of a single cell + real cell_vol = grid_vol / nb; + // The edge of such a cubic cell is cubic root of cellVolume + real edge = pow(cell_vol, 1.0 / 3.0); + + // We compute the number of cells par edge such as we cover at least the whole box. + unsigned i; + for (i = 0; i < 3; i++) + _cells_nb[i] = (unsigned)floor(tmpSize[i] / edge) + 1; + + _size = tmpSize; + + for (i = 0; i < 3; i++) + _cell_size[i] = _size[i] / _cells_nb[i]; } void Grid::insertOccluder(Polygon3r *occluder) { - const vector vertices = occluder->getVertices(); - if (vertices.size() == 0) - return; - - // add this occluder to the grid's occluders list - addOccluder(occluder); - - // find the bbox associated to this polygon - Vec3r min, max; - occluder->getBBox(min, max); - - // Retrieve the cell x, y, z cordinates associated with these min and max - Vec3u imax, imin; - getCellCoordinates(max, imax); - getCellCoordinates(min, imin); - - // We are now going to fill in the cells overlapping with the polygon bbox. - // If the polygon is a triangle (most of cases), we also check for each of these cells if it is overlapping with - // the triangle in order to only fill in the ones really overlapping the triangle. - - unsigned i, x, y, z; - vector::const_iterator it; - Vec3u coord; - - if (vertices.size() == 3) { // Triangle case - Vec3r triverts[3]; - i = 0; - for (it = vertices.begin(); it != vertices.end(); it++) { - triverts[i] = Vec3r(*it); - i++; - } - - Vec3r boxmin, boxmax; - - for (z = imin[2]; z <= imax[2]; z++) { - for (y = imin[1]; y <= imax[1]; y++) { - for (x = imin[0]; x <= imax[0]; x++) { - coord[0] = x; - coord[1] = y; - coord[2] = z; - // We retrieve the box coordinates of the current cell - getCellBox(coord, boxmin, boxmax); - // We check whether the triangle and the box ovewrlap: - Vec3r boxcenter((boxmin + boxmax) / 2.0); - Vec3r boxhalfsize(_cell_size / 2.0); - if (GeomUtils::overlapTriangleBox(boxcenter, boxhalfsize, triverts)) { - // We must then create the Cell and add it to the cells list if it does not exist yet. - // We must then add the occluder to the occluders list of this cell. - Cell *cell = getCell(coord); - if (!cell) { - cell = new Cell(boxmin); - fillCell(coord, *cell); - } - cell->addOccluder(occluder); - } - } - } - } - } - else { // The polygon is not a triangle, we add all the cells overlapping the polygon bbox. - for (z = imin[2]; z <= imax[2]; z++) { - for (y = imin[1]; y <= imax[1]; y++) { - for (x = imin[0]; x <= imax[0]; x++) { - coord[0] = x; - coord[1] = y; - coord[2] = z; - Cell *cell = getCell(coord); - if (!cell) { - Vec3r orig; - getCellOrigin(coord, orig); - cell = new Cell(orig); - fillCell(coord, *cell); - } - cell->addOccluder(occluder); - } - } - } - } + const vector vertices = occluder->getVertices(); + if (vertices.size() == 0) + return; + + // add this occluder to the grid's occluders list + addOccluder(occluder); + + // find the bbox associated to this polygon + Vec3r min, max; + occluder->getBBox(min, max); + + // Retrieve the cell x, y, z cordinates associated with these min and max + Vec3u imax, imin; + getCellCoordinates(max, imax); + getCellCoordinates(min, imin); + + // We are now going to fill in the cells overlapping with the polygon bbox. + // If the polygon is a triangle (most of cases), we also check for each of these cells if it is overlapping with + // the triangle in order to only fill in the ones really overlapping the triangle. + + unsigned i, x, y, z; + vector::const_iterator it; + Vec3u coord; + + if (vertices.size() == 3) { // Triangle case + Vec3r triverts[3]; + i = 0; + for (it = vertices.begin(); it != vertices.end(); it++) { + triverts[i] = Vec3r(*it); + i++; + } + + Vec3r boxmin, boxmax; + + for (z = imin[2]; z <= imax[2]; z++) { + for (y = imin[1]; y <= imax[1]; y++) { + for (x = imin[0]; x <= imax[0]; x++) { + coord[0] = x; + coord[1] = y; + coord[2] = z; + // We retrieve the box coordinates of the current cell + getCellBox(coord, boxmin, boxmax); + // We check whether the triangle and the box ovewrlap: + Vec3r boxcenter((boxmin + boxmax) / 2.0); + Vec3r boxhalfsize(_cell_size / 2.0); + if (GeomUtils::overlapTriangleBox(boxcenter, boxhalfsize, triverts)) { + // We must then create the Cell and add it to the cells list if it does not exist yet. + // We must then add the occluder to the occluders list of this cell. + Cell *cell = getCell(coord); + if (!cell) { + cell = new Cell(boxmin); + fillCell(coord, *cell); + } + cell->addOccluder(occluder); + } + } + } + } + } + else { // The polygon is not a triangle, we add all the cells overlapping the polygon bbox. + for (z = imin[2]; z <= imax[2]; z++) { + for (y = imin[1]; y <= imax[1]; y++) { + for (x = imin[0]; x <= imax[0]; x++) { + coord[0] = x; + coord[1] = y; + coord[2] = z; + Cell *cell = getCell(coord); + if (!cell) { + Vec3r orig; + getCellOrigin(coord, orig); + cell = new Cell(orig); + fillCell(coord, *cell); + } + cell->addOccluder(occluder); + } + } + } + } } -bool Grid::nextRayCell(Vec3u& current_cell, Vec3u& next_cell) +bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) { - next_cell = current_cell; - real t_min, t; - unsigned i; - - t_min = FLT_MAX; // init tmin with handle of the case where one or 2 _u[i] = 0. - unsigned coord = 0; // predominant coord(0=x, 1=y, 2=z) - - - // using a parametric equation of a line : B = A + t u, we find the tx, ty and tz respectively coresponding - // to the intersections with the plans: - // x = _cell_size[0], y = _cell_size[1], z = _cell_size[2] - for (i = 0; i < 3; i++) { - if (_ray_dir[i] == 0) - continue; - if (_ray_dir[i] > 0) - t = (_cell_size[i] - _pt[i]) / _ray_dir[i]; - else - t = -_pt[i] / _ray_dir[i]; - if (t < t_min) { - t_min = t; - coord = i; - } - } - - // We use the parametric line equation and the found t (tamx) to compute the B coordinates: - Vec3r pt_tmp(_pt); - _pt = pt_tmp + t_min * _ray_dir; - - // We express B coordinates in the next cell coordinates system. We just have to - // set the coordinate coord of B to 0 of _CellSize[coord] depending on the sign of _u[coord] - if (_ray_dir[coord] > 0) { - next_cell[coord]++; - _pt[coord] -= _cell_size[coord]; - // if we are out of the grid, we must stop - if (next_cell[coord] >= _cells_nb[coord]) - return false; - } - else { - int tmp = next_cell[coord] - 1; - _pt[coord] = _cell_size[coord]; - if (tmp < 0) - return false; - next_cell[coord]--; - } - - _t += t_min; - if (_t >= _t_end) - return false; - - return true; + next_cell = current_cell; + real t_min, t; + unsigned i; + + t_min = FLT_MAX; // init tmin with handle of the case where one or 2 _u[i] = 0. + unsigned coord = 0; // predominant coord(0=x, 1=y, 2=z) + + // using a parametric equation of a line : B = A + t u, we find the tx, ty and tz respectively coresponding + // to the intersections with the plans: + // x = _cell_size[0], y = _cell_size[1], z = _cell_size[2] + for (i = 0; i < 3; i++) { + if (_ray_dir[i] == 0) + continue; + if (_ray_dir[i] > 0) + t = (_cell_size[i] - _pt[i]) / _ray_dir[i]; + else + t = -_pt[i] / _ray_dir[i]; + if (t < t_min) { + t_min = t; + coord = i; + } + } + + // We use the parametric line equation and the found t (tamx) to compute the B coordinates: + Vec3r pt_tmp(_pt); + _pt = pt_tmp + t_min * _ray_dir; + + // We express B coordinates in the next cell coordinates system. We just have to + // set the coordinate coord of B to 0 of _CellSize[coord] depending on the sign of _u[coord] + if (_ray_dir[coord] > 0) { + next_cell[coord]++; + _pt[coord] -= _cell_size[coord]; + // if we are out of the grid, we must stop + if (next_cell[coord] >= _cells_nb[coord]) + return false; + } + else { + int tmp = next_cell[coord] - 1; + _pt[coord] = _cell_size[coord]; + if (tmp < 0) + return false; + next_cell[coord]--; + } + + _t += t_min; + if (_t >= _t_end) + return false; + + return true; } -void Grid::castRay(const Vec3r& orig, const Vec3r& end, OccludersSet& occluders, unsigned timestamp) +void Grid::castRay(const Vec3r &orig, + const Vec3r &end, + OccludersSet &occluders, + unsigned timestamp) { - initRay(orig, end, timestamp); - allOccludersGridVisitor visitor(occluders); - castRayInternal(visitor); + initRay(orig, end, timestamp); + allOccludersGridVisitor visitor(occluders); + castRayInternal(visitor); } -void Grid::castInfiniteRay(const Vec3r& orig, const Vec3r& dir, OccludersSet& occluders, unsigned timestamp) +void Grid::castInfiniteRay(const Vec3r &orig, + const Vec3r &dir, + OccludersSet &occluders, + unsigned timestamp) { - Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); - bool inter = initInfiniteRay(orig, dir, timestamp); - if (!inter) - return; - allOccludersGridVisitor visitor(occluders); - castRayInternal(visitor); + Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); + bool inter = initInfiniteRay(orig, dir, timestamp); + if (!inter) + return; + allOccludersGridVisitor visitor(occluders); + castRayInternal(visitor); } -Polygon3r *Grid::castRayToFindFirstIntersection(const Vec3r& orig, const Vec3r& dir, double& t, - double& u, double& v, unsigned timestamp) +Polygon3r *Grid::castRayToFindFirstIntersection( + const Vec3r &orig, const Vec3r &dir, double &t, double &u, double &v, unsigned timestamp) { - Polygon3r *occluder = 0; - Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); - bool inter = initInfiniteRay(orig, dir, timestamp); - if (!inter) { - return 0; - } - firstIntersectionGridVisitor visitor(orig, dir, _cell_size); - castRayInternal(visitor); - // ARB: This doesn't work, because occluders are unordered within any cell - // visitor.occluder() will be an occluder, but we have no guarantee it will be the *first* occluder. - // I assume that is the reason this code is not actually used for FindOccludee. - occluder = visitor.occluder(); - t = visitor.t_; - u = visitor.u_; - v = visitor.v_; - return occluder; + Polygon3r *occluder = 0; + Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); + bool inter = initInfiniteRay(orig, dir, timestamp); + if (!inter) { + return 0; + } + firstIntersectionGridVisitor visitor(orig, dir, _cell_size); + castRayInternal(visitor); + // ARB: This doesn't work, because occluders are unordered within any cell + // visitor.occluder() will be an occluder, but we have no guarantee it will be the *first* occluder. + // I assume that is the reason this code is not actually used for FindOccludee. + occluder = visitor.occluder(); + t = visitor.t_; + u = visitor.u_; + v = visitor.v_; + return occluder; } -void Grid::initRay (const Vec3r &orig, const Vec3r& end, unsigned timestamp) +void Grid::initRay(const Vec3r &orig, const Vec3r &end, unsigned timestamp) { - _ray_dir = end - orig; - _t_end = _ray_dir.norm(); - _t = 0; - _ray_dir.normalize(); - _timestamp = timestamp; - - for (unsigned i = 0; i < 3; i++) { - _current_cell[i] = (unsigned)floor((orig[i] - _orig[i]) / _cell_size[i]); - //soc unused - unsigned u = _current_cell[i]; - _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; - } - //_ray_occluders.clear(); + _ray_dir = end - orig; + _t_end = _ray_dir.norm(); + _t = 0; + _ray_dir.normalize(); + _timestamp = timestamp; + + for (unsigned i = 0; i < 3; i++) { + _current_cell[i] = (unsigned)floor((orig[i] - _orig[i]) / _cell_size[i]); + //soc unused - unsigned u = _current_cell[i]; + _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; + } + //_ray_occluders.clear(); } -bool Grid::initInfiniteRay (const Vec3r &orig, const Vec3r& dir, unsigned timestamp) +bool Grid::initInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timestamp) { - _ray_dir = dir; - _t_end = FLT_MAX; - _t = 0; - _ray_dir.normalize(); - _timestamp = timestamp; - - // check whether the origin is in or out the box: - Vec3r boxMin(_orig); - Vec3r boxMax(_orig + _size); - BBox box(boxMin, boxMax); - if (box.inside(orig)) { - for (unsigned int i = 0; i < 3; i++) { - _current_cell[i] = (unsigned int)floor((orig[i] - _orig[i]) / _cell_size[i]); - //soc unused - unsigned u = _current_cell[i]; - _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; - } - } - else { - // is the ray intersecting the box? - real tmin(-1.0), tmax(-1.0); - if (GeomUtils::intersectRayBBox(orig, _ray_dir, boxMin, boxMax, 0, _t_end, tmin, tmax)) { - BLI_assert(tmin != -1.0); - Vec3r newOrig = orig + tmin * _ray_dir; - for (unsigned int i = 0; i < 3; i++) { - _current_cell[i] = (unsigned)floor((newOrig[i] - _orig[i]) / _cell_size[i]); - if (_current_cell[i] == _cells_nb[i]) - _current_cell[i] = _cells_nb[i] - 1; - //soc unused - unsigned u = _current_cell[i]; - _pt[i] = newOrig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; - } - } - else { - return false; - } - } - //_ray_occluders.clear(); - - return true; + _ray_dir = dir; + _t_end = FLT_MAX; + _t = 0; + _ray_dir.normalize(); + _timestamp = timestamp; + + // check whether the origin is in or out the box: + Vec3r boxMin(_orig); + Vec3r boxMax(_orig + _size); + BBox box(boxMin, boxMax); + if (box.inside(orig)) { + for (unsigned int i = 0; i < 3; i++) { + _current_cell[i] = (unsigned int)floor((orig[i] - _orig[i]) / _cell_size[i]); + //soc unused - unsigned u = _current_cell[i]; + _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; + } + } + else { + // is the ray intersecting the box? + real tmin(-1.0), tmax(-1.0); + if (GeomUtils::intersectRayBBox(orig, _ray_dir, boxMin, boxMax, 0, _t_end, tmin, tmax)) { + BLI_assert(tmin != -1.0); + Vec3r newOrig = orig + tmin * _ray_dir; + for (unsigned int i = 0; i < 3; i++) { + _current_cell[i] = (unsigned)floor((newOrig[i] - _orig[i]) / _cell_size[i]); + if (_current_cell[i] == _cells_nb[i]) + _current_cell[i] = _cells_nb[i] - 1; + //soc unused - unsigned u = _current_cell[i]; + _pt[i] = newOrig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; + } + } + else { + return false; + } + } + //_ray_occluders.clear(); + + return true; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index c3a0f16a354..a2b64a446b6 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -22,9 +22,9 @@ * \brief Base class to define a cell grid surrounding the bounding box of the scene */ -#include // for memset +#include // for memset #include -#include // For POINTER_FROM_UINT, i.e. uintptr_t. +#include // For POINTER_FROM_UINT, i.e. uintptr_t. #include #include "Geom.h" @@ -34,11 +34,11 @@ #include "../system/FreestyleConfig.h" extern "C" { - #include "BLI_utildefines.h" +#include "BLI_utildefines.h" } #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -47,119 +47,142 @@ namespace Freestyle { using namespace Geometry; -typedef vector OccludersSet; +typedef vector OccludersSet; // // Class to define cells used by the regular grid // /////////////////////////////////////////////////////////////////////////////// -class Cell -{ -public: - Cell(Vec3r& orig) { - _orig = orig; - } - - virtual ~Cell() {} - - inline void addOccluder(Polygon3r *o) { - if (o) - _occluders.push_back(o); - } - - inline const Vec3r& getOrigin() { - return _orig; - } - - inline OccludersSet& getOccluders() { - return _occluders; - } - -private: - Vec3r _orig; - OccludersSet _occluders; +class Cell { + public: + Cell(Vec3r &orig) + { + _orig = orig; + } + + virtual ~Cell() + { + } + + inline void addOccluder(Polygon3r *o) + { + if (o) + _occluders.push_back(o); + } + + inline const Vec3r &getOrigin() + { + return _orig; + } + + inline OccludersSet &getOccluders() + { + return _occluders; + } + + private: + Vec3r _orig; + OccludersSet _occluders; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Cell") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Cell") #endif }; +class GridVisitor { + public: + virtual ~GridVisitor(){}; //soc -class GridVisitor -{ -public: - virtual ~GridVisitor() {}; //soc + virtual void discoverCell(Cell * /*cell*/) + { + } - virtual void discoverCell(Cell * /*cell*/) {} + virtual void examineOccluder(Polygon3r * /*occ*/) + { + } - virtual void examineOccluder(Polygon3r * /*occ*/) {} + virtual void finishCell(Cell * /*cell*/) + { + } - virtual void finishCell(Cell * /*cell*/) {} - - virtual bool stop() { - return false; - } + virtual bool stop() + { + return false; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridVisitor") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridVisitor") #endif }; /*! Gathers all the occluders belonging to the cells traversed by the ray */ -class allOccludersGridVisitor : public GridVisitor -{ -public: - allOccludersGridVisitor(OccludersSet& occluders) : GridVisitor(), occluders_(occluders) {} - - virtual void examineOccluder(Polygon3r *occ); - - OccludersSet& occluders() { - return occluders_; - } - - void clear() { - occluders_.clear(); - } - -private: - OccludersSet& occluders_; +class allOccludersGridVisitor : public GridVisitor { + public: + allOccludersGridVisitor(OccludersSet &occluders) : GridVisitor(), occluders_(occluders) + { + } + + virtual void examineOccluder(Polygon3r *occ); + + OccludersSet &occluders() + { + return occluders_; + } + + void clear() + { + occluders_.clear(); + } + + private: + OccludersSet &occluders_; }; /*! Finds the first intersection and breaks. * The occluder and the intersection information are stored and accessible. */ -class firstIntersectionGridVisitor : public GridVisitor -{ -//soc - changed order to remove warnings -public: - double u_, v_, t_; - -private: - Polygon3r *occluder_; - Vec3r ray_org_, ray_dir_, cell_size_; - Cell *current_cell_; - -public: - firstIntersectionGridVisitor(const Vec3r& ray_org, const Vec3r& ray_dir, const Vec3r& cell_size) : - GridVisitor(), u_(0), v_(0), t_(DBL_MAX), occluder_(0), ray_org_(ray_org), ray_dir_(ray_dir), - cell_size_(cell_size), current_cell_(0) - { - } - - virtual ~firstIntersectionGridVisitor() {} - - virtual void discoverCell(Cell *cell) { - current_cell_ = cell; - } - - virtual void examineOccluder(Polygon3r *occ); - - virtual bool stop(); - - Polygon3r *occluder() { - return occluder_; - } +class firstIntersectionGridVisitor : public GridVisitor { + //soc - changed order to remove warnings + public: + double u_, v_, t_; + + private: + Polygon3r *occluder_; + Vec3r ray_org_, ray_dir_, cell_size_; + Cell *current_cell_; + + public: + firstIntersectionGridVisitor(const Vec3r &ray_org, const Vec3r &ray_dir, const Vec3r &cell_size) + : GridVisitor(), + u_(0), + v_(0), + t_(DBL_MAX), + occluder_(0), + ray_org_(ray_org), + ray_dir_(ray_dir), + cell_size_(cell_size), + current_cell_(0) + { + } + + virtual ~firstIntersectionGridVisitor() + { + } + + virtual void discoverCell(Cell *cell) + { + current_cell_ = cell; + } + + virtual void examineOccluder(Polygon3r *occ); + + virtual bool stop(); + + Polygon3r *occluder() + { + return occluder_; + } }; // @@ -167,204 +190,218 @@ public: // /////////////////////////////////////////////////////////////////////////////// -class Grid -{ -public: - /*! Builds a Grid. Must be followed by a call to configure() */ - Grid() {} - - virtual ~Grid() { - clear(); - } - - /*! clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. - */ - virtual void clear(); - - /*! Sets the different parameters of the grid - * orig - * The grid origin - * size - * The grid's dimensions - * nb - * The number of cells of the grid - */ - virtual void configure(const Vec3r& orig, const Vec3r& size, unsigned nb); - - /*! returns a vector of integer containing the coordinates of the cell containing the point passed as argument - * p - * The point for which we're looking the cell - */ - inline void getCellCoordinates(const Vec3r& p, Vec3u& res) { - int tmp; - for (int i = 0; i < 3; i++) { - tmp = (int)((p[i] - _orig[i]) / _cell_size[i]); - if (tmp < 0) - res[i] = 0; - else if ((unsigned int)tmp >= _cells_nb[i]) - res[i] = _cells_nb[i] - 1; - else - res[i] = tmp; - } - } - - /*! Fills the case corresponding to coord with the cell */ - virtual void fillCell(const Vec3u& coord, Cell& cell) = 0; - - /*! returns the cell whose coordinates are pased as argument */ - virtual Cell *getCell(const Vec3u& coord) = 0; - - /*! returns the cell containing the point passed as argument. If the cell is empty (contains no occluder), - * NULL is returned - * p - * The point for which we're looking the cell - */ - inline Cell *getCell(const Vec3r& p) { - Vec3u coord; - getCellCoordinates(p, coord); - return getCell(coord); - } - - /*! Retrieves the x,y,z coordinates of the origin of the cell whose coordinates (i,j,k) is passed as argument - * cell_coord - * i,j,k integer coordinates for the cell - * orig - * x,y,x vector to be filled in with the cell origin's coordinates - */ - inline void getCellOrigin(const Vec3u& cell_coord, Vec3r& orig) { - for (unsigned int i = 0; i < 3; i++) - orig[i] = _orig[i] + cell_coord[i] * _cell_size[i]; - } - - /*! Retrieves the box corresponding to the cell whose coordinates are passed as argument. - * cell_coord - * i,j,k integer coordinates for the cell - * min_out - * The min x,y,x vector of the box. Filled in by the method. - * max_out - * The max x,y,z coordinates of the box. Filled in by the method. - */ - inline void getCellBox(const Vec3u& cell_coord, Vec3r& min_out, Vec3r& max_out) { - getCellOrigin(cell_coord, min_out); - max_out = min_out + _cell_size; - } - - /*! inserts a convex polygon occluder - * This method is quite coarse insofar as it adds all cells intersecting the polygon bounding box - * convex_poly - * The list of 3D points constituting a convex polygon - */ - void insertOccluder(Polygon3r *convex_poly); - - /*! Adds an occluder to the list of occluders */ - void addOccluder(Polygon3r *occluder) { - _occluders.push_back(occluder); - } - - /*! Casts a ray between a starting point and an ending point - * Returns the list of occluders contained in the cells intersected by this ray - * Starts with a call to InitRay. - */ - void castRay(const Vec3r& orig, const Vec3r& end, OccludersSet& occluders, unsigned timestamp); - - // Prepares to cast ray without generating OccludersSet - void initAcceleratedRay(const Vec3r& orig, const Vec3r& end, unsigned timestamp); - - /*! Casts an infinite ray (still finishing at the end of the grid) from a starting point and in a given direction. - * Returns the list of occluders contained in the cells intersected by this ray - * Starts with a call to InitRay. - */ - void castInfiniteRay(const Vec3r& orig, const Vec3r& dir, OccludersSet& occluders, unsigned timestamp); - - // Prepares to cast ray without generating OccludersSet. - bool initAcceleratedInfiniteRay(const Vec3r& orig, const Vec3r& dir, unsigned timestamp); - - /*! Casts an infinite ray (still finishing at the end of the grid) from a starting point and in a given direction. - * Returns the first intersection (occluder,t,u,v) or null. - * Starts with a call to InitRay. - */ - Polygon3r *castRayToFindFirstIntersection( - const Vec3r& orig, const Vec3r& dir, double& t, - double& u, double& v, unsigned timestamp); - - - /*! Init all structures and values for computing the cells intersected by this new ray */ - void initRay(const Vec3r &orig, const Vec3r& end, unsigned timestamp); - - /*! Init all structures and values for computing the cells intersected by this infinite ray. - * Returns false if the ray doesn't intersect the grid. - */ - bool initInfiniteRay(const Vec3r &orig, const Vec3r& dir, unsigned timestamp); - - - /*! Accessors */ - inline const Vec3r& getOrigin() const { - return _orig; - } - - inline Vec3r gridSize() const { - return _size; - } - - inline Vec3r getCellSize() const { - return _cell_size; - } - - //ARB profiling only: - inline OccludersSet *getOccluders() { - return &_occluders; - } - - void displayDebug() { - cerr << "Cells nb : " << _cells_nb << endl; - cerr << "Cell size : " << _cell_size << endl; - cerr << "Origin : " << _orig << endl; - cerr << "Occluders nb : " << _occluders.size() << endl; - } - -protected: - /*! Core of castRay and castInfiniteRay, find occluders along the given ray */ - inline void castRayInternal(GridVisitor& visitor) { - Cell *current_cell = NULL; - do { - current_cell = getCell(_current_cell); - if (current_cell) { - visitor.discoverCell(current_cell); - OccludersSet& occluders = current_cell->getOccluders(); // FIXME: I had forgotten the ref & - for (OccludersSet::iterator it = occluders.begin(); it != occluders.end(); it++) { - if (POINTER_AS_UINT((*it)->userdata2) != _timestamp) { - (*it)->userdata2 = POINTER_FROM_UINT(_timestamp); - visitor.examineOccluder(*it); - } - } - visitor.finishCell(current_cell); - } - } while ((!visitor.stop()) && (nextRayCell(_current_cell, _current_cell))); - } - - - /*! returns the cell next to the cell passed as argument. */ - bool nextRayCell(Vec3u& current_cell, Vec3u& next_cell); - - unsigned int _timestamp; - - Vec3u _cells_nb; // number of cells for x,y,z axis - Vec3r _cell_size; // cell x,y,z dimensions - Vec3r _size; // grid x,y,x dimensions - Vec3r _orig; // grid origin - - Vec3r _ray_dir; // direction vector for the ray - Vec3u _current_cell; // The current cell being processed (designated by its 3 coordinates) - Vec3r _pt; // Points corresponding to the incoming and outgoing intersections of one cell with the ray - real _t_end; // To know when we are at the end of the ray - real _t; - - //OccludersSet _ray_occluders; // Set storing the occluders contained in the cells traversed by a ray - OccludersSet _occluders; // List of all occluders inserted in the grid +class Grid { + public: + /*! Builds a Grid. Must be followed by a call to configure() */ + Grid() + { + } + + virtual ~Grid() + { + clear(); + } + + /*! clears the grid + * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + */ + virtual void clear(); + + /*! Sets the different parameters of the grid + * orig + * The grid origin + * size + * The grid's dimensions + * nb + * The number of cells of the grid + */ + virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb); + + /*! returns a vector of integer containing the coordinates of the cell containing the point passed as argument + * p + * The point for which we're looking the cell + */ + inline void getCellCoordinates(const Vec3r &p, Vec3u &res) + { + int tmp; + for (int i = 0; i < 3; i++) { + tmp = (int)((p[i] - _orig[i]) / _cell_size[i]); + if (tmp < 0) + res[i] = 0; + else if ((unsigned int)tmp >= _cells_nb[i]) + res[i] = _cells_nb[i] - 1; + else + res[i] = tmp; + } + } + + /*! Fills the case corresponding to coord with the cell */ + virtual void fillCell(const Vec3u &coord, Cell &cell) = 0; + + /*! returns the cell whose coordinates are pased as argument */ + virtual Cell *getCell(const Vec3u &coord) = 0; + + /*! returns the cell containing the point passed as argument. If the cell is empty (contains no occluder), + * NULL is returned + * p + * The point for which we're looking the cell + */ + inline Cell *getCell(const Vec3r &p) + { + Vec3u coord; + getCellCoordinates(p, coord); + return getCell(coord); + } + + /*! Retrieves the x,y,z coordinates of the origin of the cell whose coordinates (i,j,k) is passed as argument + * cell_coord + * i,j,k integer coordinates for the cell + * orig + * x,y,x vector to be filled in with the cell origin's coordinates + */ + inline void getCellOrigin(const Vec3u &cell_coord, Vec3r &orig) + { + for (unsigned int i = 0; i < 3; i++) + orig[i] = _orig[i] + cell_coord[i] * _cell_size[i]; + } + + /*! Retrieves the box corresponding to the cell whose coordinates are passed as argument. + * cell_coord + * i,j,k integer coordinates for the cell + * min_out + * The min x,y,x vector of the box. Filled in by the method. + * max_out + * The max x,y,z coordinates of the box. Filled in by the method. + */ + inline void getCellBox(const Vec3u &cell_coord, Vec3r &min_out, Vec3r &max_out) + { + getCellOrigin(cell_coord, min_out); + max_out = min_out + _cell_size; + } + + /*! inserts a convex polygon occluder + * This method is quite coarse insofar as it adds all cells intersecting the polygon bounding box + * convex_poly + * The list of 3D points constituting a convex polygon + */ + void insertOccluder(Polygon3r *convex_poly); + + /*! Adds an occluder to the list of occluders */ + void addOccluder(Polygon3r *occluder) + { + _occluders.push_back(occluder); + } + + /*! Casts a ray between a starting point and an ending point + * Returns the list of occluders contained in the cells intersected by this ray + * Starts with a call to InitRay. + */ + void castRay(const Vec3r &orig, const Vec3r &end, OccludersSet &occluders, unsigned timestamp); + + // Prepares to cast ray without generating OccludersSet + void initAcceleratedRay(const Vec3r &orig, const Vec3r &end, unsigned timestamp); + + /*! Casts an infinite ray (still finishing at the end of the grid) from a starting point and in a given direction. + * Returns the list of occluders contained in the cells intersected by this ray + * Starts with a call to InitRay. + */ + void castInfiniteRay(const Vec3r &orig, + const Vec3r &dir, + OccludersSet &occluders, + unsigned timestamp); + + // Prepares to cast ray without generating OccludersSet. + bool initAcceleratedInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timestamp); + + /*! Casts an infinite ray (still finishing at the end of the grid) from a starting point and in a given direction. + * Returns the first intersection (occluder,t,u,v) or null. + * Starts with a call to InitRay. + */ + Polygon3r *castRayToFindFirstIntersection( + const Vec3r &orig, const Vec3r &dir, double &t, double &u, double &v, unsigned timestamp); + + /*! Init all structures and values for computing the cells intersected by this new ray */ + void initRay(const Vec3r &orig, const Vec3r &end, unsigned timestamp); + + /*! Init all structures and values for computing the cells intersected by this infinite ray. + * Returns false if the ray doesn't intersect the grid. + */ + bool initInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timestamp); + + /*! Accessors */ + inline const Vec3r &getOrigin() const + { + return _orig; + } + + inline Vec3r gridSize() const + { + return _size; + } + + inline Vec3r getCellSize() const + { + return _cell_size; + } + + //ARB profiling only: + inline OccludersSet *getOccluders() + { + return &_occluders; + } + + void displayDebug() + { + cerr << "Cells nb : " << _cells_nb << endl; + cerr << "Cell size : " << _cell_size << endl; + cerr << "Origin : " << _orig << endl; + cerr << "Occluders nb : " << _occluders.size() << endl; + } + + protected: + /*! Core of castRay and castInfiniteRay, find occluders along the given ray */ + inline void castRayInternal(GridVisitor &visitor) + { + Cell *current_cell = NULL; + do { + current_cell = getCell(_current_cell); + if (current_cell) { + visitor.discoverCell(current_cell); + OccludersSet &occluders = + current_cell->getOccluders(); // FIXME: I had forgotten the ref & + for (OccludersSet::iterator it = occluders.begin(); it != occluders.end(); it++) { + if (POINTER_AS_UINT((*it)->userdata2) != _timestamp) { + (*it)->userdata2 = POINTER_FROM_UINT(_timestamp); + visitor.examineOccluder(*it); + } + } + visitor.finishCell(current_cell); + } + } while ((!visitor.stop()) && (nextRayCell(_current_cell, _current_cell))); + } + + /*! returns the cell next to the cell passed as argument. */ + bool nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell); + + unsigned int _timestamp; + + Vec3u _cells_nb; // number of cells for x,y,z axis + Vec3r _cell_size; // cell x,y,z dimensions + Vec3r _size; // grid x,y,x dimensions + Vec3r _orig; // grid origin + + Vec3r _ray_dir; // direction vector for the ray + Vec3u _current_cell; // The current cell being processed (designated by its 3 coordinates) + Vec3r + _pt; // Points corresponding to the incoming and outgoing intersections of one cell with the ray + real _t_end; // To know when we are at the end of the ray + real _t; + + //OccludersSet _ray_occluders; // Set storing the occluders contained in the cells traversed by a ray + OccludersSet _occluders; // List of all occluders inserted in the grid #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Grid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Grid") #endif }; @@ -374,22 +411,22 @@ protected: /////////////////////////////////////////////////////////////////////////////// class VirtualOccludersSet { -public: - VirtualOccludersSet(Grid& _grid) : grid (_grid) {}; - Polygon3r *begin(); - Polygon3r *next(); - Polygon3r *next(bool stopOnNewCell); + public: + VirtualOccludersSet(Grid &_grid) : grid(_grid){}; + Polygon3r *begin(); + Polygon3r *next(); + Polygon3r *next(bool stopOnNewCell); -private: - Polygon3r *firstOccluderFromNextCell(); - Grid& grid; - OccludersSet::iterator it, end; + private: + Polygon3r *firstOccluderFromNextCell(); + Grid &grid; + OccludersSet::iterator it, end; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VirtualOccludersSet") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VirtualOccludersSet") #endif }; } /* namespace Freestyle */ -#endif // __GRID_H__ +#endif // __GRID_H__ diff --git a/source/blender/freestyle/intern/geometry/GridHelpers.cpp b/source/blender/freestyle/intern/geometry/GridHelpers.cpp index 09820043136..1f87bb7b76a 100644 --- a/source/blender/freestyle/intern/geometry/GridHelpers.cpp +++ b/source/blender/freestyle/intern/geometry/GridHelpers.cpp @@ -25,23 +25,23 @@ namespace Freestyle { void GridHelpers::getDefaultViewProscenium(real viewProscenium[4]) { - // Get proscenium boundary for culling - // bufferZone determines the amount by which the area processed should exceed the actual image area. - // This is intended to avoid visible artifacts generated along the proscenium edge. - // Perhaps this is no longer needed now that entire view edges are culled at once, since that theoretically - // should eliminate visible artifacts. - // To the extent it is still useful, bufferZone should be put into the UI as configurable percentage value - const real bufferZone = 0.05; - // borderZone describes a blank border outside the proscenium, but still inside the image area. - // Only intended for exposing possible artifacts along or outside the proscenium edge during debugging. - const real borderZone = 0.0; - viewProscenium[0] = g_freestyle.viewport[2] * (borderZone - bufferZone); - viewProscenium[1] = g_freestyle.viewport[2] * (1.0f - borderZone + bufferZone); - viewProscenium[2] = g_freestyle.viewport[3] * (borderZone - bufferZone); - viewProscenium[3] = g_freestyle.viewport[3] * (1.0f - borderZone + bufferZone); + // Get proscenium boundary for culling + // bufferZone determines the amount by which the area processed should exceed the actual image area. + // This is intended to avoid visible artifacts generated along the proscenium edge. + // Perhaps this is no longer needed now that entire view edges are culled at once, since that theoretically + // should eliminate visible artifacts. + // To the extent it is still useful, bufferZone should be put into the UI as configurable percentage value + const real bufferZone = 0.05; + // borderZone describes a blank border outside the proscenium, but still inside the image area. + // Only intended for exposing possible artifacts along or outside the proscenium edge during debugging. + const real borderZone = 0.0; + viewProscenium[0] = g_freestyle.viewport[2] * (borderZone - bufferZone); + viewProscenium[1] = g_freestyle.viewport[2] * (1.0f - borderZone + bufferZone); + viewProscenium[2] = g_freestyle.viewport[3] * (borderZone - bufferZone); + viewProscenium[3] = g_freestyle.viewport[3] * (1.0f - borderZone + bufferZone); } -GridHelpers::Transform::~Transform () +GridHelpers::Transform::~Transform() { } diff --git a/source/blender/freestyle/intern/geometry/GridHelpers.h b/source/blender/freestyle/intern/geometry/GridHelpers.h index 6b0f55e3d6f..8a7503350a3 100644 --- a/source/blender/freestyle/intern/geometry/GridHelpers.h +++ b/source/blender/freestyle/intern/geometry/GridHelpers.h @@ -32,7 +32,7 @@ #include "../winged_edge/WEdge.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -40,175 +40,177 @@ namespace Freestyle { namespace GridHelpers { /*! Computes the distance from a point P to a segment AB */ -template -T closestPointToSegment(const T& P, const T& A, const T& B, real& distance) +template T closestPointToSegment(const T &P, const T &A, const T &B, real &distance) { - T AB, AP, BP; - AB = B - A; - AP = P - A; - BP = P - B; - - real c1(AB * AP); - if (c1 <= 0) { - distance = AP.norm(); - return A; // A is closest point - } - - real c2(AB * AB); - if (c2 <= c1) { - distance = BP.norm(); - return B; // B is closest point - } - - real b = c1 / c2; - T Pb, PPb; - Pb = A + b * AB; - PPb = P - Pb; - - distance = PPb.norm(); - return Pb; // closest point lies on AB + T AB, AP, BP; + AB = B - A; + AP = P - A; + BP = P - B; + + real c1(AB * AP); + if (c1 <= 0) { + distance = AP.norm(); + return A; // A is closest point + } + + real c2(AB * AB); + if (c2 <= c1) { + distance = BP.norm(); + return B; // B is closest point + } + + real b = c1 / c2; + T Pb, PPb; + Pb = A + b * AB; + PPb = P - Pb; + + distance = PPb.norm(); + return Pb; // closest point lies on AB } -inline Vec3r closestPointOnPolygon(const Vec3r& point, const Polygon3r& poly) +inline Vec3r closestPointOnPolygon(const Vec3r &point, const Polygon3r &poly) { - // First cast a ray from the point onto the polygon plane - // If the ray intersects the polygon, then the intersection point - // is the closest point on the polygon - real t, u, v; - if (poly.rayIntersect(point, poly.getNormal(), t, u, v)) { - return point + poly.getNormal() * t; - } - - // Otherwise, get the nearest point on each edge, and take the closest - real distance; - Vec3r closest = closestPointToSegment(point, poly.getVertices()[2], poly.getVertices()[0], distance); - for (unsigned int i = 0; i < 2; ++i) { - real t; - Vec3r p = closestPointToSegment(point, poly.getVertices()[i], poly.getVertices()[i + 1], t); - if (t < distance) { - distance = t; - closest = p; - } - } - return closest; + // First cast a ray from the point onto the polygon plane + // If the ray intersects the polygon, then the intersection point + // is the closest point on the polygon + real t, u, v; + if (poly.rayIntersect(point, poly.getNormal(), t, u, v)) { + return point + poly.getNormal() * t; + } + + // Otherwise, get the nearest point on each edge, and take the closest + real distance; + Vec3r closest = closestPointToSegment( + point, poly.getVertices()[2], poly.getVertices()[0], distance); + for (unsigned int i = 0; i < 2; ++i) { + real t; + Vec3r p = closestPointToSegment(point, poly.getVertices()[i], poly.getVertices()[i + 1], t); + if (t < distance) { + distance = t; + closest = p; + } + } + return closest; } -inline real distancePointToPolygon(const Vec3r& point, const Polygon3r& poly) +inline real distancePointToPolygon(const Vec3r &point, const Polygon3r &poly) { - // First cast a ray from the point onto the polygon plane - // If the ray intersects the polygon, then the intersection point - // is the closest point on the polygon - real t, u, v; - if (poly.rayIntersect(point, poly.getNormal(), t, u, v)) { - return (t > 0.0) ? t : -t; - } - - // Otherwise, get the nearest point on each edge, and take the closest - real distance = GeomUtils::distPointSegment(point, poly.getVertices()[2], poly.getVertices()[0]); - for (unsigned int i = 0; i < 2; ++i) { - real t = GeomUtils::distPointSegment(point, poly.getVertices()[i], poly.getVertices()[i + 1]); - if (t < distance) { - distance = t; - } - } - return distance; + // First cast a ray from the point onto the polygon plane + // If the ray intersects the polygon, then the intersection point + // is the closest point on the polygon + real t, u, v; + if (poly.rayIntersect(point, poly.getNormal(), t, u, v)) { + return (t > 0.0) ? t : -t; + } + + // Otherwise, get the nearest point on each edge, and take the closest + real distance = GeomUtils::distPointSegment(point, poly.getVertices()[2], poly.getVertices()[0]); + for (unsigned int i = 0; i < 2; ++i) { + real t = GeomUtils::distPointSegment(point, poly.getVertices()[i], poly.getVertices()[i + 1]); + if (t < distance) { + distance = t; + } + } + return distance; } -class Transform -{ -public: - virtual ~Transform () = 0; - virtual Vec3r operator()(const Vec3r& point) const = 0; +class Transform { + public: + virtual ~Transform() = 0; + virtual Vec3r operator()(const Vec3r &point) const = 0; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridHelpers:Transform") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridHelpers:Transform") #endif }; -inline bool insideProscenium (const real proscenium[4], const Polygon3r& polygon) +inline bool insideProscenium(const real proscenium[4], const Polygon3r &polygon) { - // N.B. The bounding box check is redundant for inserting occluders into cells, because the cell selection code - // in insertOccluders has already guaranteed that the bounding boxes will overlap. - // First check the viewport edges, since they are the easiest case - // Check if the bounding box is entirely outside the proscenium - Vec3r bbMin, bbMax; - polygon.getBBox(bbMin, bbMax); - if (bbMax[0] < proscenium[0] || bbMin[0] > proscenium[1] || bbMax[1] < proscenium[2] || bbMin[1] > proscenium[3]) { - return false; - } - - Vec3r boxCenter(proscenium[0] + (proscenium[1] - proscenium[0]) / 2.0, - proscenium[2] + (proscenium[3] - proscenium[2]) / 2.0, 0.0); - Vec3r boxHalfSize((proscenium[1] - proscenium[0]) / 2.0, - (proscenium[3] - proscenium[2]) / 2.0, 1.0); - Vec3r triverts[3] = { - Vec3r(polygon.getVertices()[0][0], polygon.getVertices()[0][1], 0.0), - Vec3r(polygon.getVertices()[1][0], polygon.getVertices()[1][1], 0.0), - Vec3r(polygon.getVertices()[2][0], polygon.getVertices()[2][1], 0.0), - }; - return GeomUtils::overlapTriangleBox(boxCenter, boxHalfSize, triverts); + // N.B. The bounding box check is redundant for inserting occluders into cells, because the cell selection code + // in insertOccluders has already guaranteed that the bounding boxes will overlap. + // First check the viewport edges, since they are the easiest case + // Check if the bounding box is entirely outside the proscenium + Vec3r bbMin, bbMax; + polygon.getBBox(bbMin, bbMax); + if (bbMax[0] < proscenium[0] || bbMin[0] > proscenium[1] || bbMax[1] < proscenium[2] || + bbMin[1] > proscenium[3]) { + return false; + } + + Vec3r boxCenter(proscenium[0] + (proscenium[1] - proscenium[0]) / 2.0, + proscenium[2] + (proscenium[3] - proscenium[2]) / 2.0, + 0.0); + Vec3r boxHalfSize( + (proscenium[1] - proscenium[0]) / 2.0, (proscenium[3] - proscenium[2]) / 2.0, 1.0); + Vec3r triverts[3] = { + Vec3r(polygon.getVertices()[0][0], polygon.getVertices()[0][1], 0.0), + Vec3r(polygon.getVertices()[1][0], polygon.getVertices()[1][1], 0.0), + Vec3r(polygon.getVertices()[2][0], polygon.getVertices()[2][1], 0.0), + }; + return GeomUtils::overlapTriangleBox(boxCenter, boxHalfSize, triverts); } -inline vector enumerateVertices(const vector& fedges) +inline vector enumerateVertices(const vector &fedges) { - vector points; - // Iterate over vertices, storing projections in points - for (vector::const_iterator woe = fedges.begin(), woend = fedges.end(); woe != woend; woe++) { - points.push_back((*woe)->GetaVertex()->GetVertex()); - } - - return points; + vector points; + // Iterate over vertices, storing projections in points + for (vector::const_iterator woe = fedges.begin(), woend = fedges.end(); woe != woend; + woe++) { + points.push_back((*woe)->GetaVertex()->GetVertex()); + } + + return points; } void getDefaultViewProscenium(real viewProscenium[4]); -inline void expandProscenium (real proscenium[4], const Polygon3r& polygon) +inline void expandProscenium(real proscenium[4], const Polygon3r &polygon) { - Vec3r bbMin, bbMax; - polygon.getBBox(bbMin, bbMax); + Vec3r bbMin, bbMax; + polygon.getBBox(bbMin, bbMax); - const real epsilon = 1.0e-6; + const real epsilon = 1.0e-6; - if (bbMin[0] <= proscenium[0]) { - proscenium[0] = bbMin[0] - epsilon; - } + if (bbMin[0] <= proscenium[0]) { + proscenium[0] = bbMin[0] - epsilon; + } - if (bbMin[1] <= proscenium[2]) { - proscenium[2] = bbMin[1] - epsilon; - } + if (bbMin[1] <= proscenium[2]) { + proscenium[2] = bbMin[1] - epsilon; + } - if (bbMax[0] >= proscenium[1]) { - proscenium[1] = bbMax[0] + epsilon; - } + if (bbMax[0] >= proscenium[1]) { + proscenium[1] = bbMax[0] + epsilon; + } - if (bbMax[1] >= proscenium[3]) { - proscenium[3] = bbMax[1] + epsilon; - } + if (bbMax[1] >= proscenium[3]) { + proscenium[3] = bbMax[1] + epsilon; + } } -inline void expandProscenium (real proscenium[4], const Vec3r& point) +inline void expandProscenium(real proscenium[4], const Vec3r &point) { - const real epsilon = 1.0e-6; + const real epsilon = 1.0e-6; - if (point[0] <= proscenium[0]) { - proscenium[0] = point[0] - epsilon; - } + if (point[0] <= proscenium[0]) { + proscenium[0] = point[0] - epsilon; + } - if (point[1] <= proscenium[2]) { - proscenium[2] = point[1] - epsilon; - } + if (point[1] <= proscenium[2]) { + proscenium[2] = point[1] - epsilon; + } - if (point[0] >= proscenium[1]) { - proscenium[1] = point[0] + epsilon; - } + if (point[0] >= proscenium[1]) { + proscenium[1] = point[0] + epsilon; + } - if (point[1] >= proscenium[3]) { - proscenium[3] = point[1] + epsilon; - } + if (point[1] >= proscenium[3]) { + proscenium[3] = point[1] + epsilon; + } } -}; // GridHelpers namespace +}; // namespace GridHelpers } /* namespace Freestyle */ -#endif // __GRIDHELPERS_H__ +#endif // __GRIDHELPERS_H__ diff --git a/source/blender/freestyle/intern/geometry/HashGrid.cpp b/source/blender/freestyle/intern/geometry/HashGrid.cpp index 4011dabe1f5..bc24290c92a 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.cpp +++ b/source/blender/freestyle/intern/geometry/HashGrid.cpp @@ -25,20 +25,20 @@ namespace Freestyle { void HashGrid::clear() { - if (!_cells.empty()) { - for (GridHashTable::iterator it = _cells.begin(); it != _cells.end(); it++) { - Cell *cell = (*it).second; - delete cell; - } - _cells.clear(); - } + if (!_cells.empty()) { + for (GridHashTable::iterator it = _cells.begin(); it != _cells.end(); it++) { + Cell *cell = (*it).second; + delete cell; + } + _cells.clear(); + } - Grid::clear(); + Grid::clear(); } -void HashGrid::configure(const Vec3r& orig, const Vec3r& size, unsigned nb) +void HashGrid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) { - Grid::configure(orig, size, nb); + Grid::configure(orig, size, nb); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/HashGrid.h b/source/blender/freestyle/intern/geometry/HashGrid.h index 289079fe0d9..b1fc4824b6f 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.h +++ b/source/blender/freestyle/intern/geometry/HashGrid.h @@ -23,13 +23,13 @@ */ #if 0 -# if defined(__GNUC__) && (__GNUC__ >= 3) +# if defined(__GNUC__) && (__GNUC__ >= 3) // hash_map is not part of the C++ standard anymore; // hash_map.h has been kept though for backward compatibility -# include -# else -# include -# endif +# include +# else +# include +# endif #endif #include @@ -39,69 +39,69 @@ namespace Freestyle { /*! Defines a hash table used for searching the Cells */ -struct GridHasher -{ +struct GridHasher { #define _MUL 950706376UL #define _MOD 2147483647UL - inline size_t operator() (const Vec3u& p) const - { - size_t res = ((unsigned long) (p[0] * _MUL)) % _MOD; - res = ((res + (unsigned long) (p[1]) * _MUL)) % _MOD; - return ((res +(unsigned long) (p[2]) * _MUL)) % _MOD; - } + inline size_t operator()(const Vec3u &p) const + { + size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD; + res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD; + return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD; + } #undef _MUL #undef _MOD }; /*! Class to define a regular grid used for ray casting computations */ -class HashGrid : public Grid -{ -public: - typedef map GridHashTable; - - HashGrid() : Grid() {} - - virtual ~HashGrid() - { - clear(); - } - - /*! clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. - */ - virtual void clear(); - - /*! Sets the different parameters of the grid - * orig - * The grid origin - * size - * The grid's dimensions - * nb - * The number of cells of the grid - */ - virtual void configure(const Vec3r& orig, const Vec3r& size, unsigned nb); - - /*! returns the cell whose coordinates are pased as argument */ - virtual Cell *getCell(const Vec3u& p) - { - Cell *found_cell = NULL; - - GridHashTable::const_iterator found = _cells.find(p); - if (found != _cells.end()) - found_cell = (*found).second; - return found_cell; - } - - /*! Fills the case p with the cell iCell */ - virtual void fillCell(const Vec3u& p, Cell& cell) - { - _cells[p] = &cell; - } - -protected: - GridHashTable _cells; +class HashGrid : public Grid { + public: + typedef map GridHashTable; + + HashGrid() : Grid() + { + } + + virtual ~HashGrid() + { + clear(); + } + + /*! clears the grid + * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + */ + virtual void clear(); + + /*! Sets the different parameters of the grid + * orig + * The grid origin + * size + * The grid's dimensions + * nb + * The number of cells of the grid + */ + virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb); + + /*! returns the cell whose coordinates are pased as argument */ + virtual Cell *getCell(const Vec3u &p) + { + Cell *found_cell = NULL; + + GridHashTable::const_iterator found = _cells.find(p); + if (found != _cells.end()) + found_cell = (*found).second; + return found_cell; + } + + /*! Fills the case p with the cell iCell */ + virtual void fillCell(const Vec3u &p, Cell &cell) + { + _cells[p] = &cell; + } + + protected: + GridHashTable _cells; }; } /* namespace Freestyle */ -#endif // __HASHGRID_H__ +#endif // __HASHGRID_H__ diff --git a/source/blender/freestyle/intern/geometry/Noise.cpp b/source/blender/freestyle/intern/geometry/Noise.cpp index 0764c89c8a3..09c29025d15 100644 --- a/source/blender/freestyle/intern/geometry/Noise.cpp +++ b/source/blender/freestyle/intern/geometry/Noise.cpp @@ -31,242 +31,243 @@ namespace Freestyle { #define SCURVE(a) ((a) * (a) * (3.0 - 2.0 * (a))) #if 0 // XXX Unused -#define REALSCALE (2.0 / 65536.0) -#define NREALSCALE (2.0 / 4096.0) +# define REALSCALE (2.0 / 65536.0) +# define NREALSCALE (2.0 / 4096.0) -#define HASH3D(a, b, c) hashTable[hashTable[hashTable[(a) & 0xfff] ^ ((b) & 0xfff)] ^ ((c) & 0xfff)] -#define HASH(a, b, c) (xtab[(xtab[(xtab[(a) & 0xff] ^ (b)) & 0xff] ^ (c)) & 0xff] & 0xff) -#define INCRSUM(m, s, x, y, z) \ - ((s) * (RTable[m] * 0.5 + RTable[m + 1] * (x) + RTable[m + 2] * (y) + RTable[m + 3] * (z))) +# define HASH3D(a, b, c) hashTable[hashTable[hashTable[(a)&0xfff] ^ ((b)&0xfff)] ^ ((c)&0xfff)] +# define HASH(a, b, c) (xtab[(xtab[(xtab[(a)&0xff] ^ (b)) & 0xff] ^ (c)) & 0xff] & 0xff) +# define INCRSUM(m, s, x, y, z) \ + ((s) * (RTable[m] * 0.5 + RTable[m + 1] * (x) + RTable[m + 2] * (y) + RTable[m + 3] * (z))) -#define MAXSIZE 500 -#define NRAND() ((float)rand() / (float)RAND_MAX) +# define MAXSIZE 500 +# define NRAND() ((float)rand() / (float)RAND_MAX) #endif #define SEEDNRAND(x) (srand(x * RAND_MAX)) #define BM 0xff -#define N 0x1000 -#if 0 // XXX Unused -#define NP 12 /* 2^N */ -#define NM 0xfff +#define N 0x1000 +#if 0 // XXX Unused +# define NP 12 /* 2^N */ +# define NM 0xfff #endif #define LERP(t, a, b) ((a) + (t) * ((b) - (a))) #define SETUP(i, b0, b1, r0, r1) \ - { \ - (t) = (i) + (N); \ - (r0) = modff((t), &(u)); \ - (r1) = (r0) - 1.0; \ - (b0) = ((int)(u)) & BM; \ - (b1) = ((b0) + 1) & BM; \ - } (void)0 + { \ + (t) = (i) + (N); \ + (r0) = modff((t), &(u)); \ + (r1) = (r0)-1.0; \ + (b0) = ((int)(u)) & BM; \ + (b1) = ((b0) + 1) & BM; \ + } \ + (void)0 static void normalize2(float v[2]) { - float s; + float s; - s = sqrt(v[0] * v[0] + v[1] * v[1]); - v[0] = v[0] / s; - v[1] = v[1] / s; + s = sqrt(v[0] * v[0] + v[1] * v[1]); + v[0] = v[0] / s; + v[1] = v[1] / s; } static void normalize3(float v[3]) { - float s; + float s; - s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] = v[0] / s; - v[1] = v[1] / s; - v[2] = v[2] / s; + s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + v[0] = v[0] / s; + v[1] = v[1] / s; + v[2] = v[2] / s; } float Noise::turbulence1(float arg, float freq, float amp, unsigned oct) { - float t; - float vec; - - for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { - vec = freq * arg; - t += smoothNoise1(vec) * amp; - } - return t; + float t; + float vec; + + for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { + vec = freq * arg; + t += smoothNoise1(vec) * amp; + } + return t; } -float Noise::turbulence2(Vec2f& v, float freq, float amp, unsigned oct) +float Noise::turbulence2(Vec2f &v, float freq, float amp, unsigned oct) { - float t; - Vec2f vec; - - for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { - vec.x() = freq * v.x(); - vec.y() = freq * v.y(); - t += smoothNoise2(vec) * amp; - } - return t; + float t; + Vec2f vec; + + for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { + vec.x() = freq * v.x(); + vec.y() = freq * v.y(); + t += smoothNoise2(vec) * amp; + } + return t; } -float Noise::turbulence3(Vec3f& v, float freq, float amp, unsigned oct) +float Noise::turbulence3(Vec3f &v, float freq, float amp, unsigned oct) { - float t; - Vec3f vec; - - for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { - vec.x() = freq * v.x(); - vec.y() = freq * v.y(); - vec.z() = freq * v.z(); - t += smoothNoise3(vec) * amp; - } - return t; + float t; + Vec3f vec; + + for (t = 0; oct > 0 && freq > 0; freq *= 2, amp /= 2, --oct) { + vec.x() = freq * v.x(); + vec.y() = freq * v.y(); + vec.z() = freq * v.z(); + t += smoothNoise3(vec) * amp; + } + return t; } // Noise functions over 1, 2, and 3 dimensions float Noise::smoothNoise1(float arg) { - int bx0, bx1; - float rx0, rx1, sx, t, u, v, vec; + int bx0, bx1; + float rx0, rx1, sx, t, u, v, vec; - vec = arg; - SETUP(vec, bx0, bx1, rx0, rx1); + vec = arg; + SETUP(vec, bx0, bx1, rx0, rx1); - sx = SCURVE(rx0); + sx = SCURVE(rx0); - u = rx0 * g1[p[bx0]]; - v = rx1 * g1[p[bx1]]; + u = rx0 * g1[p[bx0]]; + v = rx1 * g1[p[bx1]]; - return LERP(sx, u, v); + return LERP(sx, u, v); } -float Noise::smoothNoise2(Vec2f& vec) +float Noise::smoothNoise2(Vec2f &vec) { - int bx0, bx1, by0, by1, b00, b10, b01, b11; - float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v; - int i, j; + int bx0, bx1, by0, by1, b00, b10, b01, b11; + float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v; + int i, j; - SETUP(vec.x(), bx0, bx1, rx0, rx1); - SETUP(vec.y(), by0, by1, ry0, ry1); + SETUP(vec.x(), bx0, bx1, rx0, rx1); + SETUP(vec.y(), by0, by1, ry0, ry1); - i = p[bx0]; - j = p[bx1]; + i = p[bx0]; + j = p[bx1]; - b00 = p[i + by0]; - b10 = p[j + by0]; - b01 = p[i + by1]; - b11 = p[j + by1]; + b00 = p[i + by0]; + b10 = p[j + by0]; + b01 = p[i + by1]; + b11 = p[j + by1]; - sx = SCURVE(rx0); - sy = SCURVE(ry0); + sx = SCURVE(rx0); + sy = SCURVE(ry0); -#define AT2(rx, ry) ((rx) * q[0] + (ry) * q[1]) +#define AT2(rx, ry) ((rx)*q[0] + (ry)*q[1]) - q = g2[b00]; - u = AT2(rx0, ry0); - q = g2[b10]; - v = AT2(rx1, ry0); - a = LERP(sx, u, v); + q = g2[b00]; + u = AT2(rx0, ry0); + q = g2[b10]; + v = AT2(rx1, ry0); + a = LERP(sx, u, v); - q = g2[b01]; - u = AT2(rx0, ry1); - q = g2[b11]; - v = AT2(rx1, ry1); - b = LERP(sx, u, v); + q = g2[b01]; + u = AT2(rx0, ry1); + q = g2[b11]; + v = AT2(rx1, ry1); + b = LERP(sx, u, v); #undef AT2 - return LERP(sy, a, b); + return LERP(sy, a, b); } -float Noise::smoothNoise3(Vec3f& vec) +float Noise::smoothNoise3(Vec3f &vec) { - int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; - float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v; - int i, j; + int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; + float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v; + int i, j; - SETUP(vec.x(), bx0, bx1, rx0, rx1); - SETUP(vec.y(), by0, by1, ry0, ry1); - SETUP(vec.z(), bz0, bz1, rz0, rz1); + SETUP(vec.x(), bx0, bx1, rx0, rx1); + SETUP(vec.y(), by0, by1, ry0, ry1); + SETUP(vec.z(), bz0, bz1, rz0, rz1); - i = p[bx0]; - j = p[bx1]; + i = p[bx0]; + j = p[bx1]; - b00 = p[i + by0]; - b10 = p[j + by0]; - b01 = p[i + by1]; - b11 = p[j + by1]; + b00 = p[i + by0]; + b10 = p[j + by0]; + b01 = p[i + by1]; + b11 = p[j + by1]; - t = SCURVE(rx0); - sy = SCURVE(ry0); - sz = SCURVE(rz0); + t = SCURVE(rx0); + sy = SCURVE(ry0); + sz = SCURVE(rz0); -#define AT3(rx, ry, rz) ((rx) * q[0] + (ry) * q[1] + (rz) * q[2]) +#define AT3(rx, ry, rz) ((rx)*q[0] + (ry)*q[1] + (rz)*q[2]) - q = g3[b00 + bz0]; - u = AT3(rx0, ry0, rz0); - q = g3[b10 + bz0]; - v = AT3(rx1, ry0, rz0); - a = LERP(t, u, v); + q = g3[b00 + bz0]; + u = AT3(rx0, ry0, rz0); + q = g3[b10 + bz0]; + v = AT3(rx1, ry0, rz0); + a = LERP(t, u, v); - q = g3[b01 + bz0]; - u = AT3(rx0, ry1, rz0); - q = g3[b11 + bz0]; - v = AT3(rx1, ry1, rz0); - b = LERP(t, u, v); + q = g3[b01 + bz0]; + u = AT3(rx0, ry1, rz0); + q = g3[b11 + bz0]; + v = AT3(rx1, ry1, rz0); + b = LERP(t, u, v); - c = LERP(sy, a, b); + c = LERP(sy, a, b); - q = g3[b00 + bz1]; - u = AT3(rx0, ry0, rz1); - q = g3[b10 + bz1]; - v = AT3(rx1, ry0, rz1); - a = LERP(t, u, v); + q = g3[b00 + bz1]; + u = AT3(rx0, ry0, rz1); + q = g3[b10 + bz1]; + v = AT3(rx1, ry0, rz1); + a = LERP(t, u, v); - q = g3[b01 + bz1]; - u = AT3(rx0, ry1, rz1); - q = g3[b11 + bz1]; - v = AT3(rx1, ry1, rz1); - b = LERP(t, u, v); + q = g3[b01 + bz1]; + u = AT3(rx0, ry1, rz1); + q = g3[b11 + bz1]; + v = AT3(rx1, ry1, rz1); + b = LERP(t, u, v); - d = LERP(sy, a, b); + d = LERP(sy, a, b); #undef AT3 - return LERP(sz, c, d); + return LERP(sz, c, d); } Noise::Noise(long seed) { - int i, j, k; - - SEEDNRAND((seed < 0) ? time(NULL) : seed); - for (i = 0 ; i < _NOISE_B ; i++) { - p[i] = i; - g1[i] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; - - for (j = 0 ; j < 2 ; j++) - g2[i][j] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; - normalize2(g2[i]); - - for (j = 0 ; j < 3 ; j++) - g3[i][j] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; - normalize3(g3[i]); - } - - while (--i) { - k = p[i]; - p[i] = p[j = rand() % _NOISE_B]; - p[j] = k; - } - - for (i = 0 ; i < _NOISE_B + 2 ; i++) { - p[_NOISE_B + i] = p[i]; - g1[_NOISE_B + i] = g1[i]; - - for (j = 0 ; j < 2 ; j++) - g2[_NOISE_B + i][j] = g2[i][j]; - - for (j = 0 ; j < 3 ; j++) - g3[_NOISE_B + i][j] = g3[i][j]; - } + int i, j, k; + + SEEDNRAND((seed < 0) ? time(NULL) : seed); + for (i = 0; i < _NOISE_B; i++) { + p[i] = i; + g1[i] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; + + for (j = 0; j < 2; j++) + g2[i][j] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; + normalize2(g2[i]); + + for (j = 0; j < 3; j++) + g3[i][j] = (float)((rand() % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; + normalize3(g3[i]); + } + + while (--i) { + k = p[i]; + p[i] = p[j = rand() % _NOISE_B]; + p[j] = k; + } + + for (i = 0; i < _NOISE_B + 2; i++) { + p[_NOISE_B + i] = p[i]; + g1[_NOISE_B + i] = g1[i]; + + for (j = 0; j < 2; j++) + g2[_NOISE_B + i][j] = g2[i][j]; + + for (j = 0; j < 3; j++) + g3[_NOISE_B + i][j] = g3[i][j]; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/Noise.h b/source/blender/freestyle/intern/geometry/Noise.h index 6787e098306..18992092b19 100644 --- a/source/blender/freestyle/intern/geometry/Noise.h +++ b/source/blender/freestyle/intern/geometry/Noise.h @@ -27,7 +27,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -39,46 +39,47 @@ namespace Freestyle { using namespace Geometry; /*! Class to provide Perlin Noise functionalities */ -class Noise -{ -public: - /*! Builds a Noise object */ - Noise(long seed = -1); +class Noise { + public: + /*! Builds a Noise object */ + Noise(long seed = -1); - /*! Destructor */ - ~Noise() {} + /*! Destructor */ + ~Noise() + { + } - /*! Returns a noise value for a 1D element */ - float turbulence1(float arg, float freq, float amp, unsigned oct = 4); + /*! Returns a noise value for a 1D element */ + float turbulence1(float arg, float freq, float amp, unsigned oct = 4); - /*! Returns a noise value for a 2D element */ - float turbulence2(Vec2f& v, float freq, float amp, unsigned oct = 4); + /*! Returns a noise value for a 2D element */ + float turbulence2(Vec2f &v, float freq, float amp, unsigned oct = 4); - /*! Returns a noise value for a 3D element */ - float turbulence3(Vec3f& v, float freq, float amp, unsigned oct = 4); + /*! Returns a noise value for a 3D element */ + float turbulence3(Vec3f &v, float freq, float amp, unsigned oct = 4); - /*! Returns a smooth noise value for a 1D element */ - float smoothNoise1(float arg); + /*! Returns a smooth noise value for a 1D element */ + float smoothNoise1(float arg); - /*! Returns a smooth noise value for a 2D element */ - float smoothNoise2(Vec2f& vec); + /*! Returns a smooth noise value for a 2D element */ + float smoothNoise2(Vec2f &vec); - /*! Returns a smooth noise value for a 3D element */ - float smoothNoise3(Vec3f& vec); + /*! Returns a smooth noise value for a 3D element */ + float smoothNoise3(Vec3f &vec); -private: - int p[_NOISE_B + _NOISE_B + 2]; - float g3[_NOISE_B + _NOISE_B + 2][3]; - float g2[_NOISE_B + _NOISE_B + 2][2]; - float g1[_NOISE_B + _NOISE_B + 2]; - /* UNUSED */ - // int start; + private: + int p[_NOISE_B + _NOISE_B + 2]; + float g3[_NOISE_B + _NOISE_B + 2][3]; + float g2[_NOISE_B + _NOISE_B + 2][2]; + float g1[_NOISE_B + _NOISE_B + 2]; + /* UNUSED */ + // int start; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Noise") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Noise") #endif }; } /* namespace Freestyle */ -#endif // __NOISE_H__ +#endif // __NOISE_H__ diff --git a/source/blender/freestyle/intern/geometry/Polygon.h b/source/blender/freestyle/intern/geometry/Polygon.h index b2359f82477..ad8a947d21d 100644 --- a/source/blender/freestyle/intern/geometry/Polygon.h +++ b/source/blender/freestyle/intern/geometry/Polygon.h @@ -28,7 +28,7 @@ #include "GeomUtils.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -37,184 +37,193 @@ namespace Freestyle { namespace Geometry { -template -class Polygon -{ -public: - inline Polygon() - { - _id = 0; - userdata = 0; - userdata2 = 0; - } - - inline Polygon(const vector& vertices) - { - _vertices = vertices; - computeBBox(); - _id = 0; - userdata = 0; - userdata2 = 0; - } - - inline Polygon(const Polygon& poly) - { - Point p; - for (typename vector::const_iterator it = poly.getVertices().begin(); - it != poly.getVertices().end(); - it++) - { - p = *it; - _vertices.push_back(p); - } - - _id = poly.getId(); - poly.getBBox(_min, _max); - userdata = 0; - userdata2 = 0; - } - - virtual ~Polygon() {} - - // - // Accessors - // - ///////////////////////////////////////////////////////////////////////////// - inline const vector& getVertices() const - { - return _vertices; - } - - inline void getBBox(Point& min, Point& max) const - { - min = _min; - max = _max; - } - - inline Point getBBoxCenter() - { - Point result; - result = (_min + _max) / 2; - return result; - } - - inline Point getCenter() - { - Point result; - for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) - result += *it; - result /= _vertices.size(); - return result; - } - - inline unsigned getId() const - { - return _id; - } - - // - // Modifiers - // - ///////////////////////////////////////////////////////////////////////////// - inline void setVertices(const vector& vertices) - { - _vertices.clear(); - Point p; - for (typename vector::const_iterator it = vertices.begin(); it != vertices.end(); it++) { - p = *it; - _vertices.push_back(p); - } - computeBBox(); - } - - inline void setId(unsigned id) - { - _id = id; - } - - // - // Other methods - // - ///////////////////////////////////////////////////////////////////////////// - inline void computeBBox() - { - if (_vertices.empty()) - return; - - _max = _vertices[0]; - _min = _vertices[0]; - - for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) { - for (unsigned int i = 0; i < Point::dim(); i++) { - if ((*it)[i] > _max[i]) - _max[i] = (*it)[i]; - if ((*it)[i] < _min[i]) - _min[i] = (*it)[i]; - } - } - } - - // FIXME Is it possible to get rid of userdatas ? - void *userdata; - void *userdata2; // Used during ray casting - -protected: - vector _vertices; - Point _min; - Point _max; - unsigned _id; +template class Polygon { + public: + inline Polygon() + { + _id = 0; + userdata = 0; + userdata2 = 0; + } + + inline Polygon(const vector &vertices) + { + _vertices = vertices; + computeBBox(); + _id = 0; + userdata = 0; + userdata2 = 0; + } + + inline Polygon(const Polygon &poly) + { + Point p; + for (typename vector::const_iterator it = poly.getVertices().begin(); + it != poly.getVertices().end(); + it++) { + p = *it; + _vertices.push_back(p); + } + + _id = poly.getId(); + poly.getBBox(_min, _max); + userdata = 0; + userdata2 = 0; + } + + virtual ~Polygon() + { + } + + // + // Accessors + // + ///////////////////////////////////////////////////////////////////////////// + inline const vector &getVertices() const + { + return _vertices; + } + + inline void getBBox(Point &min, Point &max) const + { + min = _min; + max = _max; + } + + inline Point getBBoxCenter() + { + Point result; + result = (_min + _max) / 2; + return result; + } + + inline Point getCenter() + { + Point result; + for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) + result += *it; + result /= _vertices.size(); + return result; + } + + inline unsigned getId() const + { + return _id; + } + + // + // Modifiers + // + ///////////////////////////////////////////////////////////////////////////// + inline void setVertices(const vector &vertices) + { + _vertices.clear(); + Point p; + for (typename vector::const_iterator it = vertices.begin(); it != vertices.end(); + it++) { + p = *it; + _vertices.push_back(p); + } + computeBBox(); + } + + inline void setId(unsigned id) + { + _id = id; + } + + // + // Other methods + // + ///////////////////////////////////////////////////////////////////////////// + inline void computeBBox() + { + if (_vertices.empty()) + return; + + _max = _vertices[0]; + _min = _vertices[0]; + + for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) { + for (unsigned int i = 0; i < Point::dim(); i++) { + if ((*it)[i] > _max[i]) + _max[i] = (*it)[i]; + if ((*it)[i] < _min[i]) + _min[i] = (*it)[i]; + } + } + } + + // FIXME Is it possible to get rid of userdatas ? + void *userdata; + void *userdata2; // Used during ray casting + + protected: + vector _vertices; + Point _min; + Point _max; + unsigned _id; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Geometry:Polygon") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Geometry:Polygon") #endif }; - // // Polygon3r class // /////////////////////////////////////////////////////////////////////////////// -class Polygon3r : public Polygon -{ -public: - inline Polygon3r() : Polygon() {} - - inline Polygon3r(const vector& vertices, const Vec3r& normal) : Polygon(vertices) - { - setNormal(normal); - } - - inline Polygon3r(const Polygon3r& poly) : Polygon(poly), _normal(poly._normal) {} - - virtual ~Polygon3r() {} - - void setNormal(const Vec3r& normal) - { - _normal = normal; - } - - inline Vec3r getNormal() const - { - return _normal; - } - - /*! Check whether the Polygon intersects with the ray or not */ - inline bool rayIntersect(const Vec3r& orig, const Vec3r& dir, real& t, real& u, real& v, - real epsilon = M_EPSILON) const - { +class Polygon3r : public Polygon { + public: + inline Polygon3r() : Polygon() + { + } + + inline Polygon3r(const vector &vertices, const Vec3r &normal) : Polygon(vertices) + { + setNormal(normal); + } + + inline Polygon3r(const Polygon3r &poly) : Polygon(poly), _normal(poly._normal) + { + } + + virtual ~Polygon3r() + { + } + + void setNormal(const Vec3r &normal) + { + _normal = normal; + } + + inline Vec3r getNormal() const + { + return _normal; + } + + /*! Check whether the Polygon intersects with the ray or not */ + inline bool rayIntersect(const Vec3r &orig, + const Vec3r &dir, + real &t, + real &u, + real &v, + real epsilon = M_EPSILON) const + { #if 0 - if (_vertices.size() < 3) - return false; + if (_vertices.size() < 3) + return false; #endif - return GeomUtils::intersectRayTriangle(orig, dir, _vertices[0], _vertices[1], _vertices[2], t, u, v, epsilon); - } + return GeomUtils::intersectRayTriangle( + orig, dir, _vertices[0], _vertices[1], _vertices[2], t, u, v, epsilon); + } -private: - Vec3r _normal; + private: + Vec3r _normal; }; -} // end of namespace Geometry +} // end of namespace Geometry } /* namespace Freestyle */ -#endif // __POLYGON_H__ +#endif // __POLYGON_H__ diff --git a/source/blender/freestyle/intern/geometry/SweepLine.h b/source/blender/freestyle/intern/geometry/SweepLine.h index d7e3badbe3a..04797bc8998 100644 --- a/source/blender/freestyle/intern/geometry/SweepLine.h +++ b/source/blender/freestyle/intern/geometry/SweepLine.h @@ -26,314 +26,318 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { /*! Class to define the intersection berween two segments*/ -template -class Intersection -{ -public: - template - Intersection(EdgeClass *eA, real ta, EdgeClass *eB, real tb) - { - EdgeA = eA; - EdgeB = eB; - tA = ta; - tB = tb; - userdata = 0; - } - - Intersection(const Intersection& iBrother) - { - EdgeA = iBrother.EdgeA; - EdgeB = iBrother.EdgeB; - tA = iBrother.tA; - tB = iBrother.tB; - userdata = 0; - } - - /*! returns the parameter giving the intersection, for the edge iEdge */ - real getParameter(Edge *iEdge) - { - if (iEdge == EdgeA) - return tA; - if (iEdge == EdgeB) - return tB; - return 0; - } - -public: - void *userdata; // FIXME - - Edge *EdgeA; // first segment - Edge *EdgeB; // second segment - real tA; // parameter defining the intersection point with respect to the segment EdgeA. - real tB; // parameter defining the intersection point with respect to the segment EdgeB. +template class Intersection { + public: + template Intersection(EdgeClass *eA, real ta, EdgeClass *eB, real tb) + { + EdgeA = eA; + EdgeB = eB; + tA = ta; + tB = tb; + userdata = 0; + } + + Intersection(const Intersection &iBrother) + { + EdgeA = iBrother.EdgeA; + EdgeB = iBrother.EdgeB; + tA = iBrother.tA; + tB = iBrother.tB; + userdata = 0; + } + + /*! returns the parameter giving the intersection, for the edge iEdge */ + real getParameter(Edge *iEdge) + { + if (iEdge == EdgeA) + return tA; + if (iEdge == EdgeB) + return tB; + return 0; + } + + public: + void *userdata; // FIXME + + Edge *EdgeA; // first segment + Edge *EdgeB; // second segment + real tA; // parameter defining the intersection point with respect to the segment EdgeA. + real tB; // parameter defining the intersection point with respect to the segment EdgeB. #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Intersection") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Intersection") #endif }; #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4521) // disable warning C4521: multiple copy constructors specified +# pragma warning(push) +# pragma warning(disable : 4521) // disable warning C4521: multiple copy constructors specified #endif -template -class Segment -{ -public: - Segment() - { - } - - Segment(T& s, const Point& iA, const Point& iB) - { - _edge = s; - if (iA < iB) { - A = iA; - B = iB; - _order = true; - } - else { - A = iB; - B = iA; - _order = false; - } - } - - Segment(Segment& iBrother) - { - _edge = iBrother.edge(); - A = iBrother.A; - B = iBrother.B; - _Intersections = iBrother._Intersections; - _order = iBrother._order; - } - - Segment(const Segment& iBrother) - { - _edge = iBrother._edge; - A = iBrother.A; - B = iBrother.B; - _Intersections = iBrother._Intersections; - _order = iBrother._order; - } - - ~Segment() - { - _Intersections.clear(); - } - - inline Point operator[](const unsigned short int& i) const - { - return (i % 2 == 0) ? A : B; - } - - inline bool operator==(const Segment& iBrother) - { - if (_edge == iBrother._edge) - return true; - return false; - } - - /* Adds an intersection for this segment */ - inline void AddIntersection(Intersection > *i) - { - _Intersections.push_back(i); - } - - /*! Checks for a common vertex with another edge */ - inline bool CommonVertex(const Segment& S, Point& CP) - { - if ((A == S[0]) || (A == S[1])) { - CP = A; - return true; - } - if ((B == S[0]) || (B == S[1])) { - CP = B; - return true; - } - return false; - } - - inline vector >*>& intersections() - { - return _Intersections; - } - - inline bool order() - { - return _order; - } - - inline T& edge() - { - return _edge; - } - -private: - T _edge; - Point A; - Point B; - std::vector >*> _Intersections; // list of intersections parameters - bool _order; // true if A and B are in the same order than _edge.A and _edge.B. false otherwise. +template class Segment { + public: + Segment() + { + } + + Segment(T &s, const Point &iA, const Point &iB) + { + _edge = s; + if (iA < iB) { + A = iA; + B = iB; + _order = true; + } + else { + A = iB; + B = iA; + _order = false; + } + } + + Segment(Segment &iBrother) + { + _edge = iBrother.edge(); + A = iBrother.A; + B = iBrother.B; + _Intersections = iBrother._Intersections; + _order = iBrother._order; + } + + Segment(const Segment &iBrother) + { + _edge = iBrother._edge; + A = iBrother.A; + B = iBrother.B; + _Intersections = iBrother._Intersections; + _order = iBrother._order; + } + + ~Segment() + { + _Intersections.clear(); + } + + inline Point operator[](const unsigned short int &i) const + { + return (i % 2 == 0) ? A : B; + } + + inline bool operator==(const Segment &iBrother) + { + if (_edge == iBrother._edge) + return true; + return false; + } + + /* Adds an intersection for this segment */ + inline void AddIntersection(Intersection> *i) + { + _Intersections.push_back(i); + } + + /*! Checks for a common vertex with another edge */ + inline bool CommonVertex(const Segment &S, Point &CP) + { + if ((A == S[0]) || (A == S[1])) { + CP = A; + return true; + } + if ((B == S[0]) || (B == S[1])) { + CP = B; + return true; + } + return false; + } + + inline vector> *> &intersections() + { + return _Intersections; + } + + inline bool order() + { + return _order; + } + + inline T &edge() + { + return _edge; + } + + private: + T _edge; + Point A; + Point B; + std::vector> *> + _Intersections; // list of intersections parameters + bool _order; // true if A and B are in the same order than _edge.A and _edge.B. false otherwise. #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Segment") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Segment") #endif }; #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif /*! defines a binary function that can be overload by the user to specify at each condition the intersection * between 2 edges must be computed */ -template -struct binary_rule -{ - binary_rule() {} - template binary_rule(const binary_rule& brother) {} - virtual ~binary_rule() {} - - virtual bool operator()(T1&, T2&) - { - return true; - } +template struct binary_rule { + binary_rule() + { + } + template binary_rule(const binary_rule &brother) + { + } + virtual ~binary_rule() + { + } + + virtual bool operator()(T1 &, T2 &) + { + return true; + } }; - -template -class SweepLine -{ -public: - SweepLine() {} - ~SweepLine() - { - for (typename vector >*>::iterator i = _Intersections.begin(), - iend = _Intersections.end(); - i != iend; - i++) - { - delete (*i); - } - } - - inline void process(Point& p, vector*>& segments, +template class SweepLine { + public: + SweepLine() + { + } + ~SweepLine() + { + for (typename vector> *>::iterator i = _Intersections.begin(), + iend = _Intersections.end(); + i != iend; + i++) { + delete (*i); + } + } + + inline void process(Point &p, + vector *> &segments, #if 0 - binary_rule,Segment >& binrule = \ - binary_rule, Segment >(), + binary_rule,Segment >& binrule = \ + binary_rule, Segment >(), #else - binary_rule, Segment >& binrule, + binary_rule, Segment> &binrule, #endif - real epsilon = M_EPSILON) - { - // first we remove the segments that need to be removed and then we add the segments to add - vector*> toadd; - typename vector*>::iterator s, send; - for (s = segments.begin(), send = segments.end(); s != send; s++) { - if (p == (*(*s))[0]) - toadd.push_back((*s)); - else - remove((*s)); - } - for (s = toadd.begin(), send = toadd.end(); s != send; s++) { - add((*s), binrule, epsilon); - } - } - - inline void add(Segment *S, + real epsilon = M_EPSILON) + { + // first we remove the segments that need to be removed and then we add the segments to add + vector *> toadd; + typename vector *>::iterator s, send; + for (s = segments.begin(), send = segments.end(); s != send; s++) { + if (p == (*(*s))[0]) + toadd.push_back((*s)); + else + remove((*s)); + } + for (s = toadd.begin(), send = toadd.end(); s != send; s++) { + add((*s), binrule, epsilon); + } + } + + inline void add(Segment *S, #if 0 - binary_rule, Segment >& binrule = \ - binary_rule, Segment >(), + binary_rule, Segment >& binrule = \ + binary_rule, Segment >(), #else - binary_rule, Segment >& binrule, + binary_rule, Segment> &binrule, #endif - real epsilon) - { - real t, u; - Point CP; - Vec2r v0, v1, v2, v3; - if (true == S->order()) { - v0[0] = ((*S)[0])[0]; - v0[1] = ((*S)[0])[1]; - v1[0] = ((*S)[1])[0]; - v1[1] = ((*S)[1])[1]; - } - else { - v1[0] = ((*S)[0])[0]; - v1[1] = ((*S)[0])[1]; - v0[0] = ((*S)[1])[0]; - v0[1] = ((*S)[1])[1]; - } - for (typename std::list *>::iterator s = _set.begin(), send = _set.end(); s != send; s++) { - Segment *currentS = (*s); - if (true != binrule(*S, *currentS)) - continue; - - if (true == currentS->order()) { - v2[0] = ((*currentS)[0])[0]; - v2[1] = ((*currentS)[0])[1]; - v3[0] = ((*currentS)[1])[0]; - v3[1] = ((*currentS)[1])[1]; - } - else { - v3[0] = ((*currentS)[0])[0]; - v3[1] = ((*currentS)[0])[1]; - v2[0] = ((*currentS)[1])[0]; - v2[1] = ((*currentS)[1])[1]; - } - if (S->CommonVertex(*currentS, CP)) - continue; // the two edges have a common vertex->no need to check - - if (GeomUtils::intersect2dSeg2dSegParametric(v0, v1, v2, v3, t, u, epsilon) == GeomUtils::DO_INTERSECT) { - // create the intersection - Intersection > *inter = new Intersection >(S, t, currentS, u); - // add it to the intersections list - _Intersections.push_back(inter); - // add this intersection to the first edge intersections list - S->AddIntersection(inter); - // add this intersection to the second edge intersections list - currentS->AddIntersection(inter); - } - } - // add the added segment to the list of active segments - _set.push_back(S); - } - - inline void remove(Segment *s) - { - if (s->intersections().size() > 0) - _IntersectedEdges.push_back(s); - _set.remove(s); - } - - vector *>& intersectedEdges() - { - return _IntersectedEdges; - } - - vector >*>& intersections() - { - return _Intersections; - } - -private: - std::list *> _set; // set of active edges for a given position of the sweep line - std::vector *> _IntersectedEdges; // the list of intersected edges - std::vector > *> _Intersections; // the list of all intersections. + real epsilon) + { + real t, u; + Point CP; + Vec2r v0, v1, v2, v3; + if (true == S->order()) { + v0[0] = ((*S)[0])[0]; + v0[1] = ((*S)[0])[1]; + v1[0] = ((*S)[1])[0]; + v1[1] = ((*S)[1])[1]; + } + else { + v1[0] = ((*S)[0])[0]; + v1[1] = ((*S)[0])[1]; + v0[0] = ((*S)[1])[0]; + v0[1] = ((*S)[1])[1]; + } + for (typename std::list *>::iterator s = _set.begin(), send = _set.end(); + s != send; + s++) { + Segment *currentS = (*s); + if (true != binrule(*S, *currentS)) + continue; + + if (true == currentS->order()) { + v2[0] = ((*currentS)[0])[0]; + v2[1] = ((*currentS)[0])[1]; + v3[0] = ((*currentS)[1])[0]; + v3[1] = ((*currentS)[1])[1]; + } + else { + v3[0] = ((*currentS)[0])[0]; + v3[1] = ((*currentS)[0])[1]; + v2[0] = ((*currentS)[1])[0]; + v2[1] = ((*currentS)[1])[1]; + } + if (S->CommonVertex(*currentS, CP)) + continue; // the two edges have a common vertex->no need to check + + if (GeomUtils::intersect2dSeg2dSegParametric(v0, v1, v2, v3, t, u, epsilon) == + GeomUtils::DO_INTERSECT) { + // create the intersection + Intersection> *inter = new Intersection>( + S, t, currentS, u); + // add it to the intersections list + _Intersections.push_back(inter); + // add this intersection to the first edge intersections list + S->AddIntersection(inter); + // add this intersection to the second edge intersections list + currentS->AddIntersection(inter); + } + } + // add the added segment to the list of active segments + _set.push_back(S); + } + + inline void remove(Segment *s) + { + if (s->intersections().size() > 0) + _IntersectedEdges.push_back(s); + _set.remove(s); + } + + vector *> &intersectedEdges() + { + return _IntersectedEdges; + } + + vector> *> &intersections() + { + return _Intersections; + } + + private: + std::list *> + _set; // set of active edges for a given position of the sweep line + std::vector *> _IntersectedEdges; // the list of intersected edges + std::vector> *> _Intersections; // the list of all intersections. #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SweepLine") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SweepLine") #endif }; } /* namespace Freestyle */ -#endif // __SWEEPLINE_H__ +#endif // __SWEEPLINE_H__ diff --git a/source/blender/freestyle/intern/geometry/VecMat.h b/source/blender/freestyle/intern/geometry/VecMat.h index 2dd5c3f6718..22fcd3aef41 100644 --- a/source/blender/freestyle/intern/geometry/VecMat.h +++ b/source/blender/freestyle/intern/geometry/VecMat.h @@ -27,7 +27,7 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -35,15 +35,15 @@ namespace Freestyle { namespace VecMat { namespace Internal { - template - struct is_false {}; +template struct is_false { +}; - template <> - struct is_false - { - static inline void ensure() {} - }; -} // end of namespace Internal +template<> struct is_false { + static inline void ensure() + { + } +}; +} // end of namespace Internal // // Vector class @@ -52,571 +52,566 @@ namespace Internal { // ///////////////////////////////////////////////////////////////////////////// -template -class Vec -{ -public: - typedef T value_type; - - // constructors - inline Vec() - { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] = 0; - } - - ~Vec() - { - Internal::is_false<(N == 0)>::ensure(); - } - - template - explicit inline Vec(const U tab[N]) - { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] = (T)tab[i]; - } - - template - explicit inline Vec(const std::vector& tab) - { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] = (T)tab[i]; - } - - template - explicit inline Vec(const Vec& v) - { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] = (T)v[i]; - } - - // accessors - inline value_type operator[](const unsigned i) const - { - return this->_coord[i]; - } - - inline value_type& operator[](const unsigned i) - { - return this->_coord[i]; - } - - static inline unsigned dim() - { - return N; - } - - // various useful methods - inline value_type norm() const - { - return (T)sqrt((float)squareNorm()); - } - - inline value_type squareNorm() const - { - return (*this) * (*this); - } - - inline Vec& normalize() - { - value_type n = norm(); - for (unsigned int i = 0; i < N; i++) - this->_coord[i] /= n; - return *this; - } - - inline Vec& normalizeSafe() - { - value_type n = norm(); - if (n) { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] /= n; - } - return *this; - } - - // classical operators - inline Vec operator+(const Vec& v) const - { - Vec res(v); - res += *this; - return res; - } - - inline Vec operator-(const Vec& v) const - { - Vec res(*this); - res -= v; - return res; - } - - inline Vec operator*(const typename Vec::value_type r) const - { - Vec res(*this); - res *= r; - return res; - } - - inline Vec operator/(const typename Vec::value_type r) const - { - Vec res(*this); - if (r) - res /= r; - return res; - } - - // dot product - inline value_type operator*(const Vec& v) const - { - value_type sum = 0; - for (unsigned int i = 0; i < N; i++) - sum += (*this)[i] * v[i]; - return sum; - } - - template - inline Vec& operator=(const Vec& v) - { - if (this != &v) { - for (unsigned int i = 0; i < N; i++) - this->_coord[i] = (T)v[i]; - } - return *this; - } - - template - inline Vec& operator+=(const Vec& v) - { - for (unsigned int i = 0 ; i < N; i++) - this->_coord[i] += (T)v[i]; - return *this; - } - - template - inline Vec& operator-=(const Vec& v) - { - for (unsigned int i = 0 ; i < N; i++) - this->_coord[i] -= (T)v[i]; - return *this; - } - - template - inline Vec& operator*=(const U r) - { - for (unsigned int i = 0 ; i < N; i++) - this->_coord[i] *= r; - return *this; - } - - template - inline Vec& operator/=(const U r) - { - if (r) { - for (unsigned int i = 0 ; i < N; i++) - this->_coord[i] /= r; - } - return *this; - } - - inline bool operator==(const Vec& v) const - { - for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] != v[i]) - return false; - } - return true; - } - - inline bool operator!=(const Vec& v) const - { - for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] != v[i]) - return true; - } - return false; - } - - inline bool operator<(const Vec& v) const - { - for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] < v[i]) - return true; - if (this->_coord[i] > v[i]) - return false; - if (this->_coord[i] == v[i]) - continue; - } - return false; - } - - inline bool operator>(const Vec& v) const - { - for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] > v[i]) - return true; - if (this->_coord[i] < v[i]) - return false; - if (this->_coord[i] == v[i]) - continue; - } - return false; - } - -protected: - value_type _coord[N]; - enum { - _dim = N, - }; +template class Vec { + public: + typedef T value_type; + + // constructors + inline Vec() + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] = 0; + } + + ~Vec() + { + Internal::is_false<(N == 0)>::ensure(); + } + + template explicit inline Vec(const U tab[N]) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] = (T)tab[i]; + } + + template explicit inline Vec(const std::vector &tab) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] = (T)tab[i]; + } + + template explicit inline Vec(const Vec &v) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] = (T)v[i]; + } + + // accessors + inline value_type operator[](const unsigned i) const + { + return this->_coord[i]; + } + + inline value_type &operator[](const unsigned i) + { + return this->_coord[i]; + } + + static inline unsigned dim() + { + return N; + } + + // various useful methods + inline value_type norm() const + { + return (T)sqrt((float)squareNorm()); + } + + inline value_type squareNorm() const + { + return (*this) * (*this); + } + + inline Vec &normalize() + { + value_type n = norm(); + for (unsigned int i = 0; i < N; i++) + this->_coord[i] /= n; + return *this; + } + + inline Vec &normalizeSafe() + { + value_type n = norm(); + if (n) { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] /= n; + } + return *this; + } + + // classical operators + inline Vec operator+(const Vec &v) const + { + Vec res(v); + res += *this; + return res; + } + + inline Vec operator-(const Vec &v) const + { + Vec res(*this); + res -= v; + return res; + } + + inline Vec operator*(const typename Vec::value_type r) const + { + Vec res(*this); + res *= r; + return res; + } + + inline Vec operator/(const typename Vec::value_type r) const + { + Vec res(*this); + if (r) + res /= r; + return res; + } + + // dot product + inline value_type operator*(const Vec &v) const + { + value_type sum = 0; + for (unsigned int i = 0; i < N; i++) + sum += (*this)[i] * v[i]; + return sum; + } + + template inline Vec &operator=(const Vec &v) + { + if (this != &v) { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] = (T)v[i]; + } + return *this; + } + + template inline Vec &operator+=(const Vec &v) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] += (T)v[i]; + return *this; + } + + template inline Vec &operator-=(const Vec &v) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] -= (T)v[i]; + return *this; + } + + template inline Vec &operator*=(const U r) + { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] *= r; + return *this; + } + + template inline Vec &operator/=(const U r) + { + if (r) { + for (unsigned int i = 0; i < N; i++) + this->_coord[i] /= r; + } + return *this; + } + + inline bool operator==(const Vec &v) const + { + for (unsigned int i = 0; i < N; i++) { + if (this->_coord[i] != v[i]) + return false; + } + return true; + } + + inline bool operator!=(const Vec &v) const + { + for (unsigned int i = 0; i < N; i++) { + if (this->_coord[i] != v[i]) + return true; + } + return false; + } + + inline bool operator<(const Vec &v) const + { + for (unsigned int i = 0; i < N; i++) { + if (this->_coord[i] < v[i]) + return true; + if (this->_coord[i] > v[i]) + return false; + if (this->_coord[i] == v[i]) + continue; + } + return false; + } + + inline bool operator>(const Vec &v) const + { + for (unsigned int i = 0; i < N; i++) { + if (this->_coord[i] > v[i]) + return true; + if (this->_coord[i] < v[i]) + return false; + if (this->_coord[i] == v[i]) + continue; + } + return false; + } + + protected: + value_type _coord[N]; + enum { + _dim = N, + }; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Vec") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Vec") #endif }; - // // Vec2 class (2D Vector) // - T: value type // ///////////////////////////////////////////////////////////////////////////// -template -class Vec2 : public Vec -{ -public: - typedef typename Vec::value_type value_type; - - inline Vec2() : Vec() {} - - template - explicit inline Vec2(const U tab[2]) : Vec(tab) {} - - template - explicit inline Vec2(const std::vector& tab) : Vec(tab) {} - - template - inline Vec2(const Vec& v) : Vec(v) {} - - inline Vec2(const value_type x, const value_type y = 0) : Vec() - { - this->_coord[0] = (T)x; - this->_coord[1] = (T)y; - } - - inline value_type x() const - { - return this->_coord[0]; - } - - inline value_type& x() - { - return this->_coord[0]; - } - - inline value_type y() const - { - return this->_coord[1]; - } - - inline value_type& y() - { - return this->_coord[1]; - } - - inline void setX(const value_type v) - { - this->_coord[0] = v; - } - - inline void setY(const value_type v) - { - this->_coord[1] = v; - } - - // FIXME: hack swig -- no choice - inline Vec2 operator+(const Vec2& v) const - { - Vec2 res(v); - res += *this; - return res; - } - - inline Vec2 operator-(const Vec2& v) const - { - Vec2 res(*this); - res -= v; - return res; - } - - inline Vec2 operator*(const value_type r) const - { - Vec2 res(*this); - res *= r; - return res; - } - - inline Vec2 operator/(const value_type r) const - { - Vec2 res(*this); - if (r) - res /= r; - return res; - } - - // dot product - inline value_type operator*(const Vec2& v) const - { - value_type sum = 0; - for (unsigned int i = 0; i < 2; i++) - sum += (*this)[i] * v[i]; - return sum; - } +template class Vec2 : public Vec { + public: + typedef typename Vec::value_type value_type; + + inline Vec2() : Vec() + { + } + + template explicit inline Vec2(const U tab[2]) : Vec(tab) + { + } + + template explicit inline Vec2(const std::vector &tab) : Vec(tab) + { + } + + template inline Vec2(const Vec &v) : Vec(v) + { + } + + inline Vec2(const value_type x, const value_type y = 0) : Vec() + { + this->_coord[0] = (T)x; + this->_coord[1] = (T)y; + } + + inline value_type x() const + { + return this->_coord[0]; + } + + inline value_type &x() + { + return this->_coord[0]; + } + + inline value_type y() const + { + return this->_coord[1]; + } + + inline value_type &y() + { + return this->_coord[1]; + } + + inline void setX(const value_type v) + { + this->_coord[0] = v; + } + + inline void setY(const value_type v) + { + this->_coord[1] = v; + } + + // FIXME: hack swig -- no choice + inline Vec2 operator+(const Vec2 &v) const + { + Vec2 res(v); + res += *this; + return res; + } + + inline Vec2 operator-(const Vec2 &v) const + { + Vec2 res(*this); + res -= v; + return res; + } + + inline Vec2 operator*(const value_type r) const + { + Vec2 res(*this); + res *= r; + return res; + } + + inline Vec2 operator/(const value_type r) const + { + Vec2 res(*this); + if (r) + res /= r; + return res; + } + + // dot product + inline value_type operator*(const Vec2 &v) const + { + value_type sum = 0; + for (unsigned int i = 0; i < 2; i++) + sum += (*this)[i] * v[i]; + return sum; + } }; - // // HVec3 class (3D Vector in homogeneous coordinates) // - T: value type // ///////////////////////////////////////////////////////////////////////////// -template -class HVec3 : public Vec -{ -public: - typedef typename Vec::value_type value_type; - - inline HVec3() : Vec() {} - - template - explicit inline HVec3(const U tab[4]) : Vec(tab) {} - - template - explicit inline HVec3(const std::vector& tab) : Vec(tab) {} - - template - inline HVec3(const Vec& v) : Vec(v) {} - - inline HVec3(const value_type sx, const value_type sy = 0, const value_type sz = 0, const value_type s = 1) - { - this->_coord[0] = sx; - this->_coord[1] = sy; - this->_coord[2] = sz; - this->_coord[3] = s; - } - - template - inline HVec3(const Vec& sv, const U s = 1) - { - this->_coord[0] = (T)sv[0]; - this->_coord[1] = (T)sv[1]; - this->_coord[2] = (T)sv[2]; - this->_coord[3] = (T)s; - } - - inline value_type sx() const - { - return this->_coord[0]; - } - - inline value_type& sx() - { - return this->_coord[0]; - } - - inline value_type sy() const - { - return this->_coord[1]; - } - - inline value_type& sy() - { - return this->_coord[1]; - } - - inline value_type sz() const - { - return this->_coord[2]; - } - - inline value_type& sz() - { - return this->_coord[2]; - } - - inline value_type s() const - { - return this->_coord[3]; - } - - inline value_type& s() - { - return this->_coord[3]; - } - - // Acces to non-homogeneous coordinates in 3D - inline value_type x() const - { - return this->_coord[0] / this->_coord[3]; - } - - inline value_type y() const - { - return this->_coord[1] / this->_coord[3]; - } - - inline value_type z() const - { - return this->_coord[2] / this->_coord[3]; - } +template class HVec3 : public Vec { + public: + typedef typename Vec::value_type value_type; + + inline HVec3() : Vec() + { + } + + template explicit inline HVec3(const U tab[4]) : Vec(tab) + { + } + + template explicit inline HVec3(const std::vector &tab) : Vec(tab) + { + } + + template inline HVec3(const Vec &v) : Vec(v) + { + } + + inline HVec3(const value_type sx, + const value_type sy = 0, + const value_type sz = 0, + const value_type s = 1) + { + this->_coord[0] = sx; + this->_coord[1] = sy; + this->_coord[2] = sz; + this->_coord[3] = s; + } + + template inline HVec3(const Vec &sv, const U s = 1) + { + this->_coord[0] = (T)sv[0]; + this->_coord[1] = (T)sv[1]; + this->_coord[2] = (T)sv[2]; + this->_coord[3] = (T)s; + } + + inline value_type sx() const + { + return this->_coord[0]; + } + + inline value_type &sx() + { + return this->_coord[0]; + } + + inline value_type sy() const + { + return this->_coord[1]; + } + + inline value_type &sy() + { + return this->_coord[1]; + } + + inline value_type sz() const + { + return this->_coord[2]; + } + + inline value_type &sz() + { + return this->_coord[2]; + } + + inline value_type s() const + { + return this->_coord[3]; + } + + inline value_type &s() + { + return this->_coord[3]; + } + + // Acces to non-homogeneous coordinates in 3D + inline value_type x() const + { + return this->_coord[0] / this->_coord[3]; + } + + inline value_type y() const + { + return this->_coord[1] / this->_coord[3]; + } + + inline value_type z() const + { + return this->_coord[2] / this->_coord[3]; + } }; - // // Vec3 class (3D Vec) // - T: value type // ///////////////////////////////////////////////////////////////////////////// -template -class Vec3 : public Vec -{ -public: - typedef typename Vec::value_type value_type; - - inline Vec3() : Vec() {} - - template - explicit inline Vec3(const U tab[3]) : Vec(tab) {} - - template - explicit inline Vec3(const std::vector& tab) : Vec(tab) {} - - template - inline Vec3(const Vec& v) : Vec(v) {} - - template - inline Vec3(const HVec3& v) - { - this->_coord[0] = (T)v.x(); - this->_coord[1] = (T)v.y(); - this->_coord[2] = (T)v.z(); - } - - inline Vec3(const value_type x, const value_type y = 0, const value_type z = 0) : Vec() - { - this->_coord[0] = x; - this->_coord[1] = y; - this->_coord[2] = z; - } - - inline value_type x() const - { - return this->_coord[0]; - } - - inline value_type& x() - { - return this->_coord[0]; - } - - inline value_type y() const - { - return this->_coord[1]; - } - - inline value_type& y() - { - return this->_coord[1]; - } - - inline value_type z() const - { - return this->_coord[2]; - } - - inline value_type& z() - { - return this->_coord[2]; - } - - inline void setX(const value_type v) - { - this->_coord[0] = v; - } - - inline void setY(const value_type v) - { - this->_coord[1] = v; - } - - inline void setZ(const value_type v) - { - this->_coord[2] = v; - } - - // classical operators - // FIXME: hack swig -- no choice - inline Vec3 operator+(const Vec3& v) const - { - Vec3 res(v); - res += *this; - return res; - } - - inline Vec3 operator-(const Vec3& v) const - { - Vec3 res(*this); - res -= v; - return res; - } - - inline Vec3 operator*(const value_type r) const - { - Vec3 res(*this); - res *= r; - return res; - } - - inline Vec3 operator/(const value_type r) const - { - Vec3 res(*this); - if (r) - res /= r; - return res; - } - - // dot product - inline value_type operator*(const Vec3& v) const - { - value_type sum = 0; - for (unsigned int i = 0; i < 3; i++) - sum += (*this)[i] * v[i]; - return sum; - } - - // cross product for 3D Vectors - // FIXME: hack swig -- no choice - inline Vec3 operator^(const Vec3& v) const - { - Vec3 res((*this)[1] * v[2] - (*this)[2] * v[1], - (*this)[2] * v[0] - (*this)[0] * v[2], - (*this)[0] * v[1] - (*this)[1] * v[0]); - return res; - } - - // cross product for 3D Vectors - template - inline Vec3 operator^(const Vec& v) const - { - Vec3 res((*this)[1] * v[2] - (*this)[2] * v[1], - (*this)[2] * v[0] - (*this)[0] * v[2], - (*this)[0] * v[1] - (*this)[1] * v[0]); - return res; - } +template class Vec3 : public Vec { + public: + typedef typename Vec::value_type value_type; + + inline Vec3() : Vec() + { + } + + template explicit inline Vec3(const U tab[3]) : Vec(tab) + { + } + + template explicit inline Vec3(const std::vector &tab) : Vec(tab) + { + } + + template inline Vec3(const Vec &v) : Vec(v) + { + } + + template inline Vec3(const HVec3 &v) + { + this->_coord[0] = (T)v.x(); + this->_coord[1] = (T)v.y(); + this->_coord[2] = (T)v.z(); + } + + inline Vec3(const value_type x, const value_type y = 0, const value_type z = 0) : Vec() + { + this->_coord[0] = x; + this->_coord[1] = y; + this->_coord[2] = z; + } + + inline value_type x() const + { + return this->_coord[0]; + } + + inline value_type &x() + { + return this->_coord[0]; + } + + inline value_type y() const + { + return this->_coord[1]; + } + + inline value_type &y() + { + return this->_coord[1]; + } + + inline value_type z() const + { + return this->_coord[2]; + } + + inline value_type &z() + { + return this->_coord[2]; + } + + inline void setX(const value_type v) + { + this->_coord[0] = v; + } + + inline void setY(const value_type v) + { + this->_coord[1] = v; + } + + inline void setZ(const value_type v) + { + this->_coord[2] = v; + } + + // classical operators + // FIXME: hack swig -- no choice + inline Vec3 operator+(const Vec3 &v) const + { + Vec3 res(v); + res += *this; + return res; + } + + inline Vec3 operator-(const Vec3 &v) const + { + Vec3 res(*this); + res -= v; + return res; + } + + inline Vec3 operator*(const value_type r) const + { + Vec3 res(*this); + res *= r; + return res; + } + + inline Vec3 operator/(const value_type r) const + { + Vec3 res(*this); + if (r) + res /= r; + return res; + } + + // dot product + inline value_type operator*(const Vec3 &v) const + { + value_type sum = 0; + for (unsigned int i = 0; i < 3; i++) + sum += (*this)[i] * v[i]; + return sum; + } + + // cross product for 3D Vectors + // FIXME: hack swig -- no choice + inline Vec3 operator^(const Vec3 &v) const + { + Vec3 res((*this)[1] * v[2] - (*this)[2] * v[1], + (*this)[2] * v[0] - (*this)[0] * v[2], + (*this)[0] * v[1] - (*this)[1] * v[0]); + return res; + } + + // cross product for 3D Vectors + template inline Vec3 operator^(const Vec &v) const + { + Vec3 res((*this)[1] * v[2] - (*this)[2] * v[1], + (*this)[2] * v[0] - (*this)[0] * v[2], + (*this)[0] * v[1] - (*this)[1] * v[0]); + return res; + } }; - // // Matrix class // - T: value type @@ -628,137 +623,127 @@ public: // Dirty, but icc under Windows needs this #define _SIZE (M * N) -template -class Matrix -{ -public: - typedef T value_type; - - inline Matrix() - { - for (unsigned int i = 0; i < _SIZE; i++) - this->_coord[i] = 0; - } - - ~Matrix() - { - Internal::is_false<(M == 0)>::ensure(); - Internal::is_false<(N == 0)>::ensure(); - } - - template - explicit inline Matrix(const U tab[_SIZE]) - { - for (unsigned int i = 0; i < _SIZE; i++) - this->_coord[i] = tab[i]; - } - - template - explicit inline Matrix(const std::vector& tab) - { - for (unsigned int i = 0; i < _SIZE; i++) - this->_coord[i] = tab[i]; - } - - template - inline Matrix(const Matrix& m) - { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] = (T)m(i, j); - } - } - - inline value_type operator()(const unsigned i, const unsigned j) const - { - return this->_coord[i * N + j]; - } - - inline value_type& operator()(const unsigned i, const unsigned j) - { - return this->_coord[i * N + j]; - } - - static inline unsigned rows() - { - return M; - } - - static inline unsigned cols() - { - return N; - } - - inline Matrix& transpose() const - { - Matrix res; - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - res(j, i) = this->_coord[i * N + j]; - } - *this = res; - return *this; - } - - template - inline Matrix& operator=(const Matrix& m) - { - if (this != &m) { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] = (T)m(i, j); - } - } - return *this; - } - - template - inline Matrix& operator+=(const Matrix& m) - { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] += (T)m(i, j); - } - return *this; - } - - template - inline Matrix& operator-=(const Matrix& m) - { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] -= (T)m(i, j); - } - return *this; - } - - template - inline Matrix& operator*=(const U lambda) - { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] *= lambda; - } - return *this; - } - - template - inline Matrix& operator/=(const U lambda) - { - if (lambda) { - for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) - this->_coord[i * N + j] /= lambda; - } - } - return *this; - } - -protected: - value_type _coord[_SIZE]; +template class Matrix { + public: + typedef T value_type; + + inline Matrix() + { + for (unsigned int i = 0; i < _SIZE; i++) + this->_coord[i] = 0; + } + + ~Matrix() + { + Internal::is_false<(M == 0)>::ensure(); + Internal::is_false<(N == 0)>::ensure(); + } + + template explicit inline Matrix(const U tab[_SIZE]) + { + for (unsigned int i = 0; i < _SIZE; i++) + this->_coord[i] = tab[i]; + } + + template explicit inline Matrix(const std::vector &tab) + { + for (unsigned int i = 0; i < _SIZE; i++) + this->_coord[i] = tab[i]; + } + + template inline Matrix(const Matrix &m) + { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] = (T)m(i, j); + } + } + + inline value_type operator()(const unsigned i, const unsigned j) const + { + return this->_coord[i * N + j]; + } + + inline value_type &operator()(const unsigned i, const unsigned j) + { + return this->_coord[i * N + j]; + } + + static inline unsigned rows() + { + return M; + } + + static inline unsigned cols() + { + return N; + } + + inline Matrix &transpose() const + { + Matrix res; + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + res(j, i) = this->_coord[i * N + j]; + } + *this = res; + return *this; + } + + template inline Matrix &operator=(const Matrix &m) + { + if (this != &m) { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] = (T)m(i, j); + } + } + return *this; + } + + template inline Matrix &operator+=(const Matrix &m) + { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] += (T)m(i, j); + } + return *this; + } + + template inline Matrix &operator-=(const Matrix &m) + { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] -= (T)m(i, j); + } + return *this; + } + + template inline Matrix &operator*=(const U lambda) + { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] *= lambda; + } + return *this; + } + + template inline Matrix &operator/=(const U lambda) + { + if (lambda) { + for (unsigned int i = 0; i < M; i++) { + for (unsigned int j = 0; j < N; j++) + this->_coord[i * N + j] /= lambda; + } + } + return *this; + } + + protected: + value_type _coord[_SIZE]; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Matrix") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Matrix") #endif }; @@ -774,30 +759,33 @@ protected: // Dirty, but icc under Windows needs this #define _SIZE (N * N) -template -class SquareMatrix : public Matrix -{ -public: - typedef T value_type; - - inline SquareMatrix() : Matrix() {} - - template - explicit inline SquareMatrix(const U tab[_SIZE]) : Matrix(tab) {} - - template - explicit inline SquareMatrix(const std::vector& tab) : Matrix(tab) {} - - template - inline SquareMatrix(const Matrix& m) : Matrix(m) {} - - static inline SquareMatrix identity() - { - SquareMatrix res; - for (unsigned int i = 0; i < N; i++) - res(i, i) = 1; - return res; - } +template class SquareMatrix : public Matrix { + public: + typedef T value_type; + + inline SquareMatrix() : Matrix() + { + } + + template explicit inline SquareMatrix(const U tab[_SIZE]) : Matrix(tab) + { + } + + template explicit inline SquareMatrix(const std::vector &tab) : Matrix(tab) + { + } + + template inline SquareMatrix(const Matrix &m) : Matrix(m) + { + } + + static inline SquareMatrix identity() + { + SquareMatrix res; + for (unsigned int i = 0; i < N; i++) + res(i, i) = 1; + return res; + } }; #undef _SIZE @@ -811,75 +799,74 @@ public: template inline Vec operator+(const Vec& v1, const Vec& v2) { - Vec res(v1); - res += v2; - return res; + Vec res(v1); + res += v2; + return res; } template inline Vec operator-(const Vec& v1, const Vec& v2) { - Vec res(v1); - res -= v2; - return res; + Vec res(v1); + res -= v2; + return res; } template inline Vec operator*(const Vec& v, const typename Vec::value_type r) { - Vec res(v); - res *= r; - return res; + Vec res(v); + res *= r; + return res; } #endif -template -inline Vec operator*(const typename Vec::value_type r, const Vec& v) +template +inline Vec operator*(const typename Vec::value_type r, const Vec &v) { - Vec res(v); - res *= r; - return res; + Vec res(v); + res *= r; + return res; } #if 0 template inline Vec operator/(const Vec& v, const typename Vec::value_type r) { - Vec res(v); - if (r) - res /= r; - return res; + Vec res(v); + if (r) + res /= r; + return res; } // dot product template inline typename Vec::value_type operator*(const Vec& v1, const Vec& v2) { - typename Vec::value_type sum = 0; - for (unsigned int i = 0; i < N; i++) - sum += v1[i] * v2[i]; - return sum; + typename Vec::value_type sum = 0; + for (unsigned int i = 0; i < N; i++) + sum += v1[i] * v2[i]; + return sum; } // cross product for 3D Vectors template inline Vec3 operator^(const Vec& v1, const Vec& v2) { - Vec3 res(v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]); - return res; + Vec3 res(v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]); + return res; } #endif // stream operator -template -inline std::ostream& operator<<(std::ostream& s, const Vec& v) +template inline std::ostream &operator<<(std::ostream &s, const Vec &v) { - unsigned int i; - s << "["; - for (i = 0; i < N - 1; i++) - s << v[i] << ", "; - s << v[i] << "]"; - return s; + unsigned int i; + s << "["; + for (i = 0; i < N - 1; i++) + s << v[i] << ", "; + s << v[i] << "]"; + return s; } // @@ -887,93 +874,96 @@ inline std::ostream& operator<<(std::ostream& s, const Vec& v) // ///////////////////////////////////////////////////////////////////////////// -template -inline Matrix operator+(const Matrix& m1, const Matrix& m2) +template +inline Matrix operator+(const Matrix &m1, const Matrix &m2) { - Matrix res(m1); - res += m2; - return res; + Matrix res(m1); + res += m2; + return res; } -template -inline Matrix operator-(const Matrix& m1, const Matrix& m2) +template +inline Matrix operator-(const Matrix &m1, const Matrix &m2) { - Matrix res(m1); - res -= m2; - return res; + Matrix res(m1); + res -= m2; + return res; } -template -inline Matrix operator*(const Matrix& m1, const typename Matrix::value_type lambda) +template +inline Matrix operator*(const Matrix &m1, + const typename Matrix::value_type lambda) { - Matrix res(m1); - res *= lambda; - return res; + Matrix res(m1); + res *= lambda; + return res; } -template -inline Matrix operator*(const typename Matrix::value_type lambda, const Matrix& m1) +template +inline Matrix operator*(const typename Matrix::value_type lambda, + const Matrix &m1) { - Matrix res(m1); - res *= lambda; - return res; + Matrix res(m1); + res *= lambda; + return res; } -template -inline Matrix operator/(const Matrix& m1, const typename Matrix::value_type lambda) +template +inline Matrix operator/(const Matrix &m1, + const typename Matrix::value_type lambda) { - Matrix res(m1); - res /= lambda; - return res; + Matrix res(m1); + res /= lambda; + return res; } -template -inline Matrix operator*(const Matrix& m1, const Matrix& m2) +template +inline Matrix operator*(const Matrix &m1, const Matrix &m2) { - unsigned int i, j, k; - Matrix res; - typename Matrix::value_type scale; - - for (j = 0; j < P; j++) { - for (k = 0; k < N; k++) { - scale = m2(k, j); - for (i = 0; i < N; i++) - res(i, j) += m1(i, k) * scale; - } - } - return res; + unsigned int i, j, k; + Matrix res; + typename Matrix::value_type scale; + + for (j = 0; j < P; j++) { + for (k = 0; k < N; k++) { + scale = m2(k, j); + for (i = 0; i < N; i++) + res(i, j) += m1(i, k) * scale; + } + } + return res; } -template -inline Vec operator*(const Matrix& m, const Vec& v) +template +inline Vec operator*(const Matrix &m, const Vec &v) { - Vec res; - typename Matrix::value_type scale; - - for (unsigned int j = 0; j < M; j++) { - scale = v[j]; - for (unsigned int i = 0; i < N; i++) - res[i] += m(i, j) * scale; - } - return res; + Vec res; + typename Matrix::value_type scale; + + for (unsigned int j = 0; j < M; j++) { + scale = v[j]; + for (unsigned int i = 0; i < N; i++) + res[i] += m(i, j) * scale; + } + return res; } // stream operator -template -inline std::ostream& operator<<(std::ostream& s, const Matrix& m) +template +inline std::ostream &operator<<(std::ostream &s, const Matrix &m) { - unsigned int i, j; - for (i = 0; i < M; i++) { - s << "["; - for (j = 0; j < N - 1; j++) - s << m(i, j) << ", "; - s << m(i, j) << "]" << std::endl; - } - return s; + unsigned int i, j; + for (i = 0; i < M; i++) { + s << "["; + for (j = 0; j < N - 1; j++) + s << m(i, j) << ", "; + s << m(i, j) << "]" << std::endl; + } + return s; } -} // end of namespace VecMat +} // end of namespace VecMat } /* namespace Freestyle */ -#endif // __VECMAT_H__ +#endif // __VECMAT_H__ diff --git a/source/blender/freestyle/intern/geometry/matrix_util.cpp b/source/blender/freestyle/intern/geometry/matrix_util.cpp index 44490f4bde5..811b10813d1 100644 --- a/source/blender/freestyle/intern/geometry/matrix_util.cpp +++ b/source/blender/freestyle/intern/geometry/matrix_util.cpp @@ -39,222 +39,222 @@ namespace OGF { namespace MatrixUtil { - static const double EPS = 0.00001; - static int MAX_ITER = 100; - - void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val) - { - double *a, *v; - double a_norm, a_normEPS, thr, thr_nn; - int nb_iter = 0; - int jj; - int i, j, k, ij, ik, l, m, lm, mq, lq, ll, mm, imv, im, iq, ilv, il, nn; - int *index; - double a_ij, a_lm, a_ll, a_mm, a_im, a_il; - double a_lm_2; - double v_ilv, v_imv; - double x; - double sinx, sinx_2, cosx, cosx_2, sincos; - double delta; - - // Number of entries in mat - nn = (n * (n + 1)) / 2; - - // Step 1: Copy mat to a - a = new double[nn]; - - for (ij = 0; ij < nn; ij++) { - a[ij] = mat[ij]; - } - - // Ugly Fortran-porting trick: indices for a are between 1 and n - a--; - - // Step 2 : Init diagonalization matrix as the unit matrix - v = new double[n * n]; - - ij = 0; - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - if (i == j) { - v[ij++] = 1.0; - } - else { - v[ij++] = 0.0; - } - } - } - - // Ugly Fortran-porting trick: indices for v are between 1 and n - v--; - - // Step 3 : compute the weight of the non diagonal terms - ij = 1; - a_norm = 0.0; - for (i = 1; i <= n; i++) { - for (j = 1; j <= i; j++) { - if (i != j) { - a_ij = a[ij]; - a_norm += a_ij * a_ij; - } - ij++; - } - } - - if (a_norm != 0.0) { - a_normEPS = a_norm * EPS; - thr = a_norm; - - // Step 4 : rotations - while (thr > a_normEPS && nb_iter < MAX_ITER) { - nb_iter++; - thr_nn = thr / nn; - - for (l = 1; l < n; l++) { - for (m = l + 1; m <= n; m++) { - // compute sinx and cosx - lq = (l * l - l) / 2; - mq = (m * m - m) / 2; - - lm = l + mq; - a_lm = a[lm]; - a_lm_2 = a_lm * a_lm; - - if (a_lm_2 < thr_nn) { - continue; - } - - ll = l + lq; - mm = m + mq; - a_ll = a[ll]; - a_mm = a[mm]; - - delta = a_ll - a_mm; - - if (delta == 0.0) { - x = -M_PI / 4; - } - else { - x = -atan((a_lm + a_lm) / delta) / 2.0; - } - - sinx = sin(x); - cosx = cos(x); - sinx_2 = sinx * sinx; - cosx_2 = cosx * cosx; - sincos = sinx * cosx; - - // rotate L and M columns - ilv = n * (l - 1); - imv = n * (m - 1); - - for (i = 1; i <= n; i++) { - if ((i != l) && (i != m)) { - iq = (i * i - i) / 2; - - if (i < m) { - im = i + mq; - } - else { - im = m + iq; - } - a_im = a[im]; - - if (i < l) { - il = i + lq; - } - else { - il = l + iq; - } - a_il = a[il]; - - a[il] = a_il * cosx - a_im * sinx; - a[im] = a_il * sinx + a_im * cosx; - } - - ilv++; - imv++; - - v_ilv = v[ilv]; - v_imv = v[imv]; - - v[ilv] = cosx * v_ilv - sinx * v_imv; - v[imv] = sinx * v_ilv + cosx * v_imv; - } - - x = a_lm * sincos; - x += x; - - a[ll] = a_ll * cosx_2 + a_mm * sinx_2 - x; - a[mm] = a_ll * sinx_2 + a_mm * cosx_2 + x; - a[lm] = 0.0; - - thr = fabs(thr - a_lm_2); - } - } - } - } - - // Step 5: index conversion and copy eigen values - - // back from Fortran to C++ - a++; - - for (i = 0; i < n; i++) { - k = i + (i * (i + 1)) / 2; - eigen_val[i] = a[k]; - } - - delete[] a; - - // Step 6: sort the eigen values and eigen vectors - - index = new int[n]; - for (i = 0; i < n; i++) { - index[i] = i; - } - - for (i = 0; i < (n - 1); i++) { - x = eigen_val[i]; - k = i; - - for (j = i + 1; j < n; j++) { - if (x < eigen_val[j]) { - k = j; - x = eigen_val[j]; - } - } - - eigen_val[k] = eigen_val[i]; - eigen_val[i] = x; - - jj = index[k]; - index[k] = index[i]; - index[i] = jj; - } - - // Step 7: save the eigen vectors - - // back from Fortran to C++ - v++; - - ij = 0; - for (k = 0; k < n; k++) { - ik = index[k] * n; - for (i = 0; i < n; i++) { - eigen_vec[ij++] = v[ik++]; - } - } - - delete[] v; - delete[] index; - return; - } +static const double EPS = 0.00001; +static int MAX_ITER = 100; + +void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val) +{ + double *a, *v; + double a_norm, a_normEPS, thr, thr_nn; + int nb_iter = 0; + int jj; + int i, j, k, ij, ik, l, m, lm, mq, lq, ll, mm, imv, im, iq, ilv, il, nn; + int *index; + double a_ij, a_lm, a_ll, a_mm, a_im, a_il; + double a_lm_2; + double v_ilv, v_imv; + double x; + double sinx, sinx_2, cosx, cosx_2, sincos; + double delta; + + // Number of entries in mat + nn = (n * (n + 1)) / 2; + + // Step 1: Copy mat to a + a = new double[nn]; + + for (ij = 0; ij < nn; ij++) { + a[ij] = mat[ij]; + } + + // Ugly Fortran-porting trick: indices for a are between 1 and n + a--; + + // Step 2 : Init diagonalization matrix as the unit matrix + v = new double[n * n]; + + ij = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i == j) { + v[ij++] = 1.0; + } + else { + v[ij++] = 0.0; + } + } + } + + // Ugly Fortran-porting trick: indices for v are between 1 and n + v--; + + // Step 3 : compute the weight of the non diagonal terms + ij = 1; + a_norm = 0.0; + for (i = 1; i <= n; i++) { + for (j = 1; j <= i; j++) { + if (i != j) { + a_ij = a[ij]; + a_norm += a_ij * a_ij; + } + ij++; + } + } + + if (a_norm != 0.0) { + a_normEPS = a_norm * EPS; + thr = a_norm; + + // Step 4 : rotations + while (thr > a_normEPS && nb_iter < MAX_ITER) { + nb_iter++; + thr_nn = thr / nn; + + for (l = 1; l < n; l++) { + for (m = l + 1; m <= n; m++) { + // compute sinx and cosx + lq = (l * l - l) / 2; + mq = (m * m - m) / 2; + + lm = l + mq; + a_lm = a[lm]; + a_lm_2 = a_lm * a_lm; + + if (a_lm_2 < thr_nn) { + continue; + } + + ll = l + lq; + mm = m + mq; + a_ll = a[ll]; + a_mm = a[mm]; + + delta = a_ll - a_mm; + + if (delta == 0.0) { + x = -M_PI / 4; + } + else { + x = -atan((a_lm + a_lm) / delta) / 2.0; + } + + sinx = sin(x); + cosx = cos(x); + sinx_2 = sinx * sinx; + cosx_2 = cosx * cosx; + sincos = sinx * cosx; + + // rotate L and M columns + ilv = n * (l - 1); + imv = n * (m - 1); + + for (i = 1; i <= n; i++) { + if ((i != l) && (i != m)) { + iq = (i * i - i) / 2; + + if (i < m) { + im = i + mq; + } + else { + im = m + iq; + } + a_im = a[im]; + + if (i < l) { + il = i + lq; + } + else { + il = l + iq; + } + a_il = a[il]; + + a[il] = a_il * cosx - a_im * sinx; + a[im] = a_il * sinx + a_im * cosx; + } + + ilv++; + imv++; + + v_ilv = v[ilv]; + v_imv = v[imv]; + + v[ilv] = cosx * v_ilv - sinx * v_imv; + v[imv] = sinx * v_ilv + cosx * v_imv; + } + + x = a_lm * sincos; + x += x; + + a[ll] = a_ll * cosx_2 + a_mm * sinx_2 - x; + a[mm] = a_ll * sinx_2 + a_mm * cosx_2 + x; + a[lm] = 0.0; + + thr = fabs(thr - a_lm_2); + } + } + } + } + + // Step 5: index conversion and copy eigen values + + // back from Fortran to C++ + a++; + + for (i = 0; i < n; i++) { + k = i + (i * (i + 1)) / 2; + eigen_val[i] = a[k]; + } + + delete[] a; + + // Step 6: sort the eigen values and eigen vectors + + index = new int[n]; + for (i = 0; i < n; i++) { + index[i] = i; + } + + for (i = 0; i < (n - 1); i++) { + x = eigen_val[i]; + k = i; + + for (j = i + 1; j < n; j++) { + if (x < eigen_val[j]) { + k = j; + x = eigen_val[j]; + } + } + + eigen_val[k] = eigen_val[i]; + eigen_val[i] = x; + + jj = index[k]; + index[k] = index[i]; + index[i] = jj; + } + + // Step 7: save the eigen vectors + + // back from Fortran to C++ + v++; + + ij = 0; + for (k = 0; k < n; k++) { + ik = index[k] * n; + for (i = 0; i < n; i++) { + eigen_vec[ij++] = v[ik++]; + } + } + + delete[] v; + delete[] index; + return; +} //_________________________________________________________ -} // MatrixUtil namespace +} // namespace MatrixUtil -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/matrix_util.h b/source/blender/freestyle/intern/geometry/matrix_util.h index b587a9e5738..65e2fee84f3 100644 --- a/source/blender/freestyle/intern/geometry/matrix_util.h +++ b/source/blender/freestyle/intern/geometry/matrix_util.h @@ -40,25 +40,25 @@ namespace OGF { namespace MatrixUtil { - /** - * computes the eigen values and eigen vectors of a semi definite symmetric matrix - * - * \param mat: The matrix stored in column symmetric storage, i.e. - * matrix = { m11, m12, m22, m13, m23, m33, m14, m24, m34, m44 ... } - * size = n(n+1)/2 - * - * \param eigen_vec: (return) = { v1, v2, v3, ..., vn } - * where vk = vk0, vk1, ..., vkn - * size = n^2, must be allocated by caller - * - * \param eigen_val: (return) are in decreasing order - * size = n, must be allocated by caller - */ - void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val); +/** + * computes the eigen values and eigen vectors of a semi definite symmetric matrix + * + * \param mat: The matrix stored in column symmetric storage, i.e. + * matrix = { m11, m12, m22, m13, m23, m33, m14, m24, m34, m44 ... } + * size = n(n+1)/2 + * + * \param eigen_vec: (return) = { v1, v2, v3, ..., vn } + * where vk = vk0, vk1, ..., vkn + * size = n^2, must be allocated by caller + * + * \param eigen_val: (return) are in decreasing order + * size = n, must be allocated by caller + */ +void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val); -} // MatrixUtil namespace +} // namespace MatrixUtil -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/normal_cycle.cpp b/source/blender/freestyle/intern/geometry/normal_cycle.cpp index e0ef1ddfe12..25a39619a04 100644 --- a/source/blender/freestyle/intern/geometry/normal_cycle.cpp +++ b/source/blender/freestyle/intern/geometry/normal_cycle.cpp @@ -38,57 +38,56 @@ namespace OGF { //_________________________________________________________ - NormalCycle::NormalCycle() { } void NormalCycle::begin() { - M_[0] = M_[1] = M_[2] = M_[3] = M_[4] = M_[5] = 0; + M_[0] = M_[1] = M_[2] = M_[3] = M_[4] = M_[5] = 0; } void NormalCycle::end() { - double eigen_vectors[9]; - MatrixUtil::semi_definite_symmetric_eigen(M_, 3, eigen_vectors, eigen_value_); - - axis_[0] = Vec3r(eigen_vectors[0], eigen_vectors[1], eigen_vectors[2]); - - axis_[1] = Vec3r(eigen_vectors[3], eigen_vectors[4], eigen_vectors[5]); - - axis_[2] = Vec3r(eigen_vectors[6], eigen_vectors[7], eigen_vectors[8]); - - // Normalize the eigen vectors - for (int i = 0; i < 3; i++) { - axis_[i].normalize(); - } - - // Sort the eigen vectors - i_[0] = 0; - i_[1] = 1; - i_[2] = 2; - - double l0 = ::fabs(eigen_value_[0]); - double l1 = ::fabs(eigen_value_[1]); - double l2 = ::fabs(eigen_value_[2]); - - if (l1 > l0) { - ogf_swap(l0, l1 ); - ogf_swap(i_[0], i_[1]); - } - if (l2 > l1) { - ogf_swap(l1, l2 ); - ogf_swap(i_[1], i_[2]); - } - if (l1 > l0) { - ogf_swap(l0, l1 ); - ogf_swap(i_[0], i_[1]); - } + double eigen_vectors[9]; + MatrixUtil::semi_definite_symmetric_eigen(M_, 3, eigen_vectors, eigen_value_); + + axis_[0] = Vec3r(eigen_vectors[0], eigen_vectors[1], eigen_vectors[2]); + + axis_[1] = Vec3r(eigen_vectors[3], eigen_vectors[4], eigen_vectors[5]); + + axis_[2] = Vec3r(eigen_vectors[6], eigen_vectors[7], eigen_vectors[8]); + + // Normalize the eigen vectors + for (int i = 0; i < 3; i++) { + axis_[i].normalize(); + } + + // Sort the eigen vectors + i_[0] = 0; + i_[1] = 1; + i_[2] = 2; + + double l0 = ::fabs(eigen_value_[0]); + double l1 = ::fabs(eigen_value_[1]); + double l2 = ::fabs(eigen_value_[2]); + + if (l1 > l0) { + ogf_swap(l0, l1); + ogf_swap(i_[0], i_[1]); + } + if (l2 > l1) { + ogf_swap(l1, l2); + ogf_swap(i_[1], i_[2]); + } + if (l1 > l0) { + ogf_swap(l0, l1); + ogf_swap(i_[0], i_[1]); + } } //_________________________________________________________ -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/normal_cycle.h b/source/blender/freestyle/intern/geometry/normal_cycle.h index 275e5494962..a57bfdb953e 100644 --- a/source/blender/freestyle/intern/geometry/normal_cycle.h +++ b/source/blender/freestyle/intern/geometry/normal_cycle.h @@ -37,7 +37,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -46,11 +46,11 @@ using namespace Geometry; namespace OGF { -template inline void ogf_swap(T& x, T& y) +template inline void ogf_swap(T &x, T &y) { - T z = x ; - x = y ; - y = z ; + T z = x; + x = y; + y = z; } //_________________________________________________________ @@ -64,83 +64,85 @@ template inline void ogf_swap(T& x, T& y) * SOCG 2003 */ class NormalCycle { -public: - NormalCycle(); - void begin(); - void end(); - /** - * Note: the specified edge vector needs to be pre-clipped by the neighborhood. - */ - void accumulate_dihedral_angle(const Vec3r& edge, real angle, real neigh_area = 1.0); - - const Vec3r& eigen_vector(int i) const - { - return axis_[i_[i]]; - } - - real eigen_value(int i) const - { - return eigen_value_[i_[i]]; - } - - const Vec3r& N() const - { - return eigen_vector(2); - } - - const Vec3r& Kmax() const - { - return eigen_vector(1); - } - - const Vec3r& Kmin() const - { - return eigen_vector(0); - } - - real n() const - { - return eigen_value(2); - } - - real kmax() const - { - return eigen_value(1); - } - - real kmin() const - { - return eigen_value(0); - } - -private: - /* UNUSED */ - // real center_[3]; - Vec3r axis_[3]; - real eigen_value_[3]; - real M_[6]; - int i_[3]; + public: + NormalCycle(); + void begin(); + void end(); + /** + * Note: the specified edge vector needs to be pre-clipped by the neighborhood. + */ + void accumulate_dihedral_angle(const Vec3r &edge, real angle, real neigh_area = 1.0); + + const Vec3r &eigen_vector(int i) const + { + return axis_[i_[i]]; + } + + real eigen_value(int i) const + { + return eigen_value_[i_[i]]; + } + + const Vec3r &N() const + { + return eigen_vector(2); + } + + const Vec3r &Kmax() const + { + return eigen_vector(1); + } + + const Vec3r &Kmin() const + { + return eigen_vector(0); + } + + real n() const + { + return eigen_value(2); + } + + real kmax() const + { + return eigen_value(1); + } + + real kmin() const + { + return eigen_value(0); + } + + private: + /* UNUSED */ + // real center_[3]; + Vec3r axis_[3]; + real eigen_value_[3]; + real M_[6]; + int i_[3]; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OGF:NormalCycle") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OGF:NormalCycle") #endif }; -inline void NormalCycle::accumulate_dihedral_angle(const Vec3r& edge, const double beta, double neigh_area) +inline void NormalCycle::accumulate_dihedral_angle(const Vec3r &edge, + const double beta, + double neigh_area) { - double s = beta * neigh_area / edge.norm(); - - M_[0] += s * edge.x() * edge.x(); - M_[1] += s * edge.x() * edge.y(); - M_[2] += s * edge.y() * edge.y(); - M_[3] += s * edge.x() * edge.z(); - M_[4] += s * edge.y() * edge.z(); - M_[5] += s * edge.z() * edge.z(); + double s = beta * neigh_area / edge.norm(); + + M_[0] += s * edge.x() * edge.x(); + M_[1] += s * edge.x() * edge.y(); + M_[2] += s * edge.y() * edge.y(); + M_[3] += s * edge.x() * edge.z(); + M_[4] += s * edge.y() * edge.z(); + M_[5] += s * edge.z() * edge.z(); } //_________________________________________________________ -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/image/GaussianFilter.cpp b/source/blender/freestyle/intern/image/GaussianFilter.cpp index 540c3392aa3..8a14fe4e6dd 100644 --- a/source/blender/freestyle/intern/image/GaussianFilter.cpp +++ b/source/blender/freestyle/intern/image/GaussianFilter.cpp @@ -27,77 +27,76 @@ namespace Freestyle { GaussianFilter::GaussianFilter(float iSigma) { - _sigma = iSigma; - _mask = 0; - computeMask(); + _sigma = iSigma; + _mask = 0; + computeMask(); } -GaussianFilter::GaussianFilter(const GaussianFilter& iBrother) +GaussianFilter::GaussianFilter(const GaussianFilter &iBrother) { - _sigma = iBrother._sigma; - _maskSize = iBrother._maskSize; - _bound = iBrother._bound; - _storedMaskSize = iBrother._storedMaskSize; - _mask = new float[_maskSize * _maskSize]; - memcpy(_mask, iBrother._mask, _maskSize * _maskSize * sizeof(float)); + _sigma = iBrother._sigma; + _maskSize = iBrother._maskSize; + _bound = iBrother._bound; + _storedMaskSize = iBrother._storedMaskSize; + _mask = new float[_maskSize * _maskSize]; + memcpy(_mask, iBrother._mask, _maskSize * _maskSize * sizeof(float)); } -GaussianFilter& GaussianFilter::operator=(const GaussianFilter& iBrother) +GaussianFilter &GaussianFilter::operator=(const GaussianFilter &iBrother) { - _sigma = iBrother._sigma; - _maskSize = iBrother._maskSize; - _bound = iBrother._bound; - _storedMaskSize = iBrother._storedMaskSize; - _mask = new float[_storedMaskSize * _storedMaskSize]; - memcpy(_mask, iBrother._mask, _storedMaskSize * _storedMaskSize * sizeof(float)); - return *this; + _sigma = iBrother._sigma; + _maskSize = iBrother._maskSize; + _bound = iBrother._bound; + _storedMaskSize = iBrother._storedMaskSize; + _mask = new float[_storedMaskSize * _storedMaskSize]; + memcpy(_mask, iBrother._mask, _storedMaskSize * _storedMaskSize * sizeof(float)); + return *this; } - GaussianFilter::~GaussianFilter() { - if (0 != _mask) { - delete[] _mask; - } + if (0 != _mask) { + delete[] _mask; + } } int GaussianFilter::computeMaskSize(float sigma) { - int maskSize = (int)floor(4 * sigma) + 1; - if (0 == (maskSize % 2)) - ++maskSize; + int maskSize = (int)floor(4 * sigma) + 1; + if (0 == (maskSize % 2)) + ++maskSize; - return maskSize; + return maskSize; } void GaussianFilter::setSigma(float sigma) { - _sigma = sigma; - computeMask(); + _sigma = sigma; + computeMask(); } void GaussianFilter::computeMask() { - if (0 != _mask) { - delete[] _mask; - } - - _maskSize = computeMaskSize(_sigma); - _storedMaskSize = (_maskSize + 1) >> 1; - _bound = _storedMaskSize - 1; - - float norm = _sigma * _sigma * 2.0f * M_PI; - float invNorm = 1.0f / norm; - _mask = new float[_storedMaskSize * _storedMaskSize * sizeof(float)]; - for (int i = 0; i < _storedMaskSize; ++i) { - for (int j = 0; j < _storedMaskSize; ++j) { + if (0 != _mask) { + delete[] _mask; + } + + _maskSize = computeMaskSize(_sigma); + _storedMaskSize = (_maskSize + 1) >> 1; + _bound = _storedMaskSize - 1; + + float norm = _sigma * _sigma * 2.0f * M_PI; + float invNorm = 1.0f / norm; + _mask = new float[_storedMaskSize * _storedMaskSize * sizeof(float)]; + for (int i = 0; i < _storedMaskSize; ++i) { + for (int j = 0; j < _storedMaskSize; ++j) { #if 0 - _mask[i * _storedMaskSize + j] = exp(-(i * i + j * j) / (2.0 * _sigma * _sigma)); + _mask[i * _storedMaskSize + j] = exp(-(i * i + j * j) / (2.0 * _sigma * _sigma)); #else - _mask[i * _storedMaskSize + j] = invNorm * exp(-(i * i + j * j) / (2.0 * _sigma * _sigma)); + _mask[i * _storedMaskSize + j] = invNorm * exp(-(i * i + j * j) / (2.0 * _sigma * _sigma)); #endif - } - } + } + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/image/GaussianFilter.h b/source/blender/freestyle/intern/image/GaussianFilter.h index 527444eb484..5b74e622c33 100644 --- a/source/blender/freestyle/intern/image/GaussianFilter.h +++ b/source/blender/freestyle/intern/image/GaussianFilter.h @@ -22,8 +22,8 @@ * \brief Class to perform gaussian filtering operations on an image */ -#include // for abs -#include // for memcpy +#include // for abs +#include // for memcpy #include "../system/FreestyleConfig.h" @@ -32,84 +32,82 @@ extern "C" { } #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class GaussianFilter -{ -protected: - /* The mask is a symetrical 2d array (with respect to the middle point). - * Thus, M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j). - * For this reason, to represent a NxN array (N odd), we only store a ((N+1)/2)x((N+1)/2) array. - */ - float _sigma; - float *_mask; - int _bound; - // the real mask size (must be odd)(the size of the mask we store is ((_maskSize+1)/2)*((_maskSize+1)/2)) - int _maskSize; - int _storedMaskSize; // (_maskSize+1)/2) - -public: - GaussianFilter(float iSigma = 1.0f); - GaussianFilter(const GaussianFilter&); - GaussianFilter& operator=(const GaussianFilter&); - virtual ~GaussianFilter(); - - /*! Returns the value for pixel x,y of image "map" after a gaussian blur, made using the sigma value. - * The sigma value determines the mask size (~ 2 x sigma). - * \param map: - * The image we wish to work on. The Map template must implement the following methods: - * - float pixel(unsigned int x,unsigned int y) const; - * - unsigned width() const; - * - unsigned height() const; - * \param x: - * The abscissa of the pixel where we want to evaluate the gaussian blur. - * \param y: - * The ordinate of the pixel where we want to evaluate the gaussian blur. - * \param sigma: - * The sigma value of the gaussian function. - */ - template - float getSmoothedPixel(Map *map, int x, int y); - - /*! Compute the mask size and returns the REAL mask size ((2*_maskSize)-1) - * This method is provided for convenience. - */ - static int computeMaskSize(float sigma); - - /*! accessors */ - inline float sigma() const - { - return _sigma; - } - - inline int maskSize() const - { - return _maskSize; - } - - inline int getBound() - { - return _bound; - } - - /*! modifiers */ - void setSigma(float sigma); +class GaussianFilter { + protected: + /* The mask is a symetrical 2d array (with respect to the middle point). + * Thus, M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j). + * For this reason, to represent a NxN array (N odd), we only store a ((N+1)/2)x((N+1)/2) array. + */ + float _sigma; + float *_mask; + int _bound; + // the real mask size (must be odd)(the size of the mask we store is ((_maskSize+1)/2)*((_maskSize+1)/2)) + int _maskSize; + int _storedMaskSize; // (_maskSize+1)/2) + + public: + GaussianFilter(float iSigma = 1.0f); + GaussianFilter(const GaussianFilter &); + GaussianFilter &operator=(const GaussianFilter &); + virtual ~GaussianFilter(); + + /*! Returns the value for pixel x,y of image "map" after a gaussian blur, made using the sigma value. + * The sigma value determines the mask size (~ 2 x sigma). + * \param map: + * The image we wish to work on. The Map template must implement the following methods: + * - float pixel(unsigned int x,unsigned int y) const; + * - unsigned width() const; + * - unsigned height() const; + * \param x: + * The abscissa of the pixel where we want to evaluate the gaussian blur. + * \param y: + * The ordinate of the pixel where we want to evaluate the gaussian blur. + * \param sigma: + * The sigma value of the gaussian function. + */ + template float getSmoothedPixel(Map *map, int x, int y); + + /*! Compute the mask size and returns the REAL mask size ((2*_maskSize)-1) + * This method is provided for convenience. + */ + static int computeMaskSize(float sigma); + + /*! accessors */ + inline float sigma() const + { + return _sigma; + } + + inline int maskSize() const + { + return _maskSize; + } + + inline int getBound() + { + return _bound; + } + + /*! modifiers */ + void setSigma(float sigma); #if 0 - void SetMaskSize(int size) - { - _maskSize = size; - _storedMaskSize = (_maskSize + 1) >> 1; - } + void SetMaskSize(int size) + { + _maskSize = size; + _storedMaskSize = (_maskSize + 1) >> 1; + } #endif -protected: - void computeMask(); + protected: + void computeMask(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GaussianFilter") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GaussianFilter") #endif }; @@ -125,33 +123,32 @@ protected: * ############################################# */ -template -float GaussianFilter::getSmoothedPixel(Map *map, int x, int y) +template float GaussianFilter::getSmoothedPixel(Map *map, int x, int y) { - float sum = 0.0f; - float L = 0.0f; - int w = (int)map->width(); //soc - int h = (int)map->height(); //soc - - // Current pixel is x,y - // Sum surrounding pixels L value: - for (int i = -_bound; i <= _bound; ++i) { - if ((y + i < 0) || (y + i >= h)) - continue; - for (int j = -_bound; j <= _bound; ++j) { - if ((x + j < 0) || (x + j >= w)) - continue; - - float tmpL = map->pixel(x + j, y + i); - float m = _mask[abs(i) * _storedMaskSize + abs(j)]; - L += m * tmpL; - sum += m; - } - } - //L /= sum; - return L; + float sum = 0.0f; + float L = 0.0f; + int w = (int)map->width(); //soc + int h = (int)map->height(); //soc + + // Current pixel is x,y + // Sum surrounding pixels L value: + for (int i = -_bound; i <= _bound; ++i) { + if ((y + i < 0) || (y + i >= h)) + continue; + for (int j = -_bound; j <= _bound; ++j) { + if ((x + j < 0) || (x + j >= w)) + continue; + + float tmpL = map->pixel(x + j, y + i); + float m = _mask[abs(i) * _storedMaskSize + abs(j)]; + L += m * tmpL; + sum += m; + } + } + //L /= sum; + return L; } } /* namespace Freestyle */ -#endif // __GAUSSIANFILTER_H__ +#endif // __GAUSSIANFILTER_H__ diff --git a/source/blender/freestyle/intern/image/Image.h b/source/blender/freestyle/intern/image/Image.h index 208a8b1938c..344766bfa63 100644 --- a/source/blender/freestyle/intern/image/Image.h +++ b/source/blender/freestyle/intern/image/Image.h @@ -22,10 +22,10 @@ * \brief Class to encapsulate an array of RGB or Gray level values */ -#include // for memcpy +#include // for memcpy #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -39,376 +39,391 @@ namespace Freestyle { * You can for example only a rectangle of sw*sh, whose lower-left corner is at (ox, oy), of an image of * size w*h, and access these pixels using x,y coordinates specified in the whole image coordinate system. */ -class FrsImage -{ -public: - /*! Default constructor */ - FrsImage() - { - _storedWidth = 0; - _storedHeight = 0; - _width = 0; - _height = 0; - _Ox = 0; - _Oy = 0; - } - - /*! Copy constructor */ - FrsImage(const FrsImage& brother) - { - _storedWidth = brother._storedWidth; - _storedHeight = brother._storedHeight; - _width = brother._width; - _height = brother._height; - _Ox = brother._Ox; - _Oy = brother._Oy; - } - - /*! Builds an FrsImage from its width and height. - * The memory is allocated consequently. - */ - FrsImage(unsigned w, unsigned h) - { - _width = w; - _height = h; - _storedWidth = w; - _storedHeight = h; - _Ox = 0; - _Oy = 0; - } - - /*! Builds a partial-storing image. - * \param w: - * The width of the complete image - * \param h: - * The height of the complete image - * \param sw: - * The width of the rectangle that will actually be stored. - * \param sh: - * The height of the rectangle that will actually be stored. - * \param ox: - * The x-abscissa of the origin of the rectangle that will actually be stored. - * \param oy: - * The x-abscissa of the origin of the rectangle that will actually be stored. - */ - FrsImage(unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) - { - _width = w; - _height = h; - _storedWidth = sw; - _storedHeight = sh; - _Ox = ox; - _Oy = oy; - } - - /*! Operator= */ - FrsImage& operator=(const FrsImage& brother) - { - _width = brother._width; - _height = brother._height; - _storedWidth = brother._storedWidth; - _storedHeight = brother._storedHeight; - _Ox = brother._Ox; - _Oy = brother._Oy; - return *this; - } - - /*! Destructor */ - virtual ~FrsImage() {} - - /*! Returns the width of the complete image */ - inline unsigned width() const - { - return _width; - } - - /*! Returns the height of the complete image */ - inline unsigned height() const - { - return _height; - } - - /*! Returns the gray value for pixel x,y */ - virtual float pixel(unsigned x, unsigned y) const = 0; - - /*! Sets the array. - * \param array: - * The array containing the values we wish to store. - * Its size is sw*sh. - * \param width: - * The width of the complete image - * \param height: - * The height of the complete image - * \param sw: - * The width of the rectangle that will actually be stored. - * \param sh: - * The height of the rectangle that will actually be stored. - * \param ox: - * The x-abscissa of the origin of the rectangle that will actually be stored. - * \param oy: - * The x-abscissa of the origin of the rectangle that will actually be stored. - * \param copy: - * If true, the array is copied, otherwise the pointer is copied - */ - virtual void setArray(float *array, unsigned width, unsigned height, unsigned sw, unsigned sh, - unsigned x, unsigned y, bool copy = true) = 0; - - /*! Returns the array containing the pixels values. - * Its size is sw*sh, i.e. potentially a smaller rectangular part of the complete image. - */ - virtual float *getArray() = 0; - -protected: - unsigned _width; - unsigned _height; - unsigned _storedWidth; - unsigned _storedHeight; - unsigned _Ox; // origin of the stored part - unsigned _Oy; // origin of the stored part +class FrsImage { + public: + /*! Default constructor */ + FrsImage() + { + _storedWidth = 0; + _storedHeight = 0; + _width = 0; + _height = 0; + _Ox = 0; + _Oy = 0; + } + + /*! Copy constructor */ + FrsImage(const FrsImage &brother) + { + _storedWidth = brother._storedWidth; + _storedHeight = brother._storedHeight; + _width = brother._width; + _height = brother._height; + _Ox = brother._Ox; + _Oy = brother._Oy; + } + + /*! Builds an FrsImage from its width and height. + * The memory is allocated consequently. + */ + FrsImage(unsigned w, unsigned h) + { + _width = w; + _height = h; + _storedWidth = w; + _storedHeight = h; + _Ox = 0; + _Oy = 0; + } + + /*! Builds a partial-storing image. + * \param w: + * The width of the complete image + * \param h: + * The height of the complete image + * \param sw: + * The width of the rectangle that will actually be stored. + * \param sh: + * The height of the rectangle that will actually be stored. + * \param ox: + * The x-abscissa of the origin of the rectangle that will actually be stored. + * \param oy: + * The x-abscissa of the origin of the rectangle that will actually be stored. + */ + FrsImage(unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) + { + _width = w; + _height = h; + _storedWidth = sw; + _storedHeight = sh; + _Ox = ox; + _Oy = oy; + } + + /*! Operator= */ + FrsImage &operator=(const FrsImage &brother) + { + _width = brother._width; + _height = brother._height; + _storedWidth = brother._storedWidth; + _storedHeight = brother._storedHeight; + _Ox = brother._Ox; + _Oy = brother._Oy; + return *this; + } + + /*! Destructor */ + virtual ~FrsImage() + { + } + + /*! Returns the width of the complete image */ + inline unsigned width() const + { + return _width; + } + + /*! Returns the height of the complete image */ + inline unsigned height() const + { + return _height; + } + + /*! Returns the gray value for pixel x,y */ + virtual float pixel(unsigned x, unsigned y) const = 0; + + /*! Sets the array. + * \param array: + * The array containing the values we wish to store. + * Its size is sw*sh. + * \param width: + * The width of the complete image + * \param height: + * The height of the complete image + * \param sw: + * The width of the rectangle that will actually be stored. + * \param sh: + * The height of the rectangle that will actually be stored. + * \param ox: + * The x-abscissa of the origin of the rectangle that will actually be stored. + * \param oy: + * The x-abscissa of the origin of the rectangle that will actually be stored. + * \param copy: + * If true, the array is copied, otherwise the pointer is copied + */ + virtual void setArray(float *array, + unsigned width, + unsigned height, + unsigned sw, + unsigned sh, + unsigned x, + unsigned y, + bool copy = true) = 0; + + /*! Returns the array containing the pixels values. + * Its size is sw*sh, i.e. potentially a smaller rectangular part of the complete image. + */ + virtual float *getArray() = 0; + + protected: + unsigned _width; + unsigned _height; + unsigned _storedWidth; + unsigned _storedHeight; + unsigned _Ox; // origin of the stored part + unsigned _Oy; // origin of the stored part #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsImage") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsImage") #endif }; - // // RGBImage // /////////////////////////////////////////////////////////////////////////////// -class RGBImage : public FrsImage -{ -public: - RGBImage() : FrsImage() - { - _rgb = 0; - } - - RGBImage(const RGBImage& brother) : FrsImage(brother) - { - _rgb = new float[3 * _storedWidth * _storedHeight]; - memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); - } - - RGBImage(unsigned w, unsigned h) : FrsImage(w, h) - { - _rgb = new float[3 * _width * _height]; - } - - RGBImage(float *rgb, unsigned w, unsigned h) : FrsImage(w, h) - { - _rgb = new float[3 * _width * _height]; - memcpy(_rgb, rgb, 3 * _width * _height * sizeof(float)); - } - - /*! Builds an RGB partial image from the useful part buffer. - * \param rgb: - * The array of size 3*sw*sh containing the RGB values of the sw*sh pixels we need to stored. - * These sw*sh pixels constitute a rectangular part of a bigger RGB image containing w*h pixels. - * \param w: - * The width of the complete image - * \param h: - * The height of the complete image - * \param sw: - * The width of the part of the image we want to store and work on - * \param sh: - * The height of the part of the image we want to store and work on - */ - RGBImage(float *rgb, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) - : FrsImage(w, h, sw, sh, ox, oy) - { - _rgb = new float[3 * _storedWidth * _storedHeight]; - memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); - } - - RGBImage& operator=(const RGBImage& brother) - { - dynamic_cast(*this) = brother; - _rgb = new float[3 * _storedWidth * _storedHeight]; - memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); - return *this; - } - - virtual ~RGBImage() - { - if (_rgb) - delete[] _rgb; - } - - inline float getR(unsigned x, unsigned y) const - { - return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]; - } - - inline float getG(unsigned x, unsigned y) const - { - return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 1]; - } - - inline float getB(unsigned x, unsigned y) const - { - return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 2]; - } - - virtual void setPixel(unsigned x, unsigned y, float r, float g, float b) - { - float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]); - *tmp = r; - tmp++; - *tmp = g; - tmp++; - *tmp = b; - } - - virtual float pixel(unsigned x, unsigned y) const - { - float res = 0.0f; - float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]); - res += 11.0f * (*tmp); - tmp++; - res += 16.0f * (*tmp); - tmp++; - res += 5.0f * (*tmp); - return res / 32.0f; - } - - /*! Sets the RGB array. - * copy - * If true, the array is copied, otherwise the pointer is copied - */ - virtual void setArray(float *rgb, unsigned width, unsigned height, unsigned sw, unsigned sh, - unsigned x, unsigned y, bool copy = true) - { - _width = width; - _height = height; - _storedWidth = sw; - _storedHeight = sh; - _Ox = x; - _Oy = y; - if (!copy) { - _rgb = rgb; - return; - } - - memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); - } - - virtual float *getArray() - { - return _rgb; - } - -protected: - float *_rgb; +class RGBImage : public FrsImage { + public: + RGBImage() : FrsImage() + { + _rgb = 0; + } + + RGBImage(const RGBImage &brother) : FrsImage(brother) + { + _rgb = new float[3 * _storedWidth * _storedHeight]; + memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); + } + + RGBImage(unsigned w, unsigned h) : FrsImage(w, h) + { + _rgb = new float[3 * _width * _height]; + } + + RGBImage(float *rgb, unsigned w, unsigned h) : FrsImage(w, h) + { + _rgb = new float[3 * _width * _height]; + memcpy(_rgb, rgb, 3 * _width * _height * sizeof(float)); + } + + /*! Builds an RGB partial image from the useful part buffer. + * \param rgb: + * The array of size 3*sw*sh containing the RGB values of the sw*sh pixels we need to stored. + * These sw*sh pixels constitute a rectangular part of a bigger RGB image containing w*h pixels. + * \param w: + * The width of the complete image + * \param h: + * The height of the complete image + * \param sw: + * The width of the part of the image we want to store and work on + * \param sh: + * The height of the part of the image we want to store and work on + */ + RGBImage(float *rgb, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) + : FrsImage(w, h, sw, sh, ox, oy) + { + _rgb = new float[3 * _storedWidth * _storedHeight]; + memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); + } + + RGBImage &operator=(const RGBImage &brother) + { + dynamic_cast(*this) = brother; + _rgb = new float[3 * _storedWidth * _storedHeight]; + memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); + return *this; + } + + virtual ~RGBImage() + { + if (_rgb) + delete[] _rgb; + } + + inline float getR(unsigned x, unsigned y) const + { + return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]; + } + + inline float getG(unsigned x, unsigned y) const + { + return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 1]; + } + + inline float getB(unsigned x, unsigned y) const + { + return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 2]; + } + + virtual void setPixel(unsigned x, unsigned y, float r, float g, float b) + { + float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]); + *tmp = r; + tmp++; + *tmp = g; + tmp++; + *tmp = b; + } + + virtual float pixel(unsigned x, unsigned y) const + { + float res = 0.0f; + float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]); + res += 11.0f * (*tmp); + tmp++; + res += 16.0f * (*tmp); + tmp++; + res += 5.0f * (*tmp); + return res / 32.0f; + } + + /*! Sets the RGB array. + * copy + * If true, the array is copied, otherwise the pointer is copied + */ + virtual void setArray(float *rgb, + unsigned width, + unsigned height, + unsigned sw, + unsigned sh, + unsigned x, + unsigned y, + bool copy = true) + { + _width = width; + _height = height; + _storedWidth = sw; + _storedHeight = sh; + _Ox = x; + _Oy = y; + if (!copy) { + _rgb = rgb; + return; + } + + memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float)); + } + + virtual float *getArray() + { + return _rgb; + } + + protected: + float *_rgb; }; - // // GrayImage // /////////////////////////////////////////////////////////////////////////////// -class GrayImage : public FrsImage -{ -public: - GrayImage() : FrsImage() - { - _lvl = 0; - } - - GrayImage(const GrayImage& brother) : FrsImage(brother) - { - _lvl = new float[_storedWidth * _storedHeight]; - memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(*_lvl)); - } - - /*! Builds an empty gray image */ - GrayImage(unsigned w, unsigned h) : FrsImage(w, h) - { - _lvl = new float[_width * _height]; - } - - GrayImage(float *lvl, unsigned w, unsigned h) : FrsImage(w, h) - { - _lvl = new float[_width * _height]; - memcpy(_lvl, lvl, _width * _height * sizeof(*_lvl)); - } - - /*! Builds a partial image from the useful part buffer. - * \param lvl: - * The array of size sw*sh containing the gray values of the sw*sh pixels we need to stored. - * These sw*sh pixels constitute a rectangular part of a bigger gray image containing w*h pixels. - * \param w: - * The width of the complete image - * \param h: - * The height of the complete image - * \param sw: - * The width of the part of the image we want to store and work on - * \param sh: - * The height of the part of the image we want to store and work on - */ - GrayImage(float *lvl, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) - : FrsImage(w, h, sw, sh, ox, oy) - { - _lvl = new float[_storedWidth * _storedHeight]; - memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float)); - } - - GrayImage& operator=(const GrayImage& brother) - { - dynamic_cast(*this) = brother; - _lvl = new float[_storedWidth * _storedHeight]; - memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(float)); - return *this; - } - - virtual ~GrayImage() - { - if (_lvl) - delete[] _lvl; - } - - inline void setPixel(unsigned x, unsigned y, float v) - { - _lvl[(y - _Oy) * _storedWidth + (x - _Ox)] = v; - } - - inline float pixel(unsigned x, unsigned y) const - { - return _lvl[(y - _Oy) * _storedWidth + (x - _Ox)]; - } - - /*! Sets the array. - * copy - * If true, the array is copie, otherwise the pounsigneder is copied - */ - void setArray(float *lvl, unsigned width, unsigned height, unsigned sw, unsigned sh, - unsigned x, unsigned y, bool copy = true) - { - _width = width; - _height = height; - _storedWidth = sw; - _storedHeight = sh; - _Ox = x; - _Oy = y; - if (!copy) { - _lvl = lvl; - return; - } - - memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float)); - } - - /*! Returns the array containing the gray values. */ - virtual float *getArray() - { - return _lvl; - } - -protected: - float *_lvl; +class GrayImage : public FrsImage { + public: + GrayImage() : FrsImage() + { + _lvl = 0; + } + + GrayImage(const GrayImage &brother) : FrsImage(brother) + { + _lvl = new float[_storedWidth * _storedHeight]; + memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(*_lvl)); + } + + /*! Builds an empty gray image */ + GrayImage(unsigned w, unsigned h) : FrsImage(w, h) + { + _lvl = new float[_width * _height]; + } + + GrayImage(float *lvl, unsigned w, unsigned h) : FrsImage(w, h) + { + _lvl = new float[_width * _height]; + memcpy(_lvl, lvl, _width * _height * sizeof(*_lvl)); + } + + /*! Builds a partial image from the useful part buffer. + * \param lvl: + * The array of size sw*sh containing the gray values of the sw*sh pixels we need to stored. + * These sw*sh pixels constitute a rectangular part of a bigger gray image containing w*h pixels. + * \param w: + * The width of the complete image + * \param h: + * The height of the complete image + * \param sw: + * The width of the part of the image we want to store and work on + * \param sh: + * The height of the part of the image we want to store and work on + */ + GrayImage(float *lvl, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy) + : FrsImage(w, h, sw, sh, ox, oy) + { + _lvl = new float[_storedWidth * _storedHeight]; + memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float)); + } + + GrayImage &operator=(const GrayImage &brother) + { + dynamic_cast(*this) = brother; + _lvl = new float[_storedWidth * _storedHeight]; + memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(float)); + return *this; + } + + virtual ~GrayImage() + { + if (_lvl) + delete[] _lvl; + } + + inline void setPixel(unsigned x, unsigned y, float v) + { + _lvl[(y - _Oy) * _storedWidth + (x - _Ox)] = v; + } + + inline float pixel(unsigned x, unsigned y) const + { + return _lvl[(y - _Oy) * _storedWidth + (x - _Ox)]; + } + + /*! Sets the array. + * copy + * If true, the array is copie, otherwise the pounsigneder is copied + */ + void setArray(float *lvl, + unsigned width, + unsigned height, + unsigned sw, + unsigned sh, + unsigned x, + unsigned y, + bool copy = true) + { + _width = width; + _height = height; + _storedWidth = sw; + _storedHeight = sh; + _Ox = x; + _Oy = y; + if (!copy) { + _lvl = lvl; + return; + } + + memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float)); + } + + /*! Returns the array containing the gray values. */ + virtual float *getArray() + { + return _lvl; + } + + protected: + float *_lvl; }; } /* namespace Freestyle */ -#endif // __IMAGE_H__ +#endif // __IMAGE_H__ diff --git a/source/blender/freestyle/intern/image/ImagePyramid.cpp b/source/blender/freestyle/intern/image/ImagePyramid.cpp index 5683b282a9d..caf469328b5 100644 --- a/source/blender/freestyle/intern/image/ImagePyramid.cpp +++ b/source/blender/freestyle/intern/image/ImagePyramid.cpp @@ -32,152 +32,156 @@ namespace Freestyle { #if 0 ImagePyramid::ImagePyramid(const GrayImage& level0, unsigned nbLevels) { - BuildPyramid(level0,nbLevels); + BuildPyramid(level0,nbLevels); } #endif -ImagePyramid::ImagePyramid(const ImagePyramid& /*iBrother*/) +ImagePyramid::ImagePyramid(const ImagePyramid & /*iBrother*/) { - if (!_levels.empty()) { - for (vector::iterator im = _levels.begin(), imend = _levels.end(); im != imend; ++im) { - _levels.push_back(new GrayImage(**im)); - } - } + if (!_levels.empty()) { + for (vector::iterator im = _levels.begin(), imend = _levels.end(); im != imend; + ++im) { + _levels.push_back(new GrayImage(**im)); + } + } } ImagePyramid::~ImagePyramid() { - if (!_levels.empty()) { - for (vector::iterator im = _levels.begin(), imend = _levels.end(); im != imend; ++im) { - delete (*im); - } - _levels.clear(); - } + if (!_levels.empty()) { + for (vector::iterator im = _levels.begin(), imend = _levels.end(); im != imend; + ++im) { + delete (*im); + } + _levels.clear(); + } } GrayImage *ImagePyramid::getLevel(int l) { - return _levels[l]; + return _levels[l]; } float ImagePyramid::pixel(int x, int y, int level) { - GrayImage *img = _levels[level]; - if (0 == level) { - return img->pixel(x, y); - } - unsigned int i = 1 << level; - unsigned int sx = x >> level; - unsigned int sy = y >> level; - if (sx >= img->width()) - sx = img->width() - 1; - if (sy >= img->height()) - sy = img->height() - 1; - - // bilinear interpolation - float A = i * (sx + 1) - x; - float B = x - i * sx; - float C = i * (sy + 1) - y; - float D = y - i * sy; - - float P1(0), P2(0); - P1 = A * img->pixel(sx, sy); - if (sx < img->width() - 1) { - if (x % i != 0) - P1 += B * img->pixel(sx + 1, sy); - } - else { - P1 += B * img->pixel(sx, sy); - } - if (sy < img->height() - 1) { - if (y % i != 0) { - P2 = A * img->pixel(sx, sy + 1); - if (sx < img->width() - 1) { - if (x % i != 0) - P2 += B * img->pixel(sx + 1, sy + 1); - } - else { - P2 += B * img->pixel(sx, sy + 1); - } - } - } - else { - P2 = P1; - } - return (1.0f / (float)(1 << (2 * level))) * (C * P1 + D * P2); + GrayImage *img = _levels[level]; + if (0 == level) { + return img->pixel(x, y); + } + unsigned int i = 1 << level; + unsigned int sx = x >> level; + unsigned int sy = y >> level; + if (sx >= img->width()) + sx = img->width() - 1; + if (sy >= img->height()) + sy = img->height() - 1; + + // bilinear interpolation + float A = i * (sx + 1) - x; + float B = x - i * sx; + float C = i * (sy + 1) - y; + float D = y - i * sy; + + float P1(0), P2(0); + P1 = A * img->pixel(sx, sy); + if (sx < img->width() - 1) { + if (x % i != 0) + P1 += B * img->pixel(sx + 1, sy); + } + else { + P1 += B * img->pixel(sx, sy); + } + if (sy < img->height() - 1) { + if (y % i != 0) { + P2 = A * img->pixel(sx, sy + 1); + if (sx < img->width() - 1) { + if (x % i != 0) + P2 += B * img->pixel(sx + 1, sy + 1); + } + else { + P2 += B * img->pixel(sx, sy + 1); + } + } + } + else { + P2 = P1; + } + return (1.0f / (float)(1 << (2 * level))) * (C * P1 + D * P2); } int ImagePyramid::width(int level) { - return _levels[level]->width(); + return _levels[level]->width(); } int ImagePyramid::height(int level) { - return _levels[level]->height(); + return _levels[level]->height(); } -GaussianPyramid::GaussianPyramid(const GrayImage& level0, unsigned nbLevels, float iSigma) : ImagePyramid() +GaussianPyramid::GaussianPyramid(const GrayImage &level0, unsigned nbLevels, float iSigma) + : ImagePyramid() { - _sigma = iSigma; - BuildPyramid(level0, nbLevels); + _sigma = iSigma; + BuildPyramid(level0, nbLevels); } -GaussianPyramid::GaussianPyramid(GrayImage *level0, unsigned nbLevels, float iSigma) : ImagePyramid() +GaussianPyramid::GaussianPyramid(GrayImage *level0, unsigned nbLevels, float iSigma) + : ImagePyramid() { - _sigma = iSigma; - BuildPyramid(level0, nbLevels); + _sigma = iSigma; + BuildPyramid(level0, nbLevels); } -GaussianPyramid::GaussianPyramid(const GaussianPyramid& iBrother) : ImagePyramid(iBrother) +GaussianPyramid::GaussianPyramid(const GaussianPyramid &iBrother) : ImagePyramid(iBrother) { - _sigma = iBrother._sigma; + _sigma = iBrother._sigma; } -void GaussianPyramid::BuildPyramid(const GrayImage& level0, unsigned nbLevels) +void GaussianPyramid::BuildPyramid(const GrayImage &level0, unsigned nbLevels) { - GrayImage *pLevel = new GrayImage(level0); - BuildPyramid(pLevel, nbLevels); + GrayImage *pLevel = new GrayImage(level0); + BuildPyramid(pLevel, nbLevels); } void GaussianPyramid::BuildPyramid(GrayImage *level0, unsigned nbLevels) { - GrayImage *pLevel = level0; - _levels.push_back(pLevel); - GaussianFilter gf(_sigma); - // build the nbLevels: - unsigned w = pLevel->width(); - unsigned h = pLevel->height(); - if (nbLevels != 0) { - for (unsigned int i = 0; i < nbLevels; ++i) { //soc - w = pLevel->width() >> 1; - h = pLevel->height() >> 1; - GrayImage *img = new GrayImage(w, h); - for (unsigned int y = 0; y < h; ++y) { - for (unsigned int x = 0; x < w; ++x) { - float v = gf.getSmoothedPixel(pLevel, 2 * x, 2 * y); - img->setPixel(x, y, v); - } - } - _levels.push_back(img); - pLevel = img; - } - } - else { - while ((w > 1) && (h > 1)) { - w = pLevel->width() >> 1; - h = pLevel->height() >> 1; - GrayImage *img = new GrayImage(w, h); - for (unsigned int y = 0; y < h; ++y) { - for (unsigned int x = 0; x < w; ++x) { - float v = gf.getSmoothedPixel(pLevel, 2 * x, 2 * y); - img->setPixel(x, y, v); - } - } - _levels.push_back(img); - pLevel = img; - } - } + GrayImage *pLevel = level0; + _levels.push_back(pLevel); + GaussianFilter gf(_sigma); + // build the nbLevels: + unsigned w = pLevel->width(); + unsigned h = pLevel->height(); + if (nbLevels != 0) { + for (unsigned int i = 0; i < nbLevels; ++i) { //soc + w = pLevel->width() >> 1; + h = pLevel->height() >> 1; + GrayImage *img = new GrayImage(w, h); + for (unsigned int y = 0; y < h; ++y) { + for (unsigned int x = 0; x < w; ++x) { + float v = gf.getSmoothedPixel(pLevel, 2 * x, 2 * y); + img->setPixel(x, y, v); + } + } + _levels.push_back(img); + pLevel = img; + } + } + else { + while ((w > 1) && (h > 1)) { + w = pLevel->width() >> 1; + h = pLevel->height() >> 1; + GrayImage *img = new GrayImage(w, h); + for (unsigned int y = 0; y < h; ++y) { + for (unsigned int x = 0; x < w; ++x) { + float v = gf.getSmoothedPixel(pLevel, 2 * x, 2 * y); + img->setPixel(x, y, v); + } + } + _levels.push_back(img); + pLevel = img; + } + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/image/ImagePyramid.h b/source/blender/freestyle/intern/image/ImagePyramid.h index 023361a1d69..0e388fdf20c 100644 --- a/source/blender/freestyle/intern/image/ImagePyramid.h +++ b/source/blender/freestyle/intern/image/ImagePyramid.h @@ -27,89 +27,91 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { class GrayImage; -class ImagePyramid -{ -protected: - std::vector _levels; - -public: - ImagePyramid() {} - ImagePyramid(const ImagePyramid& iBrother); - //ImagePyramid(const GrayImage& level0, unsigned nbLevels); - virtual ~ImagePyramid(); - - /*! Builds the pyramid. - * must be overloaded by inherited classes. - * if nbLevels==0, the complete pyramid is built - */ - virtual void BuildPyramid(const GrayImage& level0, unsigned nbLevels) = 0; - - /*! Builds a pyramid without copying the base level */ - virtual void BuildPyramid(GrayImage *level0, unsigned nbLevels) = 0; - - virtual GrayImage *getLevel(int l); - /*! Returns the pixel x,y using bilinear interpolation. - * \param x: - * the abscissa specified in the finest level coordinate system - * \param y: - * the ordinate specified in the finest level coordinate system - * \param level: - * the level from which we want the pixel to be evaluated - */ - virtual float pixel(int x, int y, int level=0); - - /*! Returns the width of the level-th level image */ - virtual int width(int level=0); - - /*! Returns the height of the level-th level image */ - virtual int height(int level=0); - - /*! Returns the number of levels in the pyramid */ - inline int getNumberOfLevels() const - { - return _levels.size(); - } +class ImagePyramid { + protected: + std::vector _levels; + + public: + ImagePyramid() + { + } + ImagePyramid(const ImagePyramid &iBrother); + //ImagePyramid(const GrayImage& level0, unsigned nbLevels); + virtual ~ImagePyramid(); + + /*! Builds the pyramid. + * must be overloaded by inherited classes. + * if nbLevels==0, the complete pyramid is built + */ + virtual void BuildPyramid(const GrayImage &level0, unsigned nbLevels) = 0; + + /*! Builds a pyramid without copying the base level */ + virtual void BuildPyramid(GrayImage *level0, unsigned nbLevels) = 0; + + virtual GrayImage *getLevel(int l); + /*! Returns the pixel x,y using bilinear interpolation. + * \param x: + * the abscissa specified in the finest level coordinate system + * \param y: + * the ordinate specified in the finest level coordinate system + * \param level: + * the level from which we want the pixel to be evaluated + */ + virtual float pixel(int x, int y, int level = 0); + + /*! Returns the width of the level-th level image */ + virtual int width(int level = 0); + + /*! Returns the height of the level-th level image */ + virtual int height(int level = 0); + + /*! Returns the number of levels in the pyramid */ + inline int getNumberOfLevels() const + { + return _levels.size(); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ImagePyramid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ImagePyramid") #endif }; -class GaussianPyramid : public ImagePyramid -{ -protected: - float _sigma; - -public: - GaussianPyramid(float iSigma=1.f) : ImagePyramid() - { - _sigma = iSigma; - } - - GaussianPyramid(const GrayImage& level0, unsigned nbLevels, float iSigma=1.0f); - GaussianPyramid(GrayImage *level0, unsigned nbLevels, float iSigma=1.0f); - GaussianPyramid(const GaussianPyramid& iBrother); - virtual ~GaussianPyramid() {} - - virtual void BuildPyramid(const GrayImage& level0, unsigned nbLevels); - virtual void BuildPyramid(GrayImage *level0, unsigned nbLevels); - - /* accessors */ - inline float getSigma() const - { - return _sigma; - } - - /* modifiers */ +class GaussianPyramid : public ImagePyramid { + protected: + float _sigma; + + public: + GaussianPyramid(float iSigma = 1.f) : ImagePyramid() + { + _sigma = iSigma; + } + + GaussianPyramid(const GrayImage &level0, unsigned nbLevels, float iSigma = 1.0f); + GaussianPyramid(GrayImage *level0, unsigned nbLevels, float iSigma = 1.0f); + GaussianPyramid(const GaussianPyramid &iBrother); + virtual ~GaussianPyramid() + { + } + + virtual void BuildPyramid(const GrayImage &level0, unsigned nbLevels); + virtual void BuildPyramid(GrayImage *level0, unsigned nbLevels); + + /* accessors */ + inline float getSigma() const + { + return _sigma; + } + + /* modifiers */ }; } /* namespace Freestyle */ -#endif // __IMAGEPYRAMID_H__ +#endif // __IMAGEPYRAMID_H__ diff --git a/source/blender/freestyle/intern/python/BPy_BBox.cpp b/source/blender/freestyle/intern/python/BPy_BBox.cpp index 0916666e4cc..1f26cb51e01 100644 --- a/source/blender/freestyle/intern/python/BPy_BBox.cpp +++ b/source/blender/freestyle/intern/python/BPy_BBox.cpp @@ -29,88 +29,87 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int BBox_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&BBox_Type) < 0) - return -1; - Py_INCREF(&BBox_Type); - PyModule_AddObject(module, "BBox", (PyObject *)&BBox_Type); + if (PyType_Ready(&BBox_Type) < 0) + return -1; + Py_INCREF(&BBox_Type); + PyModule_AddObject(module, "BBox", (PyObject *)&BBox_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(BBox_doc, -"Class for representing a bounding box.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Class for representing a bounding box.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); static int BBox_init(BPy_BBox *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->bb = new BBox< Vec3r>(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->bb = new BBox(); + return 0; } static void BBox_dealloc(BPy_BBox *self) { - delete self->bb; - Py_TYPE(self)->tp_free((PyObject *)self); + delete self->bb; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *BBox_repr(BPy_BBox *self) { - return PyUnicode_FromFormat("BBox - address: %p", self->bb); + return PyUnicode_FromFormat("BBox - address: %p", self->bb); } /*-----------------------BPy_BBox type definition ------------------------------*/ PyTypeObject BBox_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BBox", /* tp_name */ - sizeof(BPy_BBox), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BBox_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)BBox_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BBox_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BBox_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BBox", /* tp_name */ + sizeof(BPy_BBox), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)BBox_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)BBox_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BBox_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BBox_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_BBox.h b/source/blender/freestyle/intern/python/BPy_BBox.h index 09978308781..84542dc6d1c 100644 --- a/source/blender/freestyle/intern/python/BPy_BBox.h +++ b/source/blender/freestyle/intern/python/BPy_BBox.h @@ -43,20 +43,17 @@ extern PyTypeObject BBox_Type; /*---------------------------Python BPy_BBox structure definition----------*/ typedef struct { - PyObject_HEAD - BBox *bb; + PyObject_HEAD BBox *bb; } BPy_BBox; /*---------------------------Python BPy_BBox visible prototypes-----------*/ int BBox_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_BBOX_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp index 60a85a4594e..6d3c91ed347 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp @@ -32,147 +32,157 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int BinaryPredicate0D_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&BinaryPredicate0D_Type) < 0) - return -1; - Py_INCREF(&BinaryPredicate0D_Type); - PyModule_AddObject(module, "BinaryPredicate0D", (PyObject *)&BinaryPredicate0D_Type); + if (PyType_Ready(&BinaryPredicate0D_Type) < 0) + return -1; + Py_INCREF(&BinaryPredicate0D_Type); + PyModule_AddObject(module, "BinaryPredicate0D", (PyObject *)&BinaryPredicate0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char BinaryPredicate0D___doc__[] = -"Base class for binary predicates working on :class:`Interface0D`\n" -"objects. A BinaryPredicate0D is typically an ordering relation\n" -"between two Interface0D objects. The predicate evaluates a relation\n" -"between the two Interface0D instances and returns a boolean value (true\n" -"or false). It is used by invoking the __call__() method.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Must be overload by inherited classes. It evaluates a relation\n" -" between two Interface0D objects.\n" -"\n" -" :arg inter1: The first Interface0D object.\n" -" :type inter1: :class:`Interface0D`\n" -" :arg inter2: The second Interface0D object.\n" -" :type inter2: :class:`Interface0D`\n" -" :return: True or false.\n" -" :rtype: bool\n"; + "Base class for binary predicates working on :class:`Interface0D`\n" + "objects. A BinaryPredicate0D is typically an ordering relation\n" + "between two Interface0D objects. The predicate evaluates a relation\n" + "between the two Interface0D instances and returns a boolean value (true\n" + "or false). It is used by invoking the __call__() method.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Must be overload by inherited classes. It evaluates a relation\n" + " between two Interface0D objects.\n" + "\n" + " :arg inter1: The first Interface0D object.\n" + " :type inter1: :class:`Interface0D`\n" + " :arg inter2: The second Interface0D object.\n" + " :type inter2: :class:`Interface0D`\n" + " :return: True or false.\n" + " :rtype: bool\n"; static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->bp0D = new BinaryPredicate0D(); - self->bp0D->py_bp0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->bp0D = new BinaryPredicate0D(); + self->bp0D->py_bp0D = (PyObject *)self; + return 0; } static void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D *self) { - if (self->bp0D) - delete self->bp0D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->bp0D) + delete self->bp0D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp0D); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp0D); } -static PyObject *BinaryPredicate0D___call__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds) +static PyObject *BinaryPredicate0D___call__(BPy_BinaryPredicate0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter1", "inter2", NULL}; - BPy_Interface0D *obj1, *obj2; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &Interface0D_Type, &obj1, &Interface0D_Type, &obj2)) - { - return NULL; - } - if (typeid(*(self->bp0D)) == typeid(BinaryPredicate0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->bp0D->operator()(*(obj1->if0D), *(obj2->if0D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyBool_from_bool(self->bp0D->result); + static const char *kwlist[] = {"inter1", "inter2", NULL}; + BPy_Interface0D *obj1, *obj2; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist, + &Interface0D_Type, + &obj1, + &Interface0D_Type, + &obj2)) { + return NULL; + } + if (typeid(*(self->bp0D)) == typeid(BinaryPredicate0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->bp0D->operator()(*(obj1->if0D), *(obj2->if0D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyBool_from_bool(self->bp0D->result); } /*----------------------BinaryPredicate0D get/setters ----------------------------*/ PyDoc_STRVAR(BinaryPredicate0D_name_doc, -"The name of the binary 0D predicate.\n" -"\n" -":type: str"); + "The name of the binary 0D predicate.\n" + "\n" + ":type: str"); static PyObject *BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_BinaryPredicate0D_getseters[] = { - {(char *)"name", (getter)BinaryPredicate0D_name_get, (setter)NULL, (char *)BinaryPredicate0D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)BinaryPredicate0D_name_get, + (setter)NULL, + (char *)BinaryPredicate0D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_BinaryPredicate0D type definition ------------------------------*/ PyTypeObject BinaryPredicate0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BinaryPredicate0D", /* tp_name */ - sizeof(BPy_BinaryPredicate0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BinaryPredicate0D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)BinaryPredicate0D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)BinaryPredicate0D___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BinaryPredicate0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_BinaryPredicate0D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BinaryPredicate0D___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BinaryPredicate0D", /* tp_name */ + sizeof(BPy_BinaryPredicate0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)BinaryPredicate0D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)BinaryPredicate0D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)BinaryPredicate0D___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BinaryPredicate0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_BinaryPredicate0D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BinaryPredicate0D___init__, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.h b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.h index 6e27872d48a..3d0575a676c 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.h +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.h @@ -37,24 +37,22 @@ extern "C" { extern PyTypeObject BinaryPredicate0D_Type; -#define BPy_BinaryPredicate0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&BinaryPredicate0D_Type)) +#define BPy_BinaryPredicate0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&BinaryPredicate0D_Type)) /*---------------------------Python BPy_BinaryPredicate0D structure definition----------*/ typedef struct { - PyObject_HEAD - BinaryPredicate0D *bp0D; + PyObject_HEAD BinaryPredicate0D *bp0D; } BPy_BinaryPredicate0D; /*---------------------------Python BPy_BinaryPredicate0D visible prototypes-----------*/ int BinaryPredicate0D_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_BINARYPREDICATE0D_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp index b745d0ed628..5b3f3945549 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp @@ -38,171 +38,181 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int BinaryPredicate1D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&BinaryPredicate1D_Type) < 0) - return -1; - Py_INCREF(&BinaryPredicate1D_Type); - PyModule_AddObject(module, "BinaryPredicate1D", (PyObject *)&BinaryPredicate1D_Type); - - if (PyType_Ready(&FalseBP1D_Type) < 0) - return -1; - Py_INCREF(&FalseBP1D_Type); - PyModule_AddObject(module, "FalseBP1D", (PyObject *)&FalseBP1D_Type); - - if (PyType_Ready(&Length2DBP1D_Type) < 0) - return -1; - Py_INCREF(&Length2DBP1D_Type); - PyModule_AddObject(module, "Length2DBP1D", (PyObject *)&Length2DBP1D_Type); - - if (PyType_Ready(&SameShapeIdBP1D_Type) < 0) - return -1; - Py_INCREF(&SameShapeIdBP1D_Type); - PyModule_AddObject(module, "SameShapeIdBP1D", (PyObject *)&SameShapeIdBP1D_Type); - - if (PyType_Ready(&TrueBP1D_Type) < 0) - return -1; - Py_INCREF(&TrueBP1D_Type); - PyModule_AddObject(module, "TrueBP1D", (PyObject *)&TrueBP1D_Type); - - if (PyType_Ready(&ViewMapGradientNormBP1D_Type) < 0) - return -1; - Py_INCREF(&ViewMapGradientNormBP1D_Type); - PyModule_AddObject(module, "ViewMapGradientNormBP1D", (PyObject *)&ViewMapGradientNormBP1D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&BinaryPredicate1D_Type) < 0) + return -1; + Py_INCREF(&BinaryPredicate1D_Type); + PyModule_AddObject(module, "BinaryPredicate1D", (PyObject *)&BinaryPredicate1D_Type); + + if (PyType_Ready(&FalseBP1D_Type) < 0) + return -1; + Py_INCREF(&FalseBP1D_Type); + PyModule_AddObject(module, "FalseBP1D", (PyObject *)&FalseBP1D_Type); + + if (PyType_Ready(&Length2DBP1D_Type) < 0) + return -1; + Py_INCREF(&Length2DBP1D_Type); + PyModule_AddObject(module, "Length2DBP1D", (PyObject *)&Length2DBP1D_Type); + + if (PyType_Ready(&SameShapeIdBP1D_Type) < 0) + return -1; + Py_INCREF(&SameShapeIdBP1D_Type); + PyModule_AddObject(module, "SameShapeIdBP1D", (PyObject *)&SameShapeIdBP1D_Type); + + if (PyType_Ready(&TrueBP1D_Type) < 0) + return -1; + Py_INCREF(&TrueBP1D_Type); + PyModule_AddObject(module, "TrueBP1D", (PyObject *)&TrueBP1D_Type); + + if (PyType_Ready(&ViewMapGradientNormBP1D_Type) < 0) + return -1; + Py_INCREF(&ViewMapGradientNormBP1D_Type); + PyModule_AddObject(module, "ViewMapGradientNormBP1D", (PyObject *)&ViewMapGradientNormBP1D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char BinaryPredicate1D___doc__[] = -"Base class for binary predicates working on :class:`Interface1D`\n" -"objects. A BinaryPredicate1D is typically an ordering relation\n" -"between two Interface1D objects. The predicate evaluates a relation\n" -"between the two Interface1D instances and returns a boolean value (true\n" -"or false). It is used by invoking the __call__() method.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Must be overload by inherited classes. It evaluates a relation\n" -" between two Interface1D objects.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`Interface1D`\n" -" :return: True or false.\n" -" :rtype: bool\n"; + "Base class for binary predicates working on :class:`Interface1D`\n" + "objects. A BinaryPredicate1D is typically an ordering relation\n" + "between two Interface1D objects. The predicate evaluates a relation\n" + "between the two Interface1D instances and returns a boolean value (true\n" + "or false). It is used by invoking the __call__() method.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Must be overload by inherited classes. It evaluates a relation\n" + " between two Interface1D objects.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`Interface1D`\n" + " :return: True or false.\n" + " :rtype: bool\n"; static int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->bp1D = new BinaryPredicate1D(); - self->bp1D->py_bp1D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->bp1D = new BinaryPredicate1D(); + self->bp1D->py_bp1D = (PyObject *)self; + return 0; } static void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D *self) { - if (self->bp1D) - delete self->bp1D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->bp1D) + delete self->bp1D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *BinaryPredicate1D___repr__(BPy_BinaryPredicate1D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp1D); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp1D); } -static PyObject *BinaryPredicate1D___call__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds) +static PyObject *BinaryPredicate1D___call__(BPy_BinaryPredicate1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter1", "inter2", NULL}; - BPy_Interface1D *obj1, *obj2; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &Interface1D_Type, &obj1, &Interface1D_Type, &obj2)) - { - return NULL; - } - if (typeid(*(self->bp1D)) == typeid(BinaryPredicate1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->bp1D->operator()(*(obj1->if1D), *(obj2->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyBool_from_bool(self->bp1D->result); + static const char *kwlist[] = {"inter1", "inter2", NULL}; + BPy_Interface1D *obj1, *obj2; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist, + &Interface1D_Type, + &obj1, + &Interface1D_Type, + &obj2)) { + return NULL; + } + if (typeid(*(self->bp1D)) == typeid(BinaryPredicate1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->bp1D->operator()(*(obj1->if1D), *(obj2->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyBool_from_bool(self->bp1D->result); } /*----------------------BinaryPredicate0D get/setters ----------------------------*/ PyDoc_STRVAR(BinaryPredicate1D_name_doc, -"The name of the binary 1D predicate.\n" -"\n" -":type: str"); + "The name of the binary 1D predicate.\n" + "\n" + ":type: str"); static PyObject *BinaryPredicate1D_name_get(BPy_BinaryPredicate1D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_BinaryPredicate1D_getseters[] = { - {(char *)"name", (getter)BinaryPredicate1D_name_get, (setter)NULL, (char *)BinaryPredicate1D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)BinaryPredicate1D_name_get, + (setter)NULL, + (char *)BinaryPredicate1D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_BinaryPredicate1D type definition ------------------------------*/ PyTypeObject BinaryPredicate1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BinaryPredicate1D", /* tp_name */ - sizeof(BPy_BinaryPredicate1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BinaryPredicate1D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)BinaryPredicate1D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)BinaryPredicate1D___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BinaryPredicate1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_BinaryPredicate1D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BinaryPredicate1D___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BinaryPredicate1D", /* tp_name */ + sizeof(BPy_BinaryPredicate1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)BinaryPredicate1D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)BinaryPredicate1D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)BinaryPredicate1D___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BinaryPredicate1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_BinaryPredicate1D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BinaryPredicate1D___init__, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.h b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.h index 20a660e3a3f..b258f293694 100644 --- a/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.h +++ b/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject BinaryPredicate1D_Type; -#define BPy_BinaryPredicate1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&BinaryPredicate1D_Type)) +#define BPy_BinaryPredicate1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&BinaryPredicate1D_Type)) /*---------------------------Python BPy_BinaryPredicate1D structure definition----------*/ typedef struct { - PyObject_HEAD - BinaryPredicate1D *bp1D; + PyObject_HEAD BinaryPredicate1D *bp1D; } BPy_BinaryPredicate1D; /*---------------------------Python BPy_BinaryPredicate1D visible prototypes-----------*/ @@ -55,5 +55,4 @@ int BinaryPredicate1D_Init(PyObject *module); } #endif - #endif /* __FREESTYLE_PYTHON_BINARYPREDICATE1D_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp b/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp index 371a549e0e3..a2e483dec7e 100644 --- a/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp +++ b/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp @@ -34,206 +34,206 @@ extern "C" { //------------------------ MODULE FUNCTIONS ---------------------------------- static char ContextFunctions_get_time_stamp___doc__[] = -".. function:: get_time_stamp()\n" -"\n" -" Returns the system time stamp.\n" -"\n" -" :return: The system time stamp.\n" -" :rtype: int\n"; - -static PyObject * -ContextFunctions_get_time_stamp(PyObject * /*self*/) + ".. function:: get_time_stamp()\n" + "\n" + " Returns the system time stamp.\n" + "\n" + " :return: The system time stamp.\n" + " :rtype: int\n"; + +static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/) { - return PyLong_FromLong(ContextFunctions::GetTimeStampCF()); + return PyLong_FromLong(ContextFunctions::GetTimeStampCF()); } static char ContextFunctions_get_canvas_width___doc__[] = -".. method:: get_canvas_width()\n" -"\n" -" Returns the canvas width.\n" -"\n" -" :return: The canvas width.\n" -" :rtype: int\n"; - -static PyObject * -ContextFunctions_get_canvas_width(PyObject * /*self*/) + ".. method:: get_canvas_width()\n" + "\n" + " Returns the canvas width.\n" + "\n" + " :return: The canvas width.\n" + " :rtype: int\n"; + +static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/) { - return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF()); + return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF()); } static char ContextFunctions_get_canvas_height___doc__[] = -".. method:: get_canvas_height()\n" -"\n" -" Returns the canvas height.\n" -"\n" -" :return: The canvas height.\n" -" :rtype: int\n"; - -static PyObject * -ContextFunctions_get_canvas_height(PyObject * /*self*/) + ".. method:: get_canvas_height()\n" + "\n" + " Returns the canvas height.\n" + "\n" + " :return: The canvas height.\n" + " :rtype: int\n"; + +static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/) { - return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF()); + return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF()); } static char ContextFunctions_get_border___doc__[] = -".. method:: get_border()\n" -"\n" -" Returns the border.\n" -"\n" -" :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n" -" :rtype: tuple\n"; - -static PyObject * -ContextFunctions_get_border(PyObject * /*self*/) + ".. method:: get_border()\n" + "\n" + " Returns the border.\n" + "\n" + " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n" + " :rtype: tuple\n"; + +static PyObject *ContextFunctions_get_border(PyObject * /*self*/) { - BBox border(ContextFunctions::GetBorderCF()); - PyObject *v = PyTuple_New(4); - PyTuple_SET_ITEMS(v, - PyLong_FromLong(border.getMin().x()), - PyLong_FromLong(border.getMin().y()), - PyLong_FromLong(border.getMax().x()), - PyLong_FromLong(border.getMax().y())); - return v; + BBox border(ContextFunctions::GetBorderCF()); + PyObject *v = PyTuple_New(4); + PyTuple_SET_ITEMS(v, + PyLong_FromLong(border.getMin().x()), + PyLong_FromLong(border.getMin().y()), + PyLong_FromLong(border.getMax().x()), + PyLong_FromLong(border.getMax().y())); + return v; } static char ContextFunctions_load_map___doc__[] = -".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n" -"\n" -" Loads an image map for further reading.\n" -"\n" -" :arg file_name: The name of the image file.\n" -" :type file_name: str\n" -" :arg map_name: The name that will be used to access this image.\n" -" :type map_name: str\n" -" :arg num_levels: The number of levels in the map pyramid\n" -" (default = 4). If num_levels == 0, the complete pyramid is\n" -" built.\n" -" :type num_levels: int\n" -" :arg sigma: The sigma value of the gaussian function.\n" -" :type sigma: float\n"; - -static PyObject * -ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds) + ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n" + "\n" + " Loads an image map for further reading.\n" + "\n" + " :arg file_name: The name of the image file.\n" + " :type file_name: str\n" + " :arg map_name: The name that will be used to access this image.\n" + " :type map_name: str\n" + " :arg num_levels: The number of levels in the map pyramid\n" + " (default = 4). If num_levels == 0, the complete pyramid is\n" + " built.\n" + " :type num_levels: int\n" + " :arg sigma: The sigma value of the gaussian function.\n" + " :type sigma: float\n"; + +static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", NULL}; - char *fileName, *mapName; - unsigned nbLevels = 4; - float sigma = 1.0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) - return NULL; - ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma); - Py_RETURN_NONE; + static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", NULL}; + char *fileName, *mapName; + unsigned nbLevels = 4; + float sigma = 1.0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) + return NULL; + ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma); + Py_RETURN_NONE; } static char ContextFunctions_read_map_pixel___doc__[] = -".. function:: read_map_pixel(map_name, level, x, y)\n" -"\n" -" Reads a pixel in a user-defined map.\n" -"\n" -" :arg map_name: The name of the map.\n" -" :type map_name: str\n" -" :arg level: The level of the pyramid in which we wish to read the\n" -" pixel.\n" -" :type level: int\n" -" :arg x: The x coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type x: int\n" -" :arg y: The y coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type y: int\n" -" :return: The floating-point value stored for that pixel.\n" -" :rtype: float\n"; - -static PyObject * -ContextFunctions_read_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) + ".. function:: read_map_pixel(map_name, level, x, y)\n" + "\n" + " Reads a pixel in a user-defined map.\n" + "\n" + " :arg map_name: The name of the map.\n" + " :type map_name: str\n" + " :arg level: The level of the pyramid in which we wish to read the\n" + " pixel.\n" + " :type level: int\n" + " :arg x: The x coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type x: int\n" + " :arg y: The y coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type y: int\n" + " :return: The floating-point value stored for that pixel.\n" + " :rtype: float\n"; + +static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"map_name", "level", "x", "y", NULL}; - char *mapName; - int level; - unsigned x, y; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) - return NULL; - return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y)); + static const char *kwlist[] = {"map_name", "level", "x", "y", NULL}; + char *mapName; + int level; + unsigned x, y; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) + return NULL; + return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y)); } static char ContextFunctions_read_complete_view_map_pixel___doc__[] = -".. function:: read_complete_view_map_pixel(level, x, y)\n" -"\n" -" Reads a pixel in the complete view map.\n" -"\n" -" :arg level: The level of the pyramid in which we wish to read the\n" -" pixel.\n" -" :type level: int\n" -" :arg x: The x coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type x: int\n" -" :arg y: The y coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type y: int\n" -" :return: The floating-point value stored for that pixel.\n" -" :rtype: float\n"; - -static PyObject * -ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) + ".. function:: read_complete_view_map_pixel(level, x, y)\n" + "\n" + " Reads a pixel in the complete view map.\n" + "\n" + " :arg level: The level of the pyramid in which we wish to read the\n" + " pixel.\n" + " :type level: int\n" + " :arg x: The x coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type x: int\n" + " :arg y: The y coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type y: int\n" + " :return: The floating-point value stored for that pixel.\n" + " :rtype: float\n"; + +static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", "x", "y", NULL}; - int level; - unsigned x, y; + static const char *kwlist[] = {"level", "x", "y", NULL}; + int level; + unsigned x, y; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) - return NULL; - return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) + return NULL; + return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y)); } static char ContextFunctions_read_directional_view_map_pixel___doc__[] = -".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n" -"\n" -" Reads a pixel in one of the oriented view map images.\n" -"\n" -" :arg orientation: The number telling which orientation we want to\n" -" check.\n" -" :type orientation: int\n" -" :arg level: The level of the pyramid in which we wish to read the\n" -" pixel.\n" -" :type level: int\n" -" :arg x: The x coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type x: int\n" -" :arg y: The y coordinate of the pixel we wish to read. The origin\n" -" is in the lower-left corner.\n" -" :type y: int\n" -" :return: The floating-point value stored for that pixel.\n" -" :rtype: float\n"; - -static PyObject * -ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) + ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n" + "\n" + " Reads a pixel in one of the oriented view map images.\n" + "\n" + " :arg orientation: The number telling which orientation we want to\n" + " check.\n" + " :type orientation: int\n" + " :arg level: The level of the pyramid in which we wish to read the\n" + " pixel.\n" + " :type level: int\n" + " :arg x: The x coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type x: int\n" + " :arg y: The y coordinate of the pixel we wish to read. The origin\n" + " is in the lower-left corner.\n" + " :type y: int\n" + " :return: The floating-point value stored for that pixel.\n" + " :rtype: float\n"; + +static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"orientation", "level", "x", "y", NULL}; - int orientation, level; - unsigned x, y; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) - return NULL; - return PyFloat_FromDouble(ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y)); + static const char *kwlist[] = {"orientation", "level", "x", "y", NULL}; + int orientation, level; + unsigned x, y; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) + return NULL; + return PyFloat_FromDouble( + ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y)); } static char ContextFunctions_get_selected_fedge___doc__[] = -".. function:: get_selected_fedge()\n" -"\n" -" Returns the selected FEdge.\n" -"\n" -" :return: The selected FEdge.\n" -" :rtype: :class:`FEdge`\n"; - -static PyObject * -ContextFunctions_get_selected_fedge(PyObject * /*self*/) + ".. function:: get_selected_fedge()\n" + "\n" + " Returns the selected FEdge.\n" + "\n" + " :return: The selected FEdge.\n" + " :rtype: :class:`FEdge`\n"; + +static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/) { - FEdge *fe = ContextFunctions::GetSelectedFEdgeCF(); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + FEdge *fe = ContextFunctions::GetSelectedFEdgeCF(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } /*-----------------------ContextFunctions module docstring-------------------------------*/ @@ -243,27 +243,43 @@ static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodu /*-----------------------ContextFunctions module functions definitions-------------------*/ static PyMethodDef module_functions[] = { - {"get_time_stamp", (PyCFunction)ContextFunctions_get_time_stamp, METH_NOARGS, - ContextFunctions_get_time_stamp___doc__}, - {"get_canvas_width", (PyCFunction)ContextFunctions_get_canvas_width, METH_NOARGS, - ContextFunctions_get_canvas_width___doc__}, - {"get_canvas_height", (PyCFunction)ContextFunctions_get_canvas_height, METH_NOARGS, - ContextFunctions_get_canvas_height___doc__}, - {"get_border", (PyCFunction)ContextFunctions_get_border, METH_NOARGS, - ContextFunctions_get_border___doc__}, - {"load_map", (PyCFunction)ContextFunctions_load_map, METH_VARARGS | METH_KEYWORDS, - ContextFunctions_load_map___doc__}, - {"read_map_pixel", (PyCFunction)ContextFunctions_read_map_pixel, METH_VARARGS | METH_KEYWORDS, - ContextFunctions_read_map_pixel___doc__}, - {"read_complete_view_map_pixel", (PyCFunction)ContextFunctions_read_complete_view_map_pixel, - METH_VARARGS | METH_KEYWORDS, - ContextFunctions_read_complete_view_map_pixel___doc__}, - {"read_directional_view_map_pixel", (PyCFunction)ContextFunctions_read_directional_view_map_pixel, - METH_VARARGS | METH_KEYWORDS, - ContextFunctions_read_directional_view_map_pixel___doc__}, - {"get_selected_fedge", (PyCFunction)ContextFunctions_get_selected_fedge, METH_NOARGS, - ContextFunctions_get_selected_fedge___doc__}, - {NULL, NULL, 0, NULL}, + {"get_time_stamp", + (PyCFunction)ContextFunctions_get_time_stamp, + METH_NOARGS, + ContextFunctions_get_time_stamp___doc__}, + {"get_canvas_width", + (PyCFunction)ContextFunctions_get_canvas_width, + METH_NOARGS, + ContextFunctions_get_canvas_width___doc__}, + {"get_canvas_height", + (PyCFunction)ContextFunctions_get_canvas_height, + METH_NOARGS, + ContextFunctions_get_canvas_height___doc__}, + {"get_border", + (PyCFunction)ContextFunctions_get_border, + METH_NOARGS, + ContextFunctions_get_border___doc__}, + {"load_map", + (PyCFunction)ContextFunctions_load_map, + METH_VARARGS | METH_KEYWORDS, + ContextFunctions_load_map___doc__}, + {"read_map_pixel", + (PyCFunction)ContextFunctions_read_map_pixel, + METH_VARARGS | METH_KEYWORDS, + ContextFunctions_read_map_pixel___doc__}, + {"read_complete_view_map_pixel", + (PyCFunction)ContextFunctions_read_complete_view_map_pixel, + METH_VARARGS | METH_KEYWORDS, + ContextFunctions_read_complete_view_map_pixel___doc__}, + {"read_directional_view_map_pixel", + (PyCFunction)ContextFunctions_read_directional_view_map_pixel, + METH_VARARGS | METH_KEYWORDS, + ContextFunctions_read_directional_view_map_pixel___doc__}, + {"get_selected_fedge", + (PyCFunction)ContextFunctions_get_selected_fedge, + METH_NOARGS, + ContextFunctions_get_selected_fedge___doc__}, + {NULL, NULL, 0, NULL}, }; /*-----------------------ContextFunctions module definition--------------------------------*/ @@ -280,18 +296,18 @@ static PyModuleDef module_definition = { int ContextFunctions_Init(PyObject *module) { - PyObject *m; + PyObject *m; - if (module == NULL) - return -1; + if (module == NULL) + return -1; - m = PyModule_Create(&module_definition); - if (m == NULL) - return -1; - Py_INCREF(m); - PyModule_AddObject(module, "ContextFunctions", m); + m = PyModule_Create(&module_definition); + if (m == NULL) + return -1; + Py_INCREF(m); + PyModule_AddObject(module, "ContextFunctions", m); - return 0; + return 0; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index e3e1d7e3301..d22061d1610 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -69,429 +69,436 @@ extern "C" { PyObject *PyBool_from_bool(bool b) { - return PyBool_FromLong(b ? 1 : 0); -} - -PyObject *Vector_from_Vec2f(Vec2f& vec) -{ - float vec_data[2]; // because vec->_coord is protected - vec_data[0] = vec.x(); - vec_data[1] = vec.y(); - return Vector_CreatePyObject(vec_data, 2, NULL); -} - -PyObject *Vector_from_Vec3f(Vec3f& vec) -{ - float vec_data[3]; // because vec->_coord is protected - vec_data[0] = vec.x(); - vec_data[1] = vec.y(); - vec_data[2] = vec.z(); - return Vector_CreatePyObject(vec_data, 3, NULL); -} - -PyObject *Vector_from_Vec3r(Vec3r& vec) -{ - float vec_data[3]; // because vec->_coord is protected - vec_data[0] = vec.x(); - vec_data[1] = vec.y(); - vec_data[2] = vec.z(); - return Vector_CreatePyObject(vec_data, 3, NULL); -} - -PyObject *BPy_Id_from_Id(Id& id) -{ - PyObject *py_id = Id_Type.tp_new(&Id_Type, 0, 0); - ((BPy_Id *)py_id)->id = new Id(id.getFirst(), id.getSecond()); - return py_id; -} - -PyObject *Any_BPy_Interface0D_from_Interface0D(Interface0D& if0D) -{ - if (typeid(if0D) == typeid(CurvePoint)) { - return BPy_CurvePoint_from_CurvePoint(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(StrokeVertex)) { - return BPy_StrokeVertex_from_StrokeVertex(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(SVertex)) { - return BPy_SVertex_from_SVertex(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(ViewVertex)) { - return BPy_ViewVertex_from_ViewVertex(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(NonTVertex)) { - return BPy_NonTVertex_from_NonTVertex(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(TVertex)) { - return BPy_TVertex_from_TVertex(dynamic_cast(if0D)); - } - else if (typeid(if0D) == typeid(Interface0D)) { - return BPy_Interface0D_from_Interface0D(if0D); - } - string msg("unexpected type: " + if0D.getExactTypeName()); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return NULL; -} - -PyObject *Any_BPy_Interface1D_from_Interface1D(Interface1D& if1D) -{ - if (typeid(if1D) == typeid(ViewEdge)) { - return BPy_ViewEdge_from_ViewEdge(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(Chain)) { - return BPy_Chain_from_Chain(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(Stroke)) { - return BPy_Stroke_from_Stroke(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(FEdgeSharp)) { - return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(FEdgeSmooth)) { - return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(FEdge)) { - return BPy_FEdge_from_FEdge(dynamic_cast(if1D)); - } - else if (typeid(if1D) == typeid(Interface1D)) { - return BPy_Interface1D_from_Interface1D(if1D); - } - string msg("unexpected type: " + if1D.getExactTypeName()); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return NULL; + return PyBool_FromLong(b ? 1 : 0); +} + +PyObject *Vector_from_Vec2f(Vec2f &vec) +{ + float vec_data[2]; // because vec->_coord is protected + vec_data[0] = vec.x(); + vec_data[1] = vec.y(); + return Vector_CreatePyObject(vec_data, 2, NULL); +} + +PyObject *Vector_from_Vec3f(Vec3f &vec) +{ + float vec_data[3]; // because vec->_coord is protected + vec_data[0] = vec.x(); + vec_data[1] = vec.y(); + vec_data[2] = vec.z(); + return Vector_CreatePyObject(vec_data, 3, NULL); +} + +PyObject *Vector_from_Vec3r(Vec3r &vec) +{ + float vec_data[3]; // because vec->_coord is protected + vec_data[0] = vec.x(); + vec_data[1] = vec.y(); + vec_data[2] = vec.z(); + return Vector_CreatePyObject(vec_data, 3, NULL); +} + +PyObject *BPy_Id_from_Id(Id &id) +{ + PyObject *py_id = Id_Type.tp_new(&Id_Type, 0, 0); + ((BPy_Id *)py_id)->id = new Id(id.getFirst(), id.getSecond()); + return py_id; +} + +PyObject *Any_BPy_Interface0D_from_Interface0D(Interface0D &if0D) +{ + if (typeid(if0D) == typeid(CurvePoint)) { + return BPy_CurvePoint_from_CurvePoint(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(StrokeVertex)) { + return BPy_StrokeVertex_from_StrokeVertex(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(SVertex)) { + return BPy_SVertex_from_SVertex(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(ViewVertex)) { + return BPy_ViewVertex_from_ViewVertex(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(NonTVertex)) { + return BPy_NonTVertex_from_NonTVertex(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(TVertex)) { + return BPy_TVertex_from_TVertex(dynamic_cast(if0D)); + } + else if (typeid(if0D) == typeid(Interface0D)) { + return BPy_Interface0D_from_Interface0D(if0D); + } + string msg("unexpected type: " + if0D.getExactTypeName()); + PyErr_SetString(PyExc_TypeError, msg.c_str()); + return NULL; +} + +PyObject *Any_BPy_Interface1D_from_Interface1D(Interface1D &if1D) +{ + if (typeid(if1D) == typeid(ViewEdge)) { + return BPy_ViewEdge_from_ViewEdge(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(Chain)) { + return BPy_Chain_from_Chain(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(Stroke)) { + return BPy_Stroke_from_Stroke(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(FEdgeSharp)) { + return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(FEdgeSmooth)) { + return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(FEdge)) { + return BPy_FEdge_from_FEdge(dynamic_cast(if1D)); + } + else if (typeid(if1D) == typeid(Interface1D)) { + return BPy_Interface1D_from_Interface1D(if1D); + } + string msg("unexpected type: " + if1D.getExactTypeName()); + PyErr_SetString(PyExc_TypeError, msg.c_str()); + return NULL; } -PyObject *Any_BPy_FEdge_from_FEdge(FEdge& fe) +PyObject *Any_BPy_FEdge_from_FEdge(FEdge &fe) { - if (typeid(fe) == typeid(FEdgeSharp)) { - return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast(fe)); - } - else if (typeid(fe) == typeid(FEdgeSmooth)) { - return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast(fe)); - } - else if (typeid(fe) == typeid(FEdge)) { - return BPy_FEdge_from_FEdge(fe); - } - string msg("unexpected type: " + fe.getExactTypeName()); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return NULL; -} - -PyObject *Any_BPy_ViewVertex_from_ViewVertex(ViewVertex& vv) -{ - if (typeid(vv) == typeid(NonTVertex)) { - return BPy_NonTVertex_from_NonTVertex(dynamic_cast(vv)); - } - else if (typeid(vv) == typeid(TVertex)) { - return BPy_TVertex_from_TVertex(dynamic_cast(vv)); - } - else if (typeid(vv) == typeid(ViewVertex)) { - return BPy_ViewVertex_from_ViewVertex(vv); - } - string msg("unexpected type: " + vv.getExactTypeName()); - PyErr_SetString(PyExc_TypeError, msg.c_str()); - return NULL; -} - -PyObject *BPy_Interface0D_from_Interface0D(Interface0D& if0D) -{ - PyObject *py_if0D = Interface0D_Type.tp_new(&Interface0D_Type, 0, 0); - ((BPy_Interface0D *)py_if0D)->if0D = &if0D; - ((BPy_Interface0D *)py_if0D)->borrowed = true; - return py_if0D; -} - -PyObject *BPy_Interface1D_from_Interface1D(Interface1D& if1D) -{ - PyObject *py_if1D = Interface1D_Type.tp_new(&Interface1D_Type, 0, 0); - ((BPy_Interface1D *)py_if1D)->if1D = &if1D; - ((BPy_Interface1D *)py_if1D)->borrowed = true; - return py_if1D; -} - -PyObject *BPy_SVertex_from_SVertex(SVertex& sv) -{ - PyObject *py_sv = SVertex_Type.tp_new(&SVertex_Type, 0, 0); - ((BPy_SVertex *)py_sv)->sv = &sv; - ((BPy_SVertex *)py_sv)->py_if0D.if0D = ((BPy_SVertex *)py_sv)->sv; - ((BPy_SVertex *)py_sv)->py_if0D.borrowed = true; - return py_sv; -} - -PyObject *BPy_FEdgeSharp_from_FEdgeSharp(FEdgeSharp& fes) -{ - PyObject *py_fe = FEdgeSharp_Type.tp_new(&FEdgeSharp_Type, 0, 0); - ((BPy_FEdgeSharp *)py_fe)->fes = &fes; - ((BPy_FEdgeSharp *)py_fe)->py_fe.fe = ((BPy_FEdgeSharp *)py_fe)->fes; - ((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSharp *)py_fe)->fes; - ((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.borrowed = true; - return py_fe; -} - -PyObject *BPy_FEdgeSmooth_from_FEdgeSmooth(FEdgeSmooth& fes) + if (typeid(fe) == typeid(FEdgeSharp)) { + return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast(fe)); + } + else if (typeid(fe) == typeid(FEdgeSmooth)) { + return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast(fe)); + } + else if (typeid(fe) == typeid(FEdge)) { + return BPy_FEdge_from_FEdge(fe); + } + string msg("unexpected type: " + fe.getExactTypeName()); + PyErr_SetString(PyExc_TypeError, msg.c_str()); + return NULL; +} + +PyObject *Any_BPy_ViewVertex_from_ViewVertex(ViewVertex &vv) +{ + if (typeid(vv) == typeid(NonTVertex)) { + return BPy_NonTVertex_from_NonTVertex(dynamic_cast(vv)); + } + else if (typeid(vv) == typeid(TVertex)) { + return BPy_TVertex_from_TVertex(dynamic_cast(vv)); + } + else if (typeid(vv) == typeid(ViewVertex)) { + return BPy_ViewVertex_from_ViewVertex(vv); + } + string msg("unexpected type: " + vv.getExactTypeName()); + PyErr_SetString(PyExc_TypeError, msg.c_str()); + return NULL; +} + +PyObject *BPy_Interface0D_from_Interface0D(Interface0D &if0D) +{ + PyObject *py_if0D = Interface0D_Type.tp_new(&Interface0D_Type, 0, 0); + ((BPy_Interface0D *)py_if0D)->if0D = &if0D; + ((BPy_Interface0D *)py_if0D)->borrowed = true; + return py_if0D; +} + +PyObject *BPy_Interface1D_from_Interface1D(Interface1D &if1D) +{ + PyObject *py_if1D = Interface1D_Type.tp_new(&Interface1D_Type, 0, 0); + ((BPy_Interface1D *)py_if1D)->if1D = &if1D; + ((BPy_Interface1D *)py_if1D)->borrowed = true; + return py_if1D; +} + +PyObject *BPy_SVertex_from_SVertex(SVertex &sv) +{ + PyObject *py_sv = SVertex_Type.tp_new(&SVertex_Type, 0, 0); + ((BPy_SVertex *)py_sv)->sv = &sv; + ((BPy_SVertex *)py_sv)->py_if0D.if0D = ((BPy_SVertex *)py_sv)->sv; + ((BPy_SVertex *)py_sv)->py_if0D.borrowed = true; + return py_sv; +} + +PyObject *BPy_FEdgeSharp_from_FEdgeSharp(FEdgeSharp &fes) +{ + PyObject *py_fe = FEdgeSharp_Type.tp_new(&FEdgeSharp_Type, 0, 0); + ((BPy_FEdgeSharp *)py_fe)->fes = &fes; + ((BPy_FEdgeSharp *)py_fe)->py_fe.fe = ((BPy_FEdgeSharp *)py_fe)->fes; + ((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSharp *)py_fe)->fes; + ((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.borrowed = true; + return py_fe; +} + +PyObject *BPy_FEdgeSmooth_from_FEdgeSmooth(FEdgeSmooth &fes) { - PyObject *py_fe = FEdgeSmooth_Type.tp_new(&FEdgeSmooth_Type, 0, 0); - ((BPy_FEdgeSmooth *)py_fe)->fes = &fes; - ((BPy_FEdgeSmooth *)py_fe)->py_fe.fe = ((BPy_FEdgeSmooth *)py_fe)->fes; - ((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSmooth *)py_fe)->fes; - ((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.borrowed = true; - return py_fe; -} - -PyObject *BPy_FEdge_from_FEdge(FEdge& fe) -{ - PyObject *py_fe = FEdge_Type.tp_new(&FEdge_Type, 0, 0); - ((BPy_FEdge *)py_fe)->fe = &fe; - ((BPy_FEdge *)py_fe)->py_if1D.if1D = ((BPy_FEdge *)py_fe)->fe; - ((BPy_FEdge *)py_fe)->py_if1D.borrowed = true; - return py_fe; + PyObject *py_fe = FEdgeSmooth_Type.tp_new(&FEdgeSmooth_Type, 0, 0); + ((BPy_FEdgeSmooth *)py_fe)->fes = &fes; + ((BPy_FEdgeSmooth *)py_fe)->py_fe.fe = ((BPy_FEdgeSmooth *)py_fe)->fes; + ((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSmooth *)py_fe)->fes; + ((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.borrowed = true; + return py_fe; +} + +PyObject *BPy_FEdge_from_FEdge(FEdge &fe) +{ + PyObject *py_fe = FEdge_Type.tp_new(&FEdge_Type, 0, 0); + ((BPy_FEdge *)py_fe)->fe = &fe; + ((BPy_FEdge *)py_fe)->py_if1D.if1D = ((BPy_FEdge *)py_fe)->fe; + ((BPy_FEdge *)py_fe)->py_if1D.borrowed = true; + return py_fe; } PyObject *BPy_Nature_from_Nature(unsigned short n) { - PyObject *args = PyTuple_New(1); - PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n)); - PyObject *py_n = Nature_Type.tp_new(&Nature_Type, args, NULL); - Py_DECREF(args); - return py_n; + PyObject *args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n)); + PyObject *py_n = Nature_Type.tp_new(&Nature_Type, args, NULL); + Py_DECREF(args); + return py_n; } -PyObject *BPy_Stroke_from_Stroke(Stroke& s) +PyObject *BPy_Stroke_from_Stroke(Stroke &s) { - PyObject *py_s = Stroke_Type.tp_new(&Stroke_Type, 0, 0); - ((BPy_Stroke *)py_s)->s = &s; - ((BPy_Stroke *)py_s)->py_if1D.if1D = ((BPy_Stroke *)py_s)->s; - ((BPy_Stroke *)py_s)->py_if1D.borrowed = true; - return py_s; + PyObject *py_s = Stroke_Type.tp_new(&Stroke_Type, 0, 0); + ((BPy_Stroke *)py_s)->s = &s; + ((BPy_Stroke *)py_s)->py_if1D.if1D = ((BPy_Stroke *)py_s)->s; + ((BPy_Stroke *)py_s)->py_if1D.borrowed = true; + return py_s; } -PyObject *BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute& sa) +PyObject *BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute &sa) { - PyObject *py_sa = StrokeAttribute_Type.tp_new(&StrokeAttribute_Type, 0, 0); - ((BPy_StrokeAttribute *)py_sa)->sa = &sa; - ((BPy_StrokeAttribute *)py_sa)->borrowed = true; - return py_sa; + PyObject *py_sa = StrokeAttribute_Type.tp_new(&StrokeAttribute_Type, 0, 0); + ((BPy_StrokeAttribute *)py_sa)->sa = &sa; + ((BPy_StrokeAttribute *)py_sa)->borrowed = true; + return py_sa; } PyObject *BPy_MediumType_from_MediumType(Stroke::MediumType n) { - PyObject *args = PyTuple_New(1); - PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n)); - PyObject *py_mt = MediumType_Type.tp_new(&MediumType_Type, args, NULL); - Py_DECREF(args); - return py_mt; + PyObject *args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n)); + PyObject *py_mt = MediumType_Type.tp_new(&MediumType_Type, args, NULL); + Py_DECREF(args); + return py_mt; } -PyObject *BPy_StrokeVertex_from_StrokeVertex(StrokeVertex& sv) +PyObject *BPy_StrokeVertex_from_StrokeVertex(StrokeVertex &sv) { - PyObject *py_sv = StrokeVertex_Type.tp_new(&StrokeVertex_Type, 0, 0); - ((BPy_StrokeVertex *)py_sv)->sv = &sv; - ((BPy_StrokeVertex *)py_sv)->py_cp.cp = ((BPy_StrokeVertex *)py_sv)->sv; - ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.if0D = ((BPy_StrokeVertex *)py_sv)->sv; - ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.borrowed = true; - return py_sv; + PyObject *py_sv = StrokeVertex_Type.tp_new(&StrokeVertex_Type, 0, 0); + ((BPy_StrokeVertex *)py_sv)->sv = &sv; + ((BPy_StrokeVertex *)py_sv)->py_cp.cp = ((BPy_StrokeVertex *)py_sv)->sv; + ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.if0D = ((BPy_StrokeVertex *)py_sv)->sv; + ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.borrowed = true; + return py_sv; } -PyObject *BPy_ViewVertex_from_ViewVertex(ViewVertex& vv) +PyObject *BPy_ViewVertex_from_ViewVertex(ViewVertex &vv) { - PyObject *py_vv = ViewVertex_Type.tp_new(&ViewVertex_Type, 0, 0); - ((BPy_ViewVertex *)py_vv)->vv = &vv; - ((BPy_ViewVertex *)py_vv)->py_if0D.if0D = ((BPy_ViewVertex *)py_vv)->vv; - ((BPy_ViewVertex *)py_vv)->py_if0D.borrowed = true; - return py_vv; + PyObject *py_vv = ViewVertex_Type.tp_new(&ViewVertex_Type, 0, 0); + ((BPy_ViewVertex *)py_vv)->vv = &vv; + ((BPy_ViewVertex *)py_vv)->py_if0D.if0D = ((BPy_ViewVertex *)py_vv)->vv; + ((BPy_ViewVertex *)py_vv)->py_if0D.borrowed = true; + return py_vv; } -PyObject *BPy_NonTVertex_from_NonTVertex(NonTVertex& ntv) +PyObject *BPy_NonTVertex_from_NonTVertex(NonTVertex &ntv) { - PyObject *py_ntv = NonTVertex_Type.tp_new(&NonTVertex_Type, 0, 0); - ((BPy_NonTVertex *)py_ntv)->ntv = &ntv; - ((BPy_NonTVertex *)py_ntv)->py_vv.vv = ((BPy_NonTVertex *)py_ntv)->ntv; - ((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.if0D = ((BPy_NonTVertex *)py_ntv)->ntv; - ((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.borrowed = true; - return py_ntv; + PyObject *py_ntv = NonTVertex_Type.tp_new(&NonTVertex_Type, 0, 0); + ((BPy_NonTVertex *)py_ntv)->ntv = &ntv; + ((BPy_NonTVertex *)py_ntv)->py_vv.vv = ((BPy_NonTVertex *)py_ntv)->ntv; + ((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.if0D = ((BPy_NonTVertex *)py_ntv)->ntv; + ((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.borrowed = true; + return py_ntv; } -PyObject *BPy_TVertex_from_TVertex(TVertex& tv) +PyObject *BPy_TVertex_from_TVertex(TVertex &tv) { - PyObject *py_tv = TVertex_Type.tp_new(&TVertex_Type, 0, 0); - ((BPy_TVertex *)py_tv)->tv = &tv; - ((BPy_TVertex *)py_tv)->py_vv.vv = ((BPy_TVertex *)py_tv)->tv; - ((BPy_TVertex *)py_tv)->py_vv.py_if0D.if0D = ((BPy_TVertex *)py_tv)->tv; - ((BPy_TVertex *)py_tv)->py_vv.py_if0D.borrowed = true; - return py_tv; + PyObject *py_tv = TVertex_Type.tp_new(&TVertex_Type, 0, 0); + ((BPy_TVertex *)py_tv)->tv = &tv; + ((BPy_TVertex *)py_tv)->py_vv.vv = ((BPy_TVertex *)py_tv)->tv; + ((BPy_TVertex *)py_tv)->py_vv.py_if0D.if0D = ((BPy_TVertex *)py_tv)->tv; + ((BPy_TVertex *)py_tv)->py_vv.py_if0D.borrowed = true; + return py_tv; } -PyObject *BPy_BBox_from_BBox(const BBox< Vec3r > &bb) +PyObject *BPy_BBox_from_BBox(const BBox &bb) { - PyObject *py_bb = BBox_Type.tp_new(&BBox_Type, 0, 0); - ((BPy_BBox *)py_bb)->bb = new BBox< Vec3r >(bb); - return py_bb; + PyObject *py_bb = BBox_Type.tp_new(&BBox_Type, 0, 0); + ((BPy_BBox *)py_bb)->bb = new BBox(bb); + return py_bb; } -PyObject *BPy_ViewEdge_from_ViewEdge(ViewEdge& ve) +PyObject *BPy_ViewEdge_from_ViewEdge(ViewEdge &ve) { - PyObject *py_ve = ViewEdge_Type.tp_new(&ViewEdge_Type, 0, 0); - ((BPy_ViewEdge *)py_ve)->ve = &ve; - ((BPy_ViewEdge *)py_ve)->py_if1D.if1D = ((BPy_ViewEdge *)py_ve)->ve; - ((BPy_ViewEdge *)py_ve)->py_if1D.borrowed = true; - return py_ve; + PyObject *py_ve = ViewEdge_Type.tp_new(&ViewEdge_Type, 0, 0); + ((BPy_ViewEdge *)py_ve)->ve = &ve; + ((BPy_ViewEdge *)py_ve)->py_if1D.if1D = ((BPy_ViewEdge *)py_ve)->ve; + ((BPy_ViewEdge *)py_ve)->py_if1D.borrowed = true; + return py_ve; } -PyObject *BPy_Chain_from_Chain(Chain& c) +PyObject *BPy_Chain_from_Chain(Chain &c) { - PyObject *py_c = Chain_Type.tp_new(&Chain_Type, 0, 0); - ((BPy_Chain *)py_c)->c = &c; - ((BPy_Chain *)py_c)->py_c.c = ((BPy_Chain *)py_c)->c; - ((BPy_Chain *)py_c)->py_c.py_if1D.if1D = ((BPy_Chain *)py_c)->c; - ((BPy_Chain *)py_c)->py_c.py_if1D.borrowed = true; - return py_c; + PyObject *py_c = Chain_Type.tp_new(&Chain_Type, 0, 0); + ((BPy_Chain *)py_c)->c = &c; + ((BPy_Chain *)py_c)->py_c.c = ((BPy_Chain *)py_c)->c; + ((BPy_Chain *)py_c)->py_c.py_if1D.if1D = ((BPy_Chain *)py_c)->c; + ((BPy_Chain *)py_c)->py_c.py_if1D.borrowed = true; + return py_c; } -PyObject *BPy_SShape_from_SShape(SShape& ss) +PyObject *BPy_SShape_from_SShape(SShape &ss) { - PyObject *py_ss = SShape_Type.tp_new(&SShape_Type, 0, 0); - ((BPy_SShape *)py_ss)->ss = &ss; - ((BPy_SShape *)py_ss)->borrowed = true; - return py_ss; + PyObject *py_ss = SShape_Type.tp_new(&SShape_Type, 0, 0); + ((BPy_SShape *)py_ss)->ss = &ss; + ((BPy_SShape *)py_ss)->borrowed = true; + return py_ss; } -PyObject *BPy_ViewShape_from_ViewShape(ViewShape& vs) +PyObject *BPy_ViewShape_from_ViewShape(ViewShape &vs) { - PyObject *py_vs = ViewShape_Type.tp_new(&ViewShape_Type, 0, 0); - ((BPy_ViewShape *)py_vs)->vs = &vs; - ((BPy_ViewShape *)py_vs)->borrowed = true; - ((BPy_ViewShape *)py_vs)->py_ss = NULL; - return py_vs; + PyObject *py_vs = ViewShape_Type.tp_new(&ViewShape_Type, 0, 0); + ((BPy_ViewShape *)py_vs)->vs = &vs; + ((BPy_ViewShape *)py_vs)->borrowed = true; + ((BPy_ViewShape *)py_vs)->py_ss = NULL; + return py_vs; } -PyObject *BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial& m) +PyObject *BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m) { - PyObject *py_m = FrsMaterial_Type.tp_new(&FrsMaterial_Type, 0, 0); - ((BPy_FrsMaterial *) py_m)->m = new FrsMaterial(m); - return py_m; + PyObject *py_m = FrsMaterial_Type.tp_new(&FrsMaterial_Type, 0, 0); + ((BPy_FrsMaterial *)py_m)->m = new FrsMaterial(m); + return py_m; } PyObject *BPy_IntegrationType_from_IntegrationType(IntegrationType i) { - PyObject *args = PyTuple_New(1); - PyTuple_SET_ITEM(args, 0, PyLong_FromLong(i)); - PyObject *py_it = IntegrationType_Type.tp_new(&IntegrationType_Type, args, NULL); - Py_DECREF(args); - return py_it; + PyObject *args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, PyLong_FromLong(i)); + PyObject *py_it = IntegrationType_Type.tp_new(&IntegrationType_Type, args, NULL); + Py_DECREF(args); + return py_it; } -PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp) +PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint &cp) { - PyObject *py_cp = CurvePoint_Type.tp_new(&CurvePoint_Type, 0, 0); - // CurvePointIterator::operator*() returns a reference of a class data - // member whose value is mutable upon iteration over different CurvePoints. - // It is likely that such a mutable reference is passed to this function, - // so that a new allocated CurvePoint instance is created here to avoid - // nasty bugs (cf. T41464). - ((BPy_CurvePoint *) py_cp)->cp = new CurvePoint(cp); - ((BPy_CurvePoint *) py_cp)->py_if0D.if0D = ((BPy_CurvePoint *)py_cp)->cp; - ((BPy_CurvePoint *) py_cp)->py_if0D.borrowed = false; - return py_cp; + PyObject *py_cp = CurvePoint_Type.tp_new(&CurvePoint_Type, 0, 0); + // CurvePointIterator::operator*() returns a reference of a class data + // member whose value is mutable upon iteration over different CurvePoints. + // It is likely that such a mutable reference is passed to this function, + // so that a new allocated CurvePoint instance is created here to avoid + // nasty bugs (cf. T41464). + ((BPy_CurvePoint *)py_cp)->cp = new CurvePoint(cp); + ((BPy_CurvePoint *)py_cp)->py_if0D.if0D = ((BPy_CurvePoint *)py_cp)->cp; + ((BPy_CurvePoint *)py_cp)->py_if0D.borrowed = false; + return py_cp; } -PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve) +PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge &dve) { - PyObject *py_dve = PyTuple_New(2); - PyTuple_SET_ITEMS(py_dve, - BPy_ViewEdge_from_ViewEdge(*(dve.first)), - PyBool_from_bool(dve.second)); - return py_dve; + PyObject *py_dve = PyTuple_New(2); + PyTuple_SET_ITEMS( + py_dve, BPy_ViewEdge_from_ViewEdge(*(dve.first)), PyBool_from_bool(dve.second)); + return py_dve; } //============================== // Iterators //============================== -PyObject *BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator& a_it) +PyObject *BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator &a_it) { - PyObject *py_a_it = AdjacencyIterator_Type.tp_new(&AdjacencyIterator_Type, 0, 0); - ((BPy_AdjacencyIterator *)py_a_it)->a_it = new AdjacencyIterator(a_it); - ((BPy_AdjacencyIterator *)py_a_it)->py_it.it = ((BPy_AdjacencyIterator *)py_a_it)->a_it; - ((BPy_AdjacencyIterator *)py_a_it)->at_start = true; - return py_a_it; + PyObject *py_a_it = AdjacencyIterator_Type.tp_new(&AdjacencyIterator_Type, 0, 0); + ((BPy_AdjacencyIterator *)py_a_it)->a_it = new AdjacencyIterator(a_it); + ((BPy_AdjacencyIterator *)py_a_it)->py_it.it = ((BPy_AdjacencyIterator *)py_a_it)->a_it; + ((BPy_AdjacencyIterator *)py_a_it)->at_start = true; + return py_a_it; } -PyObject *BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator& if0D_it, bool reversed) +PyObject *BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator &if0D_it, + bool reversed) { - PyObject *py_if0D_it = Interface0DIterator_Type.tp_new(&Interface0DIterator_Type, 0, 0); - ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it = new Interface0DIterator(if0D_it); - ((BPy_Interface0DIterator *)py_if0D_it)->py_it.it = ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it; - ((BPy_Interface0DIterator *)py_if0D_it)->at_start = true; - ((BPy_Interface0DIterator *)py_if0D_it)->reversed = reversed; - return py_if0D_it; + PyObject *py_if0D_it = Interface0DIterator_Type.tp_new(&Interface0DIterator_Type, 0, 0); + ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it = new Interface0DIterator(if0D_it); + ((BPy_Interface0DIterator *)py_if0D_it)->py_it.it = + ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it; + ((BPy_Interface0DIterator *)py_if0D_it)->at_start = true; + ((BPy_Interface0DIterator *)py_if0D_it)->reversed = reversed; + return py_if0D_it; } -PyObject *BPy_CurvePointIterator_from_CurvePointIterator(CurveInternal::CurvePointIterator& cp_it) +PyObject *BPy_CurvePointIterator_from_CurvePointIterator(CurveInternal::CurvePointIterator &cp_it) { - PyObject *py_cp_it = CurvePointIterator_Type.tp_new(&CurvePointIterator_Type, 0, 0); - ((BPy_CurvePointIterator *)py_cp_it)->cp_it = new CurveInternal::CurvePointIterator(cp_it); - ((BPy_CurvePointIterator *)py_cp_it)->py_it.it = ((BPy_CurvePointIterator *)py_cp_it)->cp_it; - return py_cp_it; + PyObject *py_cp_it = CurvePointIterator_Type.tp_new(&CurvePointIterator_Type, 0, 0); + ((BPy_CurvePointIterator *)py_cp_it)->cp_it = new CurveInternal::CurvePointIterator(cp_it); + ((BPy_CurvePointIterator *)py_cp_it)->py_it.it = ((BPy_CurvePointIterator *)py_cp_it)->cp_it; + return py_cp_it; } -PyObject *BPy_StrokeVertexIterator_from_StrokeVertexIterator(StrokeInternal::StrokeVertexIterator& sv_it, bool reversed) +PyObject *BPy_StrokeVertexIterator_from_StrokeVertexIterator( + StrokeInternal::StrokeVertexIterator &sv_it, bool reversed) { - PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new(&StrokeVertexIterator_Type, 0, 0); - ((BPy_StrokeVertexIterator *)py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator(sv_it); - ((BPy_StrokeVertexIterator *)py_sv_it)->py_it.it = ((BPy_StrokeVertexIterator *)py_sv_it)->sv_it; - ((BPy_StrokeVertexIterator *)py_sv_it)->at_start = true; - ((BPy_StrokeVertexIterator *)py_sv_it)->reversed = reversed; - return py_sv_it; + PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new(&StrokeVertexIterator_Type, 0, 0); + ((BPy_StrokeVertexIterator *)py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator(sv_it); + ((BPy_StrokeVertexIterator *)py_sv_it)->py_it.it = ((BPy_StrokeVertexIterator *)py_sv_it)->sv_it; + ((BPy_StrokeVertexIterator *)py_sv_it)->at_start = true; + ((BPy_StrokeVertexIterator *)py_sv_it)->reversed = reversed; + return py_sv_it; } -PyObject *BPy_SVertexIterator_from_SVertexIterator(ViewEdgeInternal::SVertexIterator& sv_it) +PyObject *BPy_SVertexIterator_from_SVertexIterator(ViewEdgeInternal::SVertexIterator &sv_it) { - PyObject *py_sv_it = SVertexIterator_Type.tp_new(&SVertexIterator_Type, 0, 0); - ((BPy_SVertexIterator *)py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator(sv_it); - ((BPy_SVertexIterator *)py_sv_it)->py_it.it = ((BPy_SVertexIterator *)py_sv_it)->sv_it; - return py_sv_it; + PyObject *py_sv_it = SVertexIterator_Type.tp_new(&SVertexIterator_Type, 0, 0); + ((BPy_SVertexIterator *)py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator(sv_it); + ((BPy_SVertexIterator *)py_sv_it)->py_it.it = ((BPy_SVertexIterator *)py_sv_it)->sv_it; + return py_sv_it; } -PyObject *BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ViewVertexInternal::orientedViewEdgeIterator& ove_it, bool reversed) +PyObject *BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( + ViewVertexInternal::orientedViewEdgeIterator &ove_it, bool reversed) { - PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new(&orientedViewEdgeIterator_Type, 0, 0); - ((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(ove_it); - ((BPy_orientedViewEdgeIterator *)py_ove_it)->py_it.it = ((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it; - ((BPy_orientedViewEdgeIterator *)py_ove_it)->at_start = true; - ((BPy_orientedViewEdgeIterator *)py_ove_it)->reversed = reversed; - return py_ove_it; + PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new(&orientedViewEdgeIterator_Type, 0, 0); + ((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it = + new ViewVertexInternal::orientedViewEdgeIterator(ove_it); + ((BPy_orientedViewEdgeIterator *)py_ove_it)->py_it.it = + ((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it; + ((BPy_orientedViewEdgeIterator *)py_ove_it)->at_start = true; + ((BPy_orientedViewEdgeIterator *)py_ove_it)->reversed = reversed; + return py_ove_it; } -PyObject *BPy_ViewEdgeIterator_from_ViewEdgeIterator(ViewEdgeInternal::ViewEdgeIterator& ve_it) +PyObject *BPy_ViewEdgeIterator_from_ViewEdgeIterator(ViewEdgeInternal::ViewEdgeIterator &ve_it) { - PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new(&ViewEdgeIterator_Type, 0, 0); - ((BPy_ViewEdgeIterator *)py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator(ve_it); - ((BPy_ViewEdgeIterator *)py_ve_it)->py_it.it = ((BPy_ViewEdgeIterator *)py_ve_it)->ve_it; - return py_ve_it; + PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new(&ViewEdgeIterator_Type, 0, 0); + ((BPy_ViewEdgeIterator *)py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator(ve_it); + ((BPy_ViewEdgeIterator *)py_ve_it)->py_it.it = ((BPy_ViewEdgeIterator *)py_ve_it)->ve_it; + return py_ve_it; } -PyObject *BPy_ChainingIterator_from_ChainingIterator(ChainingIterator& c_it) +PyObject *BPy_ChainingIterator_from_ChainingIterator(ChainingIterator &c_it) { - PyObject *py_c_it = ChainingIterator_Type.tp_new(&ChainingIterator_Type, 0, 0); - ((BPy_ChainingIterator *)py_c_it)->c_it = new ChainingIterator(c_it); - ((BPy_ChainingIterator *)py_c_it)->py_ve_it.py_it.it = ((BPy_ChainingIterator *)py_c_it)->c_it; - return py_c_it; + PyObject *py_c_it = ChainingIterator_Type.tp_new(&ChainingIterator_Type, 0, 0); + ((BPy_ChainingIterator *)py_c_it)->c_it = new ChainingIterator(c_it); + ((BPy_ChainingIterator *)py_c_it)->py_ve_it.py_it.it = ((BPy_ChainingIterator *)py_c_it)->c_it; + return py_c_it; } -PyObject *BPy_ChainPredicateIterator_from_ChainPredicateIterator(ChainPredicateIterator& cp_it) +PyObject *BPy_ChainPredicateIterator_from_ChainPredicateIterator(ChainPredicateIterator &cp_it) { - PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new(&ChainPredicateIterator_Type, 0, 0); - ((BPy_ChainPredicateIterator *)py_cp_it)->cp_it = new ChainPredicateIterator(cp_it); - ((BPy_ChainPredicateIterator *)py_cp_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainPredicateIterator *)py_cp_it)->cp_it; - return py_cp_it; + PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new(&ChainPredicateIterator_Type, 0, 0); + ((BPy_ChainPredicateIterator *)py_cp_it)->cp_it = new ChainPredicateIterator(cp_it); + ((BPy_ChainPredicateIterator *)py_cp_it)->py_c_it.py_ve_it.py_it.it = + ((BPy_ChainPredicateIterator *)py_cp_it)->cp_it; + return py_cp_it; } -PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouetteIterator& cs_it) +PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouetteIterator &cs_it) { - PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new(&ChainSilhouetteIterator_Type, 0, 0); - ((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it = new ChainSilhouetteIterator(cs_it); - ((BPy_ChainSilhouetteIterator *)py_cs_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it; - return py_cs_it; + PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new(&ChainSilhouetteIterator_Type, 0, 0); + ((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it = new ChainSilhouetteIterator(cs_it); + ((BPy_ChainSilhouetteIterator *)py_cs_it)->py_c_it.py_ve_it.py_it.it = + ((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it; + return py_cs_it; } //============================== @@ -500,269 +507,268 @@ PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouet bool bool_from_PyBool(PyObject *b) { - return PyObject_IsTrue(b) != 0; + return PyObject_IsTrue(b) != 0; } IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj) { - return static_cast(PyLong_AsLong(obj)); + return static_cast(PyLong_AsLong(obj)); } Stroke::MediumType MediumType_from_BPy_MediumType(PyObject *obj) { - return static_cast(PyLong_AsLong(obj)); + return static_cast(PyLong_AsLong(obj)); } Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj) { - return static_cast(PyLong_AsLong(obj)); + return static_cast(PyLong_AsLong(obj)); } bool Vec2f_ptr_from_PyObject(PyObject *obj, Vec2f &vec) { - if (Vec2f_ptr_from_Vector(obj, vec)) - return true; - if (Vec2f_ptr_from_PyList(obj, vec)) - return true; - if (Vec2f_ptr_from_PyTuple(obj, vec)) - return true; - return false; + if (Vec2f_ptr_from_Vector(obj, vec)) + return true; + if (Vec2f_ptr_from_PyList(obj, vec)) + return true; + if (Vec2f_ptr_from_PyTuple(obj, vec)) + return true; + return false; } bool Vec3f_ptr_from_PyObject(PyObject *obj, Vec3f &vec) { - if (Vec3f_ptr_from_Vector(obj, vec)) - return true; - if (Vec3f_ptr_from_Color(obj, vec)) - return true; - if (Vec3f_ptr_from_PyList(obj, vec)) - return true; - if (Vec3f_ptr_from_PyTuple(obj, vec)) - return true; - return false; + if (Vec3f_ptr_from_Vector(obj, vec)) + return true; + if (Vec3f_ptr_from_Color(obj, vec)) + return true; + if (Vec3f_ptr_from_PyList(obj, vec)) + return true; + if (Vec3f_ptr_from_PyTuple(obj, vec)) + return true; + return false; } bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r &vec) { - if (Vec3r_ptr_from_Vector(obj, vec)) - return true; - if (Vec3r_ptr_from_Color(obj, vec)) - return true; - if (Vec3r_ptr_from_PyList(obj, vec)) - return true; - if (Vec3r_ptr_from_PyTuple(obj, vec)) - return true; - return false; + if (Vec3r_ptr_from_Vector(obj, vec)) + return true; + if (Vec3r_ptr_from_Color(obj, vec)) + return true; + if (Vec3r_ptr_from_PyList(obj, vec)) + return true; + if (Vec3r_ptr_from_PyTuple(obj, vec)) + return true; + return false; } bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) - return false; - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return false; - vec[0] = ((VectorObject *)obj)->vec[0]; - vec[1] = ((VectorObject *)obj)->vec[1]; - return true; + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + return true; } bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) - return false; - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return false; - vec[0] = ((VectorObject *)obj)->vec[0]; - vec[1] = ((VectorObject *)obj)->vec[1]; - vec[2] = ((VectorObject *)obj)->vec[2]; - return true; + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + vec[2] = ((VectorObject *)obj)->vec[2]; + return true; } bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r &vec) { - if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) - return false; - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return false; - vec[0] = ((VectorObject *)obj)->vec[0]; - vec[1] = ((VectorObject *)obj)->vec[1]; - vec[2] = ((VectorObject *)obj)->vec[2]; - return true; + if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + vec[2] = ((VectorObject *)obj)->vec[2]; + return true; } bool Vec3f_ptr_from_Color(PyObject *obj, Vec3f &vec) { - if (!ColorObject_Check(obj)) - return false; - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return false; - vec[0] = ((ColorObject *)obj)->col[0]; - vec[1] = ((ColorObject *)obj)->col[1]; - vec[2] = ((ColorObject *)obj)->col[2]; - return true; + if (!ColorObject_Check(obj)) + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((ColorObject *)obj)->col[0]; + vec[1] = ((ColorObject *)obj)->col[1]; + vec[2] = ((ColorObject *)obj)->col[2]; + return true; } bool Vec3r_ptr_from_Color(PyObject *obj, Vec3r &vec) { - if (!ColorObject_Check(obj)) - return false; - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return false; - vec[0] = ((ColorObject *)obj)->col[0]; - vec[1] = ((ColorObject *)obj)->col[1]; - vec[2] = ((ColorObject *)obj)->col[2]; - return true; + if (!ColorObject_Check(obj)) + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((ColorObject *)obj)->col[0]; + vec[1] = ((ColorObject *)obj)->col[1]; + vec[2] = ((ColorObject *)obj)->col[2]; + return true; } static bool float_array_from_PyList(PyObject *obj, float *v, int n) { - for (int i = 0; i < n; i++) { - v[i] = PyFloat_AsDouble(PyList_GET_ITEM(obj, i)); - if (v[i] == -1.0f && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "list elements must be a number"); - return 0; - } - } - return 1; + for (int i = 0; i < n; i++) { + v[i] = PyFloat_AsDouble(PyList_GET_ITEM(obj, i)); + if (v[i] == -1.0f && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "list elements must be a number"); + return 0; + } + } + return 1; } bool Vec2f_ptr_from_PyList(PyObject *obj, Vec2f &vec) { - float v[2]; + float v[2]; - if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 2) - return false; - if (!float_array_from_PyList(obj, v, 2)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - return true; + if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 2) + return false; + if (!float_array_from_PyList(obj, v, 2)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + return true; } bool Vec3f_ptr_from_PyList(PyObject *obj, Vec3f &vec) { - float v[3]; + float v[3]; - if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 3) - return false; - if (!float_array_from_PyList(obj, v, 3)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - vec[2] = v[2]; - return true; + if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 3) + return false; + if (!float_array_from_PyList(obj, v, 3)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } bool Vec3r_ptr_from_PyList(PyObject *obj, Vec3r &vec) { - float v[3]; + float v[3]; - if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 3) - return false; - if (!float_array_from_PyList(obj, v, 3)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - vec[2] = v[2]; - return true; + if (!PyList_Check(obj) || PyList_GET_SIZE(obj) != 3) + return false; + if (!float_array_from_PyList(obj, v, 3)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } static bool float_array_from_PyTuple(PyObject *obj, float *v, int n) { - for (int i = 0; i < n; i++) { - v[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(obj, i)); - if (v[i] == -1.0f && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "tuple elements must be a number"); - return 0; - } - } - return 1; + for (int i = 0; i < n; i++) { + v[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(obj, i)); + if (v[i] == -1.0f && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "tuple elements must be a number"); + return 0; + } + } + return 1; } bool Vec2f_ptr_from_PyTuple(PyObject *obj, Vec2f &vec) { - float v[2]; + float v[2]; - if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 2) - return false; - if (!float_array_from_PyTuple(obj, v, 2)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - return true; + if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 2) + return false; + if (!float_array_from_PyTuple(obj, v, 2)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + return true; } bool Vec3f_ptr_from_PyTuple(PyObject *obj, Vec3f &vec) { - float v[3]; + float v[3]; - if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 3) - return false; - if (!float_array_from_PyTuple(obj, v, 3)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - vec[2] = v[2]; - return true; + if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 3) + return false; + if (!float_array_from_PyTuple(obj, v, 3)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec) { - float v[3]; + float v[3]; - if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 3) - return false; - if (!float_array_from_PyTuple(obj, v, 3)) - return false; - vec[0] = v[0]; - vec[1] = v[1]; - vec[2] = v[2]; - return true; + if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 3) + return false; + if (!float_array_from_PyTuple(obj, v, 3)) + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } // helpers for argument parsing bool float_array_from_PyObject(PyObject *obj, float *v, int n) { - if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) { - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return 0; - for (int i = 0; i < n; i++) - v[i] = ((VectorObject *)obj)->vec[i]; - return 1; - } - else if (ColorObject_Check(obj) && n == 3) { - if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) - return 0; - for (int i = 0; i < n; i++) - v[i] = ((ColorObject *)obj)->col[i]; - return 1; - } - else if (PyList_Check(obj) && PyList_GET_SIZE(obj) == n) { - return float_array_from_PyList(obj, v, n); - } - else if (PyTuple_Check(obj) && PyTuple_GET_SIZE(obj) == n) { - return float_array_from_PyTuple(obj, v, n); - } - return 0; + if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) { + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return 0; + for (int i = 0; i < n; i++) + v[i] = ((VectorObject *)obj)->vec[i]; + return 1; + } + else if (ColorObject_Check(obj) && n == 3) { + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return 0; + for (int i = 0; i < n; i++) + v[i] = ((ColorObject *)obj)->col[i]; + return 1; + } + else if (PyList_Check(obj) && PyList_GET_SIZE(obj) == n) { + return float_array_from_PyList(obj, v, n); + } + else if (PyTuple_Check(obj) && PyTuple_GET_SIZE(obj) == n) { + return float_array_from_PyTuple(obj, v, n); + } + return 0; } int convert_v4(PyObject *obj, void *v) { - return mathutils_array_parse((float *)v, 4, 4, obj, "Error parsing 4D vector"); + return mathutils_array_parse((float *)v, 4, 4, obj, "Error parsing 4D vector"); } int convert_v3(PyObject *obj, void *v) { - return mathutils_array_parse((float *)v, 3, 3, obj, "Error parsing 3D vector"); + return mathutils_array_parse((float *)v, 3, 3, obj, "Error parsing 3D vector"); } int convert_v2(PyObject *obj, void *v) { - return mathutils_array_parse((float *)v, 2, 2, obj, "Error parsing 2D vector"); + return mathutils_array_parse((float *)v, 2, 2, obj, "Error parsing 2D vector"); } - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index 1b0ce43640b..fffe25fde60 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -95,52 +95,53 @@ extern "C" { //============================== PyObject *PyBool_from_bool(bool b); -PyObject *Vector_from_Vec2f(Vec2f& v); -PyObject *Vector_from_Vec3f(Vec3f& v); -PyObject *Vector_from_Vec3r(Vec3r& v); - -PyObject *Any_BPy_Interface0D_from_Interface0D(Interface0D& if0D); -PyObject *Any_BPy_Interface1D_from_Interface1D(Interface1D& if1D); -PyObject *Any_BPy_FEdge_from_FEdge(FEdge& fe); -PyObject *Any_BPy_ViewVertex_from_ViewVertex(ViewVertex& vv); - -PyObject *BPy_BBox_from_BBox(const BBox< Vec3r > &bb); -PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp); -PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve); -PyObject *BPy_FEdge_from_FEdge(FEdge& fe); -PyObject *BPy_FEdgeSharp_from_FEdgeSharp(FEdgeSharp& fes); -PyObject *BPy_FEdgeSmooth_from_FEdgeSmooth(FEdgeSmooth& fes); -PyObject *BPy_Id_from_Id(Id& id); -PyObject *BPy_Interface0D_from_Interface0D(Interface0D& if0D); -PyObject *BPy_Interface1D_from_Interface1D(Interface1D& if1D); +PyObject *Vector_from_Vec2f(Vec2f &v); +PyObject *Vector_from_Vec3f(Vec3f &v); +PyObject *Vector_from_Vec3r(Vec3r &v); + +PyObject *Any_BPy_Interface0D_from_Interface0D(Interface0D &if0D); +PyObject *Any_BPy_Interface1D_from_Interface1D(Interface1D &if1D); +PyObject *Any_BPy_FEdge_from_FEdge(FEdge &fe); +PyObject *Any_BPy_ViewVertex_from_ViewVertex(ViewVertex &vv); + +PyObject *BPy_BBox_from_BBox(const BBox &bb); +PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint &cp); +PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge &dve); +PyObject *BPy_FEdge_from_FEdge(FEdge &fe); +PyObject *BPy_FEdgeSharp_from_FEdgeSharp(FEdgeSharp &fes); +PyObject *BPy_FEdgeSmooth_from_FEdgeSmooth(FEdgeSmooth &fes); +PyObject *BPy_Id_from_Id(Id &id); +PyObject *BPy_Interface0D_from_Interface0D(Interface0D &if0D); +PyObject *BPy_Interface1D_from_Interface1D(Interface1D &if1D); PyObject *BPy_IntegrationType_from_IntegrationType(IntegrationType i); -PyObject *BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial& m); +PyObject *BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m); PyObject *BPy_Nature_from_Nature(unsigned short n); PyObject *BPy_MediumType_from_MediumType(Stroke::MediumType n); -PyObject *BPy_SShape_from_SShape(SShape& ss); -PyObject *BPy_Stroke_from_Stroke(Stroke& s); -PyObject *BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute& sa); -PyObject *BPy_StrokeVertex_from_StrokeVertex(StrokeVertex& sv); -PyObject *BPy_SVertex_from_SVertex(SVertex& sv); -PyObject *BPy_ViewVertex_from_ViewVertex(ViewVertex& vv); -PyObject *BPy_NonTVertex_from_NonTVertex(NonTVertex& ntv); -PyObject *BPy_TVertex_from_TVertex(TVertex& tv); -PyObject *BPy_ViewEdge_from_ViewEdge(ViewEdge& ve); -PyObject *BPy_Chain_from_Chain(Chain& c); -PyObject *BPy_ViewShape_from_ViewShape(ViewShape& vs); - -PyObject *BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator& a_it); -PyObject *BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator& if0D_it, bool reversed); -PyObject *BPy_CurvePointIterator_from_CurvePointIterator(CurveInternal::CurvePointIterator& cp_it); -PyObject *BPy_StrokeVertexIterator_from_StrokeVertexIterator(StrokeInternal::StrokeVertexIterator& sv_it, - bool reversed); -PyObject *BPy_SVertexIterator_from_SVertexIterator(ViewEdgeInternal::SVertexIterator& sv_it); -PyObject *BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ViewVertexInternal::orientedViewEdgeIterator& ove_it, - bool reversed); -PyObject *BPy_ViewEdgeIterator_from_ViewEdgeIterator(ViewEdgeInternal::ViewEdgeIterator& ve_it); -PyObject *BPy_ChainingIterator_from_ChainingIterator(ChainingIterator& c_it); -PyObject *BPy_ChainPredicateIterator_from_ChainPredicateIterator(ChainPredicateIterator& cp_it); -PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouetteIterator& cs_it); +PyObject *BPy_SShape_from_SShape(SShape &ss); +PyObject *BPy_Stroke_from_Stroke(Stroke &s); +PyObject *BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute &sa); +PyObject *BPy_StrokeVertex_from_StrokeVertex(StrokeVertex &sv); +PyObject *BPy_SVertex_from_SVertex(SVertex &sv); +PyObject *BPy_ViewVertex_from_ViewVertex(ViewVertex &vv); +PyObject *BPy_NonTVertex_from_NonTVertex(NonTVertex &ntv); +PyObject *BPy_TVertex_from_TVertex(TVertex &tv); +PyObject *BPy_ViewEdge_from_ViewEdge(ViewEdge &ve); +PyObject *BPy_Chain_from_Chain(Chain &c); +PyObject *BPy_ViewShape_from_ViewShape(ViewShape &vs); + +PyObject *BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator &a_it); +PyObject *BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator &if0D_it, + bool reversed); +PyObject *BPy_CurvePointIterator_from_CurvePointIterator(CurveInternal::CurvePointIterator &cp_it); +PyObject *BPy_StrokeVertexIterator_from_StrokeVertexIterator( + StrokeInternal::StrokeVertexIterator &sv_it, bool reversed); +PyObject *BPy_SVertexIterator_from_SVertexIterator(ViewEdgeInternal::SVertexIterator &sv_it); +PyObject *BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( + ViewVertexInternal::orientedViewEdgeIterator &ove_it, bool reversed); +PyObject *BPy_ViewEdgeIterator_from_ViewEdgeIterator(ViewEdgeInternal::ViewEdgeIterator &ve_it); +PyObject *BPy_ChainingIterator_from_ChainingIterator(ChainingIterator &c_it); +PyObject *BPy_ChainPredicateIterator_from_ChainPredicateIterator(ChainPredicateIterator &cp_it); +PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouetteIterator &cs_it); //============================== // Python => C++ @@ -177,5 +178,4 @@ int convert_v2(PyObject *obj, void *v); } #endif - #endif /* __FREESTYLE_PYTHON_CONVERT_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index e3c7a972867..0b543c06ba6 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -45,7 +45,6 @@ #include "BPy_ViewMap.h" #include "BPy_ViewShape.h" - #ifdef __cplusplus extern "C" { #endif @@ -61,411 +60,441 @@ extern "C" { #include "bpy_rna.h" /* pyrna_struct_CreatePyObject() */ static char Freestyle_getCurrentScene___doc__[] = -".. function:: getCurrentScene()\n" -"\n" -" Returns the current scene.\n" -"\n" -" :return: The current scene.\n" -" :rtype: :class:`bpy.types.Scene`\n"; + ".. function:: getCurrentScene()\n" + "\n" + " Returns the current scene.\n" + "\n" + " :return: The current scene.\n" + " :rtype: :class:`bpy.types.Scene`\n"; static PyObject *Freestyle_getCurrentScene(PyObject * /*self*/) { - Scene *scene = g_freestyle.scene; - if (!scene) { - PyErr_SetString(PyExc_TypeError, "current scene not available"); - return NULL; - } - PointerRNA ptr_scene; - RNA_pointer_create(&scene->id, &RNA_Scene, scene, &ptr_scene); - return pyrna_struct_CreatePyObject(&ptr_scene); + Scene *scene = g_freestyle.scene; + if (!scene) { + PyErr_SetString(PyExc_TypeError, "current scene not available"); + return NULL; + } + PointerRNA ptr_scene; + RNA_pointer_create(&scene->id, &RNA_Scene, scene, &ptr_scene); + return pyrna_struct_CreatePyObject(&ptr_scene); } #include "DNA_material_types.h" static int ramp_blend_type(const char *type) { - if (STREQ(type, "MIX")) return MA_RAMP_BLEND; - if (STREQ(type, "ADD")) return MA_RAMP_ADD; - if (STREQ(type, "MULTIPLY")) return MA_RAMP_MULT; - if (STREQ(type, "SUBTRACT")) return MA_RAMP_SUB; - if (STREQ(type, "SCREEN")) return MA_RAMP_SCREEN; - if (STREQ(type, "DIVIDE")) return MA_RAMP_DIV; - if (STREQ(type, "DIFFERENCE")) return MA_RAMP_DIFF; - if (STREQ(type, "DARKEN")) return MA_RAMP_DARK; - if (STREQ(type, "LIGHTEN")) return MA_RAMP_LIGHT; - if (STREQ(type, "OVERLAY")) return MA_RAMP_OVERLAY; - if (STREQ(type, "DODGE")) return MA_RAMP_DODGE; - if (STREQ(type, "BURN")) return MA_RAMP_BURN; - if (STREQ(type, "HUE")) return MA_RAMP_HUE; - if (STREQ(type, "SATURATION")) return MA_RAMP_SAT; - if (STREQ(type, "VALUE")) return MA_RAMP_VAL; - if (STREQ(type, "COLOR")) return MA_RAMP_COLOR; - if (STREQ(type, "SOFT_LIGHT")) return MA_RAMP_SOFT; - if (STREQ(type, "LINEAR_LIGHT")) return MA_RAMP_LINEAR; - return -1; + if (STREQ(type, "MIX")) + return MA_RAMP_BLEND; + if (STREQ(type, "ADD")) + return MA_RAMP_ADD; + if (STREQ(type, "MULTIPLY")) + return MA_RAMP_MULT; + if (STREQ(type, "SUBTRACT")) + return MA_RAMP_SUB; + if (STREQ(type, "SCREEN")) + return MA_RAMP_SCREEN; + if (STREQ(type, "DIVIDE")) + return MA_RAMP_DIV; + if (STREQ(type, "DIFFERENCE")) + return MA_RAMP_DIFF; + if (STREQ(type, "DARKEN")) + return MA_RAMP_DARK; + if (STREQ(type, "LIGHTEN")) + return MA_RAMP_LIGHT; + if (STREQ(type, "OVERLAY")) + return MA_RAMP_OVERLAY; + if (STREQ(type, "DODGE")) + return MA_RAMP_DODGE; + if (STREQ(type, "BURN")) + return MA_RAMP_BURN; + if (STREQ(type, "HUE")) + return MA_RAMP_HUE; + if (STREQ(type, "SATURATION")) + return MA_RAMP_SAT; + if (STREQ(type, "VALUE")) + return MA_RAMP_VAL; + if (STREQ(type, "COLOR")) + return MA_RAMP_COLOR; + if (STREQ(type, "SOFT_LIGHT")) + return MA_RAMP_SOFT; + if (STREQ(type, "LINEAR_LIGHT")) + return MA_RAMP_LINEAR; + return -1; } #include "BKE_material.h" /* ramp_blend() */ static char Freestyle_blendRamp___doc__[] = -".. function:: blendRamp(type, color1, fac, color2)\n" -"\n" -" Blend two colors according to a ramp blend type.\n" -"\n" -" :arg type: Ramp blend type.\n" -" :type type: int\n" -" :arg color1: 1st color.\n" -" :type color1: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" -" :arg fac: Blend factor.\n" -" :type fac: float\n" -" :arg color2: 1st color.\n" -" :type color2: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" -" :return: Blended color in RGB format.\n" -" :rtype: :class:`mathutils.Vector`\n"; + ".. function:: blendRamp(type, color1, fac, color2)\n" + "\n" + " Blend two colors according to a ramp blend type.\n" + "\n" + " :arg type: Ramp blend type.\n" + " :type type: int\n" + " :arg color1: 1st color.\n" + " :type color1: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" + " :arg fac: Blend factor.\n" + " :type fac: float\n" + " :arg color2: 1st color.\n" + " :type color2: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" + " :return: Blended color in RGB format.\n" + " :rtype: :class:`mathutils.Vector`\n"; static PyObject *Freestyle_blendRamp(PyObject * /*self*/, PyObject *args) { - PyObject *obj1, *obj2; - char *s; - int type; - float a[3], fac, b[3]; - - if (!PyArg_ParseTuple(args, "sOfO", &s, &obj1, &fac, &obj2)) - return NULL; - type = ramp_blend_type(s); - if (type < 0) { - PyErr_SetString(PyExc_TypeError, "argument 1 is an unknown ramp blend type"); - return NULL; - } - if (mathutils_array_parse(a, 3, 3, obj1, - "argument 2 must be a 3D vector " - "(either a tuple/list of 3 elements or Vector)") == -1) - { - return NULL; - } - if (mathutils_array_parse(b, 3, 3, obj2, - "argument 4 must be a 3D vector " - "(either a tuple/list of 3 elements or Vector)") == -1) - { - return NULL; - } - ramp_blend(type, a, fac, b); - return Vector_CreatePyObject(a, 3, NULL); + PyObject *obj1, *obj2; + char *s; + int type; + float a[3], fac, b[3]; + + if (!PyArg_ParseTuple(args, "sOfO", &s, &obj1, &fac, &obj2)) + return NULL; + type = ramp_blend_type(s); + if (type < 0) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an unknown ramp blend type"); + return NULL; + } + if (mathutils_array_parse(a, + 3, + 3, + obj1, + "argument 2 must be a 3D vector " + "(either a tuple/list of 3 elements or Vector)") == -1) { + return NULL; + } + if (mathutils_array_parse(b, + 3, + 3, + obj2, + "argument 4 must be a 3D vector " + "(either a tuple/list of 3 elements or Vector)") == -1) { + return NULL; + } + ramp_blend(type, a, fac, b); + return Vector_CreatePyObject(a, 3, NULL); } #include "BKE_colorband.h" /* BKE_colorband_evaluate() */ static char Freestyle_evaluateColorRamp___doc__[] = -".. function:: evaluateColorRamp(ramp, in)\n" -"\n" -" Evaluate a color ramp at a point in the interval 0 to 1.\n" -"\n" -" :arg ramp: Color ramp object.\n" -" :type ramp: :class:`bpy.types.ColorRamp`\n" -" :arg in: Value in the interval 0 to 1.\n" -" :type in: float\n" -" :return: color in RGBA format.\n" -" :rtype: :class:`mathutils.Vector`\n"; + ".. function:: evaluateColorRamp(ramp, in)\n" + "\n" + " Evaluate a color ramp at a point in the interval 0 to 1.\n" + "\n" + " :arg ramp: Color ramp object.\n" + " :type ramp: :class:`bpy.types.ColorRamp`\n" + " :arg in: Value in the interval 0 to 1.\n" + " :type in: float\n" + " :return: color in RGBA format.\n" + " :rtype: :class:`mathutils.Vector`\n"; static PyObject *Freestyle_evaluateColorRamp(PyObject * /*self*/, PyObject *args) { - BPy_StructRNA *py_srna; - ColorBand *coba; - float in, out[4]; - - if (!(PyArg_ParseTuple(args, "O!f", &pyrna_struct_Type, &py_srna, &in))) - return NULL; - if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_ColorRamp)) { - PyErr_SetString(PyExc_TypeError, "1st argument is not a ColorRamp object"); - return NULL; - } - coba = (ColorBand *)py_srna->ptr.data; - if (!BKE_colorband_evaluate(coba, in, out)) { - PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp"); - return NULL; - } - return Vector_CreatePyObject(out, 4, NULL); + BPy_StructRNA *py_srna; + ColorBand *coba; + float in, out[4]; + + if (!(PyArg_ParseTuple(args, "O!f", &pyrna_struct_Type, &py_srna, &in))) + return NULL; + if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_ColorRamp)) { + PyErr_SetString(PyExc_TypeError, "1st argument is not a ColorRamp object"); + return NULL; + } + coba = (ColorBand *)py_srna->ptr.data; + if (!BKE_colorband_evaluate(coba, in, out)) { + PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp"); + return NULL; + } + return Vector_CreatePyObject(out, 4, NULL); } #include "DNA_color_types.h" #include "BKE_colortools.h" /* curvemapping_evaluateF() */ static char Freestyle_evaluateCurveMappingF___doc__[] = -".. function:: evaluateCurveMappingF(cumap, cur, value)\n" -"\n" -" Evaluate a curve mapping at a point in the interval 0 to 1.\n" -"\n" -" :arg cumap: Curve mapping object.\n" -" :type cumap: :class:`bpy.types.CurveMapping`\n" -" :arg cur: Index of the curve to be used (0 <= cur <= 3).\n" -" :type cur: int\n" -" :arg value: Input value in the interval 0 to 1.\n" -" :type value: float\n" -" :return: Mapped output value.\n" -" :rtype: float\n"; + ".. function:: evaluateCurveMappingF(cumap, cur, value)\n" + "\n" + " Evaluate a curve mapping at a point in the interval 0 to 1.\n" + "\n" + " :arg cumap: Curve mapping object.\n" + " :type cumap: :class:`bpy.types.CurveMapping`\n" + " :arg cur: Index of the curve to be used (0 <= cur <= 3).\n" + " :type cur: int\n" + " :arg value: Input value in the interval 0 to 1.\n" + " :type value: float\n" + " :return: Mapped output value.\n" + " :rtype: float\n"; static PyObject *Freestyle_evaluateCurveMappingF(PyObject * /*self*/, PyObject *args) { - BPy_StructRNA *py_srna; - CurveMapping *cumap; - int cur; - float value; - - if (!(PyArg_ParseTuple(args, "O!if", &pyrna_struct_Type, &py_srna, &cur, &value))) - return NULL; - if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_CurveMapping)) { - PyErr_SetString(PyExc_TypeError, "1st argument is not a CurveMapping object"); - return NULL; - } - if (cur < 0 || cur > 3) { - PyErr_SetString(PyExc_ValueError, "2nd argument is out of range"); - return NULL; - } - cumap = (CurveMapping *)py_srna->ptr.data; - curvemapping_initialize(cumap); - /* disable extrapolation if enabled */ - if ((cumap->cm[cur].flag & CUMA_EXTEND_EXTRAPOLATE)) { - cumap->cm[cur].flag &= ~(CUMA_EXTEND_EXTRAPOLATE); - curvemapping_changed(cumap, 0); - } - return PyFloat_FromDouble(curvemapping_evaluateF(cumap, cur, value)); + BPy_StructRNA *py_srna; + CurveMapping *cumap; + int cur; + float value; + + if (!(PyArg_ParseTuple(args, "O!if", &pyrna_struct_Type, &py_srna, &cur, &value))) + return NULL; + if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_CurveMapping)) { + PyErr_SetString(PyExc_TypeError, "1st argument is not a CurveMapping object"); + return NULL; + } + if (cur < 0 || cur > 3) { + PyErr_SetString(PyExc_ValueError, "2nd argument is out of range"); + return NULL; + } + cumap = (CurveMapping *)py_srna->ptr.data; + curvemapping_initialize(cumap); + /* disable extrapolation if enabled */ + if ((cumap->cm[cur].flag & CUMA_EXTEND_EXTRAPOLATE)) { + cumap->cm[cur].flag &= ~(CUMA_EXTEND_EXTRAPOLATE); + curvemapping_changed(cumap, 0); + } + return PyFloat_FromDouble(curvemapping_evaluateF(cumap, cur, value)); } /*-----------------------Freestyle module docstring----------------------------*/ static char module_docstring[] = -"This module provides classes for defining line drawing rules (such as\n" -"predicates, functions, chaining iterators, and stroke shaders), as well\n" -"as helper functions for style module writing.\n" -"\n" -"Class hierarchy:\n" -"\n" -"- :class:`BBox`\n" -"- :class:`BinaryPredicate0D`\n" -"- :class:`BinaryPredicate1D`\n" -"\n" -" - :class:`FalseBP1D`\n" -" - :class:`Length2DBP1D`\n" -" - :class:`SameShapeIdBP1D`\n" -" - :class:`TrueBP1D`\n" -" - :class:`ViewMapGradientNormBP1D`\n" -"\n" -"- :class:`Id`\n" -"- :class:`Interface0D`\n" -"\n" -" - :class:`CurvePoint`\n" -"\n" -" - :class:`StrokeVertex`\n" -"\n" -" - :class:`SVertex`\n" -" - :class:`ViewVertex`\n" -"\n" -" - :class:`NonTVertex`\n" -" - :class:`TVertex`\n" -"\n" -"- :class:`Interface1D`\n" -"\n" -" - :class:`Curve`\n" -"\n" -" - :class:`Chain`\n" -"\n" -" - :class:`FEdge`\n" -"\n" -" - :class:`FEdgeSharp`\n" -" - :class:`FEdgeSmooth`\n" -"\n" -" - :class:`Stroke`\n" -" - :class:`ViewEdge`\n" -"\n" -"- :class:`Iterator`\n" -"\n" -" - :class:`AdjacencyIterator`\n" -" - :class:`CurvePointIterator`\n" -" - :class:`Interface0DIterator`\n" -" - :class:`SVertexIterator`\n" -" - :class:`StrokeVertexIterator`\n" -" - :class:`ViewEdgeIterator`\n" -"\n" -" - :class:`ChainingIterator`\n" -"\n" -" - :class:`ChainPredicateIterator`\n" -" - :class:`ChainSilhouetteIterator`\n" -"\n" -" - :class:`orientedViewEdgeIterator`\n" -"\n" -"- :class:`Material`\n" -"- :class:`Noise`\n" -"- :class:`Operators`\n" -"- :class:`SShape`\n" -"- :class:`StrokeAttribute`\n" -"- :class:`StrokeShader`\n" -"\n" -" - :class:`BackboneStretcherShader`\n" -" - :class:`BezierCurveShader`\n" -" - :class:`BlenderTextureShader`\n" -" - :class:`CalligraphicShader`\n" -" - :class:`ColorNoiseShader`\n" -" - :class:`ColorVariationPatternShader`\n" -" - :class:`ConstantColorShader`\n" -" - :class:`ConstantThicknessShader`\n" -" - :class:`ConstrainedIncreasingThicknessShader`\n" -" - :class:`GuidingLinesShader`\n" -" - :class:`IncreasingColorShader`\n" -" - :class:`IncreasingThicknessShader`\n" -" - :class:`PolygonalizationShader`\n" -" - :class:`SamplingShader`\n" -" - :class:`SmoothingShader`\n" -" - :class:`SpatialNoiseShader`\n" -" - :class:`StrokeTextureShader`\n" -" - :class:`StrokeTextureStepShader`\n" -" - :class:`TextureAssignerShader`\n" -" - :class:`ThicknessNoiseShader`\n" -" - :class:`ThicknessVariationPatternShader`\n" -" - :class:`TipRemoverShader`\n" -" - :class:`fstreamShader`\n" -" - :class:`streamShader`\n" -"\n" -"- :class:`UnaryFunction0D`\n" -"\n" -" - :class:`UnaryFunction0DDouble`\n" -"\n" -" - :class:`Curvature2DAngleF0D`\n" -" - :class:`DensityF0D`\n" -" - :class:`GetProjectedXF0D`\n" -" - :class:`GetProjectedYF0D`\n" -" - :class:`GetProjectedZF0D`\n" -" - :class:`GetXF0D`\n" -" - :class:`GetYF0D`\n" -" - :class:`GetZF0D`\n" -" - :class:`LocalAverageDepthF0D`\n" -" - :class:`ZDiscontinuityF0D`\n" -"\n" -" - :class:`UnaryFunction0DEdgeNature`\n" -"\n" -" - :class:`CurveNatureF0D`\n" -"\n" -" - :class:`UnaryFunction0DFloat`\n" -"\n" -" - :class:`GetCurvilinearAbscissaF0D`\n" -" - :class:`GetParameterF0D`\n" -" - :class:`GetViewMapGradientNormF0D`\n" -" - :class:`ReadCompleteViewMapPixelF0D`\n" -" - :class:`ReadMapPixelF0D`\n" -" - :class:`ReadSteerableViewMapPixelF0D`\n" -"\n" -" - :class:`UnaryFunction0DId`\n" -"\n" -" - :class:`ShapeIdF0D`\n" -"\n" -" - :class:`UnaryFunction0DMaterial`\n" -"\n" -" - :class:`MaterialF0D`\n" -"\n" -" - :class:`UnaryFunction0DUnsigned`\n" -"\n" -" - :class:`QuantitativeInvisibilityF0D`\n" -"\n" -" - :class:`UnaryFunction0DVec2f`\n" -"\n" -" - :class:`Normal2DF0D`\n" -" - :class:`VertexOrientation2DF0D`\n" -"\n" -" - :class:`UnaryFunction0DVec3f`\n" -"\n" -" - :class:`VertexOrientation3DF0D`\n" -"\n" -" - :class:`UnaryFunction0DVectorViewShape`\n" -"\n" -" - :class:`GetOccludersF0D`\n" -"\n" -" - :class:`UnaryFunction0DViewShape`\n" -"\n" -" - :class:`GetOccludeeF0D`\n" -" - :class:`GetShapeF0D`\n" -"\n" -"- :class:`UnaryFunction1D`\n" -"\n" -" - :class:`UnaryFunction1DDouble`\n" -"\n" -" - :class:`Curvature2DAngleF1D`\n" -" - :class:`DensityF1D`\n" -" - :class:`GetCompleteViewMapDensityF1D`\n" -" - :class:`GetDirectionalViewMapDensityF1D`\n" -" - :class:`GetProjectedXF1D`\n" -" - :class:`GetProjectedYF1D`\n" -" - :class:`GetProjectedZF1D`\n" -" - :class:`GetSteerableViewMapDensityF1D`\n" -" - :class:`GetViewMapGradientNormF1D`\n" -" - :class:`GetXF1D`\n" -" - :class:`GetYF1D`\n" -" - :class:`GetZF1D`\n" -" - :class:`LocalAverageDepthF1D`\n" -" - :class:`ZDiscontinuityF1D`\n" -"\n" -" - :class:`UnaryFunction1DEdgeNature`\n" -"\n" -" - :class:`CurveNatureF1D`\n" -"\n" -" - :class:`UnaryFunction1DFloat`\n" -" - :class:`UnaryFunction1DUnsigned`\n" -"\n" -" - :class:`QuantitativeInvisibilityF1D`\n" -"\n" -" - :class:`UnaryFunction1DVec2f`\n" -"\n" -" - :class:`Normal2DF1D`\n" -" - :class:`Orientation2DF1D`\n" -"\n" -" - :class:`UnaryFunction1DVec3f`\n" -"\n" -" - :class:`Orientation3DF1D`\n" -"\n" -" - :class:`UnaryFunction1DVectorViewShape`\n" -"\n" -" - :class:`GetOccludeeF1D`\n" -" - :class:`GetOccludersF1D`\n" -" - :class:`GetShapeF1D`\n" -"\n" -" - :class:`UnaryFunction1DVoid`\n" -"\n" -" - :class:`ChainingTimeStampF1D`\n" -" - :class:`IncrementChainingTimeStampF1D`\n" -" - :class:`TimeStampF1D`\n" -"\n" -"- :class:`UnaryPredicate0D`\n" -"\n" -" - :class:`FalseUP0D`\n" -" - :class:`TrueUP0D`\n" -"\n" -"- :class:`UnaryPredicate1D`\n" -"\n" -" - :class:`ContourUP1D`\n" -" - :class:`DensityLowerThanUP1D`\n" -" - :class:`EqualToChainingTimeStampUP1D`\n" -" - :class:`EqualToTimeStampUP1D`\n" -" - :class:`ExternalContourUP1D`\n" -" - :class:`FalseUP1D`\n" -" - :class:`QuantitativeInvisibilityUP1D`\n" -" - :class:`ShapeUP1D`\n" -" - :class:`TrueUP1D`\n" -" - :class:`WithinImageBoundaryUP1D`\n" -"\n" -"- :class:`ViewMap`\n" -"- :class:`ViewShape`\n" -"- :class:`IntegrationType`\n" -"- :class:`MediumType`\n" -"- :class:`Nature`\n" -"\n"; + "This module provides classes for defining line drawing rules (such as\n" + "predicates, functions, chaining iterators, and stroke shaders), as well\n" + "as helper functions for style module writing.\n" + "\n" + "Class hierarchy:\n" + "\n" + "- :class:`BBox`\n" + "- :class:`BinaryPredicate0D`\n" + "- :class:`BinaryPredicate1D`\n" + "\n" + " - :class:`FalseBP1D`\n" + " - :class:`Length2DBP1D`\n" + " - :class:`SameShapeIdBP1D`\n" + " - :class:`TrueBP1D`\n" + " - :class:`ViewMapGradientNormBP1D`\n" + "\n" + "- :class:`Id`\n" + "- :class:`Interface0D`\n" + "\n" + " - :class:`CurvePoint`\n" + "\n" + " - :class:`StrokeVertex`\n" + "\n" + " - :class:`SVertex`\n" + " - :class:`ViewVertex`\n" + "\n" + " - :class:`NonTVertex`\n" + " - :class:`TVertex`\n" + "\n" + "- :class:`Interface1D`\n" + "\n" + " - :class:`Curve`\n" + "\n" + " - :class:`Chain`\n" + "\n" + " - :class:`FEdge`\n" + "\n" + " - :class:`FEdgeSharp`\n" + " - :class:`FEdgeSmooth`\n" + "\n" + " - :class:`Stroke`\n" + " - :class:`ViewEdge`\n" + "\n" + "- :class:`Iterator`\n" + "\n" + " - :class:`AdjacencyIterator`\n" + " - :class:`CurvePointIterator`\n" + " - :class:`Interface0DIterator`\n" + " - :class:`SVertexIterator`\n" + " - :class:`StrokeVertexIterator`\n" + " - :class:`ViewEdgeIterator`\n" + "\n" + " - :class:`ChainingIterator`\n" + "\n" + " - :class:`ChainPredicateIterator`\n" + " - :class:`ChainSilhouetteIterator`\n" + "\n" + " - :class:`orientedViewEdgeIterator`\n" + "\n" + "- :class:`Material`\n" + "- :class:`Noise`\n" + "- :class:`Operators`\n" + "- :class:`SShape`\n" + "- :class:`StrokeAttribute`\n" + "- :class:`StrokeShader`\n" + "\n" + " - :class:`BackboneStretcherShader`\n" + " - :class:`BezierCurveShader`\n" + " - :class:`BlenderTextureShader`\n" + " - :class:`CalligraphicShader`\n" + " - :class:`ColorNoiseShader`\n" + " - :class:`ColorVariationPatternShader`\n" + " - :class:`ConstantColorShader`\n" + " - :class:`ConstantThicknessShader`\n" + " - :class:`ConstrainedIncreasingThicknessShader`\n" + " - :class:`GuidingLinesShader`\n" + " - :class:`IncreasingColorShader`\n" + " - :class:`IncreasingThicknessShader`\n" + " - :class:`PolygonalizationShader`\n" + " - :class:`SamplingShader`\n" + " - :class:`SmoothingShader`\n" + " - :class:`SpatialNoiseShader`\n" + " - :class:`StrokeTextureShader`\n" + " - :class:`StrokeTextureStepShader`\n" + " - :class:`TextureAssignerShader`\n" + " - :class:`ThicknessNoiseShader`\n" + " - :class:`ThicknessVariationPatternShader`\n" + " - :class:`TipRemoverShader`\n" + " - :class:`fstreamShader`\n" + " - :class:`streamShader`\n" + "\n" + "- :class:`UnaryFunction0D`\n" + "\n" + " - :class:`UnaryFunction0DDouble`\n" + "\n" + " - :class:`Curvature2DAngleF0D`\n" + " - :class:`DensityF0D`\n" + " - :class:`GetProjectedXF0D`\n" + " - :class:`GetProjectedYF0D`\n" + " - :class:`GetProjectedZF0D`\n" + " - :class:`GetXF0D`\n" + " - :class:`GetYF0D`\n" + " - :class:`GetZF0D`\n" + " - :class:`LocalAverageDepthF0D`\n" + " - :class:`ZDiscontinuityF0D`\n" + "\n" + " - :class:`UnaryFunction0DEdgeNature`\n" + "\n" + " - :class:`CurveNatureF0D`\n" + "\n" + " - :class:`UnaryFunction0DFloat`\n" + "\n" + " - :class:`GetCurvilinearAbscissaF0D`\n" + " - :class:`GetParameterF0D`\n" + " - :class:`GetViewMapGradientNormF0D`\n" + " - :class:`ReadCompleteViewMapPixelF0D`\n" + " - :class:`ReadMapPixelF0D`\n" + " - :class:`ReadSteerableViewMapPixelF0D`\n" + "\n" + " - :class:`UnaryFunction0DId`\n" + "\n" + " - :class:`ShapeIdF0D`\n" + "\n" + " - :class:`UnaryFunction0DMaterial`\n" + "\n" + " - :class:`MaterialF0D`\n" + "\n" + " - :class:`UnaryFunction0DUnsigned`\n" + "\n" + " - :class:`QuantitativeInvisibilityF0D`\n" + "\n" + " - :class:`UnaryFunction0DVec2f`\n" + "\n" + " - :class:`Normal2DF0D`\n" + " - :class:`VertexOrientation2DF0D`\n" + "\n" + " - :class:`UnaryFunction0DVec3f`\n" + "\n" + " - :class:`VertexOrientation3DF0D`\n" + "\n" + " - :class:`UnaryFunction0DVectorViewShape`\n" + "\n" + " - :class:`GetOccludersF0D`\n" + "\n" + " - :class:`UnaryFunction0DViewShape`\n" + "\n" + " - :class:`GetOccludeeF0D`\n" + " - :class:`GetShapeF0D`\n" + "\n" + "- :class:`UnaryFunction1D`\n" + "\n" + " - :class:`UnaryFunction1DDouble`\n" + "\n" + " - :class:`Curvature2DAngleF1D`\n" + " - :class:`DensityF1D`\n" + " - :class:`GetCompleteViewMapDensityF1D`\n" + " - :class:`GetDirectionalViewMapDensityF1D`\n" + " - :class:`GetProjectedXF1D`\n" + " - :class:`GetProjectedYF1D`\n" + " - :class:`GetProjectedZF1D`\n" + " - :class:`GetSteerableViewMapDensityF1D`\n" + " - :class:`GetViewMapGradientNormF1D`\n" + " - :class:`GetXF1D`\n" + " - :class:`GetYF1D`\n" + " - :class:`GetZF1D`\n" + " - :class:`LocalAverageDepthF1D`\n" + " - :class:`ZDiscontinuityF1D`\n" + "\n" + " - :class:`UnaryFunction1DEdgeNature`\n" + "\n" + " - :class:`CurveNatureF1D`\n" + "\n" + " - :class:`UnaryFunction1DFloat`\n" + " - :class:`UnaryFunction1DUnsigned`\n" + "\n" + " - :class:`QuantitativeInvisibilityF1D`\n" + "\n" + " - :class:`UnaryFunction1DVec2f`\n" + "\n" + " - :class:`Normal2DF1D`\n" + " - :class:`Orientation2DF1D`\n" + "\n" + " - :class:`UnaryFunction1DVec3f`\n" + "\n" + " - :class:`Orientation3DF1D`\n" + "\n" + " - :class:`UnaryFunction1DVectorViewShape`\n" + "\n" + " - :class:`GetOccludeeF1D`\n" + " - :class:`GetOccludersF1D`\n" + " - :class:`GetShapeF1D`\n" + "\n" + " - :class:`UnaryFunction1DVoid`\n" + "\n" + " - :class:`ChainingTimeStampF1D`\n" + " - :class:`IncrementChainingTimeStampF1D`\n" + " - :class:`TimeStampF1D`\n" + "\n" + "- :class:`UnaryPredicate0D`\n" + "\n" + " - :class:`FalseUP0D`\n" + " - :class:`TrueUP0D`\n" + "\n" + "- :class:`UnaryPredicate1D`\n" + "\n" + " - :class:`ContourUP1D`\n" + " - :class:`DensityLowerThanUP1D`\n" + " - :class:`EqualToChainingTimeStampUP1D`\n" + " - :class:`EqualToTimeStampUP1D`\n" + " - :class:`ExternalContourUP1D`\n" + " - :class:`FalseUP1D`\n" + " - :class:`QuantitativeInvisibilityUP1D`\n" + " - :class:`ShapeUP1D`\n" + " - :class:`TrueUP1D`\n" + " - :class:`WithinImageBoundaryUP1D`\n" + "\n" + "- :class:`ViewMap`\n" + "- :class:`ViewShape`\n" + "- :class:`IntegrationType`\n" + "- :class:`MediumType`\n" + "- :class:`Nature`\n" + "\n"; /*-----------------------Freestyle module method def---------------------------*/ static PyMethodDef module_functions[] = { - {"getCurrentScene", (PyCFunction) Freestyle_getCurrentScene, METH_NOARGS, Freestyle_getCurrentScene___doc__}, - {"blendRamp", (PyCFunction) Freestyle_blendRamp, METH_VARARGS, Freestyle_blendRamp___doc__}, - {"evaluateColorRamp", (PyCFunction) Freestyle_evaluateColorRamp, METH_VARARGS, Freestyle_evaluateColorRamp___doc__}, - {"evaluateCurveMappingF", (PyCFunction) Freestyle_evaluateCurveMappingF, METH_VARARGS, - Freestyle_evaluateCurveMappingF___doc__}, - {NULL, NULL, 0, NULL}, + {"getCurrentScene", + (PyCFunction)Freestyle_getCurrentScene, + METH_NOARGS, + Freestyle_getCurrentScene___doc__}, + {"blendRamp", (PyCFunction)Freestyle_blendRamp, METH_VARARGS, Freestyle_blendRamp___doc__}, + {"evaluateColorRamp", + (PyCFunction)Freestyle_evaluateColorRamp, + METH_VARARGS, + Freestyle_evaluateColorRamp___doc__}, + {"evaluateCurveMappingF", + (PyCFunction)Freestyle_evaluateCurveMappingF, + METH_VARARGS, + Freestyle_evaluateCurveMappingF___doc__}, + {NULL, NULL, 0, NULL}, }; /*-----------------------Freestyle module definition---------------------------*/ @@ -481,60 +510,61 @@ static PyModuleDef module_definition = { //-------------------MODULE INITIALIZATION-------------------------------- PyObject *Freestyle_Init(void) { - PyObject *module; - - // initialize modules - module = PyModule_Create(&module_definition); - if (!module) - return NULL; - PyDict_SetItemString(PySys_GetObject("modules"), module_definition.m_name, module); - - // update 'sys.path' for Freestyle Python API modules - const char * const path = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, "freestyle"); - if (path) { - char modpath[FILE_MAX]; - BLI_join_dirfile(modpath, sizeof(modpath), path, "modules"); - PyObject *sys_path = PySys_GetObject("path"); /* borrow */ - PyObject *py_modpath = PyUnicode_FromString(modpath); - PyList_Append(sys_path, py_modpath); - Py_DECREF(py_modpath); + PyObject *module; + + // initialize modules + module = PyModule_Create(&module_definition); + if (!module) + return NULL; + PyDict_SetItemString(PySys_GetObject("modules"), module_definition.m_name, module); + + // update 'sys.path' for Freestyle Python API modules + const char *const path = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, "freestyle"); + if (path) { + char modpath[FILE_MAX]; + BLI_join_dirfile(modpath, sizeof(modpath), path, "modules"); + PyObject *sys_path = PySys_GetObject("path"); /* borrow */ + PyObject *py_modpath = PyUnicode_FromString(modpath); + PyList_Append(sys_path, py_modpath); + Py_DECREF(py_modpath); #if 0 - printf("Adding Python path: %s\n", modpath); + printf("Adding Python path: %s\n", modpath); #endif - } - else { - printf("Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.\n"); - } - - // attach its classes (adding the object types to the module) - - // those classes have to be initialized before the others - MediumType_Init(module); - Nature_Init(module); - - BBox_Init(module); - BinaryPredicate0D_Init(module); - BinaryPredicate1D_Init(module); - ContextFunctions_Init(module); - FrsMaterial_Init(module); - FrsNoise_Init(module); - Id_Init(module); - IntegrationType_Init(module); - Interface0D_Init(module); - Interface1D_Init(module); - Iterator_Init(module); - Operators_Init(module); - SShape_Init(module); - StrokeAttribute_Init(module); - StrokeShader_Init(module); - UnaryFunction0D_Init(module); - UnaryFunction1D_Init(module); - UnaryPredicate0D_Init(module); - UnaryPredicate1D_Init(module); - ViewMap_Init(module); - ViewShape_Init(module); - - return module; + } + else { + printf( + "Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.\n"); + } + + // attach its classes (adding the object types to the module) + + // those classes have to be initialized before the others + MediumType_Init(module); + Nature_Init(module); + + BBox_Init(module); + BinaryPredicate0D_Init(module); + BinaryPredicate1D_Init(module); + ContextFunctions_Init(module); + FrsMaterial_Init(module); + FrsNoise_Init(module); + Id_Init(module); + IntegrationType_Init(module); + Interface0D_Init(module); + Interface1D_Init(module); + Iterator_Init(module); + Operators_Init(module); + SShape_Init(module); + StrokeAttribute_Init(module); + StrokeShader_Init(module); + UnaryFunction0D_Init(module); + UnaryFunction1D_Init(module); + UnaryPredicate0D_Init(module); + UnaryPredicate1D_Init(module); + ViewMap_Init(module); + ViewShape_Init(module); + + return module; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp index fe1f23e2665..3ede6823062 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp @@ -28,538 +28,555 @@ extern "C" { #include "BLI_hash_mm2a.h" - /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- int FrsMaterial_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&FrsMaterial_Type) < 0) - return -1; - Py_INCREF(&FrsMaterial_Type); - PyModule_AddObject(module, "Material", (PyObject *)&FrsMaterial_Type); + if (PyType_Ready(&FrsMaterial_Type) < 0) + return -1; + Py_INCREF(&FrsMaterial_Type); + PyModule_AddObject(module, "Material", (PyObject *)&FrsMaterial_Type); - FrsMaterial_mathutils_register_callback(); + FrsMaterial_mathutils_register_callback(); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(FrsMaterial_doc, -"Class defining a material.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A Material object.\n" -" :type brother: :class:`Material`\n" -"\n" -".. method:: __init__(line, diffuse, ambient, specular, emission, shininess, priority)\n" -"\n" -" Builds a Material from its line, diffuse, ambient, specular, emissive\n" -" colors, a shininess coefficient and line color priority.\n" -"\n" -" :arg line: The line color.\n" -" :type line: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg diffuse: The diffuse color.\n" -" :type diffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg ambient: The ambient color.\n" -" :type ambient: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg specular: The specular color.\n" -" :type specular: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg emission: The emissive color.\n" -" :type emission: :class:`mathutils.Vector`, list or tuple of 4 float values\n" -" :arg shininess: The shininess coefficient.\n" -" :type shininess: float\n" -" :arg priority: The line color priority.\n" -" :type priority: int"); +PyDoc_STRVAR( + FrsMaterial_doc, + "Class defining a material.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A Material object.\n" + " :type brother: :class:`Material`\n" + "\n" + ".. method:: __init__(line, diffuse, ambient, specular, emission, shininess, priority)\n" + "\n" + " Builds a Material from its line, diffuse, ambient, specular, emissive\n" + " colors, a shininess coefficient and line color priority.\n" + "\n" + " :arg line: The line color.\n" + " :type line: :class:`mathutils.Vector`, list or tuple of 4 float values\n" + " :arg diffuse: The diffuse color.\n" + " :type diffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n" + " :arg ambient: The ambient color.\n" + " :type ambient: :class:`mathutils.Vector`, list or tuple of 4 float values\n" + " :arg specular: The specular color.\n" + " :type specular: :class:`mathutils.Vector`, list or tuple of 4 float values\n" + " :arg emission: The emissive color.\n" + " :type emission: :class:`mathutils.Vector`, list or tuple of 4 float values\n" + " :arg shininess: The shininess coefficient.\n" + " :type shininess: float\n" + " :arg priority: The line color priority.\n" + " :type priority: int"); static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"line", "diffuse", "ambient", "specular", "emission", "shininess", "priority", NULL}; - PyObject *brother = 0; - float line[4], diffuse[4], ambient[4], specular[4], emission[4], shininess; - int priority; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother)) { - if (!brother) { - self->m = new FrsMaterial(); - } - else { - FrsMaterial *m = ((BPy_FrsMaterial *)brother)->m; - if (!m) { - PyErr_SetString(PyExc_RuntimeError, "invalid Material object"); - return -1; - } - self->m = new FrsMaterial(*m); - } - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&O&fi", (char **)kwlist_2, - convert_v4, line, - convert_v4, diffuse, - convert_v4, ambient, - convert_v4, specular, - convert_v4, emission, - &shininess, &priority)) - { - self->m = new FrsMaterial(line, diffuse, ambient, specular, emission, shininess, priority); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = { + "line", "diffuse", "ambient", "specular", "emission", "shininess", "priority", NULL}; + PyObject *brother = 0; + float line[4], diffuse[4], ambient[4], specular[4], emission[4], shininess; + int priority; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother)) { + if (!brother) { + self->m = new FrsMaterial(); + } + else { + FrsMaterial *m = ((BPy_FrsMaterial *)brother)->m; + if (!m) { + PyErr_SetString(PyExc_RuntimeError, "invalid Material object"); + return -1; + } + self->m = new FrsMaterial(*m); + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O&O&O&O&O&fi", + (char **)kwlist_2, + convert_v4, + line, + convert_v4, + diffuse, + convert_v4, + ambient, + convert_v4, + specular, + convert_v4, + emission, + &shininess, + &priority)) { + self->m = new FrsMaterial(line, diffuse, ambient, specular, emission, shininess, priority); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + return 0; } static void FrsMaterial_dealloc(BPy_FrsMaterial *self) { - delete self->m; - Py_TYPE(self)->tp_free((PyObject *)self); + delete self->m; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *FrsMaterial_repr(BPy_FrsMaterial *self) { - return PyUnicode_FromFormat("Material - address: %p", self->m); + return PyUnicode_FromFormat("Material - address: %p", self->m); } /*----------------------mathutils callbacks ----------------------------*/ /* subtype */ -#define MATHUTILS_SUBTYPE_DIFFUSE 1 -#define MATHUTILS_SUBTYPE_SPECULAR 2 -#define MATHUTILS_SUBTYPE_AMBIENT 3 -#define MATHUTILS_SUBTYPE_EMISSION 4 -#define MATHUTILS_SUBTYPE_LINE 5 +#define MATHUTILS_SUBTYPE_DIFFUSE 1 +#define MATHUTILS_SUBTYPE_SPECULAR 2 +#define MATHUTILS_SUBTYPE_AMBIENT 3 +#define MATHUTILS_SUBTYPE_EMISSION 4 +#define MATHUTILS_SUBTYPE_LINE 5 static int FrsMaterial_mathutils_check(BaseMathObject *bmo) { - if (!BPy_FrsMaterial_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_FrsMaterial_Check(bmo->cb_user)) + return -1; + return 0; } static int FrsMaterial_mathutils_get(BaseMathObject *bmo, int subtype) { - BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_LINE: - bmo->data[0] = self->m->lineR(); - bmo->data[1] = self->m->lineG(); - bmo->data[2] = self->m->lineB(); - bmo->data[3] = self->m->lineA(); - break; - case MATHUTILS_SUBTYPE_DIFFUSE: - bmo->data[0] = self->m->diffuseR(); - bmo->data[1] = self->m->diffuseG(); - bmo->data[2] = self->m->diffuseB(); - bmo->data[3] = self->m->diffuseA(); - break; - case MATHUTILS_SUBTYPE_SPECULAR: - bmo->data[0] = self->m->specularR(); - bmo->data[1] = self->m->specularG(); - bmo->data[2] = self->m->specularB(); - bmo->data[3] = self->m->specularA(); - break; - case MATHUTILS_SUBTYPE_AMBIENT: - bmo->data[0] = self->m->ambientR(); - bmo->data[1] = self->m->ambientG(); - bmo->data[2] = self->m->ambientB(); - bmo->data[3] = self->m->ambientA(); - break; - case MATHUTILS_SUBTYPE_EMISSION: - bmo->data[0] = self->m->emissionR(); - bmo->data[1] = self->m->emissionG(); - bmo->data[2] = self->m->emissionB(); - bmo->data[3] = self->m->emissionA(); - break; - default: - return -1; - } - return 0; + BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_LINE: + bmo->data[0] = self->m->lineR(); + bmo->data[1] = self->m->lineG(); + bmo->data[2] = self->m->lineB(); + bmo->data[3] = self->m->lineA(); + break; + case MATHUTILS_SUBTYPE_DIFFUSE: + bmo->data[0] = self->m->diffuseR(); + bmo->data[1] = self->m->diffuseG(); + bmo->data[2] = self->m->diffuseB(); + bmo->data[3] = self->m->diffuseA(); + break; + case MATHUTILS_SUBTYPE_SPECULAR: + bmo->data[0] = self->m->specularR(); + bmo->data[1] = self->m->specularG(); + bmo->data[2] = self->m->specularB(); + bmo->data[3] = self->m->specularA(); + break; + case MATHUTILS_SUBTYPE_AMBIENT: + bmo->data[0] = self->m->ambientR(); + bmo->data[1] = self->m->ambientG(); + bmo->data[2] = self->m->ambientB(); + bmo->data[3] = self->m->ambientA(); + break; + case MATHUTILS_SUBTYPE_EMISSION: + bmo->data[0] = self->m->emissionR(); + bmo->data[1] = self->m->emissionG(); + bmo->data[2] = self->m->emissionB(); + bmo->data[3] = self->m->emissionA(); + break; + default: + return -1; + } + return 0; } static int FrsMaterial_mathutils_set(BaseMathObject *bmo, int subtype) { - BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_LINE: - self->m->setLine(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); - break; - case MATHUTILS_SUBTYPE_DIFFUSE: - self->m->setDiffuse(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); - break; - case MATHUTILS_SUBTYPE_SPECULAR: - self->m->setSpecular(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); - break; - case MATHUTILS_SUBTYPE_AMBIENT: - self->m->setAmbient(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); - break; - case MATHUTILS_SUBTYPE_EMISSION: - self->m->setEmission(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); - break; - default: - return -1; - } - return 0; + BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_LINE: + self->m->setLine(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); + break; + case MATHUTILS_SUBTYPE_DIFFUSE: + self->m->setDiffuse(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); + break; + case MATHUTILS_SUBTYPE_SPECULAR: + self->m->setSpecular(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); + break; + case MATHUTILS_SUBTYPE_AMBIENT: + self->m->setAmbient(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); + break; + case MATHUTILS_SUBTYPE_EMISSION: + self->m->setEmission(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]); + break; + default: + return -1; + } + return 0; } static int FrsMaterial_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) { - BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_LINE: - { - const float *color = self->m->line(); - bmo->data[index] = color[index]; - } - break; - case MATHUTILS_SUBTYPE_DIFFUSE: - { - const float *color = self->m->diffuse(); - bmo->data[index] = color[index]; - } - break; - case MATHUTILS_SUBTYPE_SPECULAR: - { - const float *color = self->m->specular(); - bmo->data[index] = color[index]; - } - break; - case MATHUTILS_SUBTYPE_AMBIENT: - { - const float *color = self->m->ambient(); - bmo->data[index] = color[index]; - } - break; - case MATHUTILS_SUBTYPE_EMISSION: - { - const float *color = self->m->emission(); - bmo->data[index] = color[index]; - } - break; - default: - return -1; - } - return 0; + BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_LINE: { + const float *color = self->m->line(); + bmo->data[index] = color[index]; + } break; + case MATHUTILS_SUBTYPE_DIFFUSE: { + const float *color = self->m->diffuse(); + bmo->data[index] = color[index]; + } break; + case MATHUTILS_SUBTYPE_SPECULAR: { + const float *color = self->m->specular(); + bmo->data[index] = color[index]; + } break; + case MATHUTILS_SUBTYPE_AMBIENT: { + const float *color = self->m->ambient(); + bmo->data[index] = color[index]; + } break; + case MATHUTILS_SUBTYPE_EMISSION: { + const float *color = self->m->emission(); + bmo->data[index] = color[index]; + } break; + default: + return -1; + } + return 0; } static int FrsMaterial_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) { - BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; - float color[4]; - switch (subtype) { - case MATHUTILS_SUBTYPE_LINE: - copy_v4_v4(color, self->m->line()); - color[index] = bmo->data[index]; - self->m->setLine(color[0], color[1], color[2], color[3]); - break; - case MATHUTILS_SUBTYPE_DIFFUSE: - copy_v4_v4(color, self->m->diffuse()); - color[index] = bmo->data[index]; - self->m->setDiffuse(color[0], color[1], color[2], color[3]); - break; - case MATHUTILS_SUBTYPE_SPECULAR: - copy_v4_v4(color, self->m->specular()); - color[index] = bmo->data[index]; - self->m->setSpecular(color[0], color[1], color[2], color[3]); - break; - case MATHUTILS_SUBTYPE_AMBIENT: - copy_v4_v4(color, self->m->ambient()); - color[index] = bmo->data[index]; - self->m->setAmbient(color[0], color[1], color[2], color[3]); - break; - case MATHUTILS_SUBTYPE_EMISSION: - copy_v4_v4(color, self->m->emission()); - color[index] = bmo->data[index]; - self->m->setEmission(color[0], color[1], color[2], color[3]); - break; - default: - return -1; - } - return 0; + BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user; + float color[4]; + switch (subtype) { + case MATHUTILS_SUBTYPE_LINE: + copy_v4_v4(color, self->m->line()); + color[index] = bmo->data[index]; + self->m->setLine(color[0], color[1], color[2], color[3]); + break; + case MATHUTILS_SUBTYPE_DIFFUSE: + copy_v4_v4(color, self->m->diffuse()); + color[index] = bmo->data[index]; + self->m->setDiffuse(color[0], color[1], color[2], color[3]); + break; + case MATHUTILS_SUBTYPE_SPECULAR: + copy_v4_v4(color, self->m->specular()); + color[index] = bmo->data[index]; + self->m->setSpecular(color[0], color[1], color[2], color[3]); + break; + case MATHUTILS_SUBTYPE_AMBIENT: + copy_v4_v4(color, self->m->ambient()); + color[index] = bmo->data[index]; + self->m->setAmbient(color[0], color[1], color[2], color[3]); + break; + case MATHUTILS_SUBTYPE_EMISSION: + copy_v4_v4(color, self->m->emission()); + color[index] = bmo->data[index]; + self->m->setEmission(color[0], color[1], color[2], color[3]); + break; + default: + return -1; + } + return 0; } static Mathutils_Callback FrsMaterial_mathutils_cb = { - FrsMaterial_mathutils_check, - FrsMaterial_mathutils_get, - FrsMaterial_mathutils_set, - FrsMaterial_mathutils_get_index, - FrsMaterial_mathutils_set_index, + FrsMaterial_mathutils_check, + FrsMaterial_mathutils_get, + FrsMaterial_mathutils_set, + FrsMaterial_mathutils_get_index, + FrsMaterial_mathutils_set_index, }; static unsigned char FrsMaterial_mathutils_cb_index = -1; void FrsMaterial_mathutils_register_callback() { - FrsMaterial_mathutils_cb_index = Mathutils_RegisterCallback(&FrsMaterial_mathutils_cb); + FrsMaterial_mathutils_cb_index = Mathutils_RegisterCallback(&FrsMaterial_mathutils_cb); } /*----------------------FrsMaterial get/setters ----------------------------*/ PyDoc_STRVAR(FrsMaterial_line_doc, -"RGBA components of the line color of the material.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "RGBA components of the line color of the material.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FrsMaterial_line_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_LINE); + return Vector_CreatePyObject_cb( + (PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_LINE); } static int FrsMaterial_line_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float color[4]; - if (mathutils_array_parse(color, 4, 4, value, - "value must be a 4-dimensional vector") == -1) - { - return -1; - } - self->m->setLine(color[0], color[1], color[2], color[3]); - return 0; + float color[4]; + if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) { + return -1; + } + self->m->setLine(color[0], color[1], color[2], color[3]); + return 0; } PyDoc_STRVAR(FrsMaterial_diffuse_doc, -"RGBA components of the diffuse color of the material.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "RGBA components of the diffuse color of the material.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FrsMaterial_diffuse_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_DIFFUSE); + return Vector_CreatePyObject_cb( + (PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_DIFFUSE); } static int FrsMaterial_diffuse_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float color[4]; - if (mathutils_array_parse(color, 4, 4, value, - "value must be a 4-dimensional vector") == -1) - { - return -1; - } - self->m->setDiffuse(color[0], color[1], color[2], color[3]); - return 0; + float color[4]; + if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) { + return -1; + } + self->m->setDiffuse(color[0], color[1], color[2], color[3]); + return 0; } PyDoc_STRVAR(FrsMaterial_specular_doc, -"RGBA components of the specular color of the material.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "RGBA components of the specular color of the material.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FrsMaterial_specular_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_SPECULAR); + return Vector_CreatePyObject_cb( + (PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_SPECULAR); } static int FrsMaterial_specular_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float color[4]; - if (mathutils_array_parse(color, 4, 4, value, - "value must be a 4-dimensional vector") == -1) - { - return -1; - } - self->m->setSpecular(color[0], color[1], color[2], color[3]); - return 0; + float color[4]; + if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) { + return -1; + } + self->m->setSpecular(color[0], color[1], color[2], color[3]); + return 0; } PyDoc_STRVAR(FrsMaterial_ambient_doc, -"RGBA components of the ambient color of the material.\n" -"\n" -":type: :class:`mathutils.Color`"); + "RGBA components of the ambient color of the material.\n" + "\n" + ":type: :class:`mathutils.Color`"); static PyObject *FrsMaterial_ambient_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_AMBIENT); + return Vector_CreatePyObject_cb( + (PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_AMBIENT); } static int FrsMaterial_ambient_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float color[4]; - if (mathutils_array_parse(color, 4, 4, value, - "value must be a 4-dimensional vector") == -1) - { - return -1; - } - self->m->setAmbient(color[0], color[1], color[2], color[3]); - return 0; + float color[4]; + if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) { + return -1; + } + self->m->setAmbient(color[0], color[1], color[2], color[3]); + return 0; } PyDoc_STRVAR(FrsMaterial_emission_doc, -"RGBA components of the emissive color of the material.\n" -"\n" -":type: :class:`mathutils.Color`"); + "RGBA components of the emissive color of the material.\n" + "\n" + ":type: :class:`mathutils.Color`"); static PyObject *FrsMaterial_emission_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_EMISSION); + return Vector_CreatePyObject_cb( + (PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_EMISSION); } static int FrsMaterial_emission_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float color[4]; - if (mathutils_array_parse(color, 4, 4, value, - "value must be a 4-dimensional vector") == -1) - { - return -1; - } - self->m->setEmission(color[0], color[1], color[2], color[3]); - return 0; + float color[4]; + if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) { + return -1; + } + self->m->setEmission(color[0], color[1], color[2], color[3]); + return 0; } PyDoc_STRVAR(FrsMaterial_shininess_doc, -"Shininess coefficient of the material.\n" -"\n" -":type: float"); + "Shininess coefficient of the material.\n" + "\n" + ":type: float"); static PyObject *FrsMaterial_shininess_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->m->shininess()); + return PyFloat_FromDouble(self->m->shininess()); } static int FrsMaterial_shininess_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->m->setShininess(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && + PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->m->setShininess(scalar); + return 0; } PyDoc_STRVAR(FrsMaterial_priority_doc, -"Line color priority of the material.\n" -"\n" -":type: int"); + "Line color priority of the material.\n" + "\n" + ":type: int"); static PyObject *FrsMaterial_priority_get(BPy_FrsMaterial *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->m->priority()); + return PyLong_FromLong(self->m->priority()); } static int FrsMaterial_priority_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure)) { - int scalar; - if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "value must be an integer"); - return -1; - } - self->m->setPriority(scalar); - return 0; + int scalar; + if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be an integer"); + return -1; + } + self->m->setPriority(scalar); + return 0; } static PyGetSetDef BPy_FrsMaterial_getseters[] = { - {(char *)"line", (getter)FrsMaterial_line_get, (setter)FrsMaterial_line_set, - (char *)FrsMaterial_line_doc, NULL}, - {(char *)"diffuse", (getter)FrsMaterial_diffuse_get, (setter)FrsMaterial_diffuse_set, - (char *)FrsMaterial_diffuse_doc, NULL}, - {(char *)"specular", (getter)FrsMaterial_specular_get, (setter)FrsMaterial_specular_set, - (char *)FrsMaterial_specular_doc, NULL}, - {(char *)"ambient", (getter)FrsMaterial_ambient_get, (setter)FrsMaterial_ambient_set, - (char *)FrsMaterial_ambient_doc, NULL}, - {(char *)"emission", (getter)FrsMaterial_emission_get, (setter)FrsMaterial_emission_set, - (char *)FrsMaterial_emission_doc, NULL}, - {(char *)"shininess", (getter)FrsMaterial_shininess_get, (setter)FrsMaterial_shininess_set, - (char *)FrsMaterial_shininess_doc, NULL}, - {(char *)"priority", (getter)FrsMaterial_priority_get, (setter)FrsMaterial_priority_set, - (char *)FrsMaterial_priority_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"line", + (getter)FrsMaterial_line_get, + (setter)FrsMaterial_line_set, + (char *)FrsMaterial_line_doc, + NULL}, + {(char *)"diffuse", + (getter)FrsMaterial_diffuse_get, + (setter)FrsMaterial_diffuse_set, + (char *)FrsMaterial_diffuse_doc, + NULL}, + {(char *)"specular", + (getter)FrsMaterial_specular_get, + (setter)FrsMaterial_specular_set, + (char *)FrsMaterial_specular_doc, + NULL}, + {(char *)"ambient", + (getter)FrsMaterial_ambient_get, + (setter)FrsMaterial_ambient_set, + (char *)FrsMaterial_ambient_doc, + NULL}, + {(char *)"emission", + (getter)FrsMaterial_emission_get, + (setter)FrsMaterial_emission_set, + (char *)FrsMaterial_emission_doc, + NULL}, + {(char *)"shininess", + (getter)FrsMaterial_shininess_get, + (setter)FrsMaterial_shininess_set, + (char *)FrsMaterial_shininess_doc, + NULL}, + {(char *)"priority", + (getter)FrsMaterial_priority_get, + (setter)FrsMaterial_priority_set, + (char *)FrsMaterial_priority_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; -static PyObject *BPy_FrsMaterial_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type) +static PyObject *BPy_FrsMaterial_richcmpr(PyObject *objectA, + PyObject *objectB, + int comparison_type) { - const BPy_FrsMaterial *matA = NULL, *matB = NULL; - bool result = 0; - - if (!BPy_FrsMaterial_Check(objectA) || !BPy_FrsMaterial_Check(objectB)) { - if (comparison_type == Py_NE) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; - } - } - - matA = (BPy_FrsMaterial *)objectA; - matB = (BPy_FrsMaterial *)objectB; - - switch (comparison_type) { - case Py_NE: - result = (*matA->m) != (*matB->m); - break; - case Py_EQ: - result = (*matA->m) == (*matB->m); - break; - default: - PyErr_SetString(PyExc_TypeError, "Material does not support this comparison type"); - return NULL; - } - - if (result == true) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; - } + const BPy_FrsMaterial *matA = NULL, *matB = NULL; + bool result = 0; + + if (!BPy_FrsMaterial_Check(objectA) || !BPy_FrsMaterial_Check(objectB)) { + if (comparison_type == Py_NE) { + Py_RETURN_TRUE; + } + else { + Py_RETURN_FALSE; + } + } + + matA = (BPy_FrsMaterial *)objectA; + matB = (BPy_FrsMaterial *)objectB; + + switch (comparison_type) { + case Py_NE: + result = (*matA->m) != (*matB->m); + break; + case Py_EQ: + result = (*matA->m) == (*matB->m); + break; + default: + PyErr_SetString(PyExc_TypeError, "Material does not support this comparison type"); + return NULL; + } + + if (result == true) { + Py_RETURN_TRUE; + } + else { + Py_RETURN_FALSE; + } } - static Py_hash_t FrsMaterial_hash(PyObject *self) { - return (Py_uhash_t)BLI_hash_mm2((const unsigned char *)self, sizeof(*self), 0); + return (Py_uhash_t)BLI_hash_mm2((const unsigned char *)self, sizeof(*self), 0); } /*-----------------------BPy_FrsMaterial type definition ------------------------------*/ PyTypeObject FrsMaterial_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Material", /* tp_name */ - sizeof(BPy_FrsMaterial), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)FrsMaterial_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)FrsMaterial_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)FrsMaterial_hash, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FrsMaterial_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)BPy_FrsMaterial_richcmpr, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_FrsMaterial_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FrsMaterial_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Material", /* tp_name */ + sizeof(BPy_FrsMaterial), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)FrsMaterial_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)FrsMaterial_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)FrsMaterial_hash, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FrsMaterial_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)BPy_FrsMaterial_richcmpr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_FrsMaterial_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FrsMaterial_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.h b/source/blender/freestyle/intern/python/BPy_FrsMaterial.h index 39e564ce97e..84a3ac2463f 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.h +++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject FrsMaterial_Type; -#define BPy_FrsMaterial_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&FrsMaterial_Type)) +#define BPy_FrsMaterial_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&FrsMaterial_Type)) /*---------------------------Python BPy_FrsMaterial structure definition----------*/ typedef struct { - PyObject_HEAD - FrsMaterial *m; + PyObject_HEAD FrsMaterial *m; } BPy_FrsMaterial; /*---------------------------Python BPy_FrsMaterial visible prototypes-----------*/ @@ -56,5 +56,4 @@ void FrsMaterial_mathutils_register_callback(); } #endif - #endif /* __FREESTYLE_PYTHON_FRSMATERIAL_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp index 871fe517bed..dc8a2ba6105 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -34,301 +34,325 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int FrsNoise_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&FrsNoise_Type) < 0) - return -1; - Py_INCREF(&FrsNoise_Type); - PyModule_AddObject(module, "Noise", (PyObject *)&FrsNoise_Type); + if (PyType_Ready(&FrsNoise_Type) < 0) + return -1; + Py_INCREF(&FrsNoise_Type); + PyModule_AddObject(module, "Noise", (PyObject *)&FrsNoise_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(FrsNoise_doc, -"Class to provide Perlin noise functionalities.\n" -"\n" -".. method:: __init__(seed = -1)\n" -"\n" -" Builds a Noise object. Seed is an optional argument. The seed value is used\n" -" as a seed for random number generation if it is equal to or greater than zero;\n" -" otherwise, time is used as a seed.\n" -"\n" -" :arg seed: Seed for random number generation.\n" -" :type seed: int"); + "Class to provide Perlin noise functionalities.\n" + "\n" + ".. method:: __init__(seed = -1)\n" + "\n" + " Builds a Noise object. Seed is an optional argument. The seed value is used\n" + " as a seed for random number generation if it is equal to or greater than zero;\n" + " otherwise, time is used as a seed.\n" + "\n" + " :arg seed: Seed for random number generation.\n" + " :type seed: int"); static int FrsNoise_init(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"seed", NULL}; - long seed = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|l", (char **)kwlist, &seed)) - return -1; - self->n = new Noise(seed); - self->pn = new PseudoNoise(); - return 0; + static const char *kwlist[] = {"seed", NULL}; + long seed = -1; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|l", (char **)kwlist, &seed)) + return -1; + self->n = new Noise(seed); + self->pn = new PseudoNoise(); + return 0; } static void FrsNoise_dealloc(BPy_FrsNoise *self) { - delete self->n; - delete self->pn; - Py_TYPE(self)->tp_free((PyObject *)self); + delete self->n; + delete self->pn; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *FrsNoise_repr(BPy_FrsNoise *self) { - return PyUnicode_FromFormat("Noise - address: %p", self->n); + return PyUnicode_FromFormat("Noise - address: %p", self->n); } PyDoc_STRVAR(FrsNoise_turbulence1_doc, -".. method:: turbulence1(v, freq, amp, oct=4)\n" -"\n" -" Returns a noise value for a 1D element.\n" -"\n" -" :arg v: One-dimensional sample point.\n" -" :type v: float\n" -" :arg freq: Noise frequency.\n" -" :type freq: float\n" -" :arg amp: Amplitude.\n" -" :type amp: float\n" -" :arg oct: Number of octaves.\n" -" :type oct: int\n" -" :return: A noise value.\n" -" :rtype: float"); + ".. method:: turbulence1(v, freq, amp, oct=4)\n" + "\n" + " Returns a noise value for a 1D element.\n" + "\n" + " :arg v: One-dimensional sample point.\n" + " :type v: float\n" + " :arg freq: Noise frequency.\n" + " :type freq: float\n" + " :arg amp: Amplitude.\n" + " :type amp: float\n" + " :arg oct: Number of octaves.\n" + " :type oct: int\n" + " :return: A noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_drand(BPy_FrsNoise * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"seed", NULL}; - long seed = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", (char **)kwlist, &seed)) { - PyErr_SetString(PyExc_TypeError, "optional argument 1 must be of type int"); - return NULL; - } - if (seed) { - RandGen::srand48(seed); - } - return PyFloat_FromDouble(RandGen::drand48()); + static const char *kwlist[] = {"seed", NULL}; + long seed = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", (char **)kwlist, &seed)) { + PyErr_SetString(PyExc_TypeError, "optional argument 1 must be of type int"); + return NULL; + } + if (seed) { + RandGen::srand48(seed); + } + return PyFloat_FromDouble(RandGen::drand48()); } static PyObject *FrsNoise_turbulence_smooth(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", "oct", NULL}; + static const char *kwlist[] = {"v", "oct", NULL}; - double x; // note: this has to be a double (not float) - unsigned nbOctaves = 8; + double x; // note: this has to be a double (not float) + unsigned nbOctaves = 8; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|I", (char **)kwlist, &x, &nbOctaves)) - return NULL; - return PyFloat_FromDouble(self->pn->turbulenceSmooth(x, nbOctaves)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|I", (char **)kwlist, &x, &nbOctaves)) + return NULL; + return PyFloat_FromDouble(self->pn->turbulenceSmooth(x, nbOctaves)); } static PyObject *FrsNoise_turbulence1(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; - float f1, f2, f3; - unsigned int i = 4; + static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; + float f1, f2, f3; + unsigned int i = 4; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff|I", (char **)kwlist, &f1, &f2, &f3, &i)) - return NULL; - return PyFloat_FromDouble(self->n->turbulence1(f1, f2, f3, i)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff|I", (char **)kwlist, &f1, &f2, &f3, &i)) + return NULL; + return PyFloat_FromDouble(self->n->turbulence1(f1, f2, f3, i)); } PyDoc_STRVAR(FrsNoise_turbulence2_doc, -".. method:: turbulence2(v, freq, amp, oct=4)\n" -"\n" -" Returns a noise value for a 2D element.\n" -"\n" -" :arg v: Two-dimensional sample point.\n" -" :type v: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n" -" :arg freq: Noise frequency.\n" -" :type freq: float\n" -" :arg amp: Amplitude.\n" -" :type amp: float\n" -" :arg oct: Number of octaves.\n" -" :type oct: int\n" -" :return: A noise value.\n" -" :rtype: float"); + ".. method:: turbulence2(v, freq, amp, oct=4)\n" + "\n" + " Returns a noise value for a 2D element.\n" + "\n" + " :arg v: Two-dimensional sample point.\n" + " :type v: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n" + " :arg freq: Noise frequency.\n" + " :type freq: float\n" + " :arg amp: Amplitude.\n" + " :type amp: float\n" + " :arg oct: Number of octaves.\n" + " :type oct: int\n" + " :return: A noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_turbulence2(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; - PyObject *obj1; - float f2, f3; - unsigned int i = 4; - Vec2f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) - return NULL; - if (!Vec2f_ptr_from_PyObject(obj1, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); - return NULL; - } - float t = self->n->turbulence2(vec, f2, f3, i); - return PyFloat_FromDouble(t); + static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; + PyObject *obj1; + float f2, f3; + unsigned int i = 4; + Vec2f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) + return NULL; + if (!Vec2f_ptr_from_PyObject(obj1, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); + return NULL; + } + float t = self->n->turbulence2(vec, f2, f3, i); + return PyFloat_FromDouble(t); } PyDoc_STRVAR(FrsNoise_turbulence3_doc, -".. method:: turbulence3(v, freq, amp, oct=4)\n" -"\n" -" Returns a noise value for a 3D element.\n" -"\n" -" :arg v: Three-dimensional sample point.\n" -" :type v: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" -" :arg freq: Noise frequency.\n" -" :type freq: float\n" -" :arg amp: Amplitude.\n" -" :type amp: float\n" -" :arg oct: Number of octaves.\n" -" :type oct: int\n" -" :return: A noise value.\n" -" :rtype: float"); + ".. method:: turbulence3(v, freq, amp, oct=4)\n" + "\n" + " Returns a noise value for a 3D element.\n" + "\n" + " :arg v: Three-dimensional sample point.\n" + " :type v: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" + " :arg freq: Noise frequency.\n" + " :type freq: float\n" + " :arg amp: Amplitude.\n" + " :type amp: float\n" + " :arg oct: Number of octaves.\n" + " :type oct: int\n" + " :return: A noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_turbulence3(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; - PyObject *obj1; - float f2, f3; - unsigned int i = 4; - Vec3f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) - return NULL; - if (!Vec3f_ptr_from_PyObject(obj1, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - float t = self->n->turbulence3(vec, f2, f3, i); - return PyFloat_FromDouble(t); + static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; + PyObject *obj1; + float f2, f3; + unsigned int i = 4; + Vec3f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) + return NULL; + if (!Vec3f_ptr_from_PyObject(obj1, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; + } + float t = self->n->turbulence3(vec, f2, f3, i); + return PyFloat_FromDouble(t); } PyDoc_STRVAR(FrsNoise_smoothNoise1_doc, -".. method:: smoothNoise1(v)\n" -"\n" -" Returns a smooth noise value for a 1D element.\n" -"\n" -" :arg v: One-dimensional sample point.\n" -" :type v: float\n" -" :return: A smooth noise value.\n" -" :rtype: float"); + ".. method:: smoothNoise1(v)\n" + "\n" + " Returns a smooth noise value for a 1D element.\n" + "\n" + " :arg v: One-dimensional sample point.\n" + " :type v: float\n" + " :return: A smooth noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_smoothNoise1(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", NULL}; - float f; + static const char *kwlist[] = {"v", NULL}; + float f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) - return NULL; - return PyFloat_FromDouble(self->n->smoothNoise1(f)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) + return NULL; + return PyFloat_FromDouble(self->n->smoothNoise1(f)); } PyDoc_STRVAR(FrsNoise_smoothNoise2_doc, -".. method:: smoothNoise2(v)\n" -"\n" -" Returns a smooth noise value for a 2D element.\n" -"\n" -" :arg v: Two-dimensional sample point.\n" -" :type v: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n" -" :return: A smooth noise value.\n" -" :rtype: float"); + ".. method:: smoothNoise2(v)\n" + "\n" + " Returns a smooth noise value for a 2D element.\n" + "\n" + " :arg v: Two-dimensional sample point.\n" + " :type v: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n" + " :return: A smooth noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_smoothNoise2(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", NULL}; - PyObject *obj; - Vec2f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) - return NULL; - if (!Vec2f_ptr_from_PyObject(obj, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); - return NULL; - } - float t = self->n->smoothNoise2(vec); - return PyFloat_FromDouble(t); + static const char *kwlist[] = {"v", NULL}; + PyObject *obj; + Vec2f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) + return NULL; + if (!Vec2f_ptr_from_PyObject(obj, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); + return NULL; + } + float t = self->n->smoothNoise2(vec); + return PyFloat_FromDouble(t); } PyDoc_STRVAR(FrsNoise_smoothNoise3_doc, -".. method:: smoothNoise3(v)\n" -"\n" -" Returns a smooth noise value for a 3D element.\n" -"\n" -" :arg v: Three-dimensional sample point.\n" -" :type v: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" -" :return: A smooth noise value.\n" -" :rtype: float"); + ".. method:: smoothNoise3(v)\n" + "\n" + " Returns a smooth noise value for a 3D element.\n" + "\n" + " :arg v: Three-dimensional sample point.\n" + " :type v: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n" + " :return: A smooth noise value.\n" + " :rtype: float"); static PyObject *FrsNoise_smoothNoise3(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"v", NULL}; - PyObject *obj; - Vec3f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) - return NULL; - if (!Vec3f_ptr_from_PyObject(obj, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - float t = self->n->smoothNoise3(vec); - return PyFloat_FromDouble(t); + static const char *kwlist[] = {"v", NULL}; + PyObject *obj; + Vec3f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) + return NULL; + if (!Vec3f_ptr_from_PyObject(obj, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; + } + float t = self->n->smoothNoise3(vec); + return PyFloat_FromDouble(t); } static PyMethodDef BPy_FrsNoise_methods[] = { - {"turbulence1", (PyCFunction)FrsNoise_turbulence1, METH_VARARGS | METH_KEYWORDS, FrsNoise_turbulence1_doc}, - {"turbulence2", (PyCFunction)FrsNoise_turbulence2, METH_VARARGS | METH_KEYWORDS, FrsNoise_turbulence2_doc}, - {"turbulence3", (PyCFunction)FrsNoise_turbulence3, METH_VARARGS | METH_KEYWORDS, FrsNoise_turbulence3_doc}, - {"smoothNoise1", (PyCFunction)FrsNoise_smoothNoise1, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise1_doc}, - {"smoothNoise2", (PyCFunction)FrsNoise_smoothNoise2, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise2_doc}, - {"smoothNoise3", (PyCFunction)FrsNoise_smoothNoise3, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise3_doc}, - {"rand", (PyCFunction)FrsNoise_drand, METH_VARARGS | METH_KEYWORDS, NULL}, - {"turbulence_smooth", (PyCFunction)FrsNoise_turbulence_smooth, METH_VARARGS | METH_KEYWORDS, NULL}, - {NULL, NULL, 0, NULL}, + {"turbulence1", + (PyCFunction)FrsNoise_turbulence1, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_turbulence1_doc}, + {"turbulence2", + (PyCFunction)FrsNoise_turbulence2, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_turbulence2_doc}, + {"turbulence3", + (PyCFunction)FrsNoise_turbulence3, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_turbulence3_doc}, + {"smoothNoise1", + (PyCFunction)FrsNoise_smoothNoise1, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_smoothNoise1_doc}, + {"smoothNoise2", + (PyCFunction)FrsNoise_smoothNoise2, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_smoothNoise2_doc}, + {"smoothNoise3", + (PyCFunction)FrsNoise_smoothNoise3, + METH_VARARGS | METH_KEYWORDS, + FrsNoise_smoothNoise3_doc}, + {"rand", (PyCFunction)FrsNoise_drand, METH_VARARGS | METH_KEYWORDS, NULL}, + {"turbulence_smooth", + (PyCFunction)FrsNoise_turbulence_smooth, + METH_VARARGS | METH_KEYWORDS, + NULL}, + {NULL, NULL, 0, NULL}, }; /*-----------------------BPy_FrsNoise type definition ------------------------------*/ PyTypeObject FrsNoise_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Noise", /* tp_name */ - sizeof(BPy_FrsNoise), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)FrsNoise_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)FrsNoise_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FrsNoise_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_FrsNoise_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FrsNoise_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Noise", /* tp_name */ + sizeof(BPy_FrsNoise), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)FrsNoise_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)FrsNoise_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FrsNoise_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_FrsNoise_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FrsNoise_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.h b/source/blender/freestyle/intern/python/BPy_FrsNoise.h index 109d4aba6b1..9dcf59779cf 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.h +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.h @@ -42,21 +42,18 @@ extern PyTypeObject FrsNoise_Type; /*---------------------------Python BPy_FrsNoise structure definition----------*/ typedef struct { - PyObject_HEAD - Noise *n; - PseudoNoise *pn; + PyObject_HEAD Noise *n; + PseudoNoise *pn; } BPy_FrsNoise; /*---------------------------Python BPy_FrsNoise visible prototypes-----------*/ int FrsNoise_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_FRSNOISE_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_Id.cpp b/source/blender/freestyle/intern/python/BPy_Id.cpp index fb47874cd97..4e2500a4b3d 100644 --- a/source/blender/freestyle/intern/python/BPy_Id.cpp +++ b/source/blender/freestyle/intern/python/BPy_Id.cpp @@ -31,181 +31,180 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int Id_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&Id_Type) < 0) - return -1; + if (PyType_Ready(&Id_Type) < 0) + return -1; - Py_INCREF(&Id_Type); - PyModule_AddObject(module, "Id", (PyObject *)&Id_Type); - return 0; + Py_INCREF(&Id_Type); + PyModule_AddObject(module, "Id", (PyObject *)&Id_Type); + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Id_doc, -"Class for representing an object Id.\n" -"\n" -".. method:: __init__(first=0, second=0)\n" -"\n" -" Build the Id from two numbers.\n" -"\n" -" :arg first: The first number.\n" -" :type first: int\n" -" :arg second: The second number.\n" -" :type second: int\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An Id object.\n" -" :type brother: :class:`Id`"); + "Class for representing an object Id.\n" + "\n" + ".. method:: __init__(first=0, second=0)\n" + "\n" + " Build the Id from two numbers.\n" + "\n" + " :arg first: The first number.\n" + " :type first: int\n" + " :arg second: The second number.\n" + " :type second: int\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An Id object.\n" + " :type brother: :class:`Id`"); static int Id_init(BPy_Id *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first", "second", NULL}; - PyObject *brother; - int first = 0, second = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &Id_Type, &brother)) { - self->id = new Id(*(((BPy_Id *)brother)->id)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "|ii", (char **)kwlist_2, &first, &second)) - { - self->id = new Id(first, second); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first", "second", NULL}; + PyObject *brother; + int first = 0, second = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &Id_Type, &brother)) { + self->id = new Id(*(((BPy_Id *)brother)->id)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "|ii", (char **)kwlist_2, &first, &second)) { + self->id = new Id(first, second); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + return 0; } static void Id_dealloc(BPy_Id *self) { - delete self->id; - Py_TYPE(self)->tp_free((PyObject *)self); + delete self->id; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *Id_repr(BPy_Id *self) { - return PyUnicode_FromFormat("[ first: %i, second: %i ](BPy_Id)", self->id->getFirst(), self->id->getSecond()); + return PyUnicode_FromFormat( + "[ first: %i, second: %i ](BPy_Id)", self->id->getFirst(), self->id->getSecond()); } static PyObject *Id_RichCompare(BPy_Id *o1, BPy_Id *o2, int opid) { - switch (opid) { - case Py_LT: - return PyBool_from_bool(o1->id->operator<(*(o2->id))); - case Py_LE: - return PyBool_from_bool(o1->id->operator<(*(o2->id)) || o1->id->operator==(*(o2->id))); - case Py_EQ: - return PyBool_from_bool(o1->id->operator==(*(o2->id))); - case Py_NE: - return PyBool_from_bool(o1->id->operator!=(*(o2->id))); - case Py_GT: - return PyBool_from_bool(!(o1->id->operator<(*(o2->id)) || o1->id->operator==(*(o2->id)))); - case Py_GE: - return PyBool_from_bool(!(o1->id->operator<(*(o2->id)))); - } - Py_RETURN_NONE; + switch (opid) { + case Py_LT: + return PyBool_from_bool(o1->id->operator<(*(o2->id))); + case Py_LE: + return PyBool_from_bool(o1->id->operator<(*(o2->id)) || o1->id->operator==(*(o2->id))); + case Py_EQ: + return PyBool_from_bool(o1->id->operator==(*(o2->id))); + case Py_NE: + return PyBool_from_bool(o1->id->operator!=(*(o2->id))); + case Py_GT: + return PyBool_from_bool(!(o1->id->operator<(*(o2->id)) || o1->id->operator==(*(o2->id)))); + case Py_GE: + return PyBool_from_bool(!(o1->id->operator<(*(o2->id)))); + } + Py_RETURN_NONE; } /*----------------------Id get/setters ----------------------------*/ PyDoc_STRVAR(Id_first_doc, -"The first number constituting the Id.\n" -"\n" -":type: int"); + "The first number constituting the Id.\n" + "\n" + ":type: int"); static PyObject *Id_first_get(BPy_Id *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->id->getFirst()); + return PyLong_FromLong(self->id->getFirst()); } static int Id_first_set(BPy_Id *self, PyObject *value, void *UNUSED(closure)) { - int scalar; - if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "value must be an integer"); - return -1; - } - self->id->setFirst(scalar); - return 0; + int scalar; + if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be an integer"); + return -1; + } + self->id->setFirst(scalar); + return 0; } PyDoc_STRVAR(Id_second_doc, -"The second number constituting the Id.\n" -"\n" -":type: int"); + "The second number constituting the Id.\n" + "\n" + ":type: int"); static PyObject *Id_second_get(BPy_Id *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->id->getSecond()); + return PyLong_FromLong(self->id->getSecond()); } static int Id_second_set(BPy_Id *self, PyObject *value, void *UNUSED(closure)) { - int scalar; - if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "value must be an integer"); - return -1; - } - self->id->setSecond(scalar); - return 0; + int scalar; + if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be an integer"); + return -1; + } + self->id->setSecond(scalar); + return 0; } static PyGetSetDef BPy_Id_getseters[] = { - {(char *)"first", (getter)Id_first_get, (setter)Id_first_set, (char *)Id_first_doc, NULL}, - {(char *)"second", (getter)Id_second_get, (setter)Id_second_set, (char *)Id_second_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"first", (getter)Id_first_get, (setter)Id_first_set, (char *)Id_first_doc, NULL}, + {(char *)"second", (getter)Id_second_get, (setter)Id_second_set, (char *)Id_second_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Id type definition ------------------------------*/ PyTypeObject Id_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Id", /* tp_name */ - sizeof(BPy_Id), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Id_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)Id_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Id_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)Id_RichCompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_Id_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Id_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Id", /* tp_name */ + sizeof(BPy_Id), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Id_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)Id_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Id_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)Id_RichCompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_Id_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Id_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Id.h b/source/blender/freestyle/intern/python/BPy_Id.h index bb58da25942..3544f751453 100644 --- a/source/blender/freestyle/intern/python/BPy_Id.h +++ b/source/blender/freestyle/intern/python/BPy_Id.h @@ -45,8 +45,7 @@ extern PyTypeObject Id_Type; /*---------------------------Python BPy_Id structure definition----------*/ typedef struct { - PyObject_HEAD - Id *id; + PyObject_HEAD Id *id; } BPy_Id; /*---------------------------Python BPy_Id visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp index 10b1165ba83..bfd9e5e7898 100644 --- a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp +++ b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp @@ -35,66 +35,74 @@ extern "C" { //------------------------ MODULE FUNCTIONS ---------------------------------- PyDoc_STRVAR(Integrator_integrate_doc, -".. function:: integrate(func, it, it_end, integration_type)\n" -"\n" -" Returns a single value from a set of values evaluated at each 0D\n" -" element of this 1D element.\n" -"\n" -" :arg func: The UnaryFunction0D used to compute a value at each\n" -" Interface0D.\n" -" :type func: :class:`UnaryFunction0D`\n" -" :arg it: The Interface0DIterator used to iterate over the 0D\n" -" elements of this 1D element. The integration will occur over\n" -" the 0D elements starting from the one pointed by it.\n" -" :type it: :class:`Interface0DIterator`\n" -" :arg it_end: The Interface0DIterator pointing the end of the 0D\n" -" elements of the 1D element.\n" -" :type it_end: :class:`Interface0DIterator`\n" -" :arg integration_type: The integration method used to compute a\n" -" single value from a set of values.\n" -" :type integration_type: :class:`IntegrationType`\n" -" :return: The single value obtained for the 1D element. The return\n" -" value type is float if func is of the :class:`UnaryFunction0DDouble`\n" -" or :class:`UnaryFunction0DFloat` type, and int if func is of the\n" -" :class:`UnaryFunction0DUnsigned` type.\n" -" :rtype: int or float"); + ".. function:: integrate(func, it, it_end, integration_type)\n" + "\n" + " Returns a single value from a set of values evaluated at each 0D\n" + " element of this 1D element.\n" + "\n" + " :arg func: The UnaryFunction0D used to compute a value at each\n" + " Interface0D.\n" + " :type func: :class:`UnaryFunction0D`\n" + " :arg it: The Interface0DIterator used to iterate over the 0D\n" + " elements of this 1D element. The integration will occur over\n" + " the 0D elements starting from the one pointed by it.\n" + " :type it: :class:`Interface0DIterator`\n" + " :arg it_end: The Interface0DIterator pointing the end of the 0D\n" + " elements of the 1D element.\n" + " :type it_end: :class:`Interface0DIterator`\n" + " :arg integration_type: The integration method used to compute a\n" + " single value from a set of values.\n" + " :type integration_type: :class:`IntegrationType`\n" + " :return: The single value obtained for the 1D element. The return\n" + " value type is float if func is of the :class:`UnaryFunction0DDouble`\n" + " or :class:`UnaryFunction0DFloat` type, and int if func is of the\n" + " :class:`UnaryFunction0DUnsigned` type.\n" + " :rtype: int or float"); static PyObject *Integrator_integrate(PyObject * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"func", "it", "it_end", "integration_type", NULL}; - PyObject *obj1, *obj4 = 0; - BPy_Interface0DIterator *obj2, *obj3; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!|O!", (char **)kwlist, - &UnaryFunction0D_Type, &obj1, &Interface0DIterator_Type, &obj2, - &Interface0DIterator_Type, &obj3, &IntegrationType_Type, &obj4)) - { - return NULL; - } - - Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it)); - IntegrationType t = (obj4) ? IntegrationType_from_BPy_IntegrationType(obj4) : MEAN; - - if (BPy_UnaryFunction0DDouble_Check(obj1)) { - UnaryFunction0D *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double; - double res = integrate(*fun, it, it_end, t); - return PyFloat_FromDouble(res); - } - else if (BPy_UnaryFunction0DFloat_Check(obj1)) { - UnaryFunction0D *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float; - float res = integrate(*fun, it, it_end, t); - return PyFloat_FromDouble(res); - } - else if (BPy_UnaryFunction0DUnsigned_Check(obj1)) { - UnaryFunction0D *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned; - unsigned int res = integrate(*fun, it, it_end, t); - return PyLong_FromLong(res); - } - else { - string class_name(Py_TYPE(obj1)->tp_name); - PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str()); - return NULL; - } + static const char *kwlist[] = {"func", "it", "it_end", "integration_type", NULL}; + PyObject *obj1, *obj4 = 0; + BPy_Interface0DIterator *obj2, *obj3; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!O!|O!", + (char **)kwlist, + &UnaryFunction0D_Type, + &obj1, + &Interface0DIterator_Type, + &obj2, + &Interface0DIterator_Type, + &obj3, + &IntegrationType_Type, + &obj4)) { + return NULL; + } + + Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it)); + IntegrationType t = (obj4) ? IntegrationType_from_BPy_IntegrationType(obj4) : MEAN; + + if (BPy_UnaryFunction0DDouble_Check(obj1)) { + UnaryFunction0D *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double; + double res = integrate(*fun, it, it_end, t); + return PyFloat_FromDouble(res); + } + else if (BPy_UnaryFunction0DFloat_Check(obj1)) { + UnaryFunction0D *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float; + float res = integrate(*fun, it, it_end, t); + return PyFloat_FromDouble(res); + } + else if (BPy_UnaryFunction0DUnsigned_Check(obj1)) { + UnaryFunction0D *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned; + unsigned int res = integrate(*fun, it, it_end, t); + return PyLong_FromLong(res); + } + else { + string class_name(Py_TYPE(obj1)->tp_name); + PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str()); + return NULL; + } } /*-----------------------Integrator module docstring---------------------------------------*/ @@ -104,8 +112,11 @@ PyDoc_STRVAR(module_docstring, "The Blender Freestyle.Integrator submodule\n\n") /*-----------------------Integrator module functions definitions---------------------------*/ static PyMethodDef module_functions[] = { - {"integrate", (PyCFunction) Integrator_integrate, METH_VARARGS | METH_KEYWORDS, Integrator_integrate_doc}, - {NULL, NULL, 0, NULL}, + {"integrate", + (PyCFunction)Integrator_integrate, + METH_VARARGS | METH_KEYWORDS, + Integrator_integrate_doc}, + {NULL, NULL, 0, NULL}, }; /*-----------------------Integrator module definition--------------------------------------*/ @@ -121,127 +132,114 @@ static PyModuleDef module_definition = { /*-----------------------BPy_IntegrationType type definition ------------------------------*/ PyDoc_STRVAR(IntegrationType_doc, -"Class hierarchy: int > :class:`IntegrationType`\n" -"\n" -"Different integration methods that can be invoked to integrate into a\n" -"single value the set of values obtained from each 0D element of an 1D\n" -"element:\n" -"\n" -"* IntegrationType.MEAN: The value computed for the 1D element is the\n" -" mean of the values obtained for the 0D elements.\n" -"* IntegrationType.MIN: The value computed for the 1D element is the\n" -" minimum of the values obtained for the 0D elements.\n" -"* IntegrationType.MAX: The value computed for the 1D element is the\n" -" maximum of the values obtained for the 0D elements.\n" -"* IntegrationType.FIRST: The value computed for the 1D element is the\n" -" first of the values obtained for the 0D elements.\n" -"* IntegrationType.LAST: The value computed for the 1D element is the\n" -" last of the values obtained for the 0D elements."); + "Class hierarchy: int > :class:`IntegrationType`\n" + "\n" + "Different integration methods that can be invoked to integrate into a\n" + "single value the set of values obtained from each 0D element of an 1D\n" + "element:\n" + "\n" + "* IntegrationType.MEAN: The value computed for the 1D element is the\n" + " mean of the values obtained for the 0D elements.\n" + "* IntegrationType.MIN: The value computed for the 1D element is the\n" + " minimum of the values obtained for the 0D elements.\n" + "* IntegrationType.MAX: The value computed for the 1D element is the\n" + " maximum of the values obtained for the 0D elements.\n" + "* IntegrationType.FIRST: The value computed for the 1D element is the\n" + " first of the values obtained for the 0D elements.\n" + "* IntegrationType.LAST: The value computed for the 1D element is the\n" + " last of the values obtained for the 0D elements."); PyTypeObject IntegrationType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "IntegrationType", /* tp_name */ - sizeof(PyLongObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - IntegrationType_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &PyLong_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "IntegrationType", /* tp_name */ + sizeof(PyLongObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + IntegrationType_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PyLong_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /*-----------------------BPy_IntegrationType instance definitions -------------------------*/ static PyLongObject _IntegrationType_MEAN = { - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1) - { MEAN } -}; -static PyLongObject _IntegrationType_MIN = { - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1) - { MIN } -}; -static PyLongObject _IntegrationType_MAX = { - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1) - { MAX } -}; + PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MEAN}}; +static PyLongObject _IntegrationType_MIN = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MIN}}; +static PyLongObject _IntegrationType_MAX = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MAX}}; static PyLongObject _IntegrationType_FIRST = { - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1) - { FIRST } -}; + PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){FIRST}}; static PyLongObject _IntegrationType_LAST = { - PyVarObject_HEAD_INIT(&IntegrationType_Type, 1) - { LAST } -}; + PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){LAST}}; -#define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN) -#define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN) -#define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX) +#define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN) +#define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN) +#define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX) #define BPy_IntegrationType_FIRST ((PyObject *)&_IntegrationType_FIRST) -#define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST) +#define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST) //-------------------MODULE INITIALIZATION-------------------------------- int IntegrationType_Init(PyObject *module) { - PyObject *m, *d, *f; - - if (module == NULL) - return -1; - - if (PyType_Ready(&IntegrationType_Type) < 0) - return -1; - Py_INCREF(&IntegrationType_Type); - PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type); - - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN); - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN); - PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX); - PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST); - PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST); - - m = PyModule_Create(&module_definition); - if (m == NULL) - return -1; - Py_INCREF(m); - PyModule_AddObject(module, "Integrator", m); - - // from Integrator import * - d = PyModule_GetDict(m); - for (PyMethodDef *p = module_functions; p->ml_name; p++) { - f = PyDict_GetItemString(d, p->ml_name); - Py_INCREF(f); - PyModule_AddObject(module, p->ml_name, f); - } - - return 0; + PyObject *m, *d, *f; + + if (module == NULL) + return -1; + + if (PyType_Ready(&IntegrationType_Type) < 0) + return -1; + Py_INCREF(&IntegrationType_Type); + PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type); + + PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN); + PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN); + PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX); + PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST); + PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST); + + m = PyModule_Create(&module_definition); + if (m == NULL) + return -1; + Py_INCREF(m); + PyModule_AddObject(module, "Integrator", m); + + // from Integrator import * + d = PyModule_GetDict(m); + for (PyMethodDef *p = module_functions; p->ml_name; p++) { + f = PyDict_GetItemString(d, p->ml_name); + Py_INCREF(f); + PyModule_AddObject(module, p->ml_name, f); + } + + return 0; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_IntegrationType.h b/source/blender/freestyle/intern/python/BPy_IntegrationType.h index 73cb1b26d59..525feb002e4 100644 --- a/source/blender/freestyle/intern/python/BPy_IntegrationType.h +++ b/source/blender/freestyle/intern/python/BPy_IntegrationType.h @@ -37,7 +37,8 @@ extern "C" { extern PyTypeObject IntegrationType_Type; -#define BPy_IntegrationType_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&IntegrationType_Type)) +#define BPy_IntegrationType_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&IntegrationType_Type)) /*---------------------------Python BPy_IntegrationType visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp index a08946660b5..897f2f06c28 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp @@ -39,272 +39,300 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int Interface0D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&Interface0D_Type) < 0) - return -1; - Py_INCREF(&Interface0D_Type); - PyModule_AddObject(module, "Interface0D", (PyObject *)&Interface0D_Type); - - if (PyType_Ready(&CurvePoint_Type) < 0) - return -1; - Py_INCREF(&CurvePoint_Type); - PyModule_AddObject(module, "CurvePoint", (PyObject *)&CurvePoint_Type); - - if (PyType_Ready(&SVertex_Type) < 0) - return -1; - Py_INCREF(&SVertex_Type); - PyModule_AddObject(module, "SVertex", (PyObject *)&SVertex_Type); - - if (PyType_Ready(&ViewVertex_Type) < 0) - return -1; - Py_INCREF(&ViewVertex_Type); - PyModule_AddObject(module, "ViewVertex", (PyObject *)&ViewVertex_Type); - - if (PyType_Ready(&StrokeVertex_Type) < 0) - return -1; - Py_INCREF(&StrokeVertex_Type); - PyModule_AddObject(module, "StrokeVertex", (PyObject *)&StrokeVertex_Type); - - if (PyType_Ready(&NonTVertex_Type) < 0) - return -1; - Py_INCREF(&NonTVertex_Type); - PyModule_AddObject(module, "NonTVertex", (PyObject *)&NonTVertex_Type); - - if (PyType_Ready(&TVertex_Type) < 0) - return -1; - Py_INCREF(&TVertex_Type); - PyModule_AddObject(module, "TVertex", (PyObject *)&TVertex_Type); - - SVertex_mathutils_register_callback(); - StrokeVertex_mathutils_register_callback(); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&Interface0D_Type) < 0) + return -1; + Py_INCREF(&Interface0D_Type); + PyModule_AddObject(module, "Interface0D", (PyObject *)&Interface0D_Type); + + if (PyType_Ready(&CurvePoint_Type) < 0) + return -1; + Py_INCREF(&CurvePoint_Type); + PyModule_AddObject(module, "CurvePoint", (PyObject *)&CurvePoint_Type); + + if (PyType_Ready(&SVertex_Type) < 0) + return -1; + Py_INCREF(&SVertex_Type); + PyModule_AddObject(module, "SVertex", (PyObject *)&SVertex_Type); + + if (PyType_Ready(&ViewVertex_Type) < 0) + return -1; + Py_INCREF(&ViewVertex_Type); + PyModule_AddObject(module, "ViewVertex", (PyObject *)&ViewVertex_Type); + + if (PyType_Ready(&StrokeVertex_Type) < 0) + return -1; + Py_INCREF(&StrokeVertex_Type); + PyModule_AddObject(module, "StrokeVertex", (PyObject *)&StrokeVertex_Type); + + if (PyType_Ready(&NonTVertex_Type) < 0) + return -1; + Py_INCREF(&NonTVertex_Type); + PyModule_AddObject(module, "NonTVertex", (PyObject *)&NonTVertex_Type); + + if (PyType_Ready(&TVertex_Type) < 0) + return -1; + Py_INCREF(&TVertex_Type); + PyModule_AddObject(module, "TVertex", (PyObject *)&TVertex_Type); + + SVertex_mathutils_register_callback(); + StrokeVertex_mathutils_register_callback(); + + return 0; } /*----------------------Interface1D methods ----------------------------*/ PyDoc_STRVAR(Interface0D_doc, -"Base class for any 0D element.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Base class for any 0D element.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->if0D = new Interface0D(); - self->borrowed = false; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->if0D = new Interface0D(); + self->borrowed = false; + return 0; } static void Interface0D_dealloc(BPy_Interface0D *self) { - if (self->if0D && !self->borrowed) - delete self->if0D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->if0D && !self->borrowed) + delete self->if0D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *Interface0D_repr(BPy_Interface0D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D); + return PyUnicode_FromFormat( + "type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D); } PyDoc_STRVAR(Interface0D_get_fedge_doc, -".. method:: get_fedge(inter)\n" -"\n" -" Returns the FEdge that lies between this 0D element and the 0D\n" -" element given as the argument.\n" -"\n" -" :arg inter: A 0D element.\n" -" :type inter: :class:`Interface0D`\n" -" :return: The FEdge lying between the two 0D elements.\n" -" :rtype: :class:`FEdge`"); + ".. method:: get_fedge(inter)\n" + "\n" + " Returns the FEdge that lies between this 0D element and the 0D\n" + " element given as the argument.\n" + "\n" + " :arg inter: A 0D element.\n" + " :type inter: :class:`Interface0D`\n" + " :return: The FEdge lying between the two 0D elements.\n" + " :rtype: :class:`FEdge`"); static PyObject *Interface0D_get_fedge(BPy_Interface0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *py_if0D; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0D_Type, &py_if0D)) - return NULL; - FEdge *fe = self->if0D->getFEdge(*(((BPy_Interface0D *)py_if0D)->if0D)); - if (PyErr_Occurred()) - return NULL; - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + static const char *kwlist[] = {"inter", NULL}; + PyObject *py_if0D; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0D_Type, &py_if0D)) + return NULL; + FEdge *fe = self->if0D->getFEdge(*(((BPy_Interface0D *)py_if0D)->if0D)); + if (PyErr_Occurred()) + return NULL; + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } static PyMethodDef BPy_Interface0D_methods[] = { - {"get_fedge", (PyCFunction)Interface0D_get_fedge, METH_VARARGS | METH_KEYWORDS, Interface0D_get_fedge_doc}, - {NULL, NULL, 0, NULL}, + {"get_fedge", + (PyCFunction)Interface0D_get_fedge, + METH_VARARGS | METH_KEYWORDS, + Interface0D_get_fedge_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------Interface1D get/setters ----------------------------*/ PyDoc_STRVAR(Interface0D_name_doc, -"The string of the name of this 0D element.\n" -"\n" -":type: str"); + "The string of the name of this 0D element.\n" + "\n" + ":type: str"); static PyObject *Interface0D_name_get(BPy_Interface0D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } PyDoc_STRVAR(Interface0D_point_3d_doc, -"The 3D point of this 0D element.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The 3D point of this 0D element.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *Interface0D_point_3d_get(BPy_Interface0D *self, void *UNUSED(closure)) { - Vec3f p(self->if0D->getPoint3D()); - if (PyErr_Occurred()) - return NULL; - return Vector_from_Vec3f(p); + Vec3f p(self->if0D->getPoint3D()); + if (PyErr_Occurred()) + return NULL; + return Vector_from_Vec3f(p); } PyDoc_STRVAR(Interface0D_projected_x_doc, -"The X coordinate of the projected 3D point of this 0D element.\n" -"\n" -":type: float"); + "The X coordinate of the projected 3D point of this 0D element.\n" + "\n" + ":type: float"); static PyObject *Interface0D_projected_x_get(BPy_Interface0D *self, void *UNUSED(closure)) { - real x = self->if0D->getProjectedX(); - if (PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(x); + real x = self->if0D->getProjectedX(); + if (PyErr_Occurred()) + return NULL; + return PyFloat_FromDouble(x); } PyDoc_STRVAR(Interface0D_projected_y_doc, -"The Y coordinate of the projected 3D point of this 0D element.\n" -"\n" -":type: float"); + "The Y coordinate of the projected 3D point of this 0D element.\n" + "\n" + ":type: float"); static PyObject *Interface0D_projected_y_get(BPy_Interface0D *self, void *UNUSED(closure)) { - real y = self->if0D->getProjectedY(); - if (PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(y); + real y = self->if0D->getProjectedY(); + if (PyErr_Occurred()) + return NULL; + return PyFloat_FromDouble(y); } PyDoc_STRVAR(Interface0D_projected_z_doc, -"The Z coordinate of the projected 3D point of this 0D element.\n" -"\n" -":type: float"); + "The Z coordinate of the projected 3D point of this 0D element.\n" + "\n" + ":type: float"); static PyObject *Interface0D_projected_z_get(BPy_Interface0D *self, void *UNUSED(closure)) { - real z = self->if0D->getProjectedZ(); - if (PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(z); + real z = self->if0D->getProjectedZ(); + if (PyErr_Occurred()) + return NULL; + return PyFloat_FromDouble(z); } PyDoc_STRVAR(Interface0D_point_2d_doc, -"The 2D point of this 0D element.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The 2D point of this 0D element.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *Interface0D_point_2d_get(BPy_Interface0D *self, void *UNUSED(closure)) { - Vec2f p(self->if0D->getPoint2D()); - if (PyErr_Occurred()) - return NULL; - return Vector_from_Vec2f(p); + Vec2f p(self->if0D->getPoint2D()); + if (PyErr_Occurred()) + return NULL; + return Vector_from_Vec2f(p); } PyDoc_STRVAR(Interface0D_id_doc, -"The Id of this 0D element.\n" -"\n" -":type: :class:`Id`"); + "The Id of this 0D element.\n" + "\n" + ":type: :class:`Id`"); static PyObject *Interface0D_id_get(BPy_Interface0D *self, void *UNUSED(closure)) { - Id id(self->if0D->getId()); - if (PyErr_Occurred()) - return NULL; - return BPy_Id_from_Id(id); // return a copy + Id id(self->if0D->getId()); + if (PyErr_Occurred()) + return NULL; + return BPy_Id_from_Id(id); // return a copy } PyDoc_STRVAR(Interface0D_nature_doc, -"The nature of this 0D element.\n" -"\n" -":type: :class:`Nature`"); + "The nature of this 0D element.\n" + "\n" + ":type: :class:`Nature`"); static PyObject *Interface0D_nature_get(BPy_Interface0D *self, void *UNUSED(closure)) { - Nature::VertexNature nature = self->if0D->getNature(); - if (PyErr_Occurred()) - return NULL; - return BPy_Nature_from_Nature(nature); + Nature::VertexNature nature = self->if0D->getNature(); + if (PyErr_Occurred()) + return NULL; + return BPy_Nature_from_Nature(nature); } static PyGetSetDef BPy_Interface0D_getseters[] = { - {(char *)"name", (getter)Interface0D_name_get, (setter)NULL, (char *)Interface0D_name_doc, NULL}, - {(char *)"point_3d", (getter)Interface0D_point_3d_get, (setter)NULL, (char *)Interface0D_point_3d_doc, NULL}, - {(char *)"projected_x", (getter)Interface0D_projected_x_get, (setter)NULL, - (char *)Interface0D_projected_x_doc, NULL}, - {(char *)"projected_y", (getter)Interface0D_projected_y_get, (setter)NULL, - (char *)Interface0D_projected_y_doc, NULL}, - {(char *)"projected_z", (getter)Interface0D_projected_z_get, (setter)NULL, - (char *)Interface0D_projected_z_doc, NULL}, - {(char *)"point_2d", (getter)Interface0D_point_2d_get, (setter)NULL, (char *)Interface0D_point_2d_doc, NULL}, - {(char *)"id", (getter)Interface0D_id_get, (setter)NULL, (char *)Interface0D_id_doc, NULL}, - {(char *)"nature", (getter)Interface0D_nature_get, (setter)NULL, (char *)Interface0D_nature_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)Interface0D_name_get, + (setter)NULL, + (char *)Interface0D_name_doc, + NULL}, + {(char *)"point_3d", + (getter)Interface0D_point_3d_get, + (setter)NULL, + (char *)Interface0D_point_3d_doc, + NULL}, + {(char *)"projected_x", + (getter)Interface0D_projected_x_get, + (setter)NULL, + (char *)Interface0D_projected_x_doc, + NULL}, + {(char *)"projected_y", + (getter)Interface0D_projected_y_get, + (setter)NULL, + (char *)Interface0D_projected_y_doc, + NULL}, + {(char *)"projected_z", + (getter)Interface0D_projected_z_get, + (setter)NULL, + (char *)Interface0D_projected_z_doc, + NULL}, + {(char *)"point_2d", + (getter)Interface0D_point_2d_get, + (setter)NULL, + (char *)Interface0D_point_2d_doc, + NULL}, + {(char *)"id", (getter)Interface0D_id_get, (setter)NULL, (char *)Interface0D_id_doc, NULL}, + {(char *)"nature", + (getter)Interface0D_nature_get, + (setter)NULL, + (char *)Interface0D_nature_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Interface0D type definition ------------------------------*/ PyTypeObject Interface0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Interface0D", /* tp_name */ - sizeof(BPy_Interface0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Interface0D_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)Interface0D_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Interface0D_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Interface0D_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_Interface0D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Interface0D_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Interface0D", /* tp_name */ + sizeof(BPy_Interface0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Interface0D_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)Interface0D_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Interface0D_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Interface0D_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_Interface0D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Interface0D_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Interface0D.h b/source/blender/freestyle/intern/python/BPy_Interface0D.h index 2a52394e137..81fdd40ff04 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface0D.h +++ b/source/blender/freestyle/intern/python/BPy_Interface0D.h @@ -37,13 +37,13 @@ extern "C" { extern PyTypeObject Interface0D_Type; -#define BPy_Interface0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0D_Type)) +#define BPy_Interface0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0D_Type)) /*---------------------------Python BPy_Interface0D structure definition----------*/ typedef struct { - PyObject_HEAD - Interface0D *if0D; - bool borrowed; /* true if *if0D is a borrowed object */ + PyObject_HEAD Interface0D *if0D; + bool borrowed; /* true if *if0D is a borrowed object */ } BPy_Interface0D; /*---------------------------Python BPy_Interface0D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp index 6c6965a4975..09e27da9eeb 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp @@ -40,303 +40,332 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int Interface1D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&Interface1D_Type) < 0) - return -1; - Py_INCREF(&Interface1D_Type); - PyModule_AddObject(module, "Interface1D", (PyObject *)&Interface1D_Type); - - if (PyType_Ready(&FrsCurve_Type) < 0) - return -1; - Py_INCREF(&FrsCurve_Type); - PyModule_AddObject(module, "Curve", (PyObject *)&FrsCurve_Type); - - if (PyType_Ready(&Chain_Type) < 0) - return -1; - Py_INCREF(&Chain_Type); - PyModule_AddObject(module, "Chain", (PyObject *)&Chain_Type); - - if (PyType_Ready(&FEdge_Type) < 0) - return -1; - Py_INCREF(&FEdge_Type); - PyModule_AddObject(module, "FEdge", (PyObject *)&FEdge_Type); - - if (PyType_Ready(&FEdgeSharp_Type) < 0) - return -1; - Py_INCREF(&FEdgeSharp_Type); - PyModule_AddObject(module, "FEdgeSharp", (PyObject *)&FEdgeSharp_Type); - - if (PyType_Ready(&FEdgeSmooth_Type) < 0) - return -1; - Py_INCREF(&FEdgeSmooth_Type); - PyModule_AddObject(module, "FEdgeSmooth", (PyObject *)&FEdgeSmooth_Type); - - if (PyType_Ready(&Stroke_Type) < 0) - return -1; - Py_INCREF(&Stroke_Type); - PyModule_AddObject(module, "Stroke", (PyObject *)&Stroke_Type); - - PyDict_SetItemString(Stroke_Type.tp_dict, "DRY_MEDIUM", BPy_MediumType_DRY_MEDIUM); - PyDict_SetItemString(Stroke_Type.tp_dict, "HUMID_MEDIUM", BPy_MediumType_HUMID_MEDIUM); - PyDict_SetItemString(Stroke_Type.tp_dict, "OPAQUE_MEDIUM", BPy_MediumType_OPAQUE_MEDIUM); - - if (PyType_Ready(&ViewEdge_Type) < 0) - return -1; - Py_INCREF(&ViewEdge_Type); - PyModule_AddObject(module, "ViewEdge", (PyObject *)&ViewEdge_Type); - - FEdgeSharp_mathutils_register_callback(); - FEdgeSmooth_mathutils_register_callback(); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&Interface1D_Type) < 0) + return -1; + Py_INCREF(&Interface1D_Type); + PyModule_AddObject(module, "Interface1D", (PyObject *)&Interface1D_Type); + + if (PyType_Ready(&FrsCurve_Type) < 0) + return -1; + Py_INCREF(&FrsCurve_Type); + PyModule_AddObject(module, "Curve", (PyObject *)&FrsCurve_Type); + + if (PyType_Ready(&Chain_Type) < 0) + return -1; + Py_INCREF(&Chain_Type); + PyModule_AddObject(module, "Chain", (PyObject *)&Chain_Type); + + if (PyType_Ready(&FEdge_Type) < 0) + return -1; + Py_INCREF(&FEdge_Type); + PyModule_AddObject(module, "FEdge", (PyObject *)&FEdge_Type); + + if (PyType_Ready(&FEdgeSharp_Type) < 0) + return -1; + Py_INCREF(&FEdgeSharp_Type); + PyModule_AddObject(module, "FEdgeSharp", (PyObject *)&FEdgeSharp_Type); + + if (PyType_Ready(&FEdgeSmooth_Type) < 0) + return -1; + Py_INCREF(&FEdgeSmooth_Type); + PyModule_AddObject(module, "FEdgeSmooth", (PyObject *)&FEdgeSmooth_Type); + + if (PyType_Ready(&Stroke_Type) < 0) + return -1; + Py_INCREF(&Stroke_Type); + PyModule_AddObject(module, "Stroke", (PyObject *)&Stroke_Type); + + PyDict_SetItemString(Stroke_Type.tp_dict, "DRY_MEDIUM", BPy_MediumType_DRY_MEDIUM); + PyDict_SetItemString(Stroke_Type.tp_dict, "HUMID_MEDIUM", BPy_MediumType_HUMID_MEDIUM); + PyDict_SetItemString(Stroke_Type.tp_dict, "OPAQUE_MEDIUM", BPy_MediumType_OPAQUE_MEDIUM); + + if (PyType_Ready(&ViewEdge_Type) < 0) + return -1; + Py_INCREF(&ViewEdge_Type); + PyModule_AddObject(module, "ViewEdge", (PyObject *)&ViewEdge_Type); + + FEdgeSharp_mathutils_register_callback(); + FEdgeSmooth_mathutils_register_callback(); + + return 0; } /*----------------------Interface1D methods ----------------------------*/ PyDoc_STRVAR(Interface1D_doc, -"Base class for any 1D element.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Base class for any 1D element.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); static int Interface1D_init(BPy_Interface1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->if1D = new Interface1D(); - self->borrowed = false; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->if1D = new Interface1D(); + self->borrowed = false; + return 0; } static void Interface1D_dealloc(BPy_Interface1D *self) { - if (self->if1D && !self->borrowed) - delete self->if1D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->if1D && !self->borrowed) + delete self->if1D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *Interface1D_repr(BPy_Interface1D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D); + return PyUnicode_FromFormat( + "type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D); } PyDoc_STRVAR(Interface1D_vertices_begin_doc, -".. method:: vertices_begin()\n" -"\n" -" Returns an iterator over the Interface1D vertices, pointing to the\n" -" first vertex.\n" -"\n" -" :return: An Interface0DIterator pointing to the first vertex.\n" -" :rtype: :class:`Interface0DIterator`"); + ".. method:: vertices_begin()\n" + "\n" + " Returns an iterator over the Interface1D vertices, pointing to the\n" + " first vertex.\n" + "\n" + " :return: An Interface0DIterator pointing to the first vertex.\n" + " :rtype: :class:`Interface0DIterator`"); static PyObject *Interface1D_vertices_begin(BPy_Interface1D *self) { - Interface0DIterator if0D_it(self->if1D->verticesBegin()); - return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); + Interface0DIterator if0D_it(self->if1D->verticesBegin()); + return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); } PyDoc_STRVAR(Interface1D_vertices_end_doc, -".. method:: vertices_end()\n" -"\n" -" Returns an iterator over the Interface1D vertices, pointing after\n" -" the last vertex.\n" -"\n" -" :return: An Interface0DIterator pointing after the last vertex.\n" -" :rtype: :class:`Interface0DIterator`"); + ".. method:: vertices_end()\n" + "\n" + " Returns an iterator over the Interface1D vertices, pointing after\n" + " the last vertex.\n" + "\n" + " :return: An Interface0DIterator pointing after the last vertex.\n" + " :rtype: :class:`Interface0DIterator`"); static PyObject *Interface1D_vertices_end(BPy_Interface1D *self) { - Interface0DIterator if0D_it(self->if1D->verticesEnd()); - return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, true); + Interface0DIterator if0D_it(self->if1D->verticesEnd()); + return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, true); } PyDoc_STRVAR(Interface1D_points_begin_doc, -".. method:: points_begin(t=0.0)\n" -"\n" -" Returns an iterator over the Interface1D points, pointing to the\n" -" first point. The difference with vertices_begin() is that here we can\n" -" iterate over points of the 1D element at a any given sampling.\n" -" Indeed, for each iteration, a virtual point is created.\n" -"\n" -" :arg t: A sampling with which we want to iterate over points of\n" -" this 1D element.\n" -" :type t: float\n" -" :return: An Interface0DIterator pointing to the first point.\n" -" :rtype: :class:`Interface0DIterator`"); + ".. method:: points_begin(t=0.0)\n" + "\n" + " Returns an iterator over the Interface1D points, pointing to the\n" + " first point. The difference with vertices_begin() is that here we can\n" + " iterate over points of the 1D element at a any given sampling.\n" + " Indeed, for each iteration, a virtual point is created.\n" + "\n" + " :arg t: A sampling with which we want to iterate over points of\n" + " this 1D element.\n" + " :type t: float\n" + " :return: An Interface0DIterator pointing to the first point.\n" + " :rtype: :class:`Interface0DIterator`"); static PyObject *Interface1D_points_begin(BPy_Interface1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"t", NULL}; - float f = 0.0f; + static const char *kwlist[] = {"t", NULL}; + float f = 0.0f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) - return NULL; - Interface0DIterator if0D_it(self->if1D->pointsBegin(f)); - return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) + return NULL; + Interface0DIterator if0D_it(self->if1D->pointsBegin(f)); + return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); } PyDoc_STRVAR(Interface1D_points_end_doc, -".. method:: points_end(t=0.0)\n" -"\n" -" Returns an iterator over the Interface1D points, pointing after the\n" -" last point. The difference with vertices_end() is that here we can\n" -" iterate over points of the 1D element at a given sampling. Indeed,\n" -" for each iteration, a virtual point is created.\n" -"\n" -" :arg t: A sampling with which we want to iterate over points of\n" -" this 1D element.\n" -" :type t: float\n" -" :return: An Interface0DIterator pointing after the last point.\n" -" :rtype: :class:`Interface0DIterator`"); + ".. method:: points_end(t=0.0)\n" + "\n" + " Returns an iterator over the Interface1D points, pointing after the\n" + " last point. The difference with vertices_end() is that here we can\n" + " iterate over points of the 1D element at a given sampling. Indeed,\n" + " for each iteration, a virtual point is created.\n" + "\n" + " :arg t: A sampling with which we want to iterate over points of\n" + " this 1D element.\n" + " :type t: float\n" + " :return: An Interface0DIterator pointing after the last point.\n" + " :rtype: :class:`Interface0DIterator`"); static PyObject *Interface1D_points_end(BPy_Interface1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"t", NULL}; - float f = 0.0f; + static const char *kwlist[] = {"t", NULL}; + float f = 0.0f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) - return NULL; - Interface0DIterator if0D_it(self->if1D->pointsEnd(f)); - return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, true); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) + return NULL; + Interface0DIterator if0D_it(self->if1D->pointsEnd(f)); + return BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, true); } static PyMethodDef BPy_Interface1D_methods[] = { - {"vertices_begin", (PyCFunction)Interface1D_vertices_begin, METH_NOARGS, Interface1D_vertices_begin_doc}, - {"vertices_end", (PyCFunction)Interface1D_vertices_end, METH_NOARGS, Interface1D_vertices_end_doc}, - {"points_begin", (PyCFunction)Interface1D_points_begin, METH_VARARGS | METH_KEYWORDS, Interface1D_points_begin_doc}, - {"points_end", (PyCFunction)Interface1D_points_end, METH_VARARGS | METH_KEYWORDS, Interface1D_points_end_doc}, - {NULL, NULL, 0, NULL}, + {"vertices_begin", + (PyCFunction)Interface1D_vertices_begin, + METH_NOARGS, + Interface1D_vertices_begin_doc}, + {"vertices_end", + (PyCFunction)Interface1D_vertices_end, + METH_NOARGS, + Interface1D_vertices_end_doc}, + {"points_begin", + (PyCFunction)Interface1D_points_begin, + METH_VARARGS | METH_KEYWORDS, + Interface1D_points_begin_doc}, + {"points_end", + (PyCFunction)Interface1D_points_end, + METH_VARARGS | METH_KEYWORDS, + Interface1D_points_end_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------Interface1D get/setters ----------------------------*/ PyDoc_STRVAR(Interface1D_name_doc, -"The string of the name of the 1D element.\n" -"\n" -":type: str"); + "The string of the name of the 1D element.\n" + "\n" + ":type: str"); static PyObject *Interface1D_name_get(BPy_Interface1D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } PyDoc_STRVAR(Interface1D_id_doc, -"The Id of this Interface1D.\n" -"\n" -":type: :class:`Id`"); + "The Id of this Interface1D.\n" + "\n" + ":type: :class:`Id`"); static PyObject *Interface1D_id_get(BPy_Interface1D *self, void *UNUSED(closure)) { - Id id(self->if1D->getId()); - if (PyErr_Occurred()) - return NULL; - return BPy_Id_from_Id(id); // return a copy + Id id(self->if1D->getId()); + if (PyErr_Occurred()) + return NULL; + return BPy_Id_from_Id(id); // return a copy } PyDoc_STRVAR(Interface1D_nature_doc, -"The nature of this Interface1D.\n" -"\n" -":type: :class:`Nature`"); + "The nature of this Interface1D.\n" + "\n" + ":type: :class:`Nature`"); static PyObject *Interface1D_nature_get(BPy_Interface1D *self, void *UNUSED(closure)) { - Nature::VertexNature nature = self->if1D->getNature(); - if (PyErr_Occurred()) - return NULL; - return BPy_Nature_from_Nature(nature); + Nature::VertexNature nature = self->if1D->getNature(); + if (PyErr_Occurred()) + return NULL; + return BPy_Nature_from_Nature(nature); } PyDoc_STRVAR(Interface1D_length_2d_doc, -"The 2D length of this Interface1D.\n" -"\n" -":type: float"); + "The 2D length of this Interface1D.\n" + "\n" + ":type: float"); static PyObject *Interface1D_length_2d_get(BPy_Interface1D *self, void *UNUSED(closure)) { - real length = self->if1D->getLength2D(); - if (PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble((double)length); + real length = self->if1D->getLength2D(); + if (PyErr_Occurred()) + return NULL; + return PyFloat_FromDouble((double)length); } PyDoc_STRVAR(Interface1D_time_stamp_doc, -"The time stamp of the 1D element, mainly used for selection.\n" -"\n" -":type: int"); + "The time stamp of the 1D element, mainly used for selection.\n" + "\n" + ":type: int"); static PyObject *Interface1D_time_stamp_get(BPy_Interface1D *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->if1D->getTimeStamp()); + return PyLong_FromLong(self->if1D->getTimeStamp()); } -static int Interface1D_time_stamp_set(BPy_Interface1D *self, PyObject *value, void *UNUSED(closure)) +static int Interface1D_time_stamp_set(BPy_Interface1D *self, + PyObject *value, + void *UNUSED(closure)) { - int timestamp; - - if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->if1D->setTimeStamp(timestamp); - return 0; + int timestamp; + + if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->if1D->setTimeStamp(timestamp); + return 0; } static PyGetSetDef BPy_Interface1D_getseters[] = { - {(char *)"name", (getter)Interface1D_name_get, (setter)NULL, (char *)Interface1D_name_doc, NULL}, - {(char *)"id", (getter)Interface1D_id_get, (setter)NULL, (char *)Interface1D_id_doc, NULL}, - {(char *)"nature", (getter)Interface1D_nature_get, (setter)NULL, (char *)Interface1D_nature_doc, NULL}, - {(char *)"length_2d", (getter)Interface1D_length_2d_get, (setter)NULL, (char *)Interface1D_length_2d_doc, NULL}, - {(char *)"time_stamp", (getter)Interface1D_time_stamp_get, (setter)Interface1D_time_stamp_set, - (char *)Interface1D_time_stamp_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)Interface1D_name_get, + (setter)NULL, + (char *)Interface1D_name_doc, + NULL}, + {(char *)"id", (getter)Interface1D_id_get, (setter)NULL, (char *)Interface1D_id_doc, NULL}, + {(char *)"nature", + (getter)Interface1D_nature_get, + (setter)NULL, + (char *)Interface1D_nature_doc, + NULL}, + {(char *)"length_2d", + (getter)Interface1D_length_2d_get, + (setter)NULL, + (char *)Interface1D_length_2d_doc, + NULL}, + {(char *)"time_stamp", + (getter)Interface1D_time_stamp_get, + (setter)Interface1D_time_stamp_set, + (char *)Interface1D_time_stamp_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Interface1D type definition ------------------------------*/ PyTypeObject Interface1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Interface1D", /* tp_name */ - sizeof(BPy_Interface1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Interface1D_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)Interface1D_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Interface1D_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Interface1D_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_Interface1D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Interface1D_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Interface1D", /* tp_name */ + sizeof(BPy_Interface1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Interface1D_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)Interface1D_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Interface1D_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Interface1D_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_Interface1D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Interface1D_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Interface1D.h b/source/blender/freestyle/intern/python/BPy_Interface1D.h index 204eb84d87b..db9bfa7f79c 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface1D.h +++ b/source/blender/freestyle/intern/python/BPy_Interface1D.h @@ -37,20 +37,19 @@ extern "C" { extern PyTypeObject Interface1D_Type; -#define BPy_Interface1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface1D_Type)) +#define BPy_Interface1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface1D_Type)) /*---------------------------Python BPy_Interface1D structure definition----------*/ typedef struct { - PyObject_HEAD - Interface1D *if1D; - bool borrowed; /* true if *if1D is a borrowed object */ + PyObject_HEAD Interface1D *if1D; + bool borrowed; /* true if *if1D is a borrowed object */ } BPy_Interface1D; /*---------------------------Python BPy_Interface1D visible prototypes-----------*/ int Interface1D_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.cpp b/source/blender/freestyle/intern/python/BPy_Iterator.cpp index b8ad6ef82f8..dfeaf9ac328 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.cpp +++ b/source/blender/freestyle/intern/python/BPy_Iterator.cpp @@ -41,214 +41,222 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int Iterator_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&Iterator_Type) < 0) - return -1; - Py_INCREF(&Iterator_Type); - PyModule_AddObject(module, "Iterator", (PyObject *)&Iterator_Type); - - if (PyType_Ready(&AdjacencyIterator_Type) < 0) - return -1; - Py_INCREF(&AdjacencyIterator_Type); - PyModule_AddObject(module, "AdjacencyIterator", (PyObject *)&AdjacencyIterator_Type); - - if (PyType_Ready(&Interface0DIterator_Type) < 0) - return -1; - Py_INCREF(&Interface0DIterator_Type); - PyModule_AddObject(module, "Interface0DIterator", (PyObject *)&Interface0DIterator_Type); - - if (PyType_Ready(&CurvePointIterator_Type) < 0) - return -1; - Py_INCREF(&CurvePointIterator_Type); - PyModule_AddObject(module, "CurvePointIterator", (PyObject *)&CurvePointIterator_Type); - - if (PyType_Ready(&StrokeVertexIterator_Type) < 0) - return -1; - Py_INCREF(&StrokeVertexIterator_Type); - PyModule_AddObject(module, "StrokeVertexIterator", (PyObject *)&StrokeVertexIterator_Type); - - if (PyType_Ready(&SVertexIterator_Type) < 0) - return -1; - Py_INCREF(&SVertexIterator_Type); - PyModule_AddObject(module, "SVertexIterator", (PyObject *)&SVertexIterator_Type); - - if (PyType_Ready(&orientedViewEdgeIterator_Type) < 0) - return -1; - Py_INCREF(&orientedViewEdgeIterator_Type); - PyModule_AddObject(module, "orientedViewEdgeIterator", (PyObject *)&orientedViewEdgeIterator_Type); - - if (PyType_Ready(&ViewEdgeIterator_Type) < 0) - return -1; - Py_INCREF(&ViewEdgeIterator_Type); - PyModule_AddObject(module, "ViewEdgeIterator", (PyObject *)&ViewEdgeIterator_Type); - - if (PyType_Ready(&ChainingIterator_Type) < 0) - return -1; - Py_INCREF(&ChainingIterator_Type); - PyModule_AddObject(module, "ChainingIterator", (PyObject *)&ChainingIterator_Type); - - if (PyType_Ready(&ChainPredicateIterator_Type) < 0) - return -1; - Py_INCREF(&ChainPredicateIterator_Type); - PyModule_AddObject(module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type); - - if (PyType_Ready(&ChainSilhouetteIterator_Type) < 0) - return -1; - Py_INCREF(&ChainSilhouetteIterator_Type); - PyModule_AddObject(module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&Iterator_Type) < 0) + return -1; + Py_INCREF(&Iterator_Type); + PyModule_AddObject(module, "Iterator", (PyObject *)&Iterator_Type); + + if (PyType_Ready(&AdjacencyIterator_Type) < 0) + return -1; + Py_INCREF(&AdjacencyIterator_Type); + PyModule_AddObject(module, "AdjacencyIterator", (PyObject *)&AdjacencyIterator_Type); + + if (PyType_Ready(&Interface0DIterator_Type) < 0) + return -1; + Py_INCREF(&Interface0DIterator_Type); + PyModule_AddObject(module, "Interface0DIterator", (PyObject *)&Interface0DIterator_Type); + + if (PyType_Ready(&CurvePointIterator_Type) < 0) + return -1; + Py_INCREF(&CurvePointIterator_Type); + PyModule_AddObject(module, "CurvePointIterator", (PyObject *)&CurvePointIterator_Type); + + if (PyType_Ready(&StrokeVertexIterator_Type) < 0) + return -1; + Py_INCREF(&StrokeVertexIterator_Type); + PyModule_AddObject(module, "StrokeVertexIterator", (PyObject *)&StrokeVertexIterator_Type); + + if (PyType_Ready(&SVertexIterator_Type) < 0) + return -1; + Py_INCREF(&SVertexIterator_Type); + PyModule_AddObject(module, "SVertexIterator", (PyObject *)&SVertexIterator_Type); + + if (PyType_Ready(&orientedViewEdgeIterator_Type) < 0) + return -1; + Py_INCREF(&orientedViewEdgeIterator_Type); + PyModule_AddObject( + module, "orientedViewEdgeIterator", (PyObject *)&orientedViewEdgeIterator_Type); + + if (PyType_Ready(&ViewEdgeIterator_Type) < 0) + return -1; + Py_INCREF(&ViewEdgeIterator_Type); + PyModule_AddObject(module, "ViewEdgeIterator", (PyObject *)&ViewEdgeIterator_Type); + + if (PyType_Ready(&ChainingIterator_Type) < 0) + return -1; + Py_INCREF(&ChainingIterator_Type); + PyModule_AddObject(module, "ChainingIterator", (PyObject *)&ChainingIterator_Type); + + if (PyType_Ready(&ChainPredicateIterator_Type) < 0) + return -1; + Py_INCREF(&ChainPredicateIterator_Type); + PyModule_AddObject(module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type); + + if (PyType_Ready(&ChainSilhouetteIterator_Type) < 0) + return -1; + Py_INCREF(&ChainSilhouetteIterator_Type); + PyModule_AddObject(module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Iterator_doc, -"Base class to define iterators.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Base class to define iterators.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); static int Iterator_init(BPy_Iterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->it = new Iterator(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->it = new Iterator(); + return 0; } static void Iterator_dealloc(BPy_Iterator *self) { - if (self->it) - delete self->it; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->it) + delete self->it; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *Iterator_repr(BPy_Iterator *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->it); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->it); } PyDoc_STRVAR(Iterator_increment_doc, -".. method:: increment()\n" -"\n" -" Makes the iterator point the next element."); + ".. method:: increment()\n" + "\n" + " Makes the iterator point the next element."); static PyObject *Iterator_increment(BPy_Iterator *self) { - if (self->it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); - return NULL; - } - self->it->increment(); - Py_RETURN_NONE; + if (self->it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); + return NULL; + } + self->it->increment(); + Py_RETURN_NONE; } PyDoc_STRVAR(Iterator_decrement_doc, -".. method:: decrement()\n" -"\n" -" Makes the iterator point the previous element."); + ".. method:: decrement()\n" + "\n" + " Makes the iterator point the previous element."); static PyObject *Iterator_decrement(BPy_Iterator *self) { - if (self->it->isBegin()) { - PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); - return NULL; - } - self->it->decrement(); - Py_RETURN_NONE; + if (self->it->isBegin()) { + PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); + return NULL; + } + self->it->decrement(); + Py_RETURN_NONE; } static PyMethodDef BPy_Iterator_methods[] = { - {"increment", (PyCFunction) Iterator_increment, METH_NOARGS, Iterator_increment_doc}, - {"decrement", (PyCFunction) Iterator_decrement, METH_NOARGS, Iterator_decrement_doc}, - {NULL, NULL, 0, NULL}, + {"increment", (PyCFunction)Iterator_increment, METH_NOARGS, Iterator_increment_doc}, + {"decrement", (PyCFunction)Iterator_decrement, METH_NOARGS, Iterator_decrement_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------Iterator get/setters ----------------------------*/ PyDoc_STRVAR(Iterator_name_doc, -"The string of the name of this iterator.\n" -"\n" -":type: str"); + "The string of the name of this iterator.\n" + "\n" + ":type: str"); static PyObject *Iterator_name_get(BPy_Iterator *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } PyDoc_STRVAR(Iterator_is_begin_doc, -"True if the interator points the first element.\n" -"\n" -":type: bool"); + "True if the interator points the first element.\n" + "\n" + ":type: bool"); static PyObject *Iterator_is_begin_get(BPy_Iterator *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->it->isBegin()); + return PyBool_from_bool(self->it->isBegin()); } PyDoc_STRVAR(Iterator_is_end_doc, -"True if the interator points the last element.\n" -"\n" -":type: bool"); + "True if the interator points the last element.\n" + "\n" + ":type: bool"); static PyObject *Iterator_is_end_get(BPy_Iterator *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->it->isEnd()); + return PyBool_from_bool(self->it->isEnd()); } static PyGetSetDef BPy_Iterator_getseters[] = { - {(char *)"name", (getter)Iterator_name_get, (setter)NULL, (char *)Iterator_name_doc, NULL}, - {(char *)"is_begin", (getter)Iterator_is_begin_get, (setter)NULL, (char *)Iterator_is_begin_doc, NULL}, - {(char *)"is_end", (getter)Iterator_is_end_get, (setter)NULL, (char *)Iterator_is_end_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", (getter)Iterator_name_get, (setter)NULL, (char *)Iterator_name_doc, NULL}, + {(char *)"is_begin", + (getter)Iterator_is_begin_get, + (setter)NULL, + (char *)Iterator_is_begin_doc, + NULL}, + {(char *)"is_end", + (getter)Iterator_is_end_get, + (setter)NULL, + (char *)Iterator_is_end_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Iterator type definition ------------------------------*/ PyTypeObject Iterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Iterator", /* tp_name */ - sizeof(BPy_Iterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Iterator_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)Iterator_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Iterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Iterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_Iterator_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Iterator_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Iterator", /* tp_name */ + sizeof(BPy_Iterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Iterator_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)Iterator_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Iterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Iterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_Iterator_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Iterator_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.h b/source/blender/freestyle/intern/python/BPy_Iterator.h index 2648bfa4f13..f9f80c5f1db 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.h +++ b/source/blender/freestyle/intern/python/BPy_Iterator.h @@ -41,15 +41,13 @@ extern PyTypeObject Iterator_Type; /*---------------------------Python BPy_Iterator structure definition----------*/ typedef struct { - PyObject_HEAD - Iterator *it; + PyObject_HEAD Iterator *it; } BPy_Iterator; /*---------------------------Python BPy_Iterator visible prototypes-----------*/ int Iterator_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/BPy_MediumType.cpp b/source/blender/freestyle/intern/python/BPy_MediumType.cpp index 4d73bdede67..b29c4e8057a 100644 --- a/source/blender/freestyle/intern/python/BPy_MediumType.cpp +++ b/source/blender/freestyle/intern/python/BPy_MediumType.cpp @@ -31,84 +31,80 @@ extern "C" { /*-----------------------BPy_MediumType type definition ------------------------------*/ PyDoc_STRVAR(MediumType_doc, -"Class hierarchy: int > :class:`MediumType`\n" -"\n" -"The different blending modes available to similate the interaction\n" -"media-medium:\n" -"\n" -"* Stroke.DRY_MEDIUM: To simulate a dry medium such as Pencil or Charcoal.\n" -"* Stroke.HUMID_MEDIUM: To simulate ink painting (color subtraction blending).\n" -"* Stroke.OPAQUE_MEDIUM: To simulate an opaque medium (oil, spray...)."); + "Class hierarchy: int > :class:`MediumType`\n" + "\n" + "The different blending modes available to similate the interaction\n" + "media-medium:\n" + "\n" + "* Stroke.DRY_MEDIUM: To simulate a dry medium such as Pencil or Charcoal.\n" + "* Stroke.HUMID_MEDIUM: To simulate ink painting (color subtraction blending).\n" + "* Stroke.OPAQUE_MEDIUM: To simulate an opaque medium (oil, spray...)."); PyTypeObject MediumType_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "MediumType", /* tp_name */ - sizeof(PyLongObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - MediumType_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &PyLong_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "MediumType", /* tp_name */ + sizeof(PyLongObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + MediumType_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PyLong_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /*-----------------------BPy_IntegrationType instance definitions -------------------------*/ PyLongObject _BPy_MediumType_DRY_MEDIUM = { - PyVarObject_HEAD_INIT(&MediumType_Type, 1) - { Stroke::DRY_MEDIUM }, + PyVarObject_HEAD_INIT(&MediumType_Type, 1){Stroke::DRY_MEDIUM}, }; PyLongObject _BPy_MediumType_HUMID_MEDIUM = { - PyVarObject_HEAD_INIT(&MediumType_Type, 1) - { Stroke::HUMID_MEDIUM }, + PyVarObject_HEAD_INIT(&MediumType_Type, 1){Stroke::HUMID_MEDIUM}, }; PyLongObject _BPy_MediumType_OPAQUE_MEDIUM = { - PyVarObject_HEAD_INIT(&MediumType_Type, 1) - { Stroke::OPAQUE_MEDIUM }, + PyVarObject_HEAD_INIT(&MediumType_Type, 1){Stroke::OPAQUE_MEDIUM}, }; //-------------------MODULE INITIALIZATION-------------------------------- int MediumType_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&MediumType_Type) < 0) - return -1; - Py_INCREF(&MediumType_Type); - PyModule_AddObject(module, "MediumType", (PyObject *)&MediumType_Type); + if (PyType_Ready(&MediumType_Type) < 0) + return -1; + Py_INCREF(&MediumType_Type); + PyModule_AddObject(module, "MediumType", (PyObject *)&MediumType_Type); - return 0; + return 0; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_MediumType.h b/source/blender/freestyle/intern/python/BPy_MediumType.h index 062c56f2887..5c91890c249 100644 --- a/source/blender/freestyle/intern/python/BPy_MediumType.h +++ b/source/blender/freestyle/intern/python/BPy_MediumType.h @@ -41,7 +41,7 @@ extern PyTypeObject MediumType_Type; /*---------------------------Python BPy_MediumType structure definition----------*/ typedef struct { - PyLongObject i; + PyLongObject i; } BPy_MediumType; /*---------------------------Python BPy_MediumType visible prototypes-----------*/ @@ -53,9 +53,9 @@ extern PyLongObject _BPy_MediumType_DRY_MEDIUM; extern PyLongObject _BPy_MediumType_HUMID_MEDIUM; extern PyLongObject _BPy_MediumType_OPAQUE_MEDIUM; // public constants -#define BPy_MediumType_DRY_MEDIUM ((PyObject *)&_BPy_MediumType_DRY_MEDIUM) -#define BPy_MediumType_HUMID_MEDIUM ((PyObject *)&_BPy_MediumType_HUMID_MEDIUM) -#define BPy_MediumType_OPAQUE_MEDIUM ((PyObject *)&_BPy_MediumType_OPAQUE_MEDIUM) +#define BPy_MediumType_DRY_MEDIUM ((PyObject *)&_BPy_MediumType_DRY_MEDIUM) +#define BPy_MediumType_HUMID_MEDIUM ((PyObject *)&_BPy_MediumType_HUMID_MEDIUM) +#define BPy_MediumType_OPAQUE_MEDIUM ((PyObject *)&_BPy_MediumType_OPAQUE_MEDIUM) /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Nature.cpp b/source/blender/freestyle/intern/python/BPy_Nature.cpp index 2bfec05cbe5..daefe796ff9 100644 --- a/source/blender/freestyle/intern/python/BPy_Nature.cpp +++ b/source/blender/freestyle/intern/python/BPy_Nature.cpp @@ -35,281 +35,242 @@ static PyObject *BPy_Nature_or(PyObject *a, PyObject *b); /*-----------------------BPy_Nature number method definitions --------------------*/ static PyNumberMethods nature_as_number = { - 0, /* binaryfunc nb_add */ - 0, /* binaryfunc nb_subtract */ - 0, /* binaryfunc nb_multiply */ - 0, /* binaryfunc nb_remainder */ - 0, /* binaryfunc nb_divmod */ - 0, /* ternaryfunc nb_power */ - 0, /* unaryfunc nb_negative */ - 0, /* unaryfunc nb_positive */ - 0, /* unaryfunc nb_absolute */ - 0, /* inquiry nb_bool */ - 0, /* unaryfunc nb_invert */ - 0, /* binaryfunc nb_lshift */ - 0, /* binaryfunc nb_rshift */ - (binaryfunc)BPy_Nature_and, /* binaryfunc nb_and */ - (binaryfunc)BPy_Nature_xor, /* binaryfunc nb_xor */ - (binaryfunc)BPy_Nature_or, /* binaryfunc nb_or */ - 0, /* unaryfunc nb_int */ - 0, /* void *nb_reserved */ - 0, /* unaryfunc nb_float */ - 0, /* binaryfunc nb_inplace_add */ - 0, /* binaryfunc nb_inplace_subtract */ - 0, /* binaryfunc nb_inplace_multiply */ - 0, /* binaryfunc nb_inplace_remainder */ - 0, /* ternaryfunc nb_inplace_power */ - 0, /* binaryfunc nb_inplace_lshift */ - 0, /* binaryfunc nb_inplace_rshift */ - 0, /* binaryfunc nb_inplace_and */ - 0, /* binaryfunc nb_inplace_xor */ - 0, /* binaryfunc nb_inplace_or */ - 0, /* binaryfunc nb_floor_divide */ - 0, /* binaryfunc nb_true_divide */ - 0, /* binaryfunc nb_inplace_floor_divide */ - 0, /* binaryfunc nb_inplace_true_divide */ - 0, /* unaryfunc nb_index */ + 0, /* binaryfunc nb_add */ + 0, /* binaryfunc nb_subtract */ + 0, /* binaryfunc nb_multiply */ + 0, /* binaryfunc nb_remainder */ + 0, /* binaryfunc nb_divmod */ + 0, /* ternaryfunc nb_power */ + 0, /* unaryfunc nb_negative */ + 0, /* unaryfunc nb_positive */ + 0, /* unaryfunc nb_absolute */ + 0, /* inquiry nb_bool */ + 0, /* unaryfunc nb_invert */ + 0, /* binaryfunc nb_lshift */ + 0, /* binaryfunc nb_rshift */ + (binaryfunc)BPy_Nature_and, /* binaryfunc nb_and */ + (binaryfunc)BPy_Nature_xor, /* binaryfunc nb_xor */ + (binaryfunc)BPy_Nature_or, /* binaryfunc nb_or */ + 0, /* unaryfunc nb_int */ + 0, /* void *nb_reserved */ + 0, /* unaryfunc nb_float */ + 0, /* binaryfunc nb_inplace_add */ + 0, /* binaryfunc nb_inplace_subtract */ + 0, /* binaryfunc nb_inplace_multiply */ + 0, /* binaryfunc nb_inplace_remainder */ + 0, /* ternaryfunc nb_inplace_power */ + 0, /* binaryfunc nb_inplace_lshift */ + 0, /* binaryfunc nb_inplace_rshift */ + 0, /* binaryfunc nb_inplace_and */ + 0, /* binaryfunc nb_inplace_xor */ + 0, /* binaryfunc nb_inplace_or */ + 0, /* binaryfunc nb_floor_divide */ + 0, /* binaryfunc nb_true_divide */ + 0, /* binaryfunc nb_inplace_floor_divide */ + 0, /* binaryfunc nb_inplace_true_divide */ + 0, /* unaryfunc nb_index */ }; /*-----------------------BPy_Nature docstring ------------------------------------*/ PyDoc_STRVAR(Nature_doc, -"Class hierarchy: int > :class:`Nature`\n" -"\n" -"Different possible natures of 0D and 1D elements of the ViewMap.\n" -"\n" -"Vertex natures:\n" -"\n" -"* Nature.POINT: True for any 0D element.\n" -"* Nature.S_VERTEX: True for SVertex.\n" -"* Nature.VIEW_VERTEX: True for ViewVertex.\n" -"* Nature.NON_T_VERTEX: True for NonTVertex.\n" -"* Nature.T_VERTEX: True for TVertex.\n" -"* Nature.CUSP: True for CUSP.\n" -"\n" -"Edge natures:\n" -"\n" -"* Nature.NO_FEATURE: True for non feature edges (always false for 1D\n" -" elements of the ViewMap).\n" -"* Nature.SILHOUETTE: True for silhouettes.\n" -"* Nature.BORDER: True for borders.\n" -"* Nature.CREASE: True for creases.\n" -"* Nature.RIDGE: True for ridges.\n" -"* Nature.VALLEY: True for valleys.\n" -"* Nature.SUGGESTIVE_CONTOUR: True for suggestive contours.\n" -"* Nature.MATERIAL_BOUNDARY: True for edges at material boundaries.\n" -"* Nature.EDGE_MARK: True for edges having user-defined edge marks."); + "Class hierarchy: int > :class:`Nature`\n" + "\n" + "Different possible natures of 0D and 1D elements of the ViewMap.\n" + "\n" + "Vertex natures:\n" + "\n" + "* Nature.POINT: True for any 0D element.\n" + "* Nature.S_VERTEX: True for SVertex.\n" + "* Nature.VIEW_VERTEX: True for ViewVertex.\n" + "* Nature.NON_T_VERTEX: True for NonTVertex.\n" + "* Nature.T_VERTEX: True for TVertex.\n" + "* Nature.CUSP: True for CUSP.\n" + "\n" + "Edge natures:\n" + "\n" + "* Nature.NO_FEATURE: True for non feature edges (always false for 1D\n" + " elements of the ViewMap).\n" + "* Nature.SILHOUETTE: True for silhouettes.\n" + "* Nature.BORDER: True for borders.\n" + "* Nature.CREASE: True for creases.\n" + "* Nature.RIDGE: True for ridges.\n" + "* Nature.VALLEY: True for valleys.\n" + "* Nature.SUGGESTIVE_CONTOUR: True for suggestive contours.\n" + "* Nature.MATERIAL_BOUNDARY: True for edges at material boundaries.\n" + "* Nature.EDGE_MARK: True for edges having user-defined edge marks."); /*-----------------------BPy_Nature type definition ------------------------------*/ PyTypeObject Nature_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Nature", /* tp_name */ - sizeof(PyLongObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - &nature_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - Nature_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &PyLong_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Nature", /* tp_name */ + sizeof(PyLongObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + &nature_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + Nature_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PyLong_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /*-----------------------BPy_Nature instance definitions ----------------------------------*/ -static PyLongObject _Nature_POINT = { - PyVarObject_HEAD_INIT(&Nature_Type, 0) - { Nature::POINT } -}; -static PyLongObject _Nature_S_VERTEX = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::S_VERTEX } -}; +static PyLongObject _Nature_POINT = {PyVarObject_HEAD_INIT(&Nature_Type, 0){Nature::POINT}}; +static PyLongObject _Nature_S_VERTEX = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::S_VERTEX}}; static PyLongObject _Nature_VIEW_VERTEX = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::VIEW_VERTEX } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::VIEW_VERTEX}}; static PyLongObject _Nature_NON_T_VERTEX = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::NON_T_VERTEX } -}; -static PyLongObject _Nature_T_VERTEX = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::T_VERTEX } -}; -static PyLongObject _Nature_CUSP = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::CUSP } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::NON_T_VERTEX}}; +static PyLongObject _Nature_T_VERTEX = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::T_VERTEX}}; +static PyLongObject _Nature_CUSP = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::CUSP}}; static PyLongObject _Nature_NO_FEATURE = { - PyVarObject_HEAD_INIT(&Nature_Type, 0) - { Nature::NO_FEATURE } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 0){Nature::NO_FEATURE}}; static PyLongObject _Nature_SILHOUETTE = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::SILHOUETTE } -}; -static PyLongObject _Nature_BORDER = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::BORDER } -}; -static PyLongObject _Nature_CREASE = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::CREASE } -}; -static PyLongObject _Nature_RIDGE = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::RIDGE } -}; -static PyLongObject _Nature_VALLEY = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::VALLEY } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::SILHOUETTE}}; +static PyLongObject _Nature_BORDER = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::BORDER}}; +static PyLongObject _Nature_CREASE = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::CREASE}}; +static PyLongObject _Nature_RIDGE = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::RIDGE}}; +static PyLongObject _Nature_VALLEY = {PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::VALLEY}}; static PyLongObject _Nature_SUGGESTIVE_CONTOUR = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::SUGGESTIVE_CONTOUR } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::SUGGESTIVE_CONTOUR}}; static PyLongObject _Nature_MATERIAL_BOUNDARY = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::MATERIAL_BOUNDARY } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::MATERIAL_BOUNDARY}}; static PyLongObject _Nature_EDGE_MARK = { - PyVarObject_HEAD_INIT(&Nature_Type, 1) - { Nature::EDGE_MARK } -}; + PyVarObject_HEAD_INIT(&Nature_Type, 1){Nature::EDGE_MARK}}; -#define BPy_Nature_POINT ((PyObject *)&_Nature_POINT) -#define BPy_Nature_S_VERTEX ((PyObject *)&_Nature_S_VERTEX) -#define BPy_Nature_VIEW_VERTEX ((PyObject *)&_Nature_VIEW_VERTEX) -#define BPy_Nature_NON_T_VERTEX ((PyObject *)&_Nature_NON_T_VERTEX) -#define BPy_Nature_T_VERTEX ((PyObject *)&_Nature_T_VERTEX) -#define BPy_Nature_CUSP ((PyObject *)&_Nature_CUSP) -#define BPy_Nature_NO_FEATURE ((PyObject *)&_Nature_NO_FEATURE) -#define BPy_Nature_SILHOUETTE ((PyObject *)&_Nature_SILHOUETTE) -#define BPy_Nature_BORDER ((PyObject *)&_Nature_BORDER) -#define BPy_Nature_CREASE ((PyObject *)&_Nature_CREASE) -#define BPy_Nature_RIDGE ((PyObject *)&_Nature_RIDGE) -#define BPy_Nature_VALLEY ((PyObject *)&_Nature_VALLEY) -#define BPy_Nature_SUGGESTIVE_CONTOUR ((PyObject *)&_Nature_SUGGESTIVE_CONTOUR) -#define BPy_Nature_MATERIAL_BOUNDARY ((PyObject *)&_Nature_MATERIAL_BOUNDARY) -#define BPy_Nature_EDGE_MARK ((PyObject *)&_Nature_EDGE_MARK) +#define BPy_Nature_POINT ((PyObject *)&_Nature_POINT) +#define BPy_Nature_S_VERTEX ((PyObject *)&_Nature_S_VERTEX) +#define BPy_Nature_VIEW_VERTEX ((PyObject *)&_Nature_VIEW_VERTEX) +#define BPy_Nature_NON_T_VERTEX ((PyObject *)&_Nature_NON_T_VERTEX) +#define BPy_Nature_T_VERTEX ((PyObject *)&_Nature_T_VERTEX) +#define BPy_Nature_CUSP ((PyObject *)&_Nature_CUSP) +#define BPy_Nature_NO_FEATURE ((PyObject *)&_Nature_NO_FEATURE) +#define BPy_Nature_SILHOUETTE ((PyObject *)&_Nature_SILHOUETTE) +#define BPy_Nature_BORDER ((PyObject *)&_Nature_BORDER) +#define BPy_Nature_CREASE ((PyObject *)&_Nature_CREASE) +#define BPy_Nature_RIDGE ((PyObject *)&_Nature_RIDGE) +#define BPy_Nature_VALLEY ((PyObject *)&_Nature_VALLEY) +#define BPy_Nature_SUGGESTIVE_CONTOUR ((PyObject *)&_Nature_SUGGESTIVE_CONTOUR) +#define BPy_Nature_MATERIAL_BOUNDARY ((PyObject *)&_Nature_MATERIAL_BOUNDARY) +#define BPy_Nature_EDGE_MARK ((PyObject *)&_Nature_EDGE_MARK) //-------------------MODULE INITIALIZATION-------------------------------- int Nature_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&Nature_Type) < 0) - return -1; - Py_INCREF(&Nature_Type); - PyModule_AddObject(module, "Nature", (PyObject *)&Nature_Type); + if (PyType_Ready(&Nature_Type) < 0) + return -1; + Py_INCREF(&Nature_Type); + PyModule_AddObject(module, "Nature", (PyObject *)&Nature_Type); - // VertexNature - PyDict_SetItemString(Nature_Type.tp_dict, "POINT", BPy_Nature_POINT); - PyDict_SetItemString(Nature_Type.tp_dict, "S_VERTEX", BPy_Nature_S_VERTEX); - PyDict_SetItemString(Nature_Type.tp_dict, "VIEW_VERTEX", BPy_Nature_VIEW_VERTEX); - PyDict_SetItemString(Nature_Type.tp_dict, "NON_T_VERTEX", BPy_Nature_NON_T_VERTEX); - PyDict_SetItemString(Nature_Type.tp_dict, "T_VERTEX", BPy_Nature_T_VERTEX); - PyDict_SetItemString(Nature_Type.tp_dict, "CUSP", BPy_Nature_CUSP); + // VertexNature + PyDict_SetItemString(Nature_Type.tp_dict, "POINT", BPy_Nature_POINT); + PyDict_SetItemString(Nature_Type.tp_dict, "S_VERTEX", BPy_Nature_S_VERTEX); + PyDict_SetItemString(Nature_Type.tp_dict, "VIEW_VERTEX", BPy_Nature_VIEW_VERTEX); + PyDict_SetItemString(Nature_Type.tp_dict, "NON_T_VERTEX", BPy_Nature_NON_T_VERTEX); + PyDict_SetItemString(Nature_Type.tp_dict, "T_VERTEX", BPy_Nature_T_VERTEX); + PyDict_SetItemString(Nature_Type.tp_dict, "CUSP", BPy_Nature_CUSP); - // EdgeNature - PyDict_SetItemString(Nature_Type.tp_dict, "NO_FEATURE", BPy_Nature_NO_FEATURE); - PyDict_SetItemString(Nature_Type.tp_dict, "SILHOUETTE", BPy_Nature_SILHOUETTE); - PyDict_SetItemString(Nature_Type.tp_dict, "BORDER", BPy_Nature_BORDER); - PyDict_SetItemString(Nature_Type.tp_dict, "CREASE", BPy_Nature_CREASE); - PyDict_SetItemString(Nature_Type.tp_dict, "RIDGE", BPy_Nature_RIDGE); - PyDict_SetItemString(Nature_Type.tp_dict, "VALLEY", BPy_Nature_VALLEY); - PyDict_SetItemString(Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", BPy_Nature_SUGGESTIVE_CONTOUR); - PyDict_SetItemString(Nature_Type.tp_dict, "MATERIAL_BOUNDARY", BPy_Nature_MATERIAL_BOUNDARY); - PyDict_SetItemString(Nature_Type.tp_dict, "EDGE_MARK", BPy_Nature_EDGE_MARK); + // EdgeNature + PyDict_SetItemString(Nature_Type.tp_dict, "NO_FEATURE", BPy_Nature_NO_FEATURE); + PyDict_SetItemString(Nature_Type.tp_dict, "SILHOUETTE", BPy_Nature_SILHOUETTE); + PyDict_SetItemString(Nature_Type.tp_dict, "BORDER", BPy_Nature_BORDER); + PyDict_SetItemString(Nature_Type.tp_dict, "CREASE", BPy_Nature_CREASE); + PyDict_SetItemString(Nature_Type.tp_dict, "RIDGE", BPy_Nature_RIDGE); + PyDict_SetItemString(Nature_Type.tp_dict, "VALLEY", BPy_Nature_VALLEY); + PyDict_SetItemString(Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", BPy_Nature_SUGGESTIVE_CONTOUR); + PyDict_SetItemString(Nature_Type.tp_dict, "MATERIAL_BOUNDARY", BPy_Nature_MATERIAL_BOUNDARY); + PyDict_SetItemString(Nature_Type.tp_dict, "EDGE_MARK", BPy_Nature_EDGE_MARK); - return 0; + return 0; } static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b) { - BPy_Nature *result; - long op1, op2, v; + BPy_Nature *result; + long op1, op2, v; - if (!BPy_Nature_Check(a) || !BPy_Nature_Check(b)) { - PyErr_SetString(PyExc_TypeError, "operands must be a Nature object"); - return NULL; - } + if (!BPy_Nature_Check(a) || !BPy_Nature_Check(b)) { + PyErr_SetString(PyExc_TypeError, "operands must be a Nature object"); + return NULL; + } - if ((op1 = PyLong_AsLong(a)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, "operand 1: unexpected Nature value"); - return NULL; - } - if ((op2 = PyLong_AsLong(b)) == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, "operand 2: unexpected Nature value"); - return NULL; - } - switch (op) { - case '&': - v = op1 & op2; - break; - case '^': - v = op1 ^ op2; - break; - case '|': - v = op1 | op2; - break; - default: - PyErr_BadArgument(); - return NULL; - } - if (v == 0) - result = PyObject_NewVar(BPy_Nature, &Nature_Type, 0); - else { - result = PyObject_NewVar(BPy_Nature, &Nature_Type, 1); - if (result) - result->i.ob_digit[0] = v; - } - return (PyObject *)result; + if ((op1 = PyLong_AsLong(a)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_ValueError, "operand 1: unexpected Nature value"); + return NULL; + } + if ((op2 = PyLong_AsLong(b)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_ValueError, "operand 2: unexpected Nature value"); + return NULL; + } + switch (op) { + case '&': + v = op1 & op2; + break; + case '^': + v = op1 ^ op2; + break; + case '|': + v = op1 | op2; + break; + default: + PyErr_BadArgument(); + return NULL; + } + if (v == 0) + result = PyObject_NewVar(BPy_Nature, &Nature_Type, 0); + else { + result = PyObject_NewVar(BPy_Nature, &Nature_Type, 1); + if (result) + result->i.ob_digit[0] = v; + } + return (PyObject *)result; } static PyObject *BPy_Nature_and(PyObject *a, PyObject *b) { - return BPy_Nature_bitwise(a, '&', b); + return BPy_Nature_bitwise(a, '&', b); } static PyObject *BPy_Nature_xor(PyObject *a, PyObject *b) { - return BPy_Nature_bitwise(a, '^', b); + return BPy_Nature_bitwise(a, '^', b); } static PyObject *BPy_Nature_or(PyObject *a, PyObject *b) { - return BPy_Nature_bitwise(a, '|', b); + return BPy_Nature_bitwise(a, '|', b); } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Nature.h b/source/blender/freestyle/intern/python/BPy_Nature.h index 1cdc1a82ca5..8eb33f02488 100644 --- a/source/blender/freestyle/intern/python/BPy_Nature.h +++ b/source/blender/freestyle/intern/python/BPy_Nature.h @@ -41,7 +41,7 @@ extern PyTypeObject Nature_Type; /*---------------------------Python BPy_Nature structure definition----------*/ typedef struct { - PyLongObject i; + PyLongObject i; } BPy_Nature; /*---------------------------Python BPy_Nature visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp index 6bbdcd72052..e2afda63e14 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.cpp +++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp @@ -41,724 +41,817 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int Operators_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&Operators_Type) < 0) - return -1; - Py_INCREF(&Operators_Type); - PyModule_AddObject(module, "Operators", (PyObject *)&Operators_Type); + if (PyType_Ready(&Operators_Type) < 0) + return -1; + Py_INCREF(&Operators_Type); + PyModule_AddObject(module, "Operators", (PyObject *)&Operators_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Operators_doc, -"Class defining the operators used in a style module. There are five\n" -"types of operators: Selection, chaining, splitting, sorting and\n" -"creation. All these operators are user controlled through functors,\n" -"predicates and shaders that are taken as arguments."); + "Class defining the operators used in a style module. There are five\n" + "types of operators: Selection, chaining, splitting, sorting and\n" + "creation. All these operators are user controlled through functors,\n" + "predicates and shaders that are taken as arguments."); static void Operators_dealloc(BPy_Operators *self) { - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free((PyObject *)self); } PyDoc_STRVAR(Operators_select_doc, -".. staticmethod:: select(pred)\n" -"\n" -" Selects the ViewEdges of the ViewMap verifying a specified\n" -" condition.\n" -"\n" -" :arg pred: The predicate expressing this condition.\n" -" :type pred: :class:`UnaryPredicate1D`"); + ".. staticmethod:: select(pred)\n" + "\n" + " Selects the ViewEdges of the ViewMap verifying a specified\n" + " condition.\n" + "\n" + " :arg pred: The predicate expressing this condition.\n" + " :type pred: :class:`UnaryPredicate1D`"); static PyObject *Operators_select(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"pred", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &UnaryPredicate1D_Type, &obj)) - return NULL; - if (!((BPy_UnaryPredicate1D *)obj)->up1D) { - PyErr_SetString(PyExc_TypeError, "Operators.select(): 1st argument: invalid UnaryPredicate1D object"); - return NULL; - } - if (Operators::select(*(((BPy_UnaryPredicate1D *)obj)->up1D)) < 0) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.select() failed"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"pred", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &UnaryPredicate1D_Type, &obj)) + return NULL; + if (!((BPy_UnaryPredicate1D *)obj)->up1D) { + PyErr_SetString(PyExc_TypeError, + "Operators.select(): 1st argument: invalid UnaryPredicate1D object"); + return NULL; + } + if (Operators::select(*(((BPy_UnaryPredicate1D *)obj)->up1D)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.select() failed"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_chain_doc, -".. staticmethod:: chain(it, pred, modifier)\n" -"\n" -" Builds a set of chains from the current set of ViewEdges. Each\n" -" ViewEdge of the current list starts a new chain. The chaining\n" -" operator then iterates over the ViewEdges of the ViewMap using the\n" -" user specified iterator. This operator only iterates using the\n" -" increment operator and is therefore unidirectional.\n" -"\n" -" :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n" -" the chaining rule.\n" -" :type it: :class:`ViewEdgeIterator`\n" -" :arg pred: The predicate on the ViewEdge that expresses the\n" -" stopping condition.\n" -" :type pred: :class:`UnaryPredicate1D`\n" -" :arg modifier: A function that takes a ViewEdge as argument and\n" -" that is used to modify the processed ViewEdge state (the\n" -" timestamp incrementation is a typical illustration of such a\n" -" modifier).\n" -" :type modifier: :class:`UnaryFunction1DVoid`\n" -"\n" -".. staticmethod:: chain(it, pred)\n" -"\n" -" Builds a set of chains from the current set of ViewEdges. Each\n" -" ViewEdge of the current list starts a new chain. The chaining\n" -" operator then iterates over the ViewEdges of the ViewMap using the\n" -" user specified iterator. This operator only iterates using the\n" -" increment operator and is therefore unidirectional. This chaining\n" -" operator is different from the previous one because it doesn't take\n" -" any modifier as argument. Indeed, the time stamp (insuring that a\n" -" ViewEdge is processed one time) is automatically managed in this\n" -" case.\n" -"\n" -" :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n" -" the chaining rule. \n" -" :type it: :class:`ViewEdgeIterator`\n" -" :arg pred: The predicate on the ViewEdge that expresses the\n" -" stopping condition.\n" -" :type pred: :class:`UnaryPredicate1D`"); + ".. staticmethod:: chain(it, pred, modifier)\n" + "\n" + " Builds a set of chains from the current set of ViewEdges. Each\n" + " ViewEdge of the current list starts a new chain. The chaining\n" + " operator then iterates over the ViewEdges of the ViewMap using the\n" + " user specified iterator. This operator only iterates using the\n" + " increment operator and is therefore unidirectional.\n" + "\n" + " :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n" + " the chaining rule.\n" + " :type it: :class:`ViewEdgeIterator`\n" + " :arg pred: The predicate on the ViewEdge that expresses the\n" + " stopping condition.\n" + " :type pred: :class:`UnaryPredicate1D`\n" + " :arg modifier: A function that takes a ViewEdge as argument and\n" + " that is used to modify the processed ViewEdge state (the\n" + " timestamp incrementation is a typical illustration of such a\n" + " modifier).\n" + " :type modifier: :class:`UnaryFunction1DVoid`\n" + "\n" + ".. staticmethod:: chain(it, pred)\n" + "\n" + " Builds a set of chains from the current set of ViewEdges. Each\n" + " ViewEdge of the current list starts a new chain. The chaining\n" + " operator then iterates over the ViewEdges of the ViewMap using the\n" + " user specified iterator. This operator only iterates using the\n" + " increment operator and is therefore unidirectional. This chaining\n" + " operator is different from the previous one because it doesn't take\n" + " any modifier as argument. Indeed, the time stamp (insuring that a\n" + " ViewEdge is processed one time) is automatically managed in this\n" + " case.\n" + "\n" + " :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n" + " the chaining rule. \n" + " :type it: :class:`ViewEdgeIterator`\n" + " :arg pred: The predicate on the ViewEdge that expresses the\n" + " stopping condition.\n" + " :type pred: :class:`UnaryPredicate1D`"); static PyObject *Operators_chain(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"it", "pred", "modifier", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|O!", (char **)kwlist, - &ChainingIterator_Type, &obj1, - &UnaryPredicate1D_Type, &obj2, - &UnaryFunction1DVoid_Type, &obj3)) - { - return NULL; - } - if (!((BPy_ChainingIterator *)obj1)->c_it) { - PyErr_SetString(PyExc_TypeError, "Operators.chain(): 1st argument: invalid ChainingIterator object"); - return NULL; - } - if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { - PyErr_SetString(PyExc_TypeError, "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object"); - return NULL; - } - if (!obj3) { - if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it), - *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed"); - return NULL; - } - } - else { - if (!((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void) { - PyErr_SetString(PyExc_TypeError, "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object"); - return NULL; - } - if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it), - *(((BPy_UnaryPredicate1D *)obj2)->up1D), - *(((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void)) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed"); - return NULL; - } - } - Py_RETURN_NONE; + static const char *kwlist[] = {"it", "pred", "modifier", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!|O!", + (char **)kwlist, + &ChainingIterator_Type, + &obj1, + &UnaryPredicate1D_Type, + &obj2, + &UnaryFunction1DVoid_Type, + &obj3)) { + return NULL; + } + if (!((BPy_ChainingIterator *)obj1)->c_it) { + PyErr_SetString(PyExc_TypeError, + "Operators.chain(): 1st argument: invalid ChainingIterator object"); + return NULL; + } + if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { + PyErr_SetString(PyExc_TypeError, + "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object"); + return NULL; + } + if (!obj3) { + if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it), + *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed"); + return NULL; + } + } + else { + if (!((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void) { + PyErr_SetString(PyExc_TypeError, + "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object"); + return NULL; + } + if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it), + *(((BPy_UnaryPredicate1D *)obj2)->up1D), + *(((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed"); + return NULL; + } + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_bidirectional_chain_doc, -".. staticmethod:: bidirectional_chain(it, pred)\n" -"\n" -" Builds a set of chains from the current set of ViewEdges. Each\n" -" ViewEdge of the current list potentially starts a new chain. The\n" -" chaining operator then iterates over the ViewEdges of the ViewMap\n" -" using the user specified iterator. This operator iterates both using\n" -" the increment and decrement operators and is therefore bidirectional.\n" -" This operator works with a ChainingIterator which contains the\n" -" chaining rules. It is this last one which can be told to chain only\n" -" edges that belong to the selection or not to process twice a ViewEdge\n" -" during the chaining. Each time a ViewEdge is added to a chain, its\n" -" chaining time stamp is incremented. This allows you to keep track of\n" -" the number of chains to which a ViewEdge belongs to.\n" -"\n" -" :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n" -" contains the chaining rule.\n" -" :type it: :class:`ChainingIterator`\n" -" :arg pred: The predicate on the ViewEdge that expresses the\n" -" stopping condition.\n" -" :type pred: :class:`UnaryPredicate1D`\n" -"\n" -".. staticmethod:: bidirectional_chain(it)\n" -"\n" -" The only difference with the above bidirectional chaining algorithm\n" -" is that we don't need to pass a stopping criterion. This might be\n" -" desirable when the stopping criterion is already contained in the\n" -" iterator definition. Builds a set of chains from the current set of\n" -" ViewEdges. Each ViewEdge of the current list potentially starts a new\n" -" chain. The chaining operator then iterates over the ViewEdges of the\n" -" ViewMap using the user specified iterator. This operator iterates\n" -" both using the increment and decrement operators and is therefore\n" -" bidirectional. This operator works with a ChainingIterator which\n" -" contains the chaining rules. It is this last one which can be told to\n" -" chain only edges that belong to the selection or not to process twice\n" -" a ViewEdge during the chaining. Each time a ViewEdge is added to a\n" -" chain, its chaining time stamp is incremented. This allows you to\n" -" keep track of the number of chains to which a ViewEdge belongs to.\n" -"\n" -" :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n" -" contains the chaining rule.\n" -" :type it: :class:`ChainingIterator`"); - -static PyObject *Operators_bidirectional_chain(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: bidirectional_chain(it, pred)\n" + "\n" + " Builds a set of chains from the current set of ViewEdges. Each\n" + " ViewEdge of the current list potentially starts a new chain. The\n" + " chaining operator then iterates over the ViewEdges of the ViewMap\n" + " using the user specified iterator. This operator iterates both using\n" + " the increment and decrement operators and is therefore bidirectional.\n" + " This operator works with a ChainingIterator which contains the\n" + " chaining rules. It is this last one which can be told to chain only\n" + " edges that belong to the selection or not to process twice a ViewEdge\n" + " during the chaining. Each time a ViewEdge is added to a chain, its\n" + " chaining time stamp is incremented. This allows you to keep track of\n" + " the number of chains to which a ViewEdge belongs to.\n" + "\n" + " :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n" + " contains the chaining rule.\n" + " :type it: :class:`ChainingIterator`\n" + " :arg pred: The predicate on the ViewEdge that expresses the\n" + " stopping condition.\n" + " :type pred: :class:`UnaryPredicate1D`\n" + "\n" + ".. staticmethod:: bidirectional_chain(it)\n" + "\n" + " The only difference with the above bidirectional chaining algorithm\n" + " is that we don't need to pass a stopping criterion. This might be\n" + " desirable when the stopping criterion is already contained in the\n" + " iterator definition. Builds a set of chains from the current set of\n" + " ViewEdges. Each ViewEdge of the current list potentially starts a new\n" + " chain. The chaining operator then iterates over the ViewEdges of the\n" + " ViewMap using the user specified iterator. This operator iterates\n" + " both using the increment and decrement operators and is therefore\n" + " bidirectional. This operator works with a ChainingIterator which\n" + " contains the chaining rules. It is this last one which can be told to\n" + " chain only edges that belong to the selection or not to process twice\n" + " a ViewEdge during the chaining. Each time a ViewEdge is added to a\n" + " chain, its chaining time stamp is incremented. This allows you to\n" + " keep track of the number of chains to which a ViewEdge belongs to.\n" + "\n" + " :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n" + " contains the chaining rule.\n" + " :type it: :class:`ChainingIterator`"); + +static PyObject *Operators_bidirectional_chain(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", "pred", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", (char **)kwlist, - &ChainingIterator_Type, &obj1, &UnaryPredicate1D_Type, &obj2)) - { - return NULL; - } - if (!((BPy_ChainingIterator *)obj1)->c_it) { - PyErr_SetString(PyExc_TypeError, - "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object"); - return NULL; - } - if (!obj2) { - if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it)) < 0) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed"); - return NULL; - } - } - else { - if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { - PyErr_SetString(PyExc_TypeError, - "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object"); - return NULL; - } - if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it), - *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed"); - return NULL; - } - } - Py_RETURN_NONE; + static const char *kwlist[] = {"it", "pred", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!|O!", + (char **)kwlist, + &ChainingIterator_Type, + &obj1, + &UnaryPredicate1D_Type, + &obj2)) { + return NULL; + } + if (!((BPy_ChainingIterator *)obj1)->c_it) { + PyErr_SetString( + PyExc_TypeError, + "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object"); + return NULL; + } + if (!obj2) { + if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed"); + return NULL; + } + } + else { + if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object"); + return NULL; + } + if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it), + *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed"); + return NULL; + } + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_sequential_split_doc, -".. staticmethod:: sequential_split(starting_pred, stopping_pred, sampling=0.0)\n" -"\n" -" Splits each chain of the current set of chains in a sequential way.\n" -" The points of each chain are processed (with a specified sampling)\n" -" sequentially. Each time a user specified starting condition is\n" -" verified, a new chain begins and ends as soon as a user-defined\n" -" stopping predicate is verified. This allows chains overlapping rather\n" -" than chains partitioning. The first point of the initial chain is the\n" -" first point of one of the resulting chains. The splitting ends when\n" -" no more chain can start.\n" -"\n" -" :arg starting_pred: The predicate on a point that expresses the\n" -" starting condition.\n" -" :type starting_pred: :class:`UnaryPredicate0D`\n" -" :arg stopping_pred: The predicate on a point that expresses the\n" -" stopping condition.\n" -" :type stopping_pred: :class:`UnaryPredicate0D`\n" -" :arg sampling: The resolution used to sample the chain for the\n" -" predicates evaluation. (The chain is not actually resampled;\n" -" a virtual point only progresses along the curve using this\n" -" resolution.)\n" -" :type sampling: float\n" -"\n" -".. staticmethod:: sequential_split(pred, sampling=0.0)\n" -"\n" -" Splits each chain of the current set of chains in a sequential way.\n" -" The points of each chain are processed (with a specified sampling)\n" -" sequentially and each time a user specified condition is verified,\n" -" the chain is split into two chains. The resulting set of chains is a\n" -" partition of the initial chain\n" -"\n" -" :arg pred: The predicate on a point that expresses the splitting\n" -" condition.\n" -" :type pred: :class:`UnaryPredicate0D`\n" -" :arg sampling: The resolution used to sample the chain for the\n" -" predicate evaluation. (The chain is not actually resampled; a\n" -" virtual point only progresses along the curve using this\n" -" resolution.)\n" -" :type sampling: float"); - -static PyObject *Operators_sequential_split(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: sequential_split(starting_pred, stopping_pred, sampling=0.0)\n" + "\n" + " Splits each chain of the current set of chains in a sequential way.\n" + " The points of each chain are processed (with a specified sampling)\n" + " sequentially. Each time a user specified starting condition is\n" + " verified, a new chain begins and ends as soon as a user-defined\n" + " stopping predicate is verified. This allows chains overlapping rather\n" + " than chains partitioning. The first point of the initial chain is the\n" + " first point of one of the resulting chains. The splitting ends when\n" + " no more chain can start.\n" + "\n" + " :arg starting_pred: The predicate on a point that expresses the\n" + " starting condition.\n" + " :type starting_pred: :class:`UnaryPredicate0D`\n" + " :arg stopping_pred: The predicate on a point that expresses the\n" + " stopping condition.\n" + " :type stopping_pred: :class:`UnaryPredicate0D`\n" + " :arg sampling: The resolution used to sample the chain for the\n" + " predicates evaluation. (The chain is not actually resampled;\n" + " a virtual point only progresses along the curve using this\n" + " resolution.)\n" + " :type sampling: float\n" + "\n" + ".. staticmethod:: sequential_split(pred, sampling=0.0)\n" + "\n" + " Splits each chain of the current set of chains in a sequential way.\n" + " The points of each chain are processed (with a specified sampling)\n" + " sequentially and each time a user specified condition is verified,\n" + " the chain is split into two chains. The resulting set of chains is a\n" + " partition of the initial chain\n" + "\n" + " :arg pred: The predicate on a point that expresses the splitting\n" + " condition.\n" + " :type pred: :class:`UnaryPredicate0D`\n" + " :arg sampling: The resolution used to sample the chain for the\n" + " predicate evaluation. (The chain is not actually resampled; a\n" + " virtual point only progresses along the curve using this\n" + " resolution.)\n" + " :type sampling: float"); + +static PyObject *Operators_sequential_split(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"starting_pred", "stopping_pred", "sampling", NULL}; - static const char *kwlist_2[] = {"pred", "sampling", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - float f = 0.0f; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|f", (char **)kwlist_1, - &UnaryPredicate0D_Type, &obj1, &UnaryPredicate0D_Type, &obj2, &f)) - { - if (!((BPy_UnaryPredicate0D *)obj1)->up0D) { - PyErr_SetString(PyExc_TypeError, - "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object"); - return NULL; - } - if (!((BPy_UnaryPredicate0D *)obj2)->up0D) { - PyErr_SetString(PyExc_TypeError, - "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object"); - return NULL; - } - if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), - *(((BPy_UnaryPredicate0D *)obj2)->up0D), - f) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed"); - return NULL; - } - } - else if (PyErr_Clear(), (f = 0.0f), - PyArg_ParseTupleAndKeywords(args, kwds, "O!|f", (char **)kwlist_2, - &UnaryPredicate0D_Type, &obj1, &f)) - { - if (!((BPy_UnaryPredicate0D *)obj1)->up0D) { - PyErr_SetString(PyExc_TypeError, - "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object"); - return NULL; - } - if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), f) < 0) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed"); - return NULL; - } - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist_1[] = {"starting_pred", "stopping_pred", "sampling", NULL}; + static const char *kwlist_2[] = {"pred", "sampling", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float f = 0.0f; + + if (PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!|f", + (char **)kwlist_1, + &UnaryPredicate0D_Type, + &obj1, + &UnaryPredicate0D_Type, + &obj2, + &f)) { + if (!((BPy_UnaryPredicate0D *)obj1)->up0D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object"); + return NULL; + } + if (!((BPy_UnaryPredicate0D *)obj2)->up0D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object"); + return NULL; + } + if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), + *(((BPy_UnaryPredicate0D *)obj2)->up0D), + f) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed"); + return NULL; + } + } + else if (PyErr_Clear(), + (f = 0.0f), + PyArg_ParseTupleAndKeywords( + args, kwds, "O!|f", (char **)kwlist_2, &UnaryPredicate0D_Type, &obj1, &f)) { + if (!((BPy_UnaryPredicate0D *)obj1)->up0D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object"); + return NULL; + } + if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), f) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed"); + return NULL; + } + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_recursive_split_doc, -".. staticmethod:: recursive_split(func, pred_1d, sampling=0.0)\n" -"\n" -" Splits the current set of chains in a recursive way. We process the\n" -" points of each chain (with a specified sampling) to find the point\n" -" minimizing a specified function. The chain is split in two at this\n" -" point and the two new chains are processed in the same way. The\n" -" recursivity level is controlled through a predicate 1D that expresses\n" -" a stopping condition on the chain that is about to be processed.\n" -"\n" -" :arg func: The Unary Function evaluated at each point of the chain.\n" -" The splitting point is the point minimizing this function.\n" -" :type func: :class:`UnaryFunction0DDouble`\n" -" :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n" -" condition. This predicate is evaluated for each curve before it\n" -" actually gets split. If pred_1d(chain) is true, the curve won't be\n" -" split anymore.\n" -" :type pred_1d: :class:`UnaryPredicate1D`\n" -" :arg sampling: The resolution used to sample the chain for the\n" -" predicates evaluation. (The chain is not actually resampled, a\n" -" virtual point only progresses along the curve using this\n" -" resolution.)\n" -" :type sampling: float\n" -"\n" -".. staticmethod:: recursive_split(func, pred_0d, pred_1d, sampling=0.0)\n" -"\n" -" Splits the current set of chains in a recursive way. We process the\n" -" points of each chain (with a specified sampling) to find the point\n" -" minimizing a specified function. The chain is split in two at this\n" -" point and the two new chains are processed in the same way. The user\n" -" can specify a 0D predicate to make a first selection on the points\n" -" that can potentially be split. A point that doesn't verify the 0D\n" -" predicate won't be candidate in realizing the min. The recursivity\n" -" level is controlled through a predicate 1D that expresses a stopping\n" -" condition on the chain that is about to be processed.\n" -"\n" -" :arg func: The Unary Function evaluated at each point of the chain.\n" -" The splitting point is the point minimizing this function.\n" -" :type func: :class:`UnaryFunction0DDouble`\n" -" :arg pred_0d: The Unary Predicate 0D used to select the candidate\n" -" points where the split can occur. For example, it is very likely\n" -" that would rather have your chain splitting around its middle\n" -" point than around one of its extremities. A 0D predicate working\n" -" on the curvilinear abscissa allows to add this kind of constraints.\n" -" :type pred_0d: :class:`UnaryPredicate0D`\n" -" :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n" -" condition. This predicate is evaluated for each curve before it\n" -" actually gets split. If pred_1d(chain) is true, the curve won't be\n" -" split anymore.\n" -" :type pred_1d: :class:`UnaryPredicate1D`\n" -" :arg sampling: The resolution used to sample the chain for the\n" -" predicates evaluation. (The chain is not actually resampled; a\n" -" virtual point only progresses along the curve using this\n" -" resolution.)\n" -" :type sampling: float"); - -static PyObject *Operators_recursive_split(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: recursive_split(func, pred_1d, sampling=0.0)\n" + "\n" + " Splits the current set of chains in a recursive way. We process the\n" + " points of each chain (with a specified sampling) to find the point\n" + " minimizing a specified function. The chain is split in two at this\n" + " point and the two new chains are processed in the same way. The\n" + " recursivity level is controlled through a predicate 1D that expresses\n" + " a stopping condition on the chain that is about to be processed.\n" + "\n" + " :arg func: The Unary Function evaluated at each point of the chain.\n" + " The splitting point is the point minimizing this function.\n" + " :type func: :class:`UnaryFunction0DDouble`\n" + " :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n" + " condition. This predicate is evaluated for each curve before it\n" + " actually gets split. If pred_1d(chain) is true, the curve won't be\n" + " split anymore.\n" + " :type pred_1d: :class:`UnaryPredicate1D`\n" + " :arg sampling: The resolution used to sample the chain for the\n" + " predicates evaluation. (The chain is not actually resampled, a\n" + " virtual point only progresses along the curve using this\n" + " resolution.)\n" + " :type sampling: float\n" + "\n" + ".. staticmethod:: recursive_split(func, pred_0d, pred_1d, sampling=0.0)\n" + "\n" + " Splits the current set of chains in a recursive way. We process the\n" + " points of each chain (with a specified sampling) to find the point\n" + " minimizing a specified function. The chain is split in two at this\n" + " point and the two new chains are processed in the same way. The user\n" + " can specify a 0D predicate to make a first selection on the points\n" + " that can potentially be split. A point that doesn't verify the 0D\n" + " predicate won't be candidate in realizing the min. The recursivity\n" + " level is controlled through a predicate 1D that expresses a stopping\n" + " condition on the chain that is about to be processed.\n" + "\n" + " :arg func: The Unary Function evaluated at each point of the chain.\n" + " The splitting point is the point minimizing this function.\n" + " :type func: :class:`UnaryFunction0DDouble`\n" + " :arg pred_0d: The Unary Predicate 0D used to select the candidate\n" + " points where the split can occur. For example, it is very likely\n" + " that would rather have your chain splitting around its middle\n" + " point than around one of its extremities. A 0D predicate working\n" + " on the curvilinear abscissa allows to add this kind of constraints.\n" + " :type pred_0d: :class:`UnaryPredicate0D`\n" + " :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n" + " condition. This predicate is evaluated for each curve before it\n" + " actually gets split. If pred_1d(chain) is true, the curve won't be\n" + " split anymore.\n" + " :type pred_1d: :class:`UnaryPredicate1D`\n" + " :arg sampling: The resolution used to sample the chain for the\n" + " predicates evaluation. (The chain is not actually resampled; a\n" + " virtual point only progresses along the curve using this\n" + " resolution.)\n" + " :type sampling: float"); + +static PyObject *Operators_recursive_split(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"func", "pred_1d", "sampling", NULL}; - static const char *kwlist_2[] = {"func", "pred_0d", "pred_1d", "sampling", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - float f = 0.0f; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|f", (char **)kwlist_1, - &UnaryFunction0DDouble_Type, &obj1, &UnaryPredicate1D_Type, &obj2, &f)) - { - if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) { - PyErr_SetString(PyExc_TypeError, - "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object"); - return NULL; - } - if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { - PyErr_SetString(PyExc_TypeError, - "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object"); - return NULL; - } - if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double), - *(((BPy_UnaryPredicate1D *)obj2)->up1D), - f) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed"); - return NULL; - } - } - else if (PyErr_Clear(), (f = 0.0f), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!|f", (char **)kwlist_2, - &UnaryFunction0DDouble_Type, &obj1, &UnaryPredicate0D_Type, &obj2, - &UnaryPredicate1D_Type, &obj3, &f)) - { - if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) { - PyErr_SetString(PyExc_TypeError, - "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object"); - return NULL; - } - if (!((BPy_UnaryPredicate0D *)obj2)->up0D) { - PyErr_SetString(PyExc_TypeError, - "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object"); - return NULL; - } - if (!((BPy_UnaryPredicate1D *)obj3)->up1D) { - PyErr_SetString(PyExc_TypeError, - "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object"); - return NULL; - } - if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double), - *(((BPy_UnaryPredicate0D *)obj2)->up0D), - *(((BPy_UnaryPredicate1D *)obj3)->up1D), - f) < 0) - { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed"); - return NULL; - } - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist_1[] = {"func", "pred_1d", "sampling", NULL}; + static const char *kwlist_2[] = {"func", "pred_0d", "pred_1d", "sampling", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + float f = 0.0f; + + if (PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!|f", + (char **)kwlist_1, + &UnaryFunction0DDouble_Type, + &obj1, + &UnaryPredicate1D_Type, + &obj2, + &f)) { + if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) { + PyErr_SetString( + PyExc_TypeError, + "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object"); + return NULL; + } + if (!((BPy_UnaryPredicate1D *)obj2)->up1D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object"); + return NULL; + } + if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double), + *(((BPy_UnaryPredicate1D *)obj2)->up1D), + f) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed"); + return NULL; + } + } + else if (PyErr_Clear(), + (f = 0.0f), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!O!|f", + (char **)kwlist_2, + &UnaryFunction0DDouble_Type, + &obj1, + &UnaryPredicate0D_Type, + &obj2, + &UnaryPredicate1D_Type, + &obj3, + &f)) { + if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) { + PyErr_SetString( + PyExc_TypeError, + "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object"); + return NULL; + } + if (!((BPy_UnaryPredicate0D *)obj2)->up0D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object"); + return NULL; + } + if (!((BPy_UnaryPredicate1D *)obj3)->up1D) { + PyErr_SetString( + PyExc_TypeError, + "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object"); + return NULL; + } + if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double), + *(((BPy_UnaryPredicate0D *)obj2)->up0D), + *(((BPy_UnaryPredicate1D *)obj3)->up1D), + f) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed"); + return NULL; + } + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_sort_doc, -".. staticmethod:: sort(pred)\n" -"\n" -" Sorts the current set of chains (or viewedges) according to the\n" -" comparison predicate given as argument.\n" -"\n" -" :arg pred: The binary predicate used for the comparison.\n" -" :type pred: :class:`BinaryPredicate1D`"); + ".. staticmethod:: sort(pred)\n" + "\n" + " Sorts the current set of chains (or viewedges) according to the\n" + " comparison predicate given as argument.\n" + "\n" + " :arg pred: The binary predicate used for the comparison.\n" + " :type pred: :class:`BinaryPredicate1D`"); static PyObject *Operators_sort(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"pred", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &BinaryPredicate1D_Type, &obj)) - return NULL; - if (!((BPy_BinaryPredicate1D *)obj)->bp1D) { - PyErr_SetString(PyExc_TypeError, "Operators.sort(): 1st argument: invalid BinaryPredicate1D object"); - return NULL; - } - if (Operators::sort(*(((BPy_BinaryPredicate1D *)obj)->bp1D)) < 0) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.sort() failed"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"pred", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &BinaryPredicate1D_Type, &obj)) + return NULL; + if (!((BPy_BinaryPredicate1D *)obj)->bp1D) { + PyErr_SetString(PyExc_TypeError, + "Operators.sort(): 1st argument: invalid BinaryPredicate1D object"); + return NULL; + } + if (Operators::sort(*(((BPy_BinaryPredicate1D *)obj)->bp1D)) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.sort() failed"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_create_doc, -".. staticmethod:: create(pred, shaders)\n" -"\n" -" Creates and shades the strokes from the current set of chains. A\n" -" predicate can be specified to make a selection pass on the chains.\n" -"\n" -" :arg pred: The predicate that a chain must verify in order to be\n" -" transform as a stroke.\n" -" :type pred: :class:`UnaryPredicate1D`\n" -" :arg shaders: The list of shaders used to shade the strokes.\n" -" :type shaders: list of :class:`StrokeShader` objects"); + ".. staticmethod:: create(pred, shaders)\n" + "\n" + " Creates and shades the strokes from the current set of chains. A\n" + " predicate can be specified to make a selection pass on the chains.\n" + "\n" + " :arg pred: The predicate that a chain must verify in order to be\n" + " transform as a stroke.\n" + " :type pred: :class:`UnaryPredicate1D`\n" + " :arg shaders: The list of shaders used to shade the strokes.\n" + " :type shaders: list of :class:`StrokeShader` objects"); static PyObject *Operators_create(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"pred", "shaders", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &UnaryPredicate1D_Type, &obj1, &PyList_Type, &obj2)) - { - return NULL; - } - if (!((BPy_UnaryPredicate1D *)obj1)->up1D) { - PyErr_SetString(PyExc_TypeError, "Operators.create(): 1st argument: invalid UnaryPredicate1D object"); - return NULL; - } - vector shaders; - shaders.reserve(PyList_Size(obj2)); - for (int i = 0; i < PyList_Size(obj2); i++) { - PyObject *py_ss = PyList_GET_ITEM(obj2, i); - if (!BPy_StrokeShader_Check(py_ss)) { - PyErr_SetString(PyExc_TypeError, "Operators.create(): 2nd argument must be a list of StrokeShader objects"); - return NULL; - } - StrokeShader *shader = ((BPy_StrokeShader *)py_ss)->ss; - if (!shader) { - stringstream ss; - ss << "Operators.create(): item " << (i + 1) - << " of the shaders list is invalid likely due to missing call of StrokeShader.__init__()"; - PyErr_SetString(PyExc_TypeError, ss.str().c_str()); - return NULL; - } - shaders.push_back(shader); - } - if (Operators::create(*(((BPy_UnaryPredicate1D *)obj1)->up1D), shaders) < 0) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Operators.create() failed"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"pred", "shaders", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist, + &UnaryPredicate1D_Type, + &obj1, + &PyList_Type, + &obj2)) { + return NULL; + } + if (!((BPy_UnaryPredicate1D *)obj1)->up1D) { + PyErr_SetString(PyExc_TypeError, + "Operators.create(): 1st argument: invalid UnaryPredicate1D object"); + return NULL; + } + vector shaders; + shaders.reserve(PyList_Size(obj2)); + for (int i = 0; i < PyList_Size(obj2); i++) { + PyObject *py_ss = PyList_GET_ITEM(obj2, i); + if (!BPy_StrokeShader_Check(py_ss)) { + PyErr_SetString(PyExc_TypeError, + "Operators.create(): 2nd argument must be a list of StrokeShader objects"); + return NULL; + } + StrokeShader *shader = ((BPy_StrokeShader *)py_ss)->ss; + if (!shader) { + stringstream ss; + ss << "Operators.create(): item " << (i + 1) + << " of the shaders list is invalid likely due to missing call of " + "StrokeShader.__init__()"; + PyErr_SetString(PyExc_TypeError, ss.str().c_str()); + return NULL; + } + shaders.push_back(shader); + } + if (Operators::create(*(((BPy_UnaryPredicate1D *)obj1)->up1D), shaders) < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Operators.create() failed"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_reset_doc, -".. staticmethod:: reset(delete_strokes=True)\n" -"\n" -" Resets the line stylization process to the initial state. The results of\n" -" stroke creation are accumulated if **delete_strokes** is set to False.\n" -"\n" -" :arg delete_strokes: Delete the strokes that are currently stored.\n" -" :type delete_strokes: bool\n"); + ".. staticmethod:: reset(delete_strokes=True)\n" + "\n" + " Resets the line stylization process to the initial state. The results of\n" + " stroke creation are accumulated if **delete_strokes** is set to False.\n" + "\n" + " :arg delete_strokes: Delete the strokes that are currently stored.\n" + " :type delete_strokes: bool\n"); static PyObject *Operators_reset(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"delete_strokes", NULL}; - PyObject *obj1 = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &PyBool_Type, &obj1)) { - // true is the default - Operators::reset(obj1 ? bool_from_PyBool(obj1) : true); - } - else { - PyErr_SetString(PyExc_RuntimeError, "Operators.reset() failed"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"delete_strokes", NULL}; + PyObject *obj1 = 0; + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &PyBool_Type, &obj1)) { + // true is the default + Operators::reset(obj1 ? bool_from_PyBool(obj1) : true); + } + else { + PyErr_SetString(PyExc_RuntimeError, "Operators.reset() failed"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Operators_get_viewedge_from_index_doc, -".. staticmethod:: get_viewedge_from_index(i)\n" -"\n" -" Returns the ViewEdge at the index in the current set of ViewEdges.\n" -"\n" -" :arg i: index (0 <= i < Operators.get_view_edges_size()).\n" -" :type i: int\n" -" :return: The ViewEdge object.\n" -" :rtype: :class:`ViewEdge`"); - -static PyObject *Operators_get_viewedge_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: get_viewedge_from_index(i)\n" + "\n" + " Returns the ViewEdge at the index in the current set of ViewEdges.\n" + "\n" + " :arg i: index (0 <= i < Operators.get_view_edges_size()).\n" + " :type i: int\n" + " :return: The ViewEdge object.\n" + " :rtype: :class:`ViewEdge`"); + +static PyObject *Operators_get_viewedge_from_index(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"i", NULL}; - unsigned int i; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) - return NULL; - if (i >= Operators::getViewEdgesSize()) { - PyErr_SetString(PyExc_IndexError, "index out of range"); - return NULL; - } - return BPy_ViewEdge_from_ViewEdge(*(Operators::getViewEdgeFromIndex(i))); + static const char *kwlist[] = {"i", NULL}; + unsigned int i; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) + return NULL; + if (i >= Operators::getViewEdgesSize()) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + return BPy_ViewEdge_from_ViewEdge(*(Operators::getViewEdgeFromIndex(i))); } PyDoc_STRVAR(Operators_get_chain_from_index_doc, -".. staticmethod:: get_chain_from_index(i)\n" -"\n" -" Returns the Chain at the index in the current set of Chains.\n" -"\n" -" :arg i: index (0 <= i < Operators.get_chains_size()).\n" -" :type i: int\n" -" :return: The Chain object.\n" -" :rtype: :class:`Chain`"); - -static PyObject *Operators_get_chain_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: get_chain_from_index(i)\n" + "\n" + " Returns the Chain at the index in the current set of Chains.\n" + "\n" + " :arg i: index (0 <= i < Operators.get_chains_size()).\n" + " :type i: int\n" + " :return: The Chain object.\n" + " :rtype: :class:`Chain`"); + +static PyObject *Operators_get_chain_from_index(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"i", NULL}; - unsigned int i; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) - return NULL; - if (i >= Operators::getChainsSize()) { - PyErr_SetString(PyExc_IndexError, "index out of range"); - return NULL; - } - return BPy_Chain_from_Chain(*(Operators::getChainFromIndex(i))); + static const char *kwlist[] = {"i", NULL}; + unsigned int i; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) + return NULL; + if (i >= Operators::getChainsSize()) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + return BPy_Chain_from_Chain(*(Operators::getChainFromIndex(i))); } PyDoc_STRVAR(Operators_get_stroke_from_index_doc, -".. staticmethod:: get_stroke_from_index(i)\n" -"\n" -" Returns the Stroke at the index in the current set of Strokes.\n" -"\n" -" :arg i: index (0 <= i < Operators.get_strokes_size()).\n" -" :type i: int\n" -" :return: The Stroke object.\n" -" :rtype: :class:`Stroke`"); - -static PyObject *Operators_get_stroke_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) + ".. staticmethod:: get_stroke_from_index(i)\n" + "\n" + " Returns the Stroke at the index in the current set of Strokes.\n" + "\n" + " :arg i: index (0 <= i < Operators.get_strokes_size()).\n" + " :type i: int\n" + " :return: The Stroke object.\n" + " :rtype: :class:`Stroke`"); + +static PyObject *Operators_get_stroke_from_index(BPy_Operators * /*self*/, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"i", NULL}; - unsigned int i; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) - return NULL; - if (i >= Operators::getStrokesSize()) { - PyErr_SetString(PyExc_IndexError, "index out of range"); - return NULL; - } - return BPy_Stroke_from_Stroke(*(Operators::getStrokeFromIndex(i))); + static const char *kwlist[] = {"i", NULL}; + unsigned int i; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) + return NULL; + if (i >= Operators::getStrokesSize()) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + return BPy_Stroke_from_Stroke(*(Operators::getStrokeFromIndex(i))); } PyDoc_STRVAR(Operators_get_view_edges_size_doc, -".. staticmethod:: get_view_edges_size()\n" -"\n" -" Returns the number of ViewEdges.\n" -"\n" -" :return: The number of ViewEdges.\n" -" :rtype: int"); + ".. staticmethod:: get_view_edges_size()\n" + "\n" + " Returns the number of ViewEdges.\n" + "\n" + " :return: The number of ViewEdges.\n" + " :rtype: int"); static PyObject *Operators_get_view_edges_size(BPy_Operators * /*self*/) { - return PyLong_FromLong(Operators::getViewEdgesSize()); + return PyLong_FromLong(Operators::getViewEdgesSize()); } PyDoc_STRVAR(Operators_get_chains_size_doc, -".. staticmethod:: get_chains_size()\n" -"\n" -" Returns the number of Chains.\n" -"\n" -" :return: The number of Chains.\n" -" :rtype: int"); + ".. staticmethod:: get_chains_size()\n" + "\n" + " Returns the number of Chains.\n" + "\n" + " :return: The number of Chains.\n" + " :rtype: int"); static PyObject *Operators_get_chains_size(BPy_Operators * /*self*/) { - return PyLong_FromLong(Operators::getChainsSize()); + return PyLong_FromLong(Operators::getChainsSize()); } PyDoc_STRVAR(Operators_get_strokes_size_doc, -".. staticmethod:: get_strokes_size()\n" -"\n" -" Returns the number of Strokes.\n" -"\n" -" :return: The number of Strokes.\n" -" :rtype: int"); + ".. staticmethod:: get_strokes_size()\n" + "\n" + " Returns the number of Strokes.\n" + "\n" + " :return: The number of Strokes.\n" + " :rtype: int"); static PyObject *Operators_get_strokes_size(BPy_Operators * /*self*/) { - return PyLong_FromLong(Operators::getStrokesSize()); + return PyLong_FromLong(Operators::getStrokesSize()); } /*----------------------Operators instance definitions ----------------------------*/ static PyMethodDef BPy_Operators_methods[] = { - {"select", (PyCFunction) Operators_select, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_select_doc}, - {"chain", (PyCFunction) Operators_chain, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_chain_doc}, - {"bidirectional_chain", (PyCFunction) Operators_bidirectional_chain, METH_VARARGS | METH_KEYWORDS | METH_STATIC, - Operators_bidirectional_chain_doc}, - {"sequential_split", (PyCFunction) Operators_sequential_split, METH_VARARGS | METH_KEYWORDS | METH_STATIC, - Operators_sequential_split_doc}, - {"recursive_split", (PyCFunction) Operators_recursive_split, METH_VARARGS | METH_KEYWORDS | METH_STATIC, - Operators_recursive_split_doc}, - {"sort", (PyCFunction) Operators_sort, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_sort_doc}, - {"create", (PyCFunction) Operators_create, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_create_doc}, - {"reset", (PyCFunction) Operators_reset, METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_reset_doc}, - {"get_viewedge_from_index", (PyCFunction) Operators_get_viewedge_from_index, - METH_VARARGS | METH_KEYWORDS | METH_STATIC, Operators_get_viewedge_from_index_doc}, - {"get_chain_from_index", (PyCFunction) Operators_get_chain_from_index, METH_VARARGS | METH_KEYWORDS | METH_STATIC, - Operators_get_chain_from_index_doc}, - {"get_stroke_from_index", (PyCFunction) Operators_get_stroke_from_index, METH_VARARGS | METH_KEYWORDS | METH_STATIC, - Operators_get_stroke_from_index_doc}, - {"get_view_edges_size", (PyCFunction) Operators_get_view_edges_size, METH_NOARGS | METH_STATIC, - Operators_get_view_edges_size_doc}, - {"get_chains_size", (PyCFunction) Operators_get_chains_size, METH_NOARGS | METH_STATIC, - Operators_get_chains_size_doc}, - {"get_strokes_size", (PyCFunction) Operators_get_strokes_size, METH_NOARGS | METH_STATIC, - Operators_get_strokes_size_doc}, - {NULL, NULL, 0, NULL}, + {"select", + (PyCFunction)Operators_select, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_select_doc}, + {"chain", + (PyCFunction)Operators_chain, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_chain_doc}, + {"bidirectional_chain", + (PyCFunction)Operators_bidirectional_chain, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_bidirectional_chain_doc}, + {"sequential_split", + (PyCFunction)Operators_sequential_split, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_sequential_split_doc}, + {"recursive_split", + (PyCFunction)Operators_recursive_split, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_recursive_split_doc}, + {"sort", + (PyCFunction)Operators_sort, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_sort_doc}, + {"create", + (PyCFunction)Operators_create, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_create_doc}, + {"reset", + (PyCFunction)Operators_reset, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_reset_doc}, + {"get_viewedge_from_index", + (PyCFunction)Operators_get_viewedge_from_index, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_get_viewedge_from_index_doc}, + {"get_chain_from_index", + (PyCFunction)Operators_get_chain_from_index, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_get_chain_from_index_doc}, + {"get_stroke_from_index", + (PyCFunction)Operators_get_stroke_from_index, + METH_VARARGS | METH_KEYWORDS | METH_STATIC, + Operators_get_stroke_from_index_doc}, + {"get_view_edges_size", + (PyCFunction)Operators_get_view_edges_size, + METH_NOARGS | METH_STATIC, + Operators_get_view_edges_size_doc}, + {"get_chains_size", + (PyCFunction)Operators_get_chains_size, + METH_NOARGS | METH_STATIC, + Operators_get_chains_size_doc}, + {"get_strokes_size", + (PyCFunction)Operators_get_strokes_size, + METH_NOARGS | METH_STATIC, + Operators_get_strokes_size_doc}, + {NULL, NULL, 0, NULL}, }; /*-----------------------BPy_Operators type definition ------------------------------*/ PyTypeObject Operators_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Operators", /* tp_name */ - sizeof(BPy_Operators), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Operators_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - Operators_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Operators_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Operators", /* tp_name */ + sizeof(BPy_Operators), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Operators_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + Operators_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Operators_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_Operators.h b/source/blender/freestyle/intern/python/BPy_Operators.h index 7d91edc6373..15797ca742e 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.h +++ b/source/blender/freestyle/intern/python/BPy_Operators.h @@ -41,14 +41,13 @@ extern PyTypeObject Operators_Type; /*---------------------------Python BPy_Operators structure definition----------*/ typedef struct { - PyObject_HEAD + PyObject_HEAD } BPy_Operators; /*---------------------------Python BPy_Operators visible prototypes-----------*/ int Operators_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/BPy_SShape.cpp b/source/blender/freestyle/intern/python/BPy_SShape.cpp index 024eb61736a..f8930a89a38 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_SShape.cpp @@ -35,277 +35,291 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int SShape_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&SShape_Type) < 0) - return -1; - Py_INCREF(&SShape_Type); - PyModule_AddObject(module, "SShape", (PyObject *)&SShape_Type); + if (PyType_Ready(&SShape_Type) < 0) + return -1; + Py_INCREF(&SShape_Type); + PyModule_AddObject(module, "SShape", (PyObject *)&SShape_Type); - return 0; + return 0; } /*----------------------SShape methods ----------------------------*/ PyDoc_STRVAR(SShape_doc, -"Class to define a feature shape. It is the gathering of feature\n" -"elements from an identified input shape.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An SShape object.\n" -" :type brother: :class:`SShape`"); + "Class to define a feature shape. It is the gathering of feature\n" + "elements from an identified input shape.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An SShape object.\n" + " :type brother: :class:`SShape`"); static int SShape_init(BPy_SShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"brother", NULL}; - PyObject *brother = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SShape_Type, &brother)) - return -1; - if (!brother) - self->ss = new SShape(); - else - self->ss = new SShape(*(((BPy_SShape *)brother)->ss)); - self->borrowed = false; - return 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SShape_Type, &brother)) + return -1; + if (!brother) + self->ss = new SShape(); + else + self->ss = new SShape(*(((BPy_SShape *)brother)->ss)); + self->borrowed = false; + return 0; } static void SShape_dealloc(BPy_SShape *self) { - if (self->ss && !self->borrowed) - delete self->ss; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->ss && !self->borrowed) + delete self->ss; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *SShape_repr(BPy_SShape *self) { - return PyUnicode_FromFormat("SShape - address: %p", self->ss); + return PyUnicode_FromFormat("SShape - address: %p", self->ss); } static char SShape_add_edge_doc[] = -".. method:: add_edge(edge)\n" -"\n" -" Adds an FEdge to the list of FEdges.\n" -"\n" -" :arg edge: An FEdge object.\n" -" :type edge: :class:`FEdge`\n"; + ".. method:: add_edge(edge)\n" + "\n" + " Adds an FEdge to the list of FEdges.\n" + "\n" + " :arg edge: An FEdge object.\n" + " :type edge: :class:`FEdge`\n"; static PyObject *SShape_add_edge(BPy_SShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"edge", NULL}; - PyObject *py_fe = 0; + static const char *kwlist[] = {"edge", NULL}; + PyObject *py_fe = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) - return NULL; - self->ss->AddEdge(((BPy_FEdge *)py_fe)->fe); - Py_RETURN_NONE; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) + return NULL; + self->ss->AddEdge(((BPy_FEdge *)py_fe)->fe); + Py_RETURN_NONE; } PyDoc_STRVAR(SShape_add_vertex_doc, -".. method:: add_vertex(vertex)\n" -"\n" -" Adds an SVertex to the list of SVertex of this Shape. The SShape\n" -" attribute of the SVertex is also set to this SShape.\n" -"\n" -" :arg vertex: An SVertex object.\n" -" :type vertex: :class:`SVertex`"); + ".. method:: add_vertex(vertex)\n" + "\n" + " Adds an SVertex to the list of SVertex of this Shape. The SShape\n" + " attribute of the SVertex is also set to this SShape.\n" + "\n" + " :arg vertex: An SVertex object.\n" + " :type vertex: :class:`SVertex`"); static PyObject *SShape_add_vertex(BPy_SShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"edge", NULL}; - PyObject *py_sv = 0; + static const char *kwlist[] = {"edge", NULL}; + PyObject *py_sv = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &SVertex_Type, &py_sv)) - return NULL; - self->ss->AddNewVertex(((BPy_SVertex *)py_sv)->sv); - Py_RETURN_NONE; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &SVertex_Type, &py_sv)) + return NULL; + self->ss->AddNewVertex(((BPy_SVertex *)py_sv)->sv); + Py_RETURN_NONE; } PyDoc_STRVAR(SShape_compute_bbox_doc, -".. method:: compute_bbox()\n" -"\n" -" Compute the bbox of the SShape."); + ".. method:: compute_bbox()\n" + "\n" + " Compute the bbox of the SShape."); static PyObject *SShape_compute_bbox(BPy_SShape *self) { - self->ss->ComputeBBox(); - Py_RETURN_NONE; + self->ss->ComputeBBox(); + Py_RETURN_NONE; } -// const Material & material (unsigned i) const -// const vector< Material > & materials () const -// void SetMaterials (const vector< Material > &iMaterials) +// const Material & material (unsigned i) const +// const vector< Material > & materials () const +// void SetMaterials (const vector< Material > &iMaterials) static PyMethodDef BPy_SShape_methods[] = { - {"add_edge", (PyCFunction)SShape_add_edge, METH_VARARGS | METH_KEYWORDS, SShape_add_edge_doc}, - {"add_vertex", (PyCFunction)SShape_add_vertex, METH_VARARGS | METH_KEYWORDS, SShape_add_vertex_doc}, - {"compute_bbox", (PyCFunction)SShape_compute_bbox, METH_NOARGS, SShape_compute_bbox_doc}, - {NULL, NULL, 0, NULL}, + {"add_edge", (PyCFunction)SShape_add_edge, METH_VARARGS | METH_KEYWORDS, SShape_add_edge_doc}, + {"add_vertex", + (PyCFunction)SShape_add_vertex, + METH_VARARGS | METH_KEYWORDS, + SShape_add_vertex_doc}, + {"compute_bbox", (PyCFunction)SShape_compute_bbox, METH_NOARGS, SShape_compute_bbox_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------SShape get/setters ----------------------------*/ PyDoc_STRVAR(SShape_id_doc, -"The Id of this SShape.\n" -"\n" -":type: :class:`Id`"); + "The Id of this SShape.\n" + "\n" + ":type: :class:`Id`"); static PyObject *SShape_id_get(BPy_SShape *self, void *UNUSED(closure)) { - Id id(self->ss->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->ss->getId()); + return BPy_Id_from_Id(id); // return a copy } static int SShape_id_set(BPy_SShape *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->ss->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->ss->setId(*(((BPy_Id *)value)->id)); + return 0; } PyDoc_STRVAR(SShape_name_doc, -"The name of the SShape.\n" -"\n" -":type: str"); + "The name of the SShape.\n" + "\n" + ":type: str"); static PyObject *SShape_name_get(BPy_SShape *self, void *UNUSED(closure)) { - return PyUnicode_FromString(self->ss->getName().c_str()); + return PyUnicode_FromString(self->ss->getName().c_str()); } static int SShape_name_set(BPy_SShape *self, PyObject *value, void *UNUSED(closure)) { - if (!PyUnicode_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a string"); - return -1; - } - const char *name = _PyUnicode_AsString(value); - self->ss->setName(name); - return 0; + if (!PyUnicode_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a string"); + return -1; + } + const char *name = _PyUnicode_AsString(value); + self->ss->setName(name); + return 0; } PyDoc_STRVAR(SShape_bbox_doc, -"The bounding box of the SShape.\n" -"\n" -":type: :class:`BBox`"); + "The bounding box of the SShape.\n" + "\n" + ":type: :class:`BBox`"); static PyObject *SShape_bbox_get(BPy_SShape *self, void *UNUSED(closure)) { - BBox bb(self->ss->bbox()); - return BPy_BBox_from_BBox(bb); // return a copy + BBox bb(self->ss->bbox()); + return BPy_BBox_from_BBox(bb); // return a copy } static int SShape_bbox_set(BPy_SShape *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_BBox_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a BBox"); - return -1; - } - self->ss->setBBox(*(((BPy_BBox *)value)->bb)); - return 0; + if (!BPy_BBox_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a BBox"); + return -1; + } + self->ss->setBBox(*(((BPy_BBox *)value)->bb)); + return 0; } PyDoc_STRVAR(SShape_vertices_doc, -"The list of vertices constituting this SShape.\n" -"\n" -":type: List of :class:`SVertex` objects"); + "The list of vertices constituting this SShape.\n" + "\n" + ":type: List of :class:`SVertex` objects"); static PyObject *SShape_vertices_get(BPy_SShape *self, void *UNUSED(closure)) { - vector< SVertex * > vertices = self->ss->getVertexList(); - vector< SVertex * >::iterator it; - PyObject *py_vertices = PyList_New(vertices.size()); - unsigned int i = 0; + vector vertices = self->ss->getVertexList(); + vector::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; - for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_SET_ITEM(py_vertices, i++, BPy_SVertex_from_SVertex(*(*it))); - } + for (it = vertices.begin(); it != vertices.end(); it++) { + PyList_SET_ITEM(py_vertices, i++, BPy_SVertex_from_SVertex(*(*it))); + } - return py_vertices; + return py_vertices; } PyDoc_STRVAR(SShape_edges_doc, -"The list of edges constituting this SShape.\n" -"\n" -":type: List of :class:`FEdge` objects"); + "The list of edges constituting this SShape.\n" + "\n" + ":type: List of :class:`FEdge` objects"); static PyObject *SShape_edges_get(BPy_SShape *self, void *UNUSED(closure)) { - vector< FEdge * > edges = self->ss->getEdgeList(); - vector< FEdge * >::iterator it; - PyObject *py_edges = PyList_New(edges.size()); - unsigned int i = 0; + vector edges = self->ss->getEdgeList(); + vector::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; - for (it = edges.begin(); it != edges.end(); it++) { - PyList_SET_ITEM(py_edges, i++, Any_BPy_FEdge_from_FEdge(*(*it))); - } + for (it = edges.begin(); it != edges.end(); it++) { + PyList_SET_ITEM(py_edges, i++, Any_BPy_FEdge_from_FEdge(*(*it))); + } - return py_edges; + return py_edges; } static PyGetSetDef BPy_SShape_getseters[] = { - {(char *)"id", (getter)SShape_id_get, (setter)SShape_id_set, (char *)SShape_id_doc, NULL}, - {(char *)"name", (getter)SShape_name_get, (setter)SShape_name_set, (char *)SShape_name_doc, NULL}, - {(char *)"bbox", (getter)SShape_bbox_get, (setter)SShape_bbox_set, (char *)SShape_bbox_doc, NULL}, - {(char *)"edges", (getter)SShape_edges_get, (setter)NULL, (char *)SShape_edges_doc, NULL}, - {(char *)"vertices", (getter)SShape_vertices_get, (setter)NULL, (char *)SShape_vertices_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"id", (getter)SShape_id_get, (setter)SShape_id_set, (char *)SShape_id_doc, NULL}, + {(char *)"name", + (getter)SShape_name_get, + (setter)SShape_name_set, + (char *)SShape_name_doc, + NULL}, + {(char *)"bbox", + (getter)SShape_bbox_get, + (setter)SShape_bbox_set, + (char *)SShape_bbox_doc, + NULL}, + {(char *)"edges", (getter)SShape_edges_get, (setter)NULL, (char *)SShape_edges_doc, NULL}, + {(char *)"vertices", + (getter)SShape_vertices_get, + (setter)NULL, + (char *)SShape_vertices_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SShape type definition ------------------------------*/ PyTypeObject SShape_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SShape", /* tp_name */ - sizeof(BPy_SShape), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SShape_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)SShape_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SShape_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_SShape_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_SShape_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SShape_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SShape", /* tp_name */ + sizeof(BPy_SShape), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SShape_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)SShape_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SShape_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_SShape_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_SShape_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SShape_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_SShape.h b/source/blender/freestyle/intern/python/BPy_SShape.h index 270c8cb8317..55ef11b9a0b 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.h +++ b/source/blender/freestyle/intern/python/BPy_SShape.h @@ -41,9 +41,8 @@ extern PyTypeObject SShape_Type; /*---------------------------Python BPy_SShape structure definition----------*/ typedef struct { - PyObject_HEAD - SShape *ss; - bool borrowed; /* true if *ss is a borrowed object */ + PyObject_HEAD SShape *ss; + bool borrowed; /* true if *ss is a borrowed object */ } BPy_SShape; /*---------------------------Python BPy_SShape visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index 65d4ab6ce83..03933fe1915 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -31,603 +31,680 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int StrokeAttribute_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&StrokeAttribute_Type) < 0) - return -1; - Py_INCREF(&StrokeAttribute_Type); - PyModule_AddObject(module, "StrokeAttribute", (PyObject *)&StrokeAttribute_Type); + if (PyType_Ready(&StrokeAttribute_Type) < 0) + return -1; + Py_INCREF(&StrokeAttribute_Type); + PyModule_AddObject(module, "StrokeAttribute", (PyObject *)&StrokeAttribute_Type); - StrokeAttribute_mathutils_register_callback(); - return 0; + StrokeAttribute_mathutils_register_callback(); + return 0; } //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(StrokeAttribute_doc, -"Class to define a set of attributes associated with a :class:`StrokeVertex`.\n" -"The attribute set stores the color, alpha and thickness values for a Stroke\n" -"Vertex.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A StrokeAttribute object.\n" -" :type brother: :class:`StrokeAttribute`\n" -"\n" -".. method:: __init__(red, green, blue, alpha, thickness_right, thickness_left)\n" -"\n" -" Build a stroke vertex attribute from a set of parameters.\n" -"\n" -" :arg red: Red component of a stroke color.\n" -" :type red: float\n" -" :arg green: Green component of a stroke color.\n" -" :type green: float\n" -" :arg blue: Blue component of a stroke color.\n" -" :type blue: float\n" -" :arg alpha: Alpha component of a stroke color.\n" -" :type alpha: float\n" -" :arg thickness_right: Stroke thickness on the right.\n" -" :type thickness_right: float\n" -" :arg thickness_left: Stroke thickness on the left.\n" -" :type thickness_left: float\n" -"\n" -".. method:: __init__(attribute1, attribute2, t)\n" -"\n" -" Interpolation constructor. Build a StrokeAttribute from two\n" -" StrokeAttribute objects and an interpolation parameter.\n" -"\n" -" :arg attribute1: The first StrokeAttribute object.\n" -" :type attribute1: :class:`StrokeAttribute`\n" -" :arg attribute2: The second StrokeAttribute object.\n" -" :type attribute2: :class:`StrokeAttribute`\n" -" :arg t: The interpolation parameter (0 <= t <= 1).\n" -" :type t: float\n"); + "Class to define a set of attributes associated with a :class:`StrokeVertex`.\n" + "The attribute set stores the color, alpha and thickness values for a Stroke\n" + "Vertex.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A StrokeAttribute object.\n" + " :type brother: :class:`StrokeAttribute`\n" + "\n" + ".. method:: __init__(red, green, blue, alpha, thickness_right, thickness_left)\n" + "\n" + " Build a stroke vertex attribute from a set of parameters.\n" + "\n" + " :arg red: Red component of a stroke color.\n" + " :type red: float\n" + " :arg green: Green component of a stroke color.\n" + " :type green: float\n" + " :arg blue: Blue component of a stroke color.\n" + " :type blue: float\n" + " :arg alpha: Alpha component of a stroke color.\n" + " :type alpha: float\n" + " :arg thickness_right: Stroke thickness on the right.\n" + " :type thickness_right: float\n" + " :arg thickness_left: Stroke thickness on the left.\n" + " :type thickness_left: float\n" + "\n" + ".. method:: __init__(attribute1, attribute2, t)\n" + "\n" + " Interpolation constructor. Build a StrokeAttribute from two\n" + " StrokeAttribute objects and an interpolation parameter.\n" + "\n" + " :arg attribute1: The first StrokeAttribute object.\n" + " :type attribute1: :class:`StrokeAttribute`\n" + " :arg attribute2: The second StrokeAttribute object.\n" + " :type attribute2: :class:`StrokeAttribute`\n" + " :arg t: The interpolation parameter (0 <= t <= 1).\n" + " :type t: float\n"); static int StrokeAttribute_init(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"attribute1", "attribute2", "t", NULL}; - static const char *kwlist_3[] = {"red", "green", "blue", "alpha", "thickness_right", "thickness_left", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - float red, green, blue, alpha, thickness_right, thickness_left, t; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeAttribute_Type, &obj1)) { - if (!obj1) - self->sa = new StrokeAttribute(); - else - self->sa = new StrokeAttribute(*(((BPy_StrokeAttribute *)obj1)->sa)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, - &StrokeAttribute_Type, &obj1, &StrokeAttribute_Type, &obj2, &t)) - { - self->sa = new StrokeAttribute(*(((BPy_StrokeAttribute *)obj1)->sa), *(((BPy_StrokeAttribute *)obj2)->sa), t); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "ffffff", (char **)kwlist_3, - &red, &green, &blue, &alpha, &thickness_right, &thickness_left)) - { - self->sa = new StrokeAttribute(red, green, blue, alpha, thickness_right, thickness_left); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"attribute1", "attribute2", "t", NULL}; + static const char *kwlist_3[] = { + "red", "green", "blue", "alpha", "thickness_right", "thickness_left", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float red, green, blue, alpha, thickness_right, thickness_left, t; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &StrokeAttribute_Type, &obj1)) { + if (!obj1) + self->sa = new StrokeAttribute(); + else + self->sa = new StrokeAttribute(*(((BPy_StrokeAttribute *)obj1)->sa)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!f", + (char **)kwlist_2, + &StrokeAttribute_Type, + &obj1, + &StrokeAttribute_Type, + &obj2, + &t)) { + self->sa = new StrokeAttribute( + *(((BPy_StrokeAttribute *)obj1)->sa), *(((BPy_StrokeAttribute *)obj2)->sa), t); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "ffffff", + (char **)kwlist_3, + &red, + &green, + &blue, + &alpha, + &thickness_right, + &thickness_left)) { + self->sa = new StrokeAttribute(red, green, blue, alpha, thickness_right, thickness_left); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->borrowed = false; + return 0; } static void StrokeAttribute_dealloc(BPy_StrokeAttribute *self) { - if (self->sa && !self->borrowed) - delete self->sa; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->sa && !self->borrowed) + delete self->sa; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *StrokeAttribute_repr(BPy_StrokeAttribute *self) { - stringstream repr("StrokeAttribute:"); - repr << " r: " << self->sa->getColorR() << " g: " << self->sa->getColorG() << " b: " << self->sa->getColorB() << - " a: " << self->sa->getAlpha() << - " - R: " << self->sa->getThicknessR() << " L: " << self->sa->getThicknessL(); + stringstream repr("StrokeAttribute:"); + repr << " r: " << self->sa->getColorR() << " g: " << self->sa->getColorG() + << " b: " << self->sa->getColorB() << " a: " << self->sa->getAlpha() + << " - R: " << self->sa->getThicknessR() << " L: " << self->sa->getThicknessL(); - return PyUnicode_FromString(repr.str().c_str()); + return PyUnicode_FromString(repr.str().c_str()); } PyDoc_STRVAR(StrokeAttribute_get_attribute_real_doc, -".. method:: get_attribute_real(name)\n" -"\n" -" Returns an attribute of float type.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: The attribute value.\n" -" :rtype: float\n"); - -static PyObject *StrokeAttribute_get_attribute_real(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: get_attribute_real(name)\n" + "\n" + " Returns an attribute of float type.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: The attribute value.\n" + " :rtype: float\n"); + +static PyObject *StrokeAttribute_get_attribute_real(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - double a = self->sa->getAttributeReal(attr); - return PyFloat_FromDouble(a); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + double a = self->sa->getAttributeReal(attr); + return PyFloat_FromDouble(a); } PyDoc_STRVAR(StrokeAttribute_get_attribute_vec2_doc, -".. method:: get_attribute_vec2(name)\n" -"\n" -" Returns an attribute of two-dimensional vector type.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: The attribute value.\n" -" :rtype: :class:`mathutils.Vector`\n"); - -static PyObject *StrokeAttribute_get_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: get_attribute_vec2(name)\n" + "\n" + " Returns an attribute of two-dimensional vector type.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: The attribute value.\n" + " :rtype: :class:`mathutils.Vector`\n"); + +static PyObject *StrokeAttribute_get_attribute_vec2(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - Vec2f a = self->sa->getAttributeVec2f(attr); - return Vector_from_Vec2f(a); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + Vec2f a = self->sa->getAttributeVec2f(attr); + return Vector_from_Vec2f(a); } PyDoc_STRVAR(StrokeAttribute_get_attribute_vec3_doc, -".. method:: get_attribute_vec3(name)\n" -"\n" -" Returns an attribute of three-dimensional vector type.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: The attribute value.\n" -" :rtype: :class:`mathutils.Vector`\n"); - -static PyObject *StrokeAttribute_get_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: get_attribute_vec3(name)\n" + "\n" + " Returns an attribute of three-dimensional vector type.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: The attribute value.\n" + " :rtype: :class:`mathutils.Vector`\n"); + +static PyObject *StrokeAttribute_get_attribute_vec3(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - Vec3f a = self->sa->getAttributeVec3f(attr); - return Vector_from_Vec3f(a); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + Vec3f a = self->sa->getAttributeVec3f(attr); + return Vector_from_Vec3f(a); } PyDoc_STRVAR(StrokeAttribute_has_attribute_real_doc, -".. method:: has_attribute_real(name)\n" -"\n" -" Checks whether the attribute name of float type is available.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: True if the attribute is availbale.\n" -" :rtype: bool\n"); - -static PyObject *StrokeAttribute_has_attribute_real(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: has_attribute_real(name)\n" + "\n" + " Checks whether the attribute name of float type is available.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: True if the attribute is availbale.\n" + " :rtype: bool\n"); + +static PyObject *StrokeAttribute_has_attribute_real(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - return PyBool_from_bool(self->sa->isAttributeAvailableReal(attr)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + return PyBool_from_bool(self->sa->isAttributeAvailableReal(attr)); } PyDoc_STRVAR(StrokeAttribute_has_attribute_vec2_doc, -".. method:: has_attribute_vec2(name)\n" -"\n" -" Checks whether the attribute name of two-dimensional vector type\n" -" is available.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: True if the attribute is availbale.\n" -" :rtype: bool\n"); - -static PyObject *StrokeAttribute_has_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: has_attribute_vec2(name)\n" + "\n" + " Checks whether the attribute name of two-dimensional vector type\n" + " is available.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: True if the attribute is availbale.\n" + " :rtype: bool\n"); + +static PyObject *StrokeAttribute_has_attribute_vec2(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - return PyBool_from_bool(self->sa->isAttributeAvailableVec2f(attr)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + return PyBool_from_bool(self->sa->isAttributeAvailableVec2f(attr)); } PyDoc_STRVAR(StrokeAttribute_has_attribute_vec3_doc, -".. method:: has_attribute_vec3(name)\n" -"\n" -" Checks whether the attribute name of three-dimensional vector\n" -" type is available.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :return: True if the attribute is availbale.\n" -" :rtype: bool\n"); - -static PyObject *StrokeAttribute_has_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: has_attribute_vec3(name)\n" + "\n" + " Checks whether the attribute name of three-dimensional vector\n" + " type is available.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :return: True if the attribute is availbale.\n" + " :rtype: bool\n"); + +static PyObject *StrokeAttribute_has_attribute_vec3(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", NULL}; - char *attr; + static const char *kwlist[] = {"name", NULL}; + char *attr; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) - return NULL; - return PyBool_from_bool(self->sa->isAttributeAvailableVec3f(attr)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &attr)) + return NULL; + return PyBool_from_bool(self->sa->isAttributeAvailableVec3f(attr)); } PyDoc_STRVAR(StrokeAttribute_set_attribute_real_doc, -".. method:: set_attribute_real(name, value)\n" -"\n" -" Adds a user-defined attribute of float type. If there is no\n" -" attribute of the given name, it is added. Otherwise, the new value\n" -" replaces the old one.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :arg value: The attribute value.\n" -" :type value: float\n"); - -static PyObject *StrokeAttribute_set_attribute_real(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: set_attribute_real(name, value)\n" + "\n" + " Adds a user-defined attribute of float type. If there is no\n" + " attribute of the given name, it is added. Otherwise, the new value\n" + " replaces the old one.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :arg value: The attribute value.\n" + " :type value: float\n"); + +static PyObject *StrokeAttribute_set_attribute_real(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", "value", NULL}; - char *s = 0; - double d = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd", (char **)kwlist, &s, &d)) - return NULL; - self->sa->setAttributeReal(s, d); - Py_RETURN_NONE; + static const char *kwlist[] = {"name", "value", NULL}; + char *s = 0; + double d = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sd", (char **)kwlist, &s, &d)) + return NULL; + self->sa->setAttributeReal(s, d); + Py_RETURN_NONE; } PyDoc_STRVAR(StrokeAttribute_set_attribute_vec2_doc, -".. method:: set_attribute_vec2(name, value)\n" -"\n" -" Adds a user-defined attribute of two-dimensional vector type. If\n" -" there is no attribute of the given name, it is added. Otherwise,\n" -" the new value replaces the old one.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :arg value: The attribute value.\n" -" :type value: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n"); - -static PyObject *StrokeAttribute_set_attribute_vec2(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: set_attribute_vec2(name, value)\n" + "\n" + " Adds a user-defined attribute of two-dimensional vector type. If\n" + " there is no attribute of the given name, it is added. Otherwise,\n" + " the new value replaces the old one.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :arg value: The attribute value.\n" + " :type value: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n"); + +static PyObject *StrokeAttribute_set_attribute_vec2(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", "value", NULL}; - char *s; - PyObject *obj = 0; - Vec2f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) - return NULL; - if (!Vec2f_ptr_from_PyObject(obj, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 2 must be a 2D vector (either a list of 2 elements or Vector)"); - return NULL; - } - self->sa->setAttributeVec2f(s, vec); - Py_RETURN_NONE; + static const char *kwlist[] = {"name", "value", NULL}; + char *s; + PyObject *obj = 0; + Vec2f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) + return NULL; + if (!Vec2f_ptr_from_PyObject(obj, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 2 must be a 2D vector (either a list of 2 elements or Vector)"); + return NULL; + } + self->sa->setAttributeVec2f(s, vec); + Py_RETURN_NONE; } PyDoc_STRVAR(StrokeAttribute_set_attribute_vec3_doc, -".. method:: set_attribute_vec3(name, value)\n" -"\n" -" Adds a user-defined attribute of three-dimensional vector type.\n" -" If there is no attribute of the given name, it is added.\n" -" Otherwise, the new value replaces the old one.\n" -"\n" -" :arg name: The name of the attribute.\n" -" :type name: str\n" -" :arg value: The attribute value.\n" -" :type value: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"); - -static PyObject *StrokeAttribute_set_attribute_vec3(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds) + ".. method:: set_attribute_vec3(name, value)\n" + "\n" + " Adds a user-defined attribute of three-dimensional vector type.\n" + " If there is no attribute of the given name, it is added.\n" + " Otherwise, the new value replaces the old one.\n" + "\n" + " :arg name: The name of the attribute.\n" + " :type name: str\n" + " :arg value: The attribute value.\n" + " :type value: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"); + +static PyObject *StrokeAttribute_set_attribute_vec3(BPy_StrokeAttribute *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"name", "value", NULL}; - char *s; - PyObject *obj = 0; - Vec3f vec; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) - return NULL; - if (!Vec3f_ptr_from_PyObject(obj, vec)) { - PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - self->sa->setAttributeVec3f(s, vec); - Py_RETURN_NONE; + static const char *kwlist[] = {"name", "value", NULL}; + char *s; + PyObject *obj = 0; + Vec3f vec; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) + return NULL; + if (!Vec3f_ptr_from_PyObject(obj, vec)) { + PyErr_SetString(PyExc_TypeError, + "argument 2 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; + } + self->sa->setAttributeVec3f(s, vec); + Py_RETURN_NONE; } static PyMethodDef BPy_StrokeAttribute_methods[] = { - {"get_attribute_real", (PyCFunction) StrokeAttribute_get_attribute_real, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_get_attribute_real_doc}, - {"get_attribute_vec2", (PyCFunction) StrokeAttribute_get_attribute_vec2, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_get_attribute_vec2_doc}, - {"get_attribute_vec3", (PyCFunction) StrokeAttribute_get_attribute_vec3, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_get_attribute_vec3_doc}, - {"has_attribute_real", (PyCFunction) StrokeAttribute_has_attribute_real, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_has_attribute_real_doc}, - {"has_attribute_vec2", (PyCFunction) StrokeAttribute_has_attribute_vec2, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_has_attribute_vec2_doc}, - {"has_attribute_vec3", (PyCFunction) StrokeAttribute_has_attribute_vec3, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_has_attribute_vec3_doc}, - {"set_attribute_real", (PyCFunction) StrokeAttribute_set_attribute_real, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_set_attribute_real_doc}, - {"set_attribute_vec2", (PyCFunction) StrokeAttribute_set_attribute_vec2, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_set_attribute_vec2_doc}, - {"set_attribute_vec3", (PyCFunction) StrokeAttribute_set_attribute_vec3, METH_VARARGS | METH_KEYWORDS, - StrokeAttribute_set_attribute_vec3_doc}, - {NULL, NULL, 0, NULL}, + {"get_attribute_real", + (PyCFunction)StrokeAttribute_get_attribute_real, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_get_attribute_real_doc}, + {"get_attribute_vec2", + (PyCFunction)StrokeAttribute_get_attribute_vec2, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_get_attribute_vec2_doc}, + {"get_attribute_vec3", + (PyCFunction)StrokeAttribute_get_attribute_vec3, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_get_attribute_vec3_doc}, + {"has_attribute_real", + (PyCFunction)StrokeAttribute_has_attribute_real, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_has_attribute_real_doc}, + {"has_attribute_vec2", + (PyCFunction)StrokeAttribute_has_attribute_vec2, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_has_attribute_vec2_doc}, + {"has_attribute_vec3", + (PyCFunction)StrokeAttribute_has_attribute_vec3, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_has_attribute_vec3_doc}, + {"set_attribute_real", + (PyCFunction)StrokeAttribute_set_attribute_real, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_set_attribute_real_doc}, + {"set_attribute_vec2", + (PyCFunction)StrokeAttribute_set_attribute_vec2, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_set_attribute_vec2_doc}, + {"set_attribute_vec3", + (PyCFunction)StrokeAttribute_set_attribute_vec3, + METH_VARARGS | METH_KEYWORDS, + StrokeAttribute_set_attribute_vec3_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------mathutils callbacks ----------------------------*/ /* subtype */ -#define MATHUTILS_SUBTYPE_COLOR 1 -#define MATHUTILS_SUBTYPE_THICKNESS 2 +#define MATHUTILS_SUBTYPE_COLOR 1 +#define MATHUTILS_SUBTYPE_THICKNESS 2 static int StrokeAttribute_mathutils_check(BaseMathObject *bmo) { - if (!BPy_StrokeAttribute_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_StrokeAttribute_Check(bmo->cb_user)) + return -1; + return 0; } static int StrokeAttribute_mathutils_get(BaseMathObject *bmo, int subtype) { - BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_COLOR: - bmo->data[0] = self->sa->getColorR(); - bmo->data[1] = self->sa->getColorG(); - bmo->data[2] = self->sa->getColorB(); - break; - case MATHUTILS_SUBTYPE_THICKNESS: - bmo->data[0] = self->sa->getThicknessR(); - bmo->data[1] = self->sa->getThicknessL(); - break; - default: - return -1; - } - return 0; + BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_COLOR: + bmo->data[0] = self->sa->getColorR(); + bmo->data[1] = self->sa->getColorG(); + bmo->data[2] = self->sa->getColorB(); + break; + case MATHUTILS_SUBTYPE_THICKNESS: + bmo->data[0] = self->sa->getThicknessR(); + bmo->data[1] = self->sa->getThicknessL(); + break; + default: + return -1; + } + return 0; } static int StrokeAttribute_mathutils_set(BaseMathObject *bmo, int subtype) { - BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_COLOR: - self->sa->setColor(bmo->data[0], bmo->data[1], bmo->data[2]); - break; - case MATHUTILS_SUBTYPE_THICKNESS: - self->sa->setThickness(bmo->data[0], bmo->data[1]); - break; - default: - return -1; - } - return 0; + BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_COLOR: + self->sa->setColor(bmo->data[0], bmo->data[1], bmo->data[2]); + break; + case MATHUTILS_SUBTYPE_THICKNESS: + self->sa->setThickness(bmo->data[0], bmo->data[1]); + break; + default: + return -1; + } + return 0; } static int StrokeAttribute_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) { - BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_COLOR: - switch (index) { - case 0: bmo->data[0] = self->sa->getColorR(); break; - case 1: bmo->data[1] = self->sa->getColorG(); break; - case 2: bmo->data[2] = self->sa->getColorB(); break; - default: - return -1; - } - break; - case MATHUTILS_SUBTYPE_THICKNESS: - switch (index) { - case 0: bmo->data[0] = self->sa->getThicknessR(); break; - case 1: bmo->data[1] = self->sa->getThicknessL(); break; - default: - return -1; - } - break; - default: - return -1; - } - return 0; + BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_COLOR: + switch (index) { + case 0: + bmo->data[0] = self->sa->getColorR(); + break; + case 1: + bmo->data[1] = self->sa->getColorG(); + break; + case 2: + bmo->data[2] = self->sa->getColorB(); + break; + default: + return -1; + } + break; + case MATHUTILS_SUBTYPE_THICKNESS: + switch (index) { + case 0: + bmo->data[0] = self->sa->getThicknessR(); + break; + case 1: + bmo->data[1] = self->sa->getThicknessL(); + break; + default: + return -1; + } + break; + default: + return -1; + } + return 0; } static int StrokeAttribute_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) { - BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_COLOR: - { - float r = (index == 0) ? bmo->data[0] : self->sa->getColorR(); - float g = (index == 1) ? bmo->data[1] : self->sa->getColorG(); - float b = (index == 2) ? bmo->data[2] : self->sa->getColorB(); - self->sa->setColor(r, g, b); - } - break; - case MATHUTILS_SUBTYPE_THICKNESS: - { - float tr = (index == 0) ? bmo->data[0] : self->sa->getThicknessR(); - float tl = (index == 1) ? bmo->data[1] : self->sa->getThicknessL(); - self->sa->setThickness(tr, tl); - } - break; - default: - return -1; - } - return 0; + BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_COLOR: { + float r = (index == 0) ? bmo->data[0] : self->sa->getColorR(); + float g = (index == 1) ? bmo->data[1] : self->sa->getColorG(); + float b = (index == 2) ? bmo->data[2] : self->sa->getColorB(); + self->sa->setColor(r, g, b); + } break; + case MATHUTILS_SUBTYPE_THICKNESS: { + float tr = (index == 0) ? bmo->data[0] : self->sa->getThicknessR(); + float tl = (index == 1) ? bmo->data[1] : self->sa->getThicknessL(); + self->sa->setThickness(tr, tl); + } break; + default: + return -1; + } + return 0; } static Mathutils_Callback StrokeAttribute_mathutils_cb = { - StrokeAttribute_mathutils_check, - StrokeAttribute_mathutils_get, - StrokeAttribute_mathutils_set, - StrokeAttribute_mathutils_get_index, - StrokeAttribute_mathutils_set_index, + StrokeAttribute_mathutils_check, + StrokeAttribute_mathutils_get, + StrokeAttribute_mathutils_set, + StrokeAttribute_mathutils_get_index, + StrokeAttribute_mathutils_set_index, }; static unsigned char StrokeAttribute_mathutils_cb_index = -1; void StrokeAttribute_mathutils_register_callback() { - StrokeAttribute_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeAttribute_mathutils_cb); + StrokeAttribute_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeAttribute_mathutils_cb); } /*----------------------StrokeAttribute get/setters ----------------------------*/ PyDoc_STRVAR(StrokeAttribute_alpha_doc, -"Alpha component of the stroke color.\n" -"\n" -":type: float"); + "Alpha component of the stroke color.\n" + "\n" + ":type: float"); static PyObject *StrokeAttribute_alpha_get(BPy_StrokeAttribute *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sa->getAlpha()); + return PyFloat_FromDouble(self->sa->getAlpha()); } -static int StrokeAttribute_alpha_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) +static int StrokeAttribute_alpha_set(BPy_StrokeAttribute *self, + PyObject *value, + void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->sa->setAlpha(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && + PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->sa->setAlpha(scalar); + return 0; } PyDoc_STRVAR(StrokeAttribute_color_doc, -"RGB components of the stroke color.\n" -"\n" -":type: :class:`mathutils.Color`"); + "RGB components of the stroke color.\n" + "\n" + ":type: :class:`mathutils.Color`"); static PyObject *StrokeAttribute_color_get(BPy_StrokeAttribute *self, void *UNUSED(closure)) { - return Color_CreatePyObject_cb((PyObject *)self, StrokeAttribute_mathutils_cb_index, MATHUTILS_SUBTYPE_COLOR); + return Color_CreatePyObject_cb( + (PyObject *)self, StrokeAttribute_mathutils_cb_index, MATHUTILS_SUBTYPE_COLOR); } -static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) +static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, + PyObject *value, + void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - self->sa->setColor(v[0], v[1], v[2]); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + self->sa->setColor(v[0], v[1], v[2]); + return 0; } PyDoc_STRVAR(StrokeAttribute_thickness_doc, -"Right and left components of the stroke thickness.\n" -"The right (left) component is the thickness on the right (left) of the vertex\n" -"when following the stroke.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "Right and left components of the stroke thickness.\n" + "The right (left) component is the thickness on the right (left) of the vertex\n" + "when following the stroke.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *StrokeAttribute_thickness_get(BPy_StrokeAttribute *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 2, StrokeAttribute_mathutils_cb_index, - MATHUTILS_SUBTYPE_THICKNESS); + return Vector_CreatePyObject_cb( + (PyObject *)self, 2, StrokeAttribute_mathutils_cb_index, MATHUTILS_SUBTYPE_THICKNESS); } -static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) +static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, + PyObject *value, + void *UNUSED(closure)) { - float v[2]; - if (mathutils_array_parse(v, 2, 2, value, - "value must be a 2-dimensional vector") == -1) - { - return -1; - } - self->sa->setThickness(v[0], v[1]); - return 0; + float v[2]; + if (mathutils_array_parse(v, 2, 2, value, "value must be a 2-dimensional vector") == -1) { + return -1; + } + self->sa->setThickness(v[0], v[1]); + return 0; } PyDoc_STRVAR(StrokeAttribute_visible_doc, -"The visibility flag. True if the StrokeVertex is visible.\n" -"\n" -":type: bool"); + "The visibility flag. True if the StrokeVertex is visible.\n" + "\n" + ":type: bool"); static PyObject *StrokeAttribute_visible_get(BPy_StrokeAttribute *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->sa->isVisible()); + return PyBool_from_bool(self->sa->isVisible()); } -static int StrokeAttribute_visible_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure)) +static int StrokeAttribute_visible_set(BPy_StrokeAttribute *self, + PyObject *value, + void *UNUSED(closure)) { - if (!PyBool_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be boolean"); - return -1; - } - self->sa->setVisible(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be boolean"); + return -1; + } + self->sa->setVisible(bool_from_PyBool(value)); + return 0; } static PyGetSetDef BPy_StrokeAttribute_getseters[] = { - {(char *)"alpha", (getter)StrokeAttribute_alpha_get, (setter)StrokeAttribute_alpha_set, - (char *)StrokeAttribute_alpha_doc, NULL}, - {(char *)"color", (getter)StrokeAttribute_color_get, (setter)StrokeAttribute_color_set, - (char *)StrokeAttribute_color_doc, NULL}, - {(char *)"thickness", (getter)StrokeAttribute_thickness_get, (setter)StrokeAttribute_thickness_set, - (char *)StrokeAttribute_thickness_doc, NULL}, - {(char *)"visible", (getter)StrokeAttribute_visible_get, (setter)StrokeAttribute_visible_set, - (char *)StrokeAttribute_visible_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"alpha", + (getter)StrokeAttribute_alpha_get, + (setter)StrokeAttribute_alpha_set, + (char *)StrokeAttribute_alpha_doc, + NULL}, + {(char *)"color", + (getter)StrokeAttribute_color_get, + (setter)StrokeAttribute_color_set, + (char *)StrokeAttribute_color_doc, + NULL}, + {(char *)"thickness", + (getter)StrokeAttribute_thickness_get, + (setter)StrokeAttribute_thickness_set, + (char *)StrokeAttribute_thickness_doc, + NULL}, + {(char *)"visible", + (getter)StrokeAttribute_visible_get, + (setter)StrokeAttribute_visible_set, + (char *)StrokeAttribute_visible_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeAttribute type definition ------------------------------*/ PyTypeObject StrokeAttribute_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeAttribute", /* tp_name */ - sizeof(BPy_StrokeAttribute), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)StrokeAttribute_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)StrokeAttribute_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeAttribute_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_StrokeAttribute_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_StrokeAttribute_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeAttribute_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeAttribute", /* tp_name */ + sizeof(BPy_StrokeAttribute), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)StrokeAttribute_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)StrokeAttribute_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeAttribute_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_StrokeAttribute_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_StrokeAttribute_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeAttribute_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h index 7b55fcc9444..9e14c292c0a 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h @@ -37,13 +37,13 @@ extern "C" { extern PyTypeObject StrokeAttribute_Type; -#define BPy_StrokeAttribute_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeAttribute_Type)) +#define BPy_StrokeAttribute_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeAttribute_Type)) /*---------------------------Python BPy_StrokeAttribute structure definition----------*/ typedef struct { - PyObject_HEAD - StrokeAttribute *sa; - bool borrowed; /* true if *sa is a borrowed reference */ + PyObject_HEAD StrokeAttribute *sa; + bool borrowed; /* true if *sa is a borrowed reference */ } BPy_StrokeAttribute; /*---------------------------Python BPy_StrokeAttribute visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp index 54ac10f39f7..33028512b47 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp @@ -51,245 +51,253 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int StrokeShader_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&StrokeShader_Type) < 0) - return -1; - Py_INCREF(&StrokeShader_Type); - PyModule_AddObject(module, "StrokeShader", (PyObject *)&StrokeShader_Type); - - if (PyType_Ready(&BackboneStretcherShader_Type) < 0) - return -1; - Py_INCREF(&BackboneStretcherShader_Type); - PyModule_AddObject(module, "BackboneStretcherShader", (PyObject *)&BackboneStretcherShader_Type); - - if (PyType_Ready(&BezierCurveShader_Type) < 0) - return -1; - Py_INCREF(&BezierCurveShader_Type); - PyModule_AddObject(module, "BezierCurveShader", (PyObject *)&BezierCurveShader_Type); - - if (PyType_Ready(&BlenderTextureShader_Type) < 0) - return -1; - Py_INCREF(&BlenderTextureShader_Type); - PyModule_AddObject(module, "BlenderTextureShader", (PyObject *)&BlenderTextureShader_Type); - - if (PyType_Ready(&CalligraphicShader_Type) < 0) - return -1; - Py_INCREF(&CalligraphicShader_Type); - PyModule_AddObject(module, "CalligraphicShader", (PyObject *)&CalligraphicShader_Type); - - if (PyType_Ready(&ColorNoiseShader_Type) < 0) - return -1; - Py_INCREF(&ColorNoiseShader_Type); - PyModule_AddObject(module, "ColorNoiseShader", (PyObject *)&ColorNoiseShader_Type); - - if (PyType_Ready(&ConstantColorShader_Type) < 0) - return -1; - Py_INCREF(&ConstantColorShader_Type); - PyModule_AddObject(module, "ConstantColorShader", (PyObject *)&ConstantColorShader_Type); - - if (PyType_Ready(&ConstantThicknessShader_Type) < 0) - return -1; - Py_INCREF(&ConstantThicknessShader_Type); - PyModule_AddObject(module, "ConstantThicknessShader", (PyObject *)&ConstantThicknessShader_Type); - - if (PyType_Ready(&ConstrainedIncreasingThicknessShader_Type) < 0) - return -1; - Py_INCREF(&ConstrainedIncreasingThicknessShader_Type); - PyModule_AddObject(module, "ConstrainedIncreasingThicknessShader", - (PyObject *)&ConstrainedIncreasingThicknessShader_Type); - - if (PyType_Ready(&GuidingLinesShader_Type) < 0) - return -1; - Py_INCREF(&GuidingLinesShader_Type); - PyModule_AddObject(module, "GuidingLinesShader", (PyObject *)&GuidingLinesShader_Type); - - if (PyType_Ready(&IncreasingColorShader_Type) < 0) - return -1; - Py_INCREF(&IncreasingColorShader_Type); - PyModule_AddObject(module, "IncreasingColorShader", (PyObject *)&IncreasingColorShader_Type); - - if (PyType_Ready(&IncreasingThicknessShader_Type) < 0) - return -1; - Py_INCREF(&IncreasingThicknessShader_Type); - PyModule_AddObject(module, "IncreasingThicknessShader", (PyObject *)&IncreasingThicknessShader_Type); - - if (PyType_Ready(&PolygonalizationShader_Type) < 0) - return -1; - Py_INCREF(&PolygonalizationShader_Type); - PyModule_AddObject(module, "PolygonalizationShader", (PyObject *)&PolygonalizationShader_Type); - - if (PyType_Ready(&SamplingShader_Type) < 0) - return -1; - Py_INCREF(&SamplingShader_Type); - PyModule_AddObject(module, "SamplingShader", (PyObject *)&SamplingShader_Type); - - if (PyType_Ready(&SmoothingShader_Type) < 0) - return -1; - Py_INCREF(&SmoothingShader_Type); - PyModule_AddObject(module, "SmoothingShader", (PyObject *)&SmoothingShader_Type); - - if (PyType_Ready(&SpatialNoiseShader_Type) < 0) - return -1; - Py_INCREF(&SpatialNoiseShader_Type); - PyModule_AddObject(module, "SpatialNoiseShader", (PyObject *)&SpatialNoiseShader_Type); - - if (PyType_Ready(&StrokeTextureStepShader_Type) < 0) - return -1; - Py_INCREF(&StrokeTextureStepShader_Type); - PyModule_AddObject(module, "StrokeTextureStepShader", (PyObject *)&StrokeTextureStepShader_Type); - - if (PyType_Ready(&ThicknessNoiseShader_Type) < 0) - return -1; - Py_INCREF(&ThicknessNoiseShader_Type); - PyModule_AddObject(module, "ThicknessNoiseShader", (PyObject *)&ThicknessNoiseShader_Type); - - if (PyType_Ready(&TipRemoverShader_Type) < 0) - return -1; - Py_INCREF(&TipRemoverShader_Type); - PyModule_AddObject(module, "TipRemoverShader", (PyObject *)&TipRemoverShader_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&StrokeShader_Type) < 0) + return -1; + Py_INCREF(&StrokeShader_Type); + PyModule_AddObject(module, "StrokeShader", (PyObject *)&StrokeShader_Type); + + if (PyType_Ready(&BackboneStretcherShader_Type) < 0) + return -1; + Py_INCREF(&BackboneStretcherShader_Type); + PyModule_AddObject(module, "BackboneStretcherShader", (PyObject *)&BackboneStretcherShader_Type); + + if (PyType_Ready(&BezierCurveShader_Type) < 0) + return -1; + Py_INCREF(&BezierCurveShader_Type); + PyModule_AddObject(module, "BezierCurveShader", (PyObject *)&BezierCurveShader_Type); + + if (PyType_Ready(&BlenderTextureShader_Type) < 0) + return -1; + Py_INCREF(&BlenderTextureShader_Type); + PyModule_AddObject(module, "BlenderTextureShader", (PyObject *)&BlenderTextureShader_Type); + + if (PyType_Ready(&CalligraphicShader_Type) < 0) + return -1; + Py_INCREF(&CalligraphicShader_Type); + PyModule_AddObject(module, "CalligraphicShader", (PyObject *)&CalligraphicShader_Type); + + if (PyType_Ready(&ColorNoiseShader_Type) < 0) + return -1; + Py_INCREF(&ColorNoiseShader_Type); + PyModule_AddObject(module, "ColorNoiseShader", (PyObject *)&ColorNoiseShader_Type); + + if (PyType_Ready(&ConstantColorShader_Type) < 0) + return -1; + Py_INCREF(&ConstantColorShader_Type); + PyModule_AddObject(module, "ConstantColorShader", (PyObject *)&ConstantColorShader_Type); + + if (PyType_Ready(&ConstantThicknessShader_Type) < 0) + return -1; + Py_INCREF(&ConstantThicknessShader_Type); + PyModule_AddObject(module, "ConstantThicknessShader", (PyObject *)&ConstantThicknessShader_Type); + + if (PyType_Ready(&ConstrainedIncreasingThicknessShader_Type) < 0) + return -1; + Py_INCREF(&ConstrainedIncreasingThicknessShader_Type); + PyModule_AddObject(module, + "ConstrainedIncreasingThicknessShader", + (PyObject *)&ConstrainedIncreasingThicknessShader_Type); + + if (PyType_Ready(&GuidingLinesShader_Type) < 0) + return -1; + Py_INCREF(&GuidingLinesShader_Type); + PyModule_AddObject(module, "GuidingLinesShader", (PyObject *)&GuidingLinesShader_Type); + + if (PyType_Ready(&IncreasingColorShader_Type) < 0) + return -1; + Py_INCREF(&IncreasingColorShader_Type); + PyModule_AddObject(module, "IncreasingColorShader", (PyObject *)&IncreasingColorShader_Type); + + if (PyType_Ready(&IncreasingThicknessShader_Type) < 0) + return -1; + Py_INCREF(&IncreasingThicknessShader_Type); + PyModule_AddObject( + module, "IncreasingThicknessShader", (PyObject *)&IncreasingThicknessShader_Type); + + if (PyType_Ready(&PolygonalizationShader_Type) < 0) + return -1; + Py_INCREF(&PolygonalizationShader_Type); + PyModule_AddObject(module, "PolygonalizationShader", (PyObject *)&PolygonalizationShader_Type); + + if (PyType_Ready(&SamplingShader_Type) < 0) + return -1; + Py_INCREF(&SamplingShader_Type); + PyModule_AddObject(module, "SamplingShader", (PyObject *)&SamplingShader_Type); + + if (PyType_Ready(&SmoothingShader_Type) < 0) + return -1; + Py_INCREF(&SmoothingShader_Type); + PyModule_AddObject(module, "SmoothingShader", (PyObject *)&SmoothingShader_Type); + + if (PyType_Ready(&SpatialNoiseShader_Type) < 0) + return -1; + Py_INCREF(&SpatialNoiseShader_Type); + PyModule_AddObject(module, "SpatialNoiseShader", (PyObject *)&SpatialNoiseShader_Type); + + if (PyType_Ready(&StrokeTextureStepShader_Type) < 0) + return -1; + Py_INCREF(&StrokeTextureStepShader_Type); + PyModule_AddObject(module, "StrokeTextureStepShader", (PyObject *)&StrokeTextureStepShader_Type); + + if (PyType_Ready(&ThicknessNoiseShader_Type) < 0) + return -1; + Py_INCREF(&ThicknessNoiseShader_Type); + PyModule_AddObject(module, "ThicknessNoiseShader", (PyObject *)&ThicknessNoiseShader_Type); + + if (PyType_Ready(&TipRemoverShader_Type) < 0) + return -1; + Py_INCREF(&TipRemoverShader_Type); + PyModule_AddObject(module, "TipRemoverShader", (PyObject *)&TipRemoverShader_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char StrokeShader___doc__[] = -"Base class for stroke shaders. Any stroke shader must inherit from\n" -"this class and overload the shade() method. A StrokeShader is\n" -"designed to modify stroke attributes such as thickness, color,\n" -"geometry, texture, blending mode, and so on. The basic way for this\n" -"operation is to iterate over the stroke vertices of the :class:`Stroke`\n" -"and to modify the :class:`StrokeAttribute` of each vertex. Here is a\n" -"code example of such an iteration::\n" -"\n" -" it = ioStroke.strokeVerticesBegin()\n" -" while not it.is_end:\n" -" att = it.object.attribute\n" -" ## perform here any attribute modification\n" -" it.increment()\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; + "Base class for stroke shaders. Any stroke shader must inherit from\n" + "this class and overload the shade() method. A StrokeShader is\n" + "designed to modify stroke attributes such as thickness, color,\n" + "geometry, texture, blending mode, and so on. The basic way for this\n" + "operation is to iterate over the stroke vertices of the :class:`Stroke`\n" + "and to modify the :class:`StrokeAttribute` of each vertex. Here is a\n" + "code example of such an iteration::\n" + "\n" + " it = ioStroke.strokeVerticesBegin()\n" + " while not it.is_end:\n" + " att = it.object.attribute\n" + " ## perform here any attribute modification\n" + " it.increment()\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->ss = new StrokeShader(); - self->ss->py_ss = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->ss = new StrokeShader(); + self->ss->py_ss = (PyObject *)self; + return 0; } static void StrokeShader___dealloc__(BPy_StrokeShader *self) { - if (self->ss) - delete self->ss; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->ss) + delete self->ss; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *StrokeShader___repr__(BPy_StrokeShader *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->ss); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->ss); } static char StrokeShader_shade___doc__[] = -".. method:: shade(stroke)\n" -"\n" -" The shading method. Must be overloaded by inherited classes.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`Stroke`\n"; + ".. method:: shade(stroke)\n" + "\n" + " The shading method. Must be overloaded by inherited classes.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`Stroke`\n"; static PyObject *StrokeShader_shade(BPy_StrokeShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"stroke", NULL}; - PyObject *py_s = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Stroke_Type, &py_s)) - return NULL; - - if (typeid(*(self->ss)) == typeid(StrokeShader)) { - PyErr_SetString(PyExc_TypeError, "shade method not properly overridden"); - return NULL; - } - if (self->ss->shade(*(((BPy_Stroke *)py_s)->s)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " shade method failed").c_str()); - } - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"stroke", NULL}; + PyObject *py_s = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Stroke_Type, &py_s)) + return NULL; + + if (typeid(*(self->ss)) == typeid(StrokeShader)) { + PyErr_SetString(PyExc_TypeError, "shade method not properly overridden"); + return NULL; + } + if (self->ss->shade(*(((BPy_Stroke *)py_s)->s)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " shade method failed").c_str()); + } + return NULL; + } + Py_RETURN_NONE; } static PyMethodDef BPy_StrokeShader_methods[] = { - {"shade", (PyCFunction)StrokeShader_shade, METH_VARARGS | METH_KEYWORDS, StrokeShader_shade___doc__}, - {NULL, NULL, 0, NULL}, + {"shade", + (PyCFunction)StrokeShader_shade, + METH_VARARGS | METH_KEYWORDS, + StrokeShader_shade___doc__}, + {NULL, NULL, 0, NULL}, }; /*----------------------StrokeShader get/setters ----------------------------*/ PyDoc_STRVAR(StrokeShader_name_doc, -"The name of the stroke shader.\n" -"\n" -":type: str"); + "The name of the stroke shader.\n" + "\n" + ":type: str"); static PyObject *StrokeShader_name_get(BPy_StrokeShader *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_StrokeShader_getseters[] = { - {(char *)"name", (getter)StrokeShader_name_get, (setter)NULL, (char *)StrokeShader_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)StrokeShader_name_get, + (setter)NULL, + (char *)StrokeShader_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeShader type definition ------------------------------*/ PyTypeObject StrokeShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeShader", /* tp_name */ - sizeof(BPy_StrokeShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)StrokeShader___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)StrokeShader___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_StrokeShader_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_StrokeShader_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeShader___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeShader", /* tp_name */ + sizeof(BPy_StrokeShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)StrokeShader___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)StrokeShader___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_StrokeShader_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_StrokeShader_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeShader___init__, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_StrokeShader.h b/source/blender/freestyle/intern/python/BPy_StrokeShader.h index 80a7e3fab0f..23b1196fdb9 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeShader.h +++ b/source/blender/freestyle/intern/python/BPy_StrokeShader.h @@ -41,24 +41,22 @@ extern "C" { extern PyTypeObject StrokeShader_Type; -#define BPy_StrokeShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeShader_Type)) +#define BPy_StrokeShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeShader_Type)) /*---------------------------Python BPy_StrokeShader structure definition----------*/ typedef struct { - PyObject_HEAD - StrokeShader *ss; + PyObject_HEAD StrokeShader *ss; } BPy_StrokeShader; /*---------------------------Python BPy_StrokeShader visible prototypes-----------*/ int StrokeShader_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_STROKESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp index 278faceadd4..90a9258d9e8 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp @@ -40,118 +40,121 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int UnaryFunction0D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction0D_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0D_Type); - PyModule_AddObject(module, "UnaryFunction0D", (PyObject *)&UnaryFunction0D_Type); - - UnaryFunction0DDouble_Init(module); - UnaryFunction0DEdgeNature_Init(module); - UnaryFunction0DFloat_Init(module); - UnaryFunction0DId_Init(module); - UnaryFunction0DMaterial_Init(module); - UnaryFunction0DUnsigned_Init(module); - UnaryFunction0DVec2f_Init(module); - UnaryFunction0DVec3f_Init(module); - UnaryFunction0DVectorViewShape_Init(module); - UnaryFunction0DViewShape_Init(module); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction0D_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0D_Type); + PyModule_AddObject(module, "UnaryFunction0D", (PyObject *)&UnaryFunction0D_Type); + + UnaryFunction0DDouble_Init(module); + UnaryFunction0DEdgeNature_Init(module); + UnaryFunction0DFloat_Init(module); + UnaryFunction0DId_Init(module); + UnaryFunction0DMaterial_Init(module); + UnaryFunction0DUnsigned_Init(module); + UnaryFunction0DVec2f_Init(module); + UnaryFunction0DVec3f_Init(module); + UnaryFunction0DVectorViewShape_Init(module); + UnaryFunction0DViewShape_Init(module); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0D___doc__[] = -"Base class for Unary Functions (functors) working on\n" -":class:`Interface0DIterator`. A unary function will be used by\n" -"invoking __call__() on an Interface0DIterator. In Python, several\n" -"different subclasses of UnaryFunction0D are used depending on the\n" -"types of functors' return values. For example, you would inherit from\n" -"a :class:`UnaryFunction0DDouble` if you wish to define a function that\n" -"returns a double value. Available UnaryFunction0D subclasses are:\n" -"\n" -"* :class:`UnaryFunction0DDouble`\n" -"* :class:`UnaryFunction0DEdgeNature`\n" -"* :class:`UnaryFunction0DFloat`\n" -"* :class:`UnaryFunction0DId`\n" -"* :class:`UnaryFunction0DMaterial`\n" -"* :class:`UnaryFunction0DUnsigned`\n" -"* :class:`UnaryFunction0DVec2f`\n" -"* :class:`UnaryFunction0DVec3f`\n" -"* :class:`UnaryFunction0DVectorViewShape`\n" -"* :class:`UnaryFunction0DViewShape`\n"; + "Base class for Unary Functions (functors) working on\n" + ":class:`Interface0DIterator`. A unary function will be used by\n" + "invoking __call__() on an Interface0DIterator. In Python, several\n" + "different subclasses of UnaryFunction0D are used depending on the\n" + "types of functors' return values. For example, you would inherit from\n" + "a :class:`UnaryFunction0DDouble` if you wish to define a function that\n" + "returns a double value. Available UnaryFunction0D subclasses are:\n" + "\n" + "* :class:`UnaryFunction0DDouble`\n" + "* :class:`UnaryFunction0DEdgeNature`\n" + "* :class:`UnaryFunction0DFloat`\n" + "* :class:`UnaryFunction0DId`\n" + "* :class:`UnaryFunction0DMaterial`\n" + "* :class:`UnaryFunction0DUnsigned`\n" + "* :class:`UnaryFunction0DVec2f`\n" + "* :class:`UnaryFunction0DVec3f`\n" + "* :class:`UnaryFunction0DVectorViewShape`\n" + "* :class:`UnaryFunction0DViewShape`\n"; static void UnaryFunction0D___dealloc__(BPy_UnaryFunction0D *self) { - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *UnaryFunction0D___repr__(BPy_UnaryFunction0D * /*self*/) { - return PyUnicode_FromString("UnaryFunction0D"); + return PyUnicode_FromString("UnaryFunction0D"); } /*----------------------UnaryFunction0D get/setters ----------------------------*/ PyDoc_STRVAR(UnaryFunction0D_name_doc, -"The name of the unary 0D function.\n" -"\n" -":type: str"); + "The name of the unary 0D function.\n" + "\n" + ":type: str"); static PyObject *UnaryFunction0D_name_get(BPy_UnaryFunction0D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_UnaryFunction0D_getseters[] = { - {(char *)"name", (getter)UnaryFunction0D_name_get, (setter)NULL, (char *)UnaryFunction0D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)UnaryFunction0D_name_get, + (setter)NULL, + (char *)UnaryFunction0D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction0D type definition ------------------------------*/ PyTypeObject UnaryFunction0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0D", /* tp_name */ - sizeof(BPy_UnaryFunction0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction0D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0D", /* tp_name */ + sizeof(BPy_UnaryFunction0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction0D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h index 2d045b39d82..c0834859dc8 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject UnaryFunction0D_Type; -#define BPy_UnaryFunction0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0D_Type)) +#define BPy_UnaryFunction0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0D_Type)) /*---------------------------Python BPy_UnaryFunction0D structure definition----------*/ typedef struct { - PyObject_HEAD - PyObject *py_uf0D; + PyObject_HEAD PyObject *py_uf0D; } BPy_UnaryFunction0D; /*---------------------------Python BPy_UnaryFunction0D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp index a340a7b69bc..879f090275d 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp @@ -38,114 +38,117 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int UnaryFunction1D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction1D_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1D_Type); - PyModule_AddObject(module, "UnaryFunction1D", (PyObject *)&UnaryFunction1D_Type); - - UnaryFunction1DDouble_Init(module); - UnaryFunction1DEdgeNature_Init(module); - UnaryFunction1DFloat_Init(module); - UnaryFunction1DUnsigned_Init(module); - UnaryFunction1DVec2f_Init(module); - UnaryFunction1DVec3f_Init(module); - UnaryFunction1DVectorViewShape_Init(module); - UnaryFunction1DVoid_Init(module); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction1D_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1D_Type); + PyModule_AddObject(module, "UnaryFunction1D", (PyObject *)&UnaryFunction1D_Type); + + UnaryFunction1DDouble_Init(module); + UnaryFunction1DEdgeNature_Init(module); + UnaryFunction1DFloat_Init(module); + UnaryFunction1DUnsigned_Init(module); + UnaryFunction1DVec2f_Init(module); + UnaryFunction1DVec3f_Init(module); + UnaryFunction1DVectorViewShape_Init(module); + UnaryFunction1DVoid_Init(module); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1D___doc__[] = -"Base class for Unary Functions (functors) working on\n" -":class:`Interface1D`. A unary function will be used by invoking\n" -"__call__() on an Interface1D. In Python, several different subclasses\n" -"of UnaryFunction1D are used depending on the types of functors' return\n" -"values. For example, you would inherit from a\n" -":class:`UnaryFunction1DDouble` if you wish to define a function that\n" -"returns a double value. Available UnaryFunction1D subclasses are:\n" -"\n" -"* :class:`UnaryFunction1DDouble`\n" -"* :class:`UnaryFunction1DEdgeNature`\n" -"* :class:`UnaryFunction1DFloat`\n" -"* :class:`UnaryFunction1DUnsigned`\n" -"* :class:`UnaryFunction1DVec2f`\n" -"* :class:`UnaryFunction1DVec3f`\n" -"* :class:`UnaryFunction1DVectorViewShape`\n" -"* :class:`UnaryFunction1DVoid`\n"; + "Base class for Unary Functions (functors) working on\n" + ":class:`Interface1D`. A unary function will be used by invoking\n" + "__call__() on an Interface1D. In Python, several different subclasses\n" + "of UnaryFunction1D are used depending on the types of functors' return\n" + "values. For example, you would inherit from a\n" + ":class:`UnaryFunction1DDouble` if you wish to define a function that\n" + "returns a double value. Available UnaryFunction1D subclasses are:\n" + "\n" + "* :class:`UnaryFunction1DDouble`\n" + "* :class:`UnaryFunction1DEdgeNature`\n" + "* :class:`UnaryFunction1DFloat`\n" + "* :class:`UnaryFunction1DUnsigned`\n" + "* :class:`UnaryFunction1DVec2f`\n" + "* :class:`UnaryFunction1DVec3f`\n" + "* :class:`UnaryFunction1DVectorViewShape`\n" + "* :class:`UnaryFunction1DVoid`\n"; static void UnaryFunction1D___dealloc__(BPy_UnaryFunction1D *self) { - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *UnaryFunction1D___repr__(BPy_UnaryFunction1D * /*self*/) { - return PyUnicode_FromString("UnaryFunction1D"); + return PyUnicode_FromString("UnaryFunction1D"); } /*----------------------UnaryFunction1D get/setters ----------------------------*/ PyDoc_STRVAR(UnaryFunction1D_name_doc, -"The name of the unary 1D function.\n" -"\n" -":type: str"); + "The name of the unary 1D function.\n" + "\n" + ":type: str"); static PyObject *UnaryFunction1D_name_get(BPy_UnaryFunction1D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_UnaryFunction1D_getseters[] = { - {(char *)"name", (getter)UnaryFunction1D_name_get, (setter)NULL, (char *)UnaryFunction1D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)UnaryFunction1D_name_get, + (setter)NULL, + (char *)UnaryFunction1D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1D type definition ------------------------------*/ PyTypeObject UnaryFunction1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1D", /* tp_name */ - sizeof(BPy_UnaryFunction1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1D", /* tp_name */ + sizeof(BPy_UnaryFunction1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h index 842d228cf75..dfd0e56beb6 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject UnaryFunction1D_Type; -#define BPy_UnaryFunction1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1D_Type)) +#define BPy_UnaryFunction1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1D_Type)) /*---------------------------Python BPy_UnaryFunction1D structure definition----------*/ typedef struct { - PyObject_HEAD - PyObject *py_uf1D; + PyObject_HEAD PyObject *py_uf1D; } BPy_UnaryFunction1D; /*---------------------------Python BPy_UnaryFunction1D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp index d5323b8ff40..7d1a91f156d 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp @@ -34,161 +34,167 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int UnaryPredicate0D_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryPredicate0D_Type) < 0) - return -1; - Py_INCREF(&UnaryPredicate0D_Type); - PyModule_AddObject(module, "UnaryPredicate0D", (PyObject *)&UnaryPredicate0D_Type); + if (PyType_Ready(&UnaryPredicate0D_Type) < 0) + return -1; + Py_INCREF(&UnaryPredicate0D_Type); + PyModule_AddObject(module, "UnaryPredicate0D", (PyObject *)&UnaryPredicate0D_Type); - if (PyType_Ready(&FalseUP0D_Type) < 0) - return -1; - Py_INCREF(&FalseUP0D_Type); - PyModule_AddObject(module, "FalseUP0D", (PyObject *)&FalseUP0D_Type); + if (PyType_Ready(&FalseUP0D_Type) < 0) + return -1; + Py_INCREF(&FalseUP0D_Type); + PyModule_AddObject(module, "FalseUP0D", (PyObject *)&FalseUP0D_Type); - if (PyType_Ready(&TrueUP0D_Type) < 0) - return -1; - Py_INCREF(&TrueUP0D_Type); - PyModule_AddObject(module, "TrueUP0D", (PyObject *)&TrueUP0D_Type); + if (PyType_Ready(&TrueUP0D_Type) < 0) + return -1; + Py_INCREF(&TrueUP0D_Type); + PyModule_AddObject(module, "TrueUP0D", (PyObject *)&TrueUP0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryPredicate0D___doc__[] = -"Base class for unary predicates that work on\n" -":class:`Interface0DIterator`. A UnaryPredicate0D is a functor that\n" -"evaluates a condition on an Interface0DIterator and returns true or\n" -"false depending on whether this condition is satisfied or not. The\n" -"UnaryPredicate0D is used by invoking its __call__() method. Any\n" -"inherited class must overload the __call__() method.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Must be overload by inherited classes.\n" -"\n" -" :arg it: The Interface0DIterator pointing onto the Interface0D at\n" -" which we wish to evaluate the predicate.\n" -" :type it: :class:`Interface0DIterator`\n" -" :return: True if the condition is satisfied, false otherwise.\n" -" :rtype: bool\n"; + "Base class for unary predicates that work on\n" + ":class:`Interface0DIterator`. A UnaryPredicate0D is a functor that\n" + "evaluates a condition on an Interface0DIterator and returns true or\n" + "false depending on whether this condition is satisfied or not. The\n" + "UnaryPredicate0D is used by invoking its __call__() method. Any\n" + "inherited class must overload the __call__() method.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Must be overload by inherited classes.\n" + "\n" + " :arg it: The Interface0DIterator pointing onto the Interface0D at\n" + " which we wish to evaluate the predicate.\n" + " :type it: :class:`Interface0DIterator`\n" + " :return: True if the condition is satisfied, false otherwise.\n" + " :rtype: bool\n"; static int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->up0D = new UnaryPredicate0D(); - self->up0D->py_up0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->up0D = new UnaryPredicate0D(); + self->up0D->py_up0D = (PyObject *)self; + return 0; } static void UnaryPredicate0D___dealloc__(BPy_UnaryPredicate0D *self) { - if (self->up0D) - delete self->up0D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->up0D) + delete self->up0D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *UnaryPredicate0D___repr__(BPy_UnaryPredicate0D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up0D); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up0D); } -static PyObject *UnaryPredicate0D___call__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryPredicate0D___call__(BPy_UnaryPredicate0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *py_if0D_it; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &py_if0D_it)) - return NULL; - - Interface0DIterator *if0D_it = ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it; - - if (!if0D_it) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface0DIterator").c_str()); - return NULL; - } - if (typeid(*(self->up0D)) == typeid(UnaryPredicate0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->up0D->operator()(*if0D_it) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyBool_from_bool(self->up0D->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *py_if0D_it; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &py_if0D_it)) + return NULL; + + Interface0DIterator *if0D_it = ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it; + + if (!if0D_it) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface0DIterator").c_str()); + return NULL; + } + if (typeid(*(self->up0D)) == typeid(UnaryPredicate0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->up0D->operator()(*if0D_it) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyBool_from_bool(self->up0D->result); } /*----------------------UnaryPredicate0D get/setters ----------------------------*/ PyDoc_STRVAR(UnaryPredicate0D_name_doc, -"The name of the unary 0D predicate.\n" -"\n" -":type: str"); + "The name of the unary 0D predicate.\n" + "\n" + ":type: str"); static PyObject *UnaryPredicate0D_name_get(BPy_UnaryPredicate0D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_UnaryPredicate0D_getseters[] = { - {(char *)"name", (getter)UnaryPredicate0D_name_get, (setter)NULL, (char *)UnaryPredicate0D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)UnaryPredicate0D_name_get, + (setter)NULL, + (char *)UnaryPredicate0D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryPredicate0D type definition ------------------------------*/ PyTypeObject UnaryPredicate0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryPredicate0D", /* tp_name */ - sizeof(BPy_UnaryPredicate0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryPredicate0D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryPredicate0D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryPredicate0D___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryPredicate0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryPredicate0D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryPredicate0D___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryPredicate0D", /* tp_name */ + sizeof(BPy_UnaryPredicate0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryPredicate0D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryPredicate0D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryPredicate0D___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryPredicate0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryPredicate0D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryPredicate0D___init__, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.h b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.h index 685120cfb0c..d422b10f18e 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject UnaryPredicate0D_Type; -#define BPy_UnaryPredicate0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryPredicate0D_Type)) +#define BPy_UnaryPredicate0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryPredicate0D_Type)) /*---------------------------Python BPy_UnaryPredicate0D structure definition----------*/ typedef struct { - PyObject_HEAD - UnaryPredicate0D *up0D; + PyObject_HEAD UnaryPredicate0D *up0D; } BPy_UnaryPredicate0D; /*---------------------------Python BPy_UnaryPredicate0D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp index 11ab9eb2a2b..3c728d1a852 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp @@ -43,200 +43,207 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int UnaryPredicate1D_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryPredicate1D_Type) < 0) - return -1; - Py_INCREF(&UnaryPredicate1D_Type); - PyModule_AddObject(module, "UnaryPredicate1D", (PyObject *)&UnaryPredicate1D_Type); - - if (PyType_Ready(&ContourUP1D_Type) < 0) - return -1; - Py_INCREF(&ContourUP1D_Type); - PyModule_AddObject(module, "ContourUP1D", (PyObject *)&ContourUP1D_Type); - - if (PyType_Ready(&DensityLowerThanUP1D_Type) < 0) - return -1; - Py_INCREF(&DensityLowerThanUP1D_Type); - PyModule_AddObject(module, "DensityLowerThanUP1D", (PyObject *)&DensityLowerThanUP1D_Type); - - if (PyType_Ready(&EqualToChainingTimeStampUP1D_Type) < 0) - return -1; - Py_INCREF(&EqualToChainingTimeStampUP1D_Type); - PyModule_AddObject(module, "EqualToChainingTimeStampUP1D", (PyObject *)&EqualToChainingTimeStampUP1D_Type); - - if (PyType_Ready(&EqualToTimeStampUP1D_Type) < 0) - return -1; - Py_INCREF(&EqualToTimeStampUP1D_Type); - PyModule_AddObject(module, "EqualToTimeStampUP1D", (PyObject *)&EqualToTimeStampUP1D_Type); - - if (PyType_Ready(&ExternalContourUP1D_Type) < 0) - return -1; - Py_INCREF(&ExternalContourUP1D_Type); - PyModule_AddObject(module, "ExternalContourUP1D", (PyObject *)&ExternalContourUP1D_Type); - - if (PyType_Ready(&FalseUP1D_Type) < 0) - return -1; - Py_INCREF(&FalseUP1D_Type); - PyModule_AddObject(module, "FalseUP1D", (PyObject *)&FalseUP1D_Type); - - if (PyType_Ready(&QuantitativeInvisibilityUP1D_Type) < 0) - return -1; - Py_INCREF(&QuantitativeInvisibilityUP1D_Type); - PyModule_AddObject(module, "QuantitativeInvisibilityUP1D", (PyObject *)&QuantitativeInvisibilityUP1D_Type); - - if (PyType_Ready(&ShapeUP1D_Type) < 0) - return -1; - Py_INCREF(&ShapeUP1D_Type); - PyModule_AddObject(module, "ShapeUP1D", (PyObject *)&ShapeUP1D_Type); - - if (PyType_Ready(&TrueUP1D_Type) < 0) - return -1; - Py_INCREF(&TrueUP1D_Type); - PyModule_AddObject(module, "TrueUP1D", (PyObject *)&TrueUP1D_Type); - - if (PyType_Ready(&WithinImageBoundaryUP1D_Type) < 0) - return -1; - Py_INCREF(&WithinImageBoundaryUP1D_Type); - PyModule_AddObject(module, "WithinImageBoundaryUP1D", (PyObject *)&WithinImageBoundaryUP1D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryPredicate1D_Type) < 0) + return -1; + Py_INCREF(&UnaryPredicate1D_Type); + PyModule_AddObject(module, "UnaryPredicate1D", (PyObject *)&UnaryPredicate1D_Type); + + if (PyType_Ready(&ContourUP1D_Type) < 0) + return -1; + Py_INCREF(&ContourUP1D_Type); + PyModule_AddObject(module, "ContourUP1D", (PyObject *)&ContourUP1D_Type); + + if (PyType_Ready(&DensityLowerThanUP1D_Type) < 0) + return -1; + Py_INCREF(&DensityLowerThanUP1D_Type); + PyModule_AddObject(module, "DensityLowerThanUP1D", (PyObject *)&DensityLowerThanUP1D_Type); + + if (PyType_Ready(&EqualToChainingTimeStampUP1D_Type) < 0) + return -1; + Py_INCREF(&EqualToChainingTimeStampUP1D_Type); + PyModule_AddObject( + module, "EqualToChainingTimeStampUP1D", (PyObject *)&EqualToChainingTimeStampUP1D_Type); + + if (PyType_Ready(&EqualToTimeStampUP1D_Type) < 0) + return -1; + Py_INCREF(&EqualToTimeStampUP1D_Type); + PyModule_AddObject(module, "EqualToTimeStampUP1D", (PyObject *)&EqualToTimeStampUP1D_Type); + + if (PyType_Ready(&ExternalContourUP1D_Type) < 0) + return -1; + Py_INCREF(&ExternalContourUP1D_Type); + PyModule_AddObject(module, "ExternalContourUP1D", (PyObject *)&ExternalContourUP1D_Type); + + if (PyType_Ready(&FalseUP1D_Type) < 0) + return -1; + Py_INCREF(&FalseUP1D_Type); + PyModule_AddObject(module, "FalseUP1D", (PyObject *)&FalseUP1D_Type); + + if (PyType_Ready(&QuantitativeInvisibilityUP1D_Type) < 0) + return -1; + Py_INCREF(&QuantitativeInvisibilityUP1D_Type); + PyModule_AddObject( + module, "QuantitativeInvisibilityUP1D", (PyObject *)&QuantitativeInvisibilityUP1D_Type); + + if (PyType_Ready(&ShapeUP1D_Type) < 0) + return -1; + Py_INCREF(&ShapeUP1D_Type); + PyModule_AddObject(module, "ShapeUP1D", (PyObject *)&ShapeUP1D_Type); + + if (PyType_Ready(&TrueUP1D_Type) < 0) + return -1; + Py_INCREF(&TrueUP1D_Type); + PyModule_AddObject(module, "TrueUP1D", (PyObject *)&TrueUP1D_Type); + + if (PyType_Ready(&WithinImageBoundaryUP1D_Type) < 0) + return -1; + Py_INCREF(&WithinImageBoundaryUP1D_Type); + PyModule_AddObject(module, "WithinImageBoundaryUP1D", (PyObject *)&WithinImageBoundaryUP1D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryPredicate1D___doc__[] = -"Base class for unary predicates that work on :class:`Interface1D`. A\n" -"UnaryPredicate1D is a functor that evaluates a condition on a\n" -"Interface1D and returns true or false depending on whether this\n" -"condition is satisfied or not. The UnaryPredicate1D is used by\n" -"invoking its __call__() method. Any inherited class must overload the\n" -"__call__() method.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Must be overload by inherited classes.\n" -"\n" -" :arg inter: The Interface1D on which we wish to evaluate the predicate.\n" -" :type inter: :class:`Interface1D`\n" -" :return: True if the condition is satisfied, false otherwise.\n" -" :rtype: bool\n"; + "Base class for unary predicates that work on :class:`Interface1D`. A\n" + "UnaryPredicate1D is a functor that evaluates a condition on a\n" + "Interface1D and returns true or false depending on whether this\n" + "condition is satisfied or not. The UnaryPredicate1D is used by\n" + "invoking its __call__() method. Any inherited class must overload the\n" + "__call__() method.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Must be overload by inherited classes.\n" + "\n" + " :arg inter: The Interface1D on which we wish to evaluate the predicate.\n" + " :type inter: :class:`Interface1D`\n" + " :return: True if the condition is satisfied, false otherwise.\n" + " :rtype: bool\n"; static int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->up1D = new UnaryPredicate1D(); - self->up1D->py_up1D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->up1D = new UnaryPredicate1D(); + self->up1D->py_up1D = (PyObject *)self; + return 0; } static void UnaryPredicate1D___dealloc__(BPy_UnaryPredicate1D *self) { - if (self->up1D) - delete self->up1D; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->up1D) + delete self->up1D; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *UnaryPredicate1D___repr__(BPy_UnaryPredicate1D *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up1D); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up1D); } -static PyObject *UnaryPredicate1D___call__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryPredicate1D___call__(BPy_UnaryPredicate1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *py_if1D; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &py_if1D)) - return NULL; - - Interface1D *if1D = ((BPy_Interface1D *)py_if1D)->if1D; - - if (!if1D) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface1D").c_str()); - return NULL; - } - if (typeid(*(self->up1D)) == typeid(UnaryPredicate1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->up1D->operator()(*if1D) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyBool_from_bool(self->up1D->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *py_if1D; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &py_if1D)) + return NULL; + + Interface1D *if1D = ((BPy_Interface1D *)py_if1D)->if1D; + + if (!if1D) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface1D").c_str()); + return NULL; + } + if (typeid(*(self->up1D)) == typeid(UnaryPredicate1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->up1D->operator()(*if1D) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyBool_from_bool(self->up1D->result); } /*----------------------UnaryPredicate1D get/setters ----------------------------*/ PyDoc_STRVAR(UnaryPredicate1D_name_doc, -"The name of the unary 1D predicate.\n" -"\n" -":type: str"); + "The name of the unary 1D predicate.\n" + "\n" + ":type: str"); static PyObject *UnaryPredicate1D_name_get(BPy_UnaryPredicate1D *self, void *UNUSED(closure)) { - return PyUnicode_FromString(Py_TYPE(self)->tp_name); + return PyUnicode_FromString(Py_TYPE(self)->tp_name); } static PyGetSetDef BPy_UnaryPredicate1D_getseters[] = { - {(char *)"name", (getter)UnaryPredicate1D_name_get, (setter)NULL, (char *)UnaryPredicate1D_name_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"name", + (getter)UnaryPredicate1D_name_get, + (setter)NULL, + (char *)UnaryPredicate1D_name_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryPredicate1D type definition ------------------------------*/ PyTypeObject UnaryPredicate1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryPredicate1D", /* tp_name */ - sizeof(BPy_UnaryPredicate1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryPredicate1D___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryPredicate1D___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryPredicate1D___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryPredicate1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryPredicate1D_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryPredicate1D___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryPredicate1D", /* tp_name */ + sizeof(BPy_UnaryPredicate1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryPredicate1D___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryPredicate1D___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryPredicate1D___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryPredicate1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryPredicate1D_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryPredicate1D___init__, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.h b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.h index cd44569aac0..22358fab525 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.h +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.h @@ -37,12 +37,12 @@ extern "C" { extern PyTypeObject UnaryPredicate1D_Type; -#define BPy_UnaryPredicate1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryPredicate1D_Type)) +#define BPy_UnaryPredicate1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryPredicate1D_Type)) /*---------------------------Python BPy_UnaryPredicate1D structure definition----------*/ typedef struct { - PyObject_HEAD - UnaryPredicate1D *up1D; + PyObject_HEAD UnaryPredicate1D *up1D; } BPy_UnaryPredicate1D; /*---------------------------Python BPy_UnaryPredicate1D visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_ViewMap.cpp b/source/blender/freestyle/intern/python/BPy_ViewMap.cpp index 39dd784bdfc..a46a63da03a 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewMap.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewMap.cpp @@ -34,177 +34,183 @@ extern "C" { //-------------------MODULE INITIALIZATION-------------------------------- int ViewMap_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready( &ViewMap_Type ) < 0) - return -1; - Py_INCREF(&ViewMap_Type); - PyModule_AddObject(module, "ViewMap", (PyObject *)&ViewMap_Type); + if (PyType_Ready(&ViewMap_Type) < 0) + return -1; + Py_INCREF(&ViewMap_Type); + PyModule_AddObject(module, "ViewMap", (PyObject *)&ViewMap_Type); - return 0; + return 0; } /*----------------------ViewMap methods----------------------------*/ PyDoc_STRVAR(ViewMap_doc, -"Class defining the ViewMap.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Class defining the ViewMap.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->vm = new ViewMap(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->vm = new ViewMap(); + return 0; } static void ViewMap_dealloc(BPy_ViewMap *self) { - if (self->vm) - delete self->vm; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->vm) + delete self->vm; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *ViewMap_repr(BPy_ViewMap *self) { - return PyUnicode_FromFormat("ViewMap - address: %p", self->vm); + return PyUnicode_FromFormat("ViewMap - address: %p", self->vm); } PyDoc_STRVAR(ViewMap_get_closest_viewedge_doc, -".. method:: get_closest_viewedge(x, y)\n" -"\n" -" Gets the ViewEdge nearest to the 2D point specified as arguments.\n" -"\n" -" :arg x: X coordinate of a 2D point.\n" -" :type x: float\n" -" :arg y: Y coordinate of a 2D point.\n" -" :type y: float\n" -" :return: The ViewEdge nearest to the specified 2D point.\n" -" :rtype: :class:`ViewEdge`"); + ".. method:: get_closest_viewedge(x, y)\n" + "\n" + " Gets the ViewEdge nearest to the 2D point specified as arguments.\n" + "\n" + " :arg x: X coordinate of a 2D point.\n" + " :type x: float\n" + " :arg y: Y coordinate of a 2D point.\n" + " :type y: float\n" + " :return: The ViewEdge nearest to the specified 2D point.\n" + " :rtype: :class:`ViewEdge`"); static PyObject *ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"x", "y", NULL}; - double x, y; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) - return NULL; - ViewEdge *ve = const_cast(self->vm->getClosestViewEdge(x, y)); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + static const char *kwlist[] = {"x", "y", NULL}; + double x, y; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) + return NULL; + ViewEdge *ve = const_cast(self->vm->getClosestViewEdge(x, y)); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } PyDoc_STRVAR(ViewMap_get_closest_fedge_doc, -".. method:: get_closest_fedge(x, y)\n" -"\n" -" Gets the FEdge nearest to the 2D point specified as arguments.\n" -"\n" -" :arg x: X coordinate of a 2D point.\n" -" :type x: float\n" -" :arg y: Y coordinate of a 2D point.\n" -" :type y: float\n" -" :return: The FEdge nearest to the specified 2D point.\n" -" :rtype: :class:`FEdge`"); + ".. method:: get_closest_fedge(x, y)\n" + "\n" + " Gets the FEdge nearest to the 2D point specified as arguments.\n" + "\n" + " :arg x: X coordinate of a 2D point.\n" + " :type x: float\n" + " :arg y: Y coordinate of a 2D point.\n" + " :type y: float\n" + " :return: The FEdge nearest to the specified 2D point.\n" + " :rtype: :class:`FEdge`"); static PyObject *ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"x", "y", NULL}; - double x, y; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) - return NULL; - FEdge *fe = const_cast(self->vm->getClosestFEdge(x, y)); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + static const char *kwlist[] = {"x", "y", NULL}; + double x, y; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) + return NULL; + FEdge *fe = const_cast(self->vm->getClosestFEdge(x, y)); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } // static ViewMap *getInstance (); static PyMethodDef BPy_ViewMap_methods[] = { - {"get_closest_viewedge", (PyCFunction)ViewMap_get_closest_viewedge, METH_VARARGS | METH_KEYWORDS, - ViewMap_get_closest_viewedge_doc}, - {"get_closest_fedge", (PyCFunction)ViewMap_get_closest_fedge, METH_VARARGS | METH_KEYWORDS, - ViewMap_get_closest_fedge_doc}, - {NULL, NULL, 0, NULL}, + {"get_closest_viewedge", + (PyCFunction)ViewMap_get_closest_viewedge, + METH_VARARGS | METH_KEYWORDS, + ViewMap_get_closest_viewedge_doc}, + {"get_closest_fedge", + (PyCFunction)ViewMap_get_closest_fedge, + METH_VARARGS | METH_KEYWORDS, + ViewMap_get_closest_fedge_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewMap get/setters ----------------------------*/ PyDoc_STRVAR(ViewMap_scene_bbox_doc, -"The 3D bounding box of the scene.\n" -"\n" -":type: :class:`BBox`"); + "The 3D bounding box of the scene.\n" + "\n" + ":type: :class:`BBox`"); static PyObject *ViewMap_scene_bbox_get(BPy_ViewMap *self, void *UNUSED(closure)) { - return BPy_BBox_from_BBox(self->vm->getScene3dBBox()); + return BPy_BBox_from_BBox(self->vm->getScene3dBBox()); } static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_BBox_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a BBox"); - return -1; - } - self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb)); - return 0; + if (!BPy_BBox_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a BBox"); + return -1; + } + self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb)); + return 0; } static PyGetSetDef BPy_ViewMap_getseters[] = { - {(char *)"scene_bbox", (getter)ViewMap_scene_bbox_get, (setter)ViewMap_scene_bbox_set, - (char *)ViewMap_scene_bbox_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"scene_bbox", + (getter)ViewMap_scene_bbox_get, + (setter)ViewMap_scene_bbox_set, + (char *)ViewMap_scene_bbox_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewMap type definition ------------------------------*/ PyTypeObject ViewMap_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewMap", /* tp_name */ - sizeof(BPy_ViewMap), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)ViewMap_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)ViewMap_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewMap_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewMap_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewMap_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewMap_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewMap", /* tp_name */ + sizeof(BPy_ViewMap), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)ViewMap_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)ViewMap_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewMap_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewMap_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewMap_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewMap_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_ViewMap.h b/source/blender/freestyle/intern/python/BPy_ViewMap.h index f3659a096ab..fe1cd39deb3 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewMap.h +++ b/source/blender/freestyle/intern/python/BPy_ViewMap.h @@ -41,8 +41,7 @@ extern PyTypeObject ViewMap_Type; /*---------------------------Python BPy_ViewMap structure definition----------*/ typedef struct { - PyObject_HEAD - ViewMap *vm; + PyObject_HEAD ViewMap *vm; } BPy_ViewMap; /*---------------------------Python BPy_ViewMap visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index 1cd55f512f7..743a0ba79dc 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -35,336 +35,355 @@ extern "C" { int ViewShape_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&ViewShape_Type) < 0) - return -1; - Py_INCREF(&ViewShape_Type); - PyModule_AddObject(module, "ViewShape", (PyObject *)&ViewShape_Type); + if (PyType_Ready(&ViewShape_Type) < 0) + return -1; + Py_INCREF(&ViewShape_Type); + PyModule_AddObject(module, "ViewShape", (PyObject *)&ViewShape_Type); - return 0; + return 0; } /*----------------------ViewShape methods ----------------------------*/ PyDoc_STRVAR(ViewShape_doc, -"Class gathering the elements of the ViewMap (i.e., :class:`ViewVertex`\n" -"and :class:`ViewEdge`) that are issued from the same input shape.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ViewShape object.\n" -" :type brother: :class:`ViewShape`\n" -"\n" -".. method:: __init__(sshape)\n" -"\n" -" Builds a ViewShape from an SShape.\n" -"\n" -" :arg sshape: An SShape object.\n" -" :type sshape: :class:`SShape`"); + "Class gathering the elements of the ViewMap (i.e., :class:`ViewVertex`\n" + "and :class:`ViewEdge`) that are issued from the same input shape.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ViewShape object.\n" + " :type brother: :class:`ViewShape`\n" + "\n" + ".. method:: __init__(sshape)\n" + "\n" + " Builds a ViewShape from an SShape.\n" + "\n" + " :arg sshape: An SShape object.\n" + " :type sshape: :class:`SShape`"); static int ViewShape_init(BPy_ViewShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"sshape", NULL}; - PyObject *obj = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &ViewShape_Type, &obj)) { - if (!obj) { - self->vs = new ViewShape(); - self->py_ss = NULL; - } - else { - self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs)); - self->py_ss = ((BPy_ViewShape *)obj)->py_ss; - } - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &SShape_Type, &obj)) - { - BPy_SShape *py_ss = (BPy_SShape *)obj; - self->vs = new ViewShape(py_ss->ss); - self->py_ss = (!py_ss->borrowed) ? py_ss : NULL; - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->borrowed = false; - Py_XINCREF(self->py_ss); - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"sshape", NULL}; + PyObject *obj = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &ViewShape_Type, &obj)) { + if (!obj) { + self->vs = new ViewShape(); + self->py_ss = NULL; + } + else { + self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs)); + self->py_ss = ((BPy_ViewShape *)obj)->py_ss; + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &SShape_Type, &obj)) { + BPy_SShape *py_ss = (BPy_SShape *)obj; + self->vs = new ViewShape(py_ss->ss); + self->py_ss = (!py_ss->borrowed) ? py_ss : NULL; + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->borrowed = false; + Py_XINCREF(self->py_ss); + return 0; } static void ViewShape_dealloc(BPy_ViewShape *self) { - if (self->py_ss) { - self->vs->setSShape((SShape *)NULL); - Py_DECREF(self->py_ss); - } - if (self->vs && !self->borrowed) - delete self->vs; - Py_TYPE(self)->tp_free((PyObject *)self); + if (self->py_ss) { + self->vs->setSShape((SShape *)NULL); + Py_DECREF(self->py_ss); + } + if (self->vs && !self->borrowed) + delete self->vs; + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject *ViewShape_repr(BPy_ViewShape *self) { - return PyUnicode_FromFormat("ViewShape - address: %p", self->vs); + return PyUnicode_FromFormat("ViewShape - address: %p", self->vs); } PyDoc_STRVAR(ViewShape_add_edge_doc, -".. method:: add_edge(edge)\n" -"\n" -" Adds a ViewEdge to the list of ViewEdge objects.\n" -"\n" -" :arg edge: A ViewEdge object.\n" -" :type edge: :class:`ViewEdge`\n"); + ".. method:: add_edge(edge)\n" + "\n" + " Adds a ViewEdge to the list of ViewEdge objects.\n" + "\n" + " :arg edge: A ViewEdge object.\n" + " :type edge: :class:`ViewEdge`\n"); static PyObject *ViewShape_add_edge(BPy_ViewShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"edge", NULL}; - PyObject *py_ve = 0; + static const char *kwlist[] = {"edge", NULL}; + PyObject *py_ve = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) - return NULL; - self->vs->AddEdge(((BPy_ViewEdge *)py_ve)->ve); - Py_RETURN_NONE; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) + return NULL; + self->vs->AddEdge(((BPy_ViewEdge *)py_ve)->ve); + Py_RETURN_NONE; } PyDoc_STRVAR(ViewShape_add_vertex_doc, -".. method:: add_vertex(vertex)\n" -"\n" -" Adds a ViewVertex to the list of the ViewVertex objects.\n" -"\n" -" :arg vertex: A ViewVertex object.\n" -" :type vertex: :class:`ViewVertex`"); + ".. method:: add_vertex(vertex)\n" + "\n" + " Adds a ViewVertex to the list of the ViewVertex objects.\n" + "\n" + " :arg vertex: A ViewVertex object.\n" + " :type vertex: :class:`ViewVertex`"); static PyObject *ViewShape_add_vertex(BPy_ViewShape *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"vertex", NULL}; - PyObject *py_vv = 0; + static const char *kwlist[] = {"vertex", NULL}; + PyObject *py_vv = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewVertex_Type, &py_vv)) - return NULL; - self->vs->AddVertex(((BPy_ViewVertex *)py_vv)->vv); - Py_RETURN_NONE; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewVertex_Type, &py_vv)) + return NULL; + self->vs->AddVertex(((BPy_ViewVertex *)py_vv)->vv); + Py_RETURN_NONE; } // virtual ViewShape *duplicate() static PyMethodDef BPy_ViewShape_methods[] = { - {"add_edge", (PyCFunction)ViewShape_add_edge, METH_VARARGS | METH_KEYWORDS, ViewShape_add_edge_doc}, - {"add_vertex", (PyCFunction)ViewShape_add_vertex, METH_VARARGS | METH_KEYWORDS, ViewShape_add_vertex_doc}, - {NULL, NULL, 0, NULL}, + {"add_edge", + (PyCFunction)ViewShape_add_edge, + METH_VARARGS | METH_KEYWORDS, + ViewShape_add_edge_doc}, + {"add_vertex", + (PyCFunction)ViewShape_add_vertex, + METH_VARARGS | METH_KEYWORDS, + ViewShape_add_vertex_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewShape get/setters ----------------------------*/ PyDoc_STRVAR(ViewShape_sshape_doc, -"The SShape on top of which this ViewShape is built.\n" -"\n" -":type: :class:`SShape`"); + "The SShape on top of which this ViewShape is built.\n" + "\n" + ":type: :class:`SShape`"); static PyObject *ViewShape_sshape_get(BPy_ViewShape *self, void *UNUSED(closure)) { - SShape *ss = self->vs->sshape(); - if (!ss) - Py_RETURN_NONE; - return BPy_SShape_from_SShape(*ss); + SShape *ss = self->vs->sshape(); + if (!ss) + Py_RETURN_NONE; + return BPy_SShape_from_SShape(*ss); } static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SShape_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SShape"); - return -1; - } - BPy_SShape *py_ss = (BPy_SShape *)value; - self->vs->setSShape(py_ss->ss); - if (self->py_ss) - Py_DECREF(self->py_ss); - if (!py_ss->borrowed) { - self->py_ss = py_ss; - Py_INCREF(self->py_ss); - } - return 0; + if (!BPy_SShape_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SShape"); + return -1; + } + BPy_SShape *py_ss = (BPy_SShape *)value; + self->vs->setSShape(py_ss->ss); + if (self->py_ss) + Py_DECREF(self->py_ss); + if (!py_ss->borrowed) { + self->py_ss = py_ss; + Py_INCREF(self->py_ss); + } + return 0; } PyDoc_STRVAR(ViewShape_vertices_doc, -"The list of ViewVertex objects contained in this ViewShape.\n" -"\n" -":type: List of :class:`ViewVertex` objects"); + "The list of ViewVertex objects contained in this ViewShape.\n" + "\n" + ":type: List of :class:`ViewVertex` objects"); static PyObject *ViewShape_vertices_get(BPy_ViewShape *self, void *UNUSED(closure)) { - vector vertices = self->vs->vertices(); - vector::iterator it; - PyObject *py_vertices = PyList_New(vertices.size()); - unsigned int i = 0; - - for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_SET_ITEM(py_vertices, i++, Any_BPy_ViewVertex_from_ViewVertex(*(*it))); - } - return py_vertices; + vector vertices = self->vs->vertices(); + vector::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; + + for (it = vertices.begin(); it != vertices.end(); it++) { + PyList_SET_ITEM(py_vertices, i++, Any_BPy_ViewVertex_from_ViewVertex(*(*it))); + } + return py_vertices; } static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure)) { - PyObject *item; - vector< ViewVertex *> v; - - if (!PyList_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); - return -1; - } - - v.reserve(PyList_GET_SIZE(value)); - for (unsigned int i = 0; i < PyList_GET_SIZE(value); i++) { - item = PyList_GET_ITEM(value, i); - if (BPy_ViewVertex_Check(item)) { - v.push_back(((BPy_ViewVertex *)item)->vv); - } - else { - PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); - return -1; - } - } - self->vs->setVertices(v); - return 0; + PyObject *item; + vector v; + + if (!PyList_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); + return -1; + } + + v.reserve(PyList_GET_SIZE(value)); + for (unsigned int i = 0; i < PyList_GET_SIZE(value); i++) { + item = PyList_GET_ITEM(value, i); + if (BPy_ViewVertex_Check(item)) { + v.push_back(((BPy_ViewVertex *)item)->vv); + } + else { + PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); + return -1; + } + } + self->vs->setVertices(v); + return 0; } PyDoc_STRVAR(ViewShape_edges_doc, -"The list of ViewEdge objects contained in this ViewShape.\n" -"\n" -":type: List of :class:`ViewEdge` objects"); + "The list of ViewEdge objects contained in this ViewShape.\n" + "\n" + ":type: List of :class:`ViewEdge` objects"); static PyObject *ViewShape_edges_get(BPy_ViewShape *self, void *UNUSED(closure)) { - vector edges = self->vs->edges(); - vector::iterator it; - PyObject *py_edges = PyList_New(edges.size()); - unsigned int i = 0; - - for (it = edges.begin(); it != edges.end(); it++) { - PyList_SET_ITEM(py_edges, i++, BPy_ViewEdge_from_ViewEdge(*(*it))); - } - return py_edges; + vector edges = self->vs->edges(); + vector::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; + + for (it = edges.begin(); it != edges.end(); it++) { + PyList_SET_ITEM(py_edges, i++, BPy_ViewEdge_from_ViewEdge(*(*it))); + } + return py_edges; } static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure)) { - PyObject *item; - vector v; - - if (!PyList_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects"); - return -1; - } - - v.reserve(PyList_GET_SIZE(value)); - for (int i = 0; i < PyList_GET_SIZE(value); i++) { - item = PyList_GET_ITEM(value, i); - if (BPy_ViewEdge_Check(item)) { - v.push_back(((BPy_ViewEdge *)item)->ve); - } - else { - PyErr_SetString(PyExc_TypeError, "argument must be list of ViewEdge objects"); - return -1; - } - } - self->vs->setEdges(v); - return 0; + PyObject *item; + vector v; + + if (!PyList_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects"); + return -1; + } + + v.reserve(PyList_GET_SIZE(value)); + for (int i = 0; i < PyList_GET_SIZE(value); i++) { + item = PyList_GET_ITEM(value, i); + if (BPy_ViewEdge_Check(item)) { + v.push_back(((BPy_ViewEdge *)item)->ve); + } + else { + PyErr_SetString(PyExc_TypeError, "argument must be list of ViewEdge objects"); + return -1; + } + } + self->vs->setEdges(v); + return 0; } PyDoc_STRVAR(ViewShape_name_doc, -"The name of the ViewShape.\n" -"\n" -":type: str"); + "The name of the ViewShape.\n" + "\n" + ":type: str"); static PyObject *ViewShape_name_get(BPy_ViewShape *self, void *UNUSED(closure)) { - return PyUnicode_FromString(self->vs->getName().c_str()); + return PyUnicode_FromString(self->vs->getName().c_str()); } PyDoc_STRVAR(ViewShape_library_path_doc, -"The library path of the ViewShape.\n" -"\n" -":type: str, or None if the ViewShape is not part of a library"); + "The library path of the ViewShape.\n" + "\n" + ":type: str, or None if the ViewShape is not part of a library"); static PyObject *ViewShape_library_path_get(BPy_ViewShape *self, void *UNUSED(closure)) { - return PyUnicode_FromString(self->vs->getLibraryPath().c_str()); + return PyUnicode_FromString(self->vs->getLibraryPath().c_str()); } PyDoc_STRVAR(ViewShape_id_doc, -"The Id of this ViewShape.\n" -"\n" -":type: :class:`Id`"); + "The Id of this ViewShape.\n" + "\n" + ":type: :class:`Id`"); static PyObject *ViewShape_id_get(BPy_ViewShape *self, void *UNUSED(closure)) { - Id id(self->vs->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->vs->getId()); + return BPy_Id_from_Id(id); // return a copy } static PyGetSetDef BPy_ViewShape_getseters[] = { - {(char *)"sshape", (getter)ViewShape_sshape_get, (setter)ViewShape_sshape_set, (char *)ViewShape_sshape_doc, NULL}, - {(char *)"vertices", (getter)ViewShape_vertices_get, (setter)ViewShape_vertices_set, - (char *)ViewShape_vertices_doc, NULL}, - {(char *)"edges", (getter)ViewShape_edges_get, (setter)ViewShape_edges_set, (char *)ViewShape_edges_doc, NULL}, - {(char *)"name", (getter)ViewShape_name_get, (setter)NULL, (char *)ViewShape_name_doc, NULL}, - {(char *)"library_path", (getter)ViewShape_library_path_get, (setter)NULL, (char *)ViewShape_library_path_doc, NULL}, - {(char *)"id", (getter)ViewShape_id_get, (setter)NULL, (char *)ViewShape_id_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"sshape", + (getter)ViewShape_sshape_get, + (setter)ViewShape_sshape_set, + (char *)ViewShape_sshape_doc, + NULL}, + {(char *)"vertices", + (getter)ViewShape_vertices_get, + (setter)ViewShape_vertices_set, + (char *)ViewShape_vertices_doc, + NULL}, + {(char *)"edges", + (getter)ViewShape_edges_get, + (setter)ViewShape_edges_set, + (char *)ViewShape_edges_doc, + NULL}, + {(char *)"name", (getter)ViewShape_name_get, (setter)NULL, (char *)ViewShape_name_doc, NULL}, + {(char *)"library_path", + (getter)ViewShape_library_path_get, + (setter)NULL, + (char *)ViewShape_library_path_doc, + NULL}, + {(char *)"id", (getter)ViewShape_id_get, (setter)NULL, (char *)ViewShape_id_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewShape type definition ------------------------------*/ PyTypeObject ViewShape_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewShape", /* tp_name */ - sizeof(BPy_ViewShape), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)ViewShape_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)ViewShape_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewShape_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewShape_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewShape_getseters, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewShape_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewShape", /* tp_name */ + sizeof(BPy_ViewShape), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)ViewShape_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)ViewShape_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewShape_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewShape_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewShape_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewShape_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.h b/source/blender/freestyle/intern/python/BPy_ViewShape.h index 551e16c4438..3158353136f 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.h +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.h @@ -43,10 +43,9 @@ extern PyTypeObject ViewShape_Type; /*---------------------------Python BPy_ViewShape structure definition----------*/ typedef struct { - PyObject_HEAD - ViewShape *vs; - bool borrowed; /* true if *vs a borrowed object */ - BPy_SShape *py_ss; + PyObject_HEAD ViewShape *vs; + bool borrowed; /* true if *vs a borrowed object */ + BPy_SShape *py_ss; } BPy_ViewShape; /*---------------------------Python BPy_ViewShape visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.cpp index 0a84e3d5144..f8b2d5a1ab5 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.cpp @@ -29,69 +29,68 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char FalseBP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Always returns false.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`freestyle.types.Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`freestyle.types.Interface1D`\n" -" :return: False.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Always returns false.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`freestyle.types.Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`freestyle.types.Interface1D`\n" + " :return: False.\n" + " :rtype: bool\n"; static int FalseBP1D___init__(BPy_FalseBP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_bp1D.bp1D = new Predicates1D::FalseBP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_bp1D.bp1D = new Predicates1D::FalseBP1D(); + return 0; } /*-----------------------BPy_FalseBP1D type definition ------------------------------*/ PyTypeObject FalseBP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FalseBP1D", /* tp_name */ - sizeof(BPy_FalseBP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FalseBP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &BinaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FalseBP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FalseBP1D", /* tp_name */ + sizeof(BPy_FalseBP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FalseBP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &BinaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FalseBP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.h index 120cda356c4..abb9eca9b30 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_FalseBP1D.h @@ -35,7 +35,7 @@ extern PyTypeObject FalseBP1D_Type; /*---------------------------Python BPy_FalseBP1D structure definition----------*/ typedef struct { - BPy_BinaryPredicate1D py_bp1D; + BPy_BinaryPredicate1D py_bp1D; } BPy_FalseBP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.cpp index 50046fa0e1c..7387252bfd0 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.cpp @@ -29,71 +29,70 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Length2DBP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`Length2DBP1D`\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Returns true if the 2D length of inter1 is less than the 2D length\n" -" of inter2.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`freestyle.types.Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`freestyle.types.Interface1D`\n" -" :return: True or false.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`Length2DBP1D`\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Returns true if the 2D length of inter1 is less than the 2D length\n" + " of inter2.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`freestyle.types.Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`freestyle.types.Interface1D`\n" + " :return: True or false.\n" + " :rtype: bool\n"; static int Length2DBP1D___init__(BPy_Length2DBP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_bp1D.bp1D = new Predicates1D::Length2DBP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_bp1D.bp1D = new Predicates1D::Length2DBP1D(); + return 0; } /*-----------------------BPy_Length2DBP1D type definition ------------------------------*/ PyTypeObject Length2DBP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Length2DBP1D", /* tp_name */ - sizeof(BPy_Length2DBP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Length2DBP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &BinaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Length2DBP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Length2DBP1D", /* tp_name */ + sizeof(BPy_Length2DBP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Length2DBP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &BinaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Length2DBP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.h index 3e73dfa9ad4..6ad2373c570 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_Length2DBP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject Length2DBP1D_Type; -#define BPy_Length2DBP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Length2DBP1D_Type)) +#define BPy_Length2DBP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Length2DBP1D_Type)) /*---------------------------Python BPy_Length2DBP1D structure definition----------*/ typedef struct { - BPy_BinaryPredicate1D py_bp1D; + BPy_BinaryPredicate1D py_bp1D; } BPy_Length2DBP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.cpp index cee814e62de..005bbded74f 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.cpp @@ -29,70 +29,69 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char SameShapeIdBP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`SameShapeIdBP1D`\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Returns true if inter1 and inter2 belong to the same shape.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`freestyle.types.Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`freestyle.types.Interface1D`\n" -" :return: True or false.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`SameShapeIdBP1D`\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Returns true if inter1 and inter2 belong to the same shape.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`freestyle.types.Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`freestyle.types.Interface1D`\n" + " :return: True or false.\n" + " :rtype: bool\n"; static int SameShapeIdBP1D___init__(BPy_SameShapeIdBP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_bp1D.bp1D = new Predicates1D::SameShapeIdBP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_bp1D.bp1D = new Predicates1D::SameShapeIdBP1D(); + return 0; } /*-----------------------BPy_SameShapeIdBP1D type definition ------------------------------*/ PyTypeObject SameShapeIdBP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SameShapeIdBP1D", /* tp_name */ - sizeof(BPy_SameShapeIdBP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SameShapeIdBP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &BinaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SameShapeIdBP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SameShapeIdBP1D", /* tp_name */ + sizeof(BPy_SameShapeIdBP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SameShapeIdBP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &BinaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SameShapeIdBP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.h index f20c4b48fb8..75fc5eaa271 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_SameShapeIdBP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject SameShapeIdBP1D_Type; -#define BPy_SameShapeIdBP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SameShapeIdBP1D_Type)) +#define BPy_SameShapeIdBP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SameShapeIdBP1D_Type)) /*---------------------------Python BPy_SameShapeIdBP1D structure definition----------*/ typedef struct { - BPy_BinaryPredicate1D py_bp1D; + BPy_BinaryPredicate1D py_bp1D; } BPy_SameShapeIdBP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.cpp index 1375aa2d549..363c0386915 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.cpp @@ -29,70 +29,69 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char TrueBP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`TrueBP1D`\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Always returns true.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`freestyle.types.Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`freestyle.types.Interface1D`\n" -" :return: True.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`TrueBP1D`\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Always returns true.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`freestyle.types.Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`freestyle.types.Interface1D`\n" + " :return: True.\n" + " :rtype: bool\n"; static int TrueBP1D___init__(BPy_TrueBP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_bp1D.bp1D = new Predicates1D::TrueBP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_bp1D.bp1D = new Predicates1D::TrueBP1D(); + return 0; } /*-----------------------BPy_TrueBP1D type definition ------------------------------*/ PyTypeObject TrueBP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TrueBP1D", /* tp_name */ - sizeof(BPy_TrueBP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TrueBP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &BinaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TrueBP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TrueBP1D", /* tp_name */ + sizeof(BPy_TrueBP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TrueBP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &BinaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TrueBP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.h index 66fb7bc254d..ed6a783fa47 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_TrueBP1D.h @@ -35,7 +35,7 @@ extern PyTypeObject TrueBP1D_Type; /*---------------------------Python BPy_TrueBP1D structure definition----------*/ typedef struct { - BPy_BinaryPredicate1D py_bp1D; + BPy_BinaryPredicate1D py_bp1D; } BPy_TrueBP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.cpp b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.cpp index a7e5e7295a2..2068fe820d0 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.cpp +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.cpp @@ -34,91 +34,94 @@ extern "C" { //ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0) static char ViewMapGradientNormBP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`ViewMapGradientNormBP1D`\n" -"\n" -".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a ViewMapGradientNormBP1D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain:\n" -" GetViewMapGradientNormF0D is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter1, inter2)\n" -"\n" -" Returns true if the evaluation of the Gradient norm Function is\n" -" higher for inter1 than for inter2.\n" -"\n" -" :arg inter1: The first Interface1D object.\n" -" :type inter1: :class:`freestyle.types.Interface1D`\n" -" :arg inter2: The second Interface1D object.\n" -" :type inter2: :class:`freestyle.types.Interface1D`\n" -" :return: True or false.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > " + ":class:`ViewMapGradientNormBP1D`\n" + "\n" + ".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" + "\n" + " Builds a ViewMapGradientNormBP1D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain:\n" + " GetViewMapGradientNormF0D is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter1, inter2)\n" + "\n" + " Returns true if the evaluation of the Gradient norm Function is\n" + " higher for inter1 than for inter2.\n" + "\n" + " :arg inter1: The first Interface1D object.\n" + " :type inter1: :class:`freestyle.types.Interface1D`\n" + " :arg inter2: The second Interface1D object.\n" + " :type inter2: :class:`freestyle.types.Interface1D`\n" + " :return: True or false.\n" + " :rtype: bool\n"; -static int ViewMapGradientNormBP1D___init__(BPy_ViewMapGradientNormBP1D *self, PyObject *args, PyObject *kwds) +static int ViewMapGradientNormBP1D___init__(BPy_ViewMapGradientNormBP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - int i; - float f = 2.0; + static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + int i; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_bp1D.bp1D = new Predicates1D::ViewMapGradientNormBP1D(i, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_bp1D.bp1D = new Predicates1D::ViewMapGradientNormBP1D(i, t, f); + return 0; } /*-----------------------BPy_ViewMapGradientNormBP1D type definition ------------------------------*/ PyTypeObject ViewMapGradientNormBP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewMapGradientNormBP1D", /* tp_name */ - sizeof(BPy_ViewMapGradientNormBP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewMapGradientNormBP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &BinaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewMapGradientNormBP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewMapGradientNormBP1D", /* tp_name */ + sizeof(BPy_ViewMapGradientNormBP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewMapGradientNormBP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &BinaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewMapGradientNormBP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.h b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.h index 7d7fce837db..1a451a688fb 100644 --- a/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.h +++ b/source/blender/freestyle/intern/python/BinaryPredicate1D/BPy_ViewMapGradientNormBP1D.h @@ -32,11 +32,11 @@ extern "C" { extern PyTypeObject ViewMapGradientNormBP1D_Type; #define BPy_ViewMapGradientNormBP1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewMapGradientNormBP1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewMapGradientNormBP1D_Type)) /*---------------------------Python BPy_ViewMapGradientNormBP1D structure definition----------*/ typedef struct { - BPy_BinaryPredicate1D py_bp1D; + BPy_BinaryPredicate1D py_bp1D; } BPy_ViewMapGradientNormBP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index f4e174af761..c86602c78b1 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -57,271 +57,275 @@ #include "UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.h" // BinaryPredicate0D: __call__ -int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, Interface0D& i1, Interface0D& i2) +int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, + Interface0D &i1, + Interface0D &i2) { - if (!bp0D->py_bp0D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp0D) not initialized"); - return -1; - } - PyObject *arg1 = Any_BPy_Interface0D_from_Interface0D(i1); - PyObject *arg2 = Any_BPy_Interface0D_from_Interface0D(i2); - if (!arg1 || !arg2) { - Py_XDECREF(arg1); - Py_XDECREF(arg2); - return -1; - } - PyObject *result = PyObject_CallMethod((PyObject *)bp0D->py_bp0D, "__call__", "OO", arg1, arg2); - Py_DECREF(arg1); - Py_DECREF(arg2); - if (!result) - return -1; - int ret = PyObject_IsTrue(result); - Py_DECREF(result); - if (ret < 0) - return -1; - bp0D->result = ret; - return 0; + if (!bp0D->py_bp0D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp0D) not initialized"); + return -1; + } + PyObject *arg1 = Any_BPy_Interface0D_from_Interface0D(i1); + PyObject *arg2 = Any_BPy_Interface0D_from_Interface0D(i2); + if (!arg1 || !arg2) { + Py_XDECREF(arg1); + Py_XDECREF(arg2); + return -1; + } + PyObject *result = PyObject_CallMethod((PyObject *)bp0D->py_bp0D, "__call__", "OO", arg1, arg2); + Py_DECREF(arg1); + Py_DECREF(arg2); + if (!result) + return -1; + int ret = PyObject_IsTrue(result); + Py_DECREF(result); + if (ret < 0) + return -1; + bp0D->result = ret; + return 0; } // BinaryPredicate1D: __call__ -int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, Interface1D& i1, Interface1D& i2) +int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, + Interface1D &i1, + Interface1D &i2) { - if (!bp1D->py_bp1D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp1D) not initialized"); - return -1; - } - PyObject *arg1 = Any_BPy_Interface1D_from_Interface1D(i1); - PyObject *arg2 = Any_BPy_Interface1D_from_Interface1D(i2); - if (!arg1 || !arg2) { - Py_XDECREF(arg1); - Py_XDECREF(arg2); - return -1; - } - PyObject *result = PyObject_CallMethod((PyObject *)bp1D->py_bp1D, "__call__", "OO", arg1, arg2); - Py_DECREF(arg1); - Py_DECREF(arg2); - if (!result) - return -1; - int ret = PyObject_IsTrue(result); - Py_DECREF(result); - if (ret < 0) - return -1; - bp1D->result = ret; - return 0; + if (!bp1D->py_bp1D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp1D) not initialized"); + return -1; + } + PyObject *arg1 = Any_BPy_Interface1D_from_Interface1D(i1); + PyObject *arg2 = Any_BPy_Interface1D_from_Interface1D(i2); + if (!arg1 || !arg2) { + Py_XDECREF(arg1); + Py_XDECREF(arg2); + return -1; + } + PyObject *result = PyObject_CallMethod((PyObject *)bp1D->py_bp1D, "__call__", "OO", arg1, arg2); + Py_DECREF(arg1); + Py_DECREF(arg2); + if (!result) + return -1; + int ret = PyObject_IsTrue(result); + Py_DECREF(result); + if (ret < 0) + return -1; + bp1D->result = ret; + return 0; } // UnaryPredicate0D: __call__ -int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator& if0D_it) +int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator &if0D_it) { - if (!up0D->py_up0D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up0D) not initialized"); - return -1; - } - PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod((PyObject *)up0D->py_up0D, "__call__", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - int ret = PyObject_IsTrue(result); - Py_DECREF(result); - if (ret < 0) - return -1; - up0D->result = ret; - return 0; + if (!up0D->py_up0D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up0D) not initialized"); + return -1; + } + PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod((PyObject *)up0D->py_up0D, "__call__", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + int ret = PyObject_IsTrue(result); + Py_DECREF(result); + if (ret < 0) + return -1; + up0D->result = ret; + return 0; } // UnaryPredicate1D: __call__ -int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D& if1D) +int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D &if1D) { - if (!up1D->py_up1D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up1D) not initialized"); - return -1; - } - PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod((PyObject *)up1D->py_up1D, "__call__", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - int ret = PyObject_IsTrue(result); - Py_DECREF(result); - if (ret < 0) - return -1; - up1D->result = ret; - return 0; + if (!up1D->py_up1D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up1D) not initialized"); + return -1; + } + PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod((PyObject *)up1D->py_up1D, "__call__", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + int ret = PyObject_IsTrue(result); + Py_DECREF(result); + if (ret < 0) + return -1; + up1D->result = ret; + return 0; } // StrokeShader: shade -int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke& s) +int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke &s) { - if (!ss->py_ss) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_ss) not initialized"); - return -1; - } - PyObject *arg = BPy_Stroke_from_Stroke(s); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod((PyObject *)ss->py_ss, "shade", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - Py_DECREF(result); - return 0; + if (!ss->py_ss) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_ss) not initialized"); + return -1; + } + PyObject *arg = BPy_Stroke_from_Stroke(s); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod((PyObject *)ss->py_ss, "shade", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + Py_DECREF(result); + return 0; } // ChainingIterator: init, traverse int Director_BPy_ChainingIterator_init(ChainingIterator *c_it) { - if (!c_it->py_c_it) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized"); - return -1; - } - PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "init", NULL); - if (!result) - return -1; - Py_DECREF(result); - return 0; + if (!c_it->py_c_it) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized"); + return -1; + } + PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "init", NULL); + if (!result) + return -1; + Py_DECREF(result); + return 0; } -int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator& a_it) +int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it) { - if (!c_it->py_c_it) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized"); - return -1; - } - PyObject *arg = BPy_AdjacencyIterator_from_AdjacencyIterator(a_it); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "traverse", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - if (BPy_ViewEdge_Check(result)) { - c_it->result = ((BPy_ViewEdge *)result)->ve; - } - else if (result == Py_None) { - c_it->result = NULL; - } - else { - PyErr_SetString(PyExc_RuntimeError, "traverse method returned a wrong value"); - Py_DECREF(result); - return -1; - } - Py_DECREF(result); - return 0; + if (!c_it->py_c_it) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized"); + return -1; + } + PyObject *arg = BPy_AdjacencyIterator_from_AdjacencyIterator(a_it); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "traverse", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + if (BPy_ViewEdge_Check(result)) { + c_it->result = ((BPy_ViewEdge *)result)->ve; + } + else if (result == Py_None) { + c_it->result = NULL; + } + else { + PyErr_SetString(PyExc_RuntimeError, "traverse method returned a wrong value"); + Py_DECREF(result); + return -1; + } + Py_DECREF(result); + return 0; } // BPy_UnaryFunction{0D,1D}: __call__ -int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator& if0D_it) +int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it) { - if (!py_uf0D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf0D) not initialized"); - return -1; - } - PyObject *obj = (PyObject *)py_uf0D; - PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - if (BPy_UnaryFunction0DDouble_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = PyFloat_AsDouble(result); - } - else if (BPy_UnaryFunction0DEdgeNature_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = EdgeNature_from_BPy_Nature(result); - } - else if (BPy_UnaryFunction0DFloat_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = PyFloat_AsDouble(result); - } - else if (BPy_UnaryFunction0DId_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = *(((BPy_Id *)result)->id); - } - else if (BPy_UnaryFunction0DMaterial_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = *(((BPy_FrsMaterial *)result)->m); - } - else if (BPy_UnaryFunction0DUnsigned_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = PyLong_AsLong(result); - } - else if (BPy_UnaryFunction0DVec2f_Check(obj)) { - Vec2f vec; - if (!Vec2f_ptr_from_Vector(result, vec)) - return -1; - ((UnaryFunction0D *)uf0D)->result = vec; - } - else if (BPy_UnaryFunction0DVec3f_Check(obj)) { - Vec3f vec; - if (!Vec3f_ptr_from_Vector(result, vec)) - return -1; - ((UnaryFunction0D *)uf0D)->result = vec; - } - else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) { - vector vec; - vec.reserve(PyList_Size(result)); - for (int i = 0; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; - vec.push_back(b); - } - ((UnaryFunction0D< vector > *)uf0D)->result = vec; - } - else if (BPy_UnaryFunction0DViewShape_Check(obj)) { - ((UnaryFunction0D *)uf0D)->result = ((BPy_ViewShape *)result)->vs; - } - Py_DECREF(result); - return 0; + if (!py_uf0D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf0D) not initialized"); + return -1; + } + PyObject *obj = (PyObject *)py_uf0D; + PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + if (BPy_UnaryFunction0DDouble_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = PyFloat_AsDouble(result); + } + else if (BPy_UnaryFunction0DEdgeNature_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = EdgeNature_from_BPy_Nature(result); + } + else if (BPy_UnaryFunction0DFloat_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = PyFloat_AsDouble(result); + } + else if (BPy_UnaryFunction0DId_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = *(((BPy_Id *)result)->id); + } + else if (BPy_UnaryFunction0DMaterial_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = *(((BPy_FrsMaterial *)result)->m); + } + else if (BPy_UnaryFunction0DUnsigned_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = PyLong_AsLong(result); + } + else if (BPy_UnaryFunction0DVec2f_Check(obj)) { + Vec2f vec; + if (!Vec2f_ptr_from_Vector(result, vec)) + return -1; + ((UnaryFunction0D *)uf0D)->result = vec; + } + else if (BPy_UnaryFunction0DVec3f_Check(obj)) { + Vec3f vec; + if (!Vec3f_ptr_from_Vector(result, vec)) + return -1; + ((UnaryFunction0D *)uf0D)->result = vec; + } + else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) { + vector vec; + vec.reserve(PyList_Size(result)); + for (int i = 0; i < PyList_Size(result); i++) { + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; + vec.push_back(b); + } + ((UnaryFunction0D> *)uf0D)->result = vec; + } + else if (BPy_UnaryFunction0DViewShape_Check(obj)) { + ((UnaryFunction0D *)uf0D)->result = ((BPy_ViewShape *)result)->vs; + } + Py_DECREF(result); + return 0; } -int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D& if1D) +int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D) { - if (!py_uf1D) { // internal error - PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf1D) not initialized"); - return -1; - } - PyObject *obj = (PyObject *)py_uf1D; - PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D); - if (!arg) - return -1; - PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg); - Py_DECREF(arg); - if (!result) - return -1; - if (BPy_UnaryFunction1DDouble_Check(obj)) { - ((UnaryFunction1D *)uf1D)->result = PyFloat_AsDouble(result); - } - else if (BPy_UnaryFunction1DEdgeNature_Check(obj)) { - ((UnaryFunction1D *)uf1D)->result = EdgeNature_from_BPy_Nature(result); - } - else if (BPy_UnaryFunction1DFloat_Check(obj)) { - ((UnaryFunction1D *)uf1D)->result = PyFloat_AsDouble(result); - } - else if (BPy_UnaryFunction1DUnsigned_Check(obj)) { - ((UnaryFunction1D *)uf1D)->result = PyLong_AsLong(result); - } - else if (BPy_UnaryFunction1DVec2f_Check(obj)) { - Vec2f vec; - if (!Vec2f_ptr_from_Vector(result, vec)) - return -1; - ((UnaryFunction1D *)uf1D)->result = vec; - } - else if (BPy_UnaryFunction1DVec3f_Check(obj)) { - Vec3f vec; - if (!Vec3f_ptr_from_Vector(result, vec)) - return -1; - ((UnaryFunction1D *)uf1D)->result = vec; - } - else if (BPy_UnaryFunction1DVectorViewShape_Check(obj)) { - vector vec; - vec.reserve(PyList_Size(result)); - for (int i = 1; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; - vec.push_back(b); - } - ((UnaryFunction1D< vector > *)uf1D)->result = vec; - } - Py_DECREF(result); - return 0; + if (!py_uf1D) { // internal error + PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf1D) not initialized"); + return -1; + } + PyObject *obj = (PyObject *)py_uf1D; + PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D); + if (!arg) + return -1; + PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg); + Py_DECREF(arg); + if (!result) + return -1; + if (BPy_UnaryFunction1DDouble_Check(obj)) { + ((UnaryFunction1D *)uf1D)->result = PyFloat_AsDouble(result); + } + else if (BPy_UnaryFunction1DEdgeNature_Check(obj)) { + ((UnaryFunction1D *)uf1D)->result = EdgeNature_from_BPy_Nature(result); + } + else if (BPy_UnaryFunction1DFloat_Check(obj)) { + ((UnaryFunction1D *)uf1D)->result = PyFloat_AsDouble(result); + } + else if (BPy_UnaryFunction1DUnsigned_Check(obj)) { + ((UnaryFunction1D *)uf1D)->result = PyLong_AsLong(result); + } + else if (BPy_UnaryFunction1DVec2f_Check(obj)) { + Vec2f vec; + if (!Vec2f_ptr_from_Vector(result, vec)) + return -1; + ((UnaryFunction1D *)uf1D)->result = vec; + } + else if (BPy_UnaryFunction1DVec3f_Check(obj)) { + Vec3f vec; + if (!Vec3f_ptr_from_Vector(result, vec)) + return -1; + ((UnaryFunction1D *)uf1D)->result = vec; + } + else if (BPy_UnaryFunction1DVectorViewShape_Check(obj)) { + vector vec; + vec.reserve(PyList_Size(result)); + for (int i = 1; i < PyList_Size(result); i++) { + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; + vec.push_back(b); + } + ((UnaryFunction1D> *)uf1D)->result = vec; + } + Py_DECREF(result); + return 0; } diff --git a/source/blender/freestyle/intern/python/Director.h b/source/blender/freestyle/intern/python/Director.h index cf89b7f84e6..5c087e411ff 100644 --- a/source/blender/freestyle/intern/python/Director.h +++ b/source/blender/freestyle/intern/python/Director.h @@ -33,31 +33,35 @@ class Interface1D; class Interface0DIterator; class Stroke; class StrokeShader; -} +} // namespace Freestyle using namespace Freestyle; // BinaryPredicate0D: __call__ -int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, Interface0D& i1, Interface0D& i2); +int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, + Interface0D &i1, + Interface0D &i2); // BinaryPredicate1D: __call__ -int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, Interface1D& i1, Interface1D& i2); +int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, + Interface1D &i1, + Interface1D &i2); // UnaryFunction{0D,1D}: __call__ -int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator& if0D_it); -int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D& if1D); +int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it); +int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D); // UnaryPredicate0D: __call__ -int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator& if0D_it); +int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator &if0D_it); // UnaryPredicate1D: __call__ -int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D& if1D); +int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D &if1D); // StrokeShader: shade -int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke& s); +int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke &s); // ChainingIterator: init, traverse int Director_BPy_ChainingIterator_init(ChainingIterator *c_it); -int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator& a_it); +int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it); -#endif // __FREESTYLE_PYTHON_DIRECTOR_H__ +#endif // __FREESTYLE_PYTHON_DIRECTOR_H__ diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index d000677ab55..e685491f682 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -32,236 +32,260 @@ extern "C" { /*----------------------CurvePoint methods----------------------------*/ PyDoc_STRVAR(CurvePoint_doc, -"Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n" -"\n" -"Class to represent a point of a curve. A CurvePoint can be any point\n" -"of a 1D curve (it doesn't have to be a vertex of the curve). Any\n" -":class:`Interface1D` is built upon ViewEdges, themselves built upon\n" -"FEdges. Therefore, a curve is basically a polyline made of a list of\n" -":class:`SVertex` objects. Thus, a CurvePoint is built by linearly\n" -"interpolating two :class:`SVertex` instances. CurvePoint can be used\n" -"as virtual points while querying 0D information along a curve at a\n" -"given resolution.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Defult constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A CurvePoint object.\n" -" :type brother: :class:`CurvePoint`\n" -"\n" -".. method:: __init__(first_vertex, second_vertex, t2d)\n" -"\n" -" Builds a CurvePoint from two SVertex objects and an interpolation parameter.\n" -"\n" -" :arg first_vertex: The first SVertex.\n" -" :type first_vertex: :class:`SVertex`\n" -" :arg second_vertex: The second SVertex.\n" -" :type second_vertex: :class:`SVertex`\n" -" :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" -" first_vertex and second_vertex.\n" -" :type t2d: float\n" -"\n" -".. method:: __init__(first_point, second_point, t2d)\n" -"\n" -" Builds a CurvePoint from two CurvePoint objects and an interpolation\n" -" parameter.\n" -"\n" -" :arg first_point: The first CurvePoint.\n" -" :type first_point: :class:`CurvePoint`\n" -" :arg second_point: The second CurvePoint.\n" -" :type second_point: :class:`CurvePoint`\n" -" :arg t2d: The 2D interpolation parameter used to linearly interpolate\n" -" first_point and second_point.\n" -" :type t2d: float"); + "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n" + "\n" + "Class to represent a point of a curve. A CurvePoint can be any point\n" + "of a 1D curve (it doesn't have to be a vertex of the curve). Any\n" + ":class:`Interface1D` is built upon ViewEdges, themselves built upon\n" + "FEdges. Therefore, a curve is basically a polyline made of a list of\n" + ":class:`SVertex` objects. Thus, a CurvePoint is built by linearly\n" + "interpolating two :class:`SVertex` instances. CurvePoint can be used\n" + "as virtual points while querying 0D information along a curve at a\n" + "given resolution.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Defult constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A CurvePoint object.\n" + " :type brother: :class:`CurvePoint`\n" + "\n" + ".. method:: __init__(first_vertex, second_vertex, t2d)\n" + "\n" + " Builds a CurvePoint from two SVertex objects and an interpolation parameter.\n" + "\n" + " :arg first_vertex: The first SVertex.\n" + " :type first_vertex: :class:`SVertex`\n" + " :arg second_vertex: The second SVertex.\n" + " :type second_vertex: :class:`SVertex`\n" + " :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" + " first_vertex and second_vertex.\n" + " :type t2d: float\n" + "\n" + ".. method:: __init__(first_point, second_point, t2d)\n" + "\n" + " Builds a CurvePoint from two CurvePoint objects and an interpolation\n" + " parameter.\n" + "\n" + " :arg first_point: The first CurvePoint.\n" + " :type first_point: :class:`CurvePoint`\n" + " :arg second_point: The second CurvePoint.\n" + " :type second_point: :class:`CurvePoint`\n" + " :arg t2d: The 2D interpolation parameter used to linearly interpolate\n" + " first_point and second_point.\n" + " :type t2d: float"); static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", NULL}; - static const char *kwlist_3[] = {"first_point", "second_point", "t2d", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - float t2d; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", NULL}; + static const char *kwlist_3[] = {"first_point", "second_point", "t2d", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t2d; - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) { - if (!obj1) - self->cp = new CurvePoint(); - else - self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, - &SVertex_Type, &obj1, &SVertex_Type, &obj2, &t2d)) - { - self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_3, - &CurvePoint_Type, &obj1, &CurvePoint_Type, &obj2, &t2d)) - { - CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp; - CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp; - if (!cp1 || cp1->A() == 0 || cp1->B() == 0) { - PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); - return -1; - } - if (!cp2 || cp2->A() == 0 || cp2->B() == 0) { - PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object"); - return -1; - } - self->cp = new CurvePoint(cp1, cp2, t2d); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_if0D.if0D = self->cp; - self->py_if0D.borrowed = false; - return 0; + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) { + if (!obj1) + self->cp = new CurvePoint(); + else + self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!f", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2, + &t2d)) { + self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!f", + (char **)kwlist_3, + &CurvePoint_Type, + &obj1, + &CurvePoint_Type, + &obj2, + &t2d)) { + CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp; + CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp; + if (!cp1 || cp1->A() == 0 || cp1->B() == 0) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); + return -1; + } + if (!cp2 || cp2->A() == 0 || cp2->B() == 0) { + PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object"); + return -1; + } + self->cp = new CurvePoint(cp1, cp2, t2d); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_if0D.if0D = self->cp; + self->py_if0D.borrowed = false; + return 0; } -///bool operator== (const CurvePoint &b) +///bool operator== (const CurvePoint &b) /*----------------------CurvePoint get/setters ----------------------------*/ PyDoc_STRVAR(CurvePoint_first_svertex_doc, -"The first SVertex upon which the CurvePoint is built.\n" -"\n" -":type: :class:`SVertex`"); + "The first SVertex upon which the CurvePoint is built.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure)) { - SVertex *A = self->cp->A(); - if (A) - return BPy_SVertex_from_SVertex(*A); - Py_RETURN_NONE; + SVertex *A = self->cp->A(); + if (A) + return BPy_SVertex_from_SVertex(*A); + Py_RETURN_NONE; } -static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) +static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->cp->setA(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->cp->setA(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(CurvePoint_second_svertex_doc, -"The second SVertex upon which the CurvePoint is built.\n" -"\n" -":type: :class:`SVertex`"); + "The second SVertex upon which the CurvePoint is built.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure)) { - SVertex *B = self->cp->B(); - if (B) - return BPy_SVertex_from_SVertex(*B); - Py_RETURN_NONE; + SVertex *B = self->cp->B(); + if (B) + return BPy_SVertex_from_SVertex(*B); + Py_RETURN_NONE; } -static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) +static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->cp->setB(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->cp->setB(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(CurvePoint_fedge_doc, -"Gets the FEdge for the two SVertices that given CurvePoints consists out of.\n" -"A shortcut for CurvePoint.first_svertex.get_fedge(CurvePoint.second_svertex).\n" -"\n" -":type: :class:`FEdge`"); + "Gets the FEdge for the two SVertices that given CurvePoints consists out of.\n" + "A shortcut for CurvePoint.first_svertex.get_fedge(CurvePoint.second_svertex).\n" + "\n" + ":type: :class:`FEdge`"); static PyObject *CurvePoint_fedge_get(BPy_CurvePoint *self, void *UNUSED(closure)) { - SVertex *A = self->cp->A(); - Interface0D *B = (Interface0D *)self->cp->B(); - // B can be NULL under certain circumstances - if (B) - return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*B))); - Py_RETURN_NONE; + SVertex *A = self->cp->A(); + Interface0D *B = (Interface0D *)self->cp->B(); + // B can be NULL under certain circumstances + if (B) + return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*B))); + Py_RETURN_NONE; } PyDoc_STRVAR(CurvePoint_t2d_doc, -"The 2D interpolation parameter.\n" -"\n" -":type: float"); + "The 2D interpolation parameter.\n" + "\n" + ":type: float"); static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->cp->t2d()); + return PyFloat_FromDouble(self->cp->t2d()); } static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->cp->setT2d(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->cp->setT2d(scalar); + return 0; } static PyGetSetDef BPy_CurvePoint_getseters[] = { - {(char *)"first_svertex", (getter)CurvePoint_first_svertex_get, (setter)CurvePoint_first_svertex_set, - (char *)CurvePoint_first_svertex_doc, NULL}, - {(char *)"second_svertex", (getter)CurvePoint_second_svertex_get, (setter)CurvePoint_second_svertex_set, - (char *)CurvePoint_second_svertex_doc, NULL}, - {(char *)"fedge", (getter)CurvePoint_fedge_get, NULL, - CurvePoint_fedge_doc, NULL}, - {(char *)"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, (char *)CurvePoint_t2d_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"first_svertex", + (getter)CurvePoint_first_svertex_get, + (setter)CurvePoint_first_svertex_set, + (char *)CurvePoint_first_svertex_doc, + NULL}, + {(char *)"second_svertex", + (getter)CurvePoint_second_svertex_get, + (setter)CurvePoint_second_svertex_set, + (char *)CurvePoint_second_svertex_doc, + NULL}, + {(char *)"fedge", (getter)CurvePoint_fedge_get, NULL, CurvePoint_fedge_doc, NULL}, + {(char *)"t2d", + (getter)CurvePoint_t2d_get, + (setter)CurvePoint_t2d_set, + (char *)CurvePoint_t2d_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_CurvePoint type definition ------------------------------*/ PyTypeObject CurvePoint_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CurvePoint", /* tp_name */ - sizeof(BPy_CurvePoint), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurvePoint_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_CurvePoint_getseters, /* tp_getset */ - &Interface0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CurvePoint_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CurvePoint", /* tp_name */ + sizeof(BPy_CurvePoint), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurvePoint_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_CurvePoint_getseters, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurvePoint_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h index 7cc78a12167..d0f4087f8a6 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h @@ -37,8 +37,8 @@ extern PyTypeObject CurvePoint_Type; /*---------------------------Python BPy_CurvePoint structure definition----------*/ typedef struct { - BPy_Interface0D py_if0D; - CurvePoint *cp; + BPy_Interface0D py_if0D; + CurvePoint *cp; } BPy_CurvePoint; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index f4b232a957e..f4b8ca07d3f 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -33,433 +33,463 @@ extern "C" { /*----------------------SVertex methods ----------------------------*/ PyDoc_STRVAR(SVertex_doc, -"Class hierarchy: :class:`Interface0D` > :class:`SVertex`\n" -"\n" -"Class to define a vertex of the embedding.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A SVertex object.\n" -" :type brother: :class:`SVertex`\n" -"\n" -".. method:: __init__(point_3d, id)\n" -"\n" -" Builds a SVertex from 3D coordinates and an Id.\n" -"\n" -" :arg point_3d: A three-dimensional vector.\n" -" :type point_3d: :class:`mathutils.Vector`\n" -" :arg id: An Id object.\n" -" :type id: :class:`Id`"); + "Class hierarchy: :class:`Interface0D` > :class:`SVertex`\n" + "\n" + "Class to define a vertex of the embedding.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A SVertex object.\n" + " :type brother: :class:`SVertex`\n" + "\n" + ".. method:: __init__(point_3d, id)\n" + "\n" + " Builds a SVertex from 3D coordinates and an Id.\n" + "\n" + " :arg point_3d: A three-dimensional vector.\n" + " :type point_3d: :class:`mathutils.Vector`\n" + " :arg id: An Id object.\n" + " :type id: :class:`Id`"); static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"point_3d", "id", NULL}; - PyObject *obj = 0; - float v[3]; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertex_Type, &obj)) { - if (!obj) - self->sv = new SVertex(); - else - self->sv = new SVertex(*(((BPy_SVertex *)obj)->sv)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O&O!", (char **)kwlist_2, convert_v3, v, &Id_Type, &obj)) - { - Vec3r point_3d(v[0], v[1], v[2]); - self->sv = new SVertex(point_3d, *(((BPy_Id *)obj)->id)); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_if0D.if0D = self->sv; - self->py_if0D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"point_3d", "id", NULL}; + PyObject *obj = 0; + float v[3]; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertex_Type, &obj)) { + if (!obj) + self->sv = new SVertex(); + else + self->sv = new SVertex(*(((BPy_SVertex *)obj)->sv)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "O&O!", (char **)kwlist_2, convert_v3, v, &Id_Type, &obj)) { + Vec3r point_3d(v[0], v[1], v[2]); + self->sv = new SVertex(point_3d, *(((BPy_Id *)obj)->id)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_if0D.if0D = self->sv; + self->py_if0D.borrowed = false; + return 0; } PyDoc_STRVAR(SVertex_add_normal_doc, -".. method:: add_normal(normal)\n" -"\n" -" Adds a normal to the SVertex's set of normals. If the same normal\n" -" is already in the set, nothing changes.\n" -"\n" -" :arg normal: A three-dimensional vector.\n" -" :type normal: :class:`mathutils.Vector`, list or tuple of 3 real numbers"); + ".. method:: add_normal(normal)\n" + "\n" + " Adds a normal to the SVertex's set of normals. If the same normal\n" + " is already in the set, nothing changes.\n" + "\n" + " :arg normal: A three-dimensional vector.\n" + " :type normal: :class:`mathutils.Vector`, list or tuple of 3 real numbers"); static PyObject *SVertex_add_normal(BPy_SVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"normal", NULL}; - PyObject *py_normal; - Vec3r n; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &py_normal)) - return NULL; - if (!Vec3r_ptr_from_PyObject(py_normal, n)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - self->sv->AddNormal(n); - Py_RETURN_NONE; + static const char *kwlist[] = {"normal", NULL}; + PyObject *py_normal; + Vec3r n; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &py_normal)) + return NULL; + if (!Vec3r_ptr_from_PyObject(py_normal, n)) { + PyErr_SetString(PyExc_TypeError, + "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; + } + self->sv->AddNormal(n); + Py_RETURN_NONE; } PyDoc_STRVAR(SVertex_add_fedge_doc, -".. method:: add_fedge(fedge)\n" -"\n" -" Add an FEdge to the list of edges emanating from this SVertex.\n" -"\n" -" :arg fedge: An FEdge.\n" -" :type fedge: :class:`FEdge`"); + ".. method:: add_fedge(fedge)\n" + "\n" + " Add an FEdge to the list of edges emanating from this SVertex.\n" + "\n" + " :arg fedge: An FEdge.\n" + " :type fedge: :class:`FEdge`"); static PyObject *SVertex_add_fedge(BPy_SVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"fedge", NULL}; - PyObject *py_fe; + static const char *kwlist[] = {"fedge", NULL}; + PyObject *py_fe; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) - return NULL; - self->sv->AddFEdge(((BPy_FEdge *)py_fe)->fe); - Py_RETURN_NONE; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) + return NULL; + self->sv->AddFEdge(((BPy_FEdge *)py_fe)->fe); + Py_RETURN_NONE; } -// virtual bool operator== (const SVertex &brother) +// virtual bool operator== (const SVertex &brother) static PyMethodDef BPy_SVertex_methods[] = { - {"add_normal", (PyCFunction)SVertex_add_normal, METH_VARARGS | METH_KEYWORDS, SVertex_add_normal_doc}, - {"add_fedge", (PyCFunction)SVertex_add_fedge, METH_VARARGS | METH_KEYWORDS, SVertex_add_fedge_doc}, - {NULL, NULL, 0, NULL}, + {"add_normal", + (PyCFunction)SVertex_add_normal, + METH_VARARGS | METH_KEYWORDS, + SVertex_add_normal_doc}, + {"add_fedge", + (PyCFunction)SVertex_add_fedge, + METH_VARARGS | METH_KEYWORDS, + SVertex_add_fedge_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------mathutils callbacks ----------------------------*/ /* subtype */ -#define MATHUTILS_SUBTYPE_POINT3D 1 -#define MATHUTILS_SUBTYPE_POINT2D 2 +#define MATHUTILS_SUBTYPE_POINT3D 1 +#define MATHUTILS_SUBTYPE_POINT2D 2 static int SVertex_mathutils_check(BaseMathObject *bmo) { - if (!BPy_SVertex_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_SVertex_Check(bmo->cb_user)) + return -1; + return 0; } static int SVertex_mathutils_get(BaseMathObject *bmo, int subtype) { - BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_POINT3D: - bmo->data[0] = self->sv->getX(); - bmo->data[1] = self->sv->getY(); - bmo->data[2] = self->sv->getZ(); - break; - case MATHUTILS_SUBTYPE_POINT2D: - bmo->data[0] = self->sv->getProjectedX(); - bmo->data[1] = self->sv->getProjectedY(); - bmo->data[2] = self->sv->getProjectedZ(); - break; - default: - return -1; - } - return 0; + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + bmo->data[0] = self->sv->getX(); + bmo->data[1] = self->sv->getY(); + bmo->data[2] = self->sv->getZ(); + break; + case MATHUTILS_SUBTYPE_POINT2D: + bmo->data[0] = self->sv->getProjectedX(); + bmo->data[1] = self->sv->getProjectedY(); + bmo->data[2] = self->sv->getProjectedZ(); + break; + default: + return -1; + } + return 0; } static int SVertex_mathutils_set(BaseMathObject *bmo, int subtype) { - BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_POINT3D: - { - Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); - self->sv->setPoint3D(p); - } - break; - case MATHUTILS_SUBTYPE_POINT2D: - { - Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); - self->sv->setPoint2D(p); - } - break; - default: - return -1; - } - return 0; + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->sv->setPoint3D(p); + } break; + case MATHUTILS_SUBTYPE_POINT2D: { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->sv->setPoint2D(p); + } break; + default: + return -1; + } + return 0; } static int SVertex_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) { - BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_POINT3D: - switch (index) { - case 0: bmo->data[0] = self->sv->getX(); break; - case 1: bmo->data[1] = self->sv->getY(); break; - case 2: bmo->data[2] = self->sv->getZ(); break; - default: - return -1; - } - break; - case MATHUTILS_SUBTYPE_POINT2D: - switch (index) { - case 0: bmo->data[0] = self->sv->getProjectedX(); break; - case 1: bmo->data[1] = self->sv->getProjectedY(); break; - case 2: bmo->data[2] = self->sv->getProjectedZ(); break; - default: - return -1; - } - break; - default: - return -1; - } - return 0; + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + switch (index) { + case 0: + bmo->data[0] = self->sv->getX(); + break; + case 1: + bmo->data[1] = self->sv->getY(); + break; + case 2: + bmo->data[2] = self->sv->getZ(); + break; + default: + return -1; + } + break; + case MATHUTILS_SUBTYPE_POINT2D: + switch (index) { + case 0: + bmo->data[0] = self->sv->getProjectedX(); + break; + case 1: + bmo->data[1] = self->sv->getProjectedY(); + break; + case 2: + bmo->data[2] = self->sv->getProjectedZ(); + break; + default: + return -1; + } + break; + default: + return -1; + } + return 0; } static int SVertex_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) { - BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_POINT3D: - { - Vec3r p(self->sv->point3D()); - p[index] = bmo->data[index]; - self->sv->setPoint3D(p); - } - break; - case MATHUTILS_SUBTYPE_POINT2D: - { - Vec3r p(self->sv->point2D()); - p[index] = bmo->data[index]; - self->sv->setPoint2D(p); - } - break; - default: - return -1; - } - return 0; + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: { + Vec3r p(self->sv->point3D()); + p[index] = bmo->data[index]; + self->sv->setPoint3D(p); + } break; + case MATHUTILS_SUBTYPE_POINT2D: { + Vec3r p(self->sv->point2D()); + p[index] = bmo->data[index]; + self->sv->setPoint2D(p); + } break; + default: + return -1; + } + return 0; } static Mathutils_Callback SVertex_mathutils_cb = { - SVertex_mathutils_check, - SVertex_mathutils_get, - SVertex_mathutils_set, - SVertex_mathutils_get_index, - SVertex_mathutils_set_index, + SVertex_mathutils_check, + SVertex_mathutils_get, + SVertex_mathutils_set, + SVertex_mathutils_get_index, + SVertex_mathutils_set_index, }; static unsigned char SVertex_mathutils_cb_index = -1; void SVertex_mathutils_register_callback() { - SVertex_mathutils_cb_index = Mathutils_RegisterCallback(&SVertex_mathutils_cb); + SVertex_mathutils_cb_index = Mathutils_RegisterCallback(&SVertex_mathutils_cb); } /*----------------------SVertex get/setters ----------------------------*/ PyDoc_STRVAR(SVertex_point_3d_doc, -"The 3D coordinates of the SVertex.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The 3D coordinates of the SVertex.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *SVertex_point_3d_get(BPy_SVertex *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT3D); + return Vector_CreatePyObject_cb( + (PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT3D); } static int SVertex_point_3d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - Vec3r p(v[0], v[1], v[2]); - self->sv->setPoint3D(p); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + Vec3r p(v[0], v[1], v[2]); + self->sv->setPoint3D(p); + return 0; } PyDoc_STRVAR(SVertex_point_2d_doc, -"The projected 3D coordinates of the SVertex.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The projected 3D coordinates of the SVertex.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *SVertex_point_2d_get(BPy_SVertex *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT2D); + return Vector_CreatePyObject_cb( + (PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT2D); } static int SVertex_point_2d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - Vec3r p(v[0], v[1], v[2]); - self->sv->setPoint2D(p); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + Vec3r p(v[0], v[1], v[2]); + self->sv->setPoint2D(p); + return 0; } PyDoc_STRVAR(SVertex_id_doc, -"The Id of this SVertex.\n" -"\n" -":type: :class:`Id`"); + "The Id of this SVertex.\n" + "\n" + ":type: :class:`Id`"); static PyObject *SVertex_id_get(BPy_SVertex *self, void *UNUSED(closure)) { - Id id(self->sv->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->sv->getId()); + return BPy_Id_from_Id(id); // return a copy } static int SVertex_id_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->sv->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->sv->setId(*(((BPy_Id *)value)->id)); + return 0; } PyDoc_STRVAR(SVertex_normals_doc, -"The normals for this Vertex as a list. In a sharp surface, an SVertex\n" -"has exactly one normal. In a smooth surface, an SVertex can have any\n" -"number of normals.\n" -"\n" -":type: list of :class:`mathutils.Vector` objects"); + "The normals for this Vertex as a list. In a sharp surface, an SVertex\n" + "has exactly one normal. In a smooth surface, an SVertex can have any\n" + "number of normals.\n" + "\n" + ":type: list of :class:`mathutils.Vector` objects"); static PyObject *SVertex_normals_get(BPy_SVertex *self, void *UNUSED(closure)) { - PyObject *py_normals; - set< Vec3r > normals = self->sv->normals(); - set< Vec3r >::iterator it; - py_normals = PyList_New(normals.size()); - unsigned int i = 0; - - for (it = normals.begin(); it != normals.end(); it++) { - Vec3r v(*it); - PyList_SET_ITEM(py_normals, i++, Vector_from_Vec3r(v)); - } - return py_normals; + PyObject *py_normals; + set normals = self->sv->normals(); + set::iterator it; + py_normals = PyList_New(normals.size()); + unsigned int i = 0; + + for (it = normals.begin(); it != normals.end(); it++) { + Vec3r v(*it); + PyList_SET_ITEM(py_normals, i++, Vector_from_Vec3r(v)); + } + return py_normals; } PyDoc_STRVAR(SVertex_normals_size_doc, -"The number of different normals for this SVertex.\n" -"\n" -":type: int"); + "The number of different normals for this SVertex.\n" + "\n" + ":type: int"); static PyObject *SVertex_normals_size_get(BPy_SVertex *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->sv->normalsSize()); + return PyLong_FromLong(self->sv->normalsSize()); } PyDoc_STRVAR(SVertex_viewvertex_doc, -"If this SVertex is also a ViewVertex, this property refers to the\n" -"ViewVertex, and None otherwise.\n" -"\n" -":type: :class:`ViewVertex`"); + "If this SVertex is also a ViewVertex, this property refers to the\n" + "ViewVertex, and None otherwise.\n" + "\n" + ":type: :class:`ViewVertex`"); static PyObject *SVertex_viewvertex_get(BPy_SVertex *self, void *UNUSED(closure)) { - ViewVertex *vv = self->sv->viewvertex(); - if (vv) - return Any_BPy_ViewVertex_from_ViewVertex(*vv); - Py_RETURN_NONE; + ViewVertex *vv = self->sv->viewvertex(); + if (vv) + return Any_BPy_ViewVertex_from_ViewVertex(*vv); + Py_RETURN_NONE; } PyDoc_STRVAR(SVertex_curvatures_doc, -"Curvature information expressed in the form of a seven-element tuple\n" -"(K1, e1, K2, e2, Kr, er, dKr), where K1 and K2 are scalar values\n" -"representing the first (maximum) and second (minimum) principal\n" -"curvatures at this SVertex, respectively; e1 and e2 are\n" -"three-dimensional vectors representing the first and second principal\n" -"directions, i.e. the directions of the normal plane where the\n" -"curvature takes its maximum and minimum values, respectively; and Kr,\n" -"er and dKr are the radial curvature, radial direction, and the\n" -"derivative of the radial curvature at this SVertex, respectively.\n" -"\n" -":type: tuple"); + "Curvature information expressed in the form of a seven-element tuple\n" + "(K1, e1, K2, e2, Kr, er, dKr), where K1 and K2 are scalar values\n" + "representing the first (maximum) and second (minimum) principal\n" + "curvatures at this SVertex, respectively; e1 and e2 are\n" + "three-dimensional vectors representing the first and second principal\n" + "directions, i.e. the directions of the normal plane where the\n" + "curvature takes its maximum and minimum values, respectively; and Kr,\n" + "er and dKr are the radial curvature, radial direction, and the\n" + "derivative of the radial curvature at this SVertex, respectively.\n" + "\n" + ":type: tuple"); static PyObject *SVertex_curvatures_get(BPy_SVertex *self, void *UNUSED(closure)) { - const CurvatureInfo *info = self->sv->getCurvatureInfo(); - if (!info) - Py_RETURN_NONE; - Vec3r e1(info->e1.x(), info->e1.y(), info->e1.z()); - Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z()); - Vec3r er(info->er.x(), info->er.y(), info->er.z()); - PyObject *retval = PyTuple_New(7); - PyTuple_SET_ITEMS(retval, - PyFloat_FromDouble(info->K1), - PyFloat_FromDouble(info->K2), - Vector_from_Vec3r(e1), - Vector_from_Vec3r(e2), - PyFloat_FromDouble(info->Kr), - Vector_from_Vec3r(er), - PyFloat_FromDouble(info->dKr)); - return retval; + const CurvatureInfo *info = self->sv->getCurvatureInfo(); + if (!info) + Py_RETURN_NONE; + Vec3r e1(info->e1.x(), info->e1.y(), info->e1.z()); + Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z()); + Vec3r er(info->er.x(), info->er.y(), info->er.z()); + PyObject *retval = PyTuple_New(7); + PyTuple_SET_ITEMS(retval, + PyFloat_FromDouble(info->K1), + PyFloat_FromDouble(info->K2), + Vector_from_Vec3r(e1), + Vector_from_Vec3r(e2), + PyFloat_FromDouble(info->Kr), + Vector_from_Vec3r(er), + PyFloat_FromDouble(info->dKr)); + return retval; } static PyGetSetDef BPy_SVertex_getseters[] = { - {(char *)"point_3d", (getter)SVertex_point_3d_get, (setter)SVertex_point_3d_set, - (char *)SVertex_point_3d_doc, NULL}, - {(char *)"point_2d", (getter)SVertex_point_2d_get, (setter)SVertex_point_2d_set, - (char *)SVertex_point_2d_doc, NULL}, - {(char *)"id", (getter)SVertex_id_get, (setter)SVertex_id_set, (char *)SVertex_id_doc, NULL}, - {(char *)"normals", (getter)SVertex_normals_get, (setter)NULL, (char *)SVertex_normals_doc, NULL}, - {(char *)"normals_size", (getter)SVertex_normals_size_get, (setter)NULL, (char *)SVertex_normals_size_doc, NULL}, - {(char *)"viewvertex", (getter)SVertex_viewvertex_get, (setter)NULL, (char *)SVertex_viewvertex_doc, NULL}, - {(char *)"curvatures", (getter)SVertex_curvatures_get, (setter)NULL, (char *)SVertex_curvatures_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"point_3d", + (getter)SVertex_point_3d_get, + (setter)SVertex_point_3d_set, + (char *)SVertex_point_3d_doc, + NULL}, + {(char *)"point_2d", + (getter)SVertex_point_2d_get, + (setter)SVertex_point_2d_set, + (char *)SVertex_point_2d_doc, + NULL}, + {(char *)"id", (getter)SVertex_id_get, (setter)SVertex_id_set, (char *)SVertex_id_doc, NULL}, + {(char *)"normals", + (getter)SVertex_normals_get, + (setter)NULL, + (char *)SVertex_normals_doc, + NULL}, + {(char *)"normals_size", + (getter)SVertex_normals_size_get, + (setter)NULL, + (char *)SVertex_normals_size_doc, + NULL}, + {(char *)"viewvertex", + (getter)SVertex_viewvertex_get, + (setter)NULL, + (char *)SVertex_viewvertex_doc, + NULL}, + {(char *)"curvatures", + (getter)SVertex_curvatures_get, + (setter)NULL, + (char *)SVertex_curvatures_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SVertex type definition ------------------------------*/ PyTypeObject SVertex_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SVertex", /* tp_name */ - sizeof(BPy_SVertex), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SVertex_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_SVertex_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_SVertex_getseters, /* tp_getset */ - &Interface0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SVertex_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SVertex", /* tp_name */ + sizeof(BPy_SVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SVertex_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_SVertex_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_SVertex_getseters, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SVertex_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h index dabc7119539..20a14f1422c 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h @@ -37,8 +37,8 @@ extern PyTypeObject SVertex_Type; /*---------------------------Python BPy_SVertex structure definition----------*/ typedef struct { - BPy_Interface0D py_if0D; - SVertex *sv; + BPy_Interface0D py_if0D; + SVertex *sv; } BPy_SVertex; /*---------------------------Python BPy_SVertex visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index 155dbf26888..1ff46482911 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -33,164 +33,168 @@ extern "C" { /*----------------------ViewVertex methods----------------------------*/ PyDoc_STRVAR(ViewVertex_doc, -"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n" -"\n" -"Class to define a view vertex. A view vertex is a feature vertex\n" -"corresponding to a point of the image graph, where the characteristics\n" -"of an edge (e.g., nature and visibility) might change. A\n" -":class:`ViewVertex` can be of two kinds: A :class:`TVertex` when it\n" -"corresponds to the intersection between two ViewEdges or a\n" -":class:`NonTVertex` when it corresponds to a vertex of the initial\n" -"input mesh (it is the case for vertices such as corners for example).\n" -"Thus, this class can be specialized into two classes, the\n" -":class:`TVertex` class and the :class:`NonTVertex` class."); + "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n" + "\n" + "Class to define a view vertex. A view vertex is a feature vertex\n" + "corresponding to a point of the image graph, where the characteristics\n" + "of an edge (e.g., nature and visibility) might change. A\n" + ":class:`ViewVertex` can be of two kinds: A :class:`TVertex` when it\n" + "corresponds to the intersection between two ViewEdges or a\n" + ":class:`NonTVertex` when it corresponds to a vertex of the initial\n" + "input mesh (it is the case for vertices such as corners for example).\n" + "Thus, this class can be specialized into two classes, the\n" + ":class:`TVertex` class and the :class:`NonTVertex` class."); static int ViewVertex_init(BPy_ViewVertex * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/) { - PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class"); - return -1; + PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class"); + return -1; } PyDoc_STRVAR(ViewVertex_edges_begin_doc, -".. method:: edges_begin()\n" -"\n" -" Returns an iterator over the ViewEdges that goes to or comes from\n" -" this ViewVertex pointing to the first ViewEdge of the list. The\n" -" orientedViewEdgeIterator allows to iterate in CCW order over these\n" -" ViewEdges and to get the orientation for each ViewEdge\n" -" (incoming/outgoing).\n" -"\n" -" :return: An orientedViewEdgeIterator pointing to the first ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`"); + ".. method:: edges_begin()\n" + "\n" + " Returns an iterator over the ViewEdges that goes to or comes from\n" + " this ViewVertex pointing to the first ViewEdge of the list. The\n" + " orientedViewEdgeIterator allows to iterate in CCW order over these\n" + " ViewEdges and to get the orientation for each ViewEdge\n" + " (incoming/outgoing).\n" + "\n" + " :return: An orientedViewEdgeIterator pointing to the first ViewEdge.\n" + " :rtype: :class:`orientedViewEdgeIterator`"); static PyObject *ViewVertex_edges_begin(BPy_ViewVertex *self) { - ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesBegin()); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, false); + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesBegin()); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, false); } PyDoc_STRVAR(ViewVertex_edges_end_doc, -".. method:: edges_end()\n" -"\n" -" Returns an orientedViewEdgeIterator over the ViewEdges around this\n" -" ViewVertex, pointing after the last ViewEdge.\n" -"\n" -" :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`"); + ".. method:: edges_end()\n" + "\n" + " Returns an orientedViewEdgeIterator over the ViewEdges around this\n" + " ViewVertex, pointing after the last ViewEdge.\n" + "\n" + " :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n" + " :rtype: :class:`orientedViewEdgeIterator`"); static PyObject *ViewVertex_edges_end(BPy_ViewVertex * /*self*/) { #if 0 - ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesEnd()); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, 1); + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesEnd()); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, 1); #else - PyErr_SetString(PyExc_NotImplementedError, "edges_end method currently disabled"); - return NULL; + PyErr_SetString(PyExc_NotImplementedError, "edges_end method currently disabled"); + return NULL; #endif } PyDoc_STRVAR(ViewVertex_edges_iterator_doc, -".. method:: edges_iterator(edge)\n" -"\n" -" Returns an orientedViewEdgeIterator pointing to the ViewEdge given\n" -" as argument.\n" -"\n" -" :arg edge: A ViewEdge object.\n" -" :type edge: :class:`ViewEdge`\n" -" :return: An orientedViewEdgeIterator pointing to the given ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`"); + ".. method:: edges_iterator(edge)\n" + "\n" + " Returns an orientedViewEdgeIterator pointing to the ViewEdge given\n" + " as argument.\n" + "\n" + " :arg edge: A ViewEdge object.\n" + " :type edge: :class:`ViewEdge`\n" + " :return: An orientedViewEdgeIterator pointing to the given ViewEdge.\n" + " :rtype: :class:`orientedViewEdgeIterator`"); static PyObject *ViewVertex_edges_iterator(BPy_ViewVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"edge", NULL}; - PyObject *py_ve; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) - return NULL; - ViewEdge *ve = ((BPy_ViewEdge *)py_ve)->ve; - ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesIterator(ve)); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, false); + static const char *kwlist[] = {"edge", NULL}; + PyObject *py_ve; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) + return NULL; + ViewEdge *ve = ((BPy_ViewEdge *)py_ve)->ve; + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesIterator(ve)); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, false); } static PyMethodDef BPy_ViewVertex_methods[] = { - {"edges_begin", (PyCFunction)ViewVertex_edges_begin, METH_NOARGS, ViewVertex_edges_begin_doc}, - {"edges_end", (PyCFunction)ViewVertex_edges_end, METH_NOARGS, ViewVertex_edges_end_doc}, - {"edges_iterator", (PyCFunction)ViewVertex_edges_iterator, METH_VARARGS | METH_KEYWORDS, - ViewVertex_edges_iterator_doc}, - {NULL, NULL, 0, NULL}, + {"edges_begin", (PyCFunction)ViewVertex_edges_begin, METH_NOARGS, ViewVertex_edges_begin_doc}, + {"edges_end", (PyCFunction)ViewVertex_edges_end, METH_NOARGS, ViewVertex_edges_end_doc}, + {"edges_iterator", + (PyCFunction)ViewVertex_edges_iterator, + METH_VARARGS | METH_KEYWORDS, + ViewVertex_edges_iterator_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewVertex get/setters ----------------------------*/ PyDoc_STRVAR(ViewVertex_nature_doc, -"The nature of this ViewVertex.\n" -"\n" -":type: :class:`Nature`"); + "The nature of this ViewVertex.\n" + "\n" + ":type: :class:`Nature`"); static PyObject *ViewVertex_nature_get(BPy_ViewVertex *self, void *UNUSED(closure)) { - Nature::VertexNature nature = self->vv->getNature(); - if (PyErr_Occurred()) - return NULL; - return BPy_Nature_from_Nature(nature); // return a copy + Nature::VertexNature nature = self->vv->getNature(); + if (PyErr_Occurred()) + return NULL; + return BPy_Nature_from_Nature(nature); // return a copy } static int ViewVertex_nature_set(BPy_ViewVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Nature_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a Nature"); - return -1; - } - self->vv->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); - return 0; + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->vv->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; } static PyGetSetDef BPy_ViewVertex_getseters[] = { - {(char *)"nature", (getter)ViewVertex_nature_get, (setter)ViewVertex_nature_set, - (char *)ViewVertex_nature_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"nature", + (getter)ViewVertex_nature_get, + (setter)ViewVertex_nature_set, + (char *)ViewVertex_nature_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewVertex type definition ------------------------------*/ PyTypeObject ViewVertex_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewVertex", /* tp_name */ - sizeof(BPy_ViewVertex), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewVertex_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewVertex_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewVertex_getseters, /* tp_getset */ - &Interface0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewVertex_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewVertex", /* tp_name */ + sizeof(BPy_ViewVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewVertex_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewVertex_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewVertex_getseters, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewVertex_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h index 63bff6557fc..6769efa4673 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h @@ -37,8 +37,8 @@ extern PyTypeObject ViewVertex_Type; /*---------------------------Python BPy_ViewVertex structure definition----------*/ typedef struct { - BPy_Interface0D py_if0D; - ViewVertex *vv; + BPy_Interface0D py_if0D; + ViewVertex *vv; } BPy_ViewVertex; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp index 0df055194ae..3637899fbc2 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -33,342 +33,381 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(StrokeVertex_doc, -"Class hierarchy: :class:`Interface0D` > :class:`CurvePoint` > :class:`StrokeVertex`\n" -"\n" -"Class to define a stroke vertex.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A StrokeVertex object.\n" -" :type brother: :class:`StrokeVertex`\n" -"\n" -".. method:: __init__(first_vertex, second_vertex, t3d)\n" -"\n" -" Build a stroke vertex from 2 stroke vertices and an interpolation\n" -" parameter.\n" -"\n" -" :arg first_vertex: The first StrokeVertex.\n" -" :type first_vertex: :class:`StrokeVertex`\n" -" :arg second_vertex: The second StrokeVertex.\n" -" :type second_vertex: :class:`StrokeVertex`\n" -" :arg t3d: An interpolation parameter.\n" -" :type t3d: float\n" -"\n" -".. method:: __init__(point)\n" -"\n" -" Build a stroke vertex from a CurvePoint\n" -"\n" -" :arg point: A CurvePoint object.\n" -" :type point: :class:`CurvePoint`\n" -"\n" -".. method:: __init__(svertex)\n" -"\n" -" Build a stroke vertex from a SVertex\n" -"\n" -" :arg svertex: An SVertex object.\n" -" :type svertex: :class:`SVertex`\n" -"\n" -".. method:: __init__(svertex, attribute)\n" -"\n" -" Build a stroke vertex from an SVertex and a StrokeAttribute object.\n" -"\n" -" :arg svertex: An SVertex object.\n" -" :type svertex: :class:`SVertex`\n" -" :arg attribute: A StrokeAttribute object.\n" -" :type attribute: :class:`StrokeAttribute`"); +PyDoc_STRVAR( + StrokeVertex_doc, + "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint` > :class:`StrokeVertex`\n" + "\n" + "Class to define a stroke vertex.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A StrokeVertex object.\n" + " :type brother: :class:`StrokeVertex`\n" + "\n" + ".. method:: __init__(first_vertex, second_vertex, t3d)\n" + "\n" + " Build a stroke vertex from 2 stroke vertices and an interpolation\n" + " parameter.\n" + "\n" + " :arg first_vertex: The first StrokeVertex.\n" + " :type first_vertex: :class:`StrokeVertex`\n" + " :arg second_vertex: The second StrokeVertex.\n" + " :type second_vertex: :class:`StrokeVertex`\n" + " :arg t3d: An interpolation parameter.\n" + " :type t3d: float\n" + "\n" + ".. method:: __init__(point)\n" + "\n" + " Build a stroke vertex from a CurvePoint\n" + "\n" + " :arg point: A CurvePoint object.\n" + " :type point: :class:`CurvePoint`\n" + "\n" + ".. method:: __init__(svertex)\n" + "\n" + " Build a stroke vertex from a SVertex\n" + "\n" + " :arg svertex: An SVertex object.\n" + " :type svertex: :class:`SVertex`\n" + "\n" + ".. method:: __init__(svertex, attribute)\n" + "\n" + " Build a stroke vertex from an SVertex and a StrokeAttribute object.\n" + "\n" + " :arg svertex: An SVertex object.\n" + " :type svertex: :class:`SVertex`\n" + " :arg attribute: A StrokeAttribute object.\n" + " :type attribute: :class:`StrokeAttribute`"); static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t3d", NULL}; - static const char *kwlist_3[] = {"point", NULL}; - static const char *kwlist_4[] = {"svertex", "attribute", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - float t3d; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeVertex_Type, &obj1)) { - if (!obj1) { - self->sv = new StrokeVertex(); - } - else { - if (!((BPy_StrokeVertex *)obj1)->sv) { - PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); - return -1; - } - self->sv = new StrokeVertex(*(((BPy_StrokeVertex *)obj1)->sv)); - } - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, - &StrokeVertex_Type, &obj1, &StrokeVertex_Type, &obj2, &t3d)) - { - StrokeVertex *sv1 = ((BPy_StrokeVertex *)obj1)->sv; - StrokeVertex *sv2 = ((BPy_StrokeVertex *)obj2)->sv; - if (!sv1 || (sv1->A() == 0 && sv1->B() == 0)) { - PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); - return -1; - } - if (!sv2 || (sv2->A() == 0 && sv2->B() == 0)) { - PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object"); - return -1; - } - self->sv = new StrokeVertex(sv1, sv2, t3d); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &CurvePoint_Type, &obj1)) - { - CurvePoint *cp = ((BPy_CurvePoint *)obj1)->cp; - if (!cp || cp->A() == 0 || cp->B() == 0) { - PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); - return -1; - } - self->sv = new StrokeVertex(cp); - } - else if (PyErr_Clear(), (obj2 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", (char **)kwlist_4, - &SVertex_Type, &obj1, &StrokeAttribute_Type, &obj2)) - { - if (!obj2) - self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv); - else - self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv, *(((BPy_StrokeAttribute *)obj2)->sa)); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_cp.cp = self->sv; - self->py_cp.py_if0D.if0D = self->sv; - self->py_cp.py_if0D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t3d", NULL}; + static const char *kwlist_3[] = {"point", NULL}; + static const char *kwlist_4[] = {"svertex", "attribute", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t3d; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &StrokeVertex_Type, &obj1)) { + if (!obj1) { + self->sv = new StrokeVertex(); + } + else { + if (!((BPy_StrokeVertex *)obj1)->sv) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); + return -1; + } + self->sv = new StrokeVertex(*(((BPy_StrokeVertex *)obj1)->sv)); + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!f", + (char **)kwlist_2, + &StrokeVertex_Type, + &obj1, + &StrokeVertex_Type, + &obj2, + &t3d)) { + StrokeVertex *sv1 = ((BPy_StrokeVertex *)obj1)->sv; + StrokeVertex *sv2 = ((BPy_StrokeVertex *)obj2)->sv; + if (!sv1 || (sv1->A() == 0 && sv1->B() == 0)) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); + return -1; + } + if (!sv2 || (sv2->A() == 0 && sv2->B() == 0)) { + PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object"); + return -1; + } + self->sv = new StrokeVertex(sv1, sv2, t3d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_3, &CurvePoint_Type, &obj1)) { + CurvePoint *cp = ((BPy_CurvePoint *)obj1)->cp; + if (!cp || cp->A() == 0 || cp->B() == 0) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); + return -1; + } + self->sv = new StrokeVertex(cp); + } + else if (PyErr_Clear(), + (obj2 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!|O!", + (char **)kwlist_4, + &SVertex_Type, + &obj1, + &StrokeAttribute_Type, + &obj2)) { + if (!obj2) + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv); + else + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv, *(((BPy_StrokeAttribute *)obj2)->sa)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_cp.cp = self->sv; + self->py_cp.py_if0D.if0D = self->sv; + self->py_cp.py_if0D.borrowed = false; + return 0; } -// real operator[] (const int i) const -// real & operator[] (const int i) +// real operator[] (const int i) const +// real & operator[] (const int i) /*----------------------mathutils callbacks ----------------------------*/ static int StrokeVertex_mathutils_check(BaseMathObject *bmo) { - if (!BPy_StrokeVertex_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_StrokeVertex_Check(bmo->cb_user)) + return -1; + return 0; } static int StrokeVertex_mathutils_get(BaseMathObject *bmo, int /*subtype*/) { - BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; - bmo->data[0] = (float)self->sv->x(); - bmo->data[1] = (float)self->sv->y(); - return 0; + BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; + bmo->data[0] = (float)self->sv->x(); + bmo->data[1] = (float)self->sv->y(); + return 0; } static int StrokeVertex_mathutils_set(BaseMathObject *bmo, int /*subtype*/) { - BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; - self->sv->setX((real)bmo->data[0]); - self->sv->setY((real)bmo->data[1]); - return 0; + BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; + self->sv->setX((real)bmo->data[0]); + self->sv->setY((real)bmo->data[1]); + return 0; } static int StrokeVertex_mathutils_get_index(BaseMathObject *bmo, int /*subtype*/, int index) { - BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; - switch (index) { - case 0: bmo->data[0] = (float)self->sv->x(); break; - case 1: bmo->data[1] = (float)self->sv->y(); break; - default: - return -1; - } - return 0; + BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; + switch (index) { + case 0: + bmo->data[0] = (float)self->sv->x(); + break; + case 1: + bmo->data[1] = (float)self->sv->y(); + break; + default: + return -1; + } + return 0; } static int StrokeVertex_mathutils_set_index(BaseMathObject *bmo, int /*subtype*/, int index) { - BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; - switch (index) { - case 0: self->sv->setX((real)bmo->data[0]); break; - case 1: self->sv->setY((real)bmo->data[1]); break; - default: - return -1; - } - return 0; + BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; + switch (index) { + case 0: + self->sv->setX((real)bmo->data[0]); + break; + case 1: + self->sv->setY((real)bmo->data[1]); + break; + default: + return -1; + } + return 0; } static Mathutils_Callback StrokeVertex_mathutils_cb = { - StrokeVertex_mathutils_check, - StrokeVertex_mathutils_get, - StrokeVertex_mathutils_set, - StrokeVertex_mathutils_get_index, - StrokeVertex_mathutils_set_index, + StrokeVertex_mathutils_check, + StrokeVertex_mathutils_get, + StrokeVertex_mathutils_set, + StrokeVertex_mathutils_get_index, + StrokeVertex_mathutils_set_index, }; static unsigned char StrokeVertex_mathutils_cb_index = -1; void StrokeVertex_mathutils_register_callback() { - StrokeVertex_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeVertex_mathutils_cb); + StrokeVertex_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeVertex_mathutils_cb); } /*----------------------StrokeVertex get/setters ----------------------------*/ PyDoc_STRVAR(StrokeVertex_attribute_doc, -"StrokeAttribute for this StrokeVertex.\n" -"\n" -":type: :class:`StrokeAttribute`"); + "StrokeAttribute for this StrokeVertex.\n" + "\n" + ":type: :class:`StrokeAttribute`"); static PyObject *StrokeVertex_attribute_get(BPy_StrokeVertex *self, void *UNUSED(closure)) { - return BPy_StrokeAttribute_from_StrokeAttribute(self->sv->attribute()); + return BPy_StrokeAttribute_from_StrokeAttribute(self->sv->attribute()); } -static int StrokeVertex_attribute_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure)) +static int StrokeVertex_attribute_set(BPy_StrokeVertex *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_StrokeAttribute_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a StrokeAttribute object"); - return -1; - } - self->sv->setAttribute(*(((BPy_StrokeAttribute *)value)->sa)); - return 0; + if (!BPy_StrokeAttribute_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a StrokeAttribute object"); + return -1; + } + self->sv->setAttribute(*(((BPy_StrokeAttribute *)value)->sa)); + return 0; } PyDoc_STRVAR(StrokeVertex_curvilinear_abscissa_doc, -"Curvilinear abscissa of this StrokeVertex in the Stroke.\n" -"\n" -":type: float"); + "Curvilinear abscissa of this StrokeVertex in the Stroke.\n" + "\n" + ":type: float"); -static PyObject *StrokeVertex_curvilinear_abscissa_get(BPy_StrokeVertex *self, void *UNUSED(closure)) +static PyObject *StrokeVertex_curvilinear_abscissa_get(BPy_StrokeVertex *self, + void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv->curvilinearAbscissa()); + return PyFloat_FromDouble(self->sv->curvilinearAbscissa()); } -static int StrokeVertex_curvilinear_abscissa_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure)) +static int StrokeVertex_curvilinear_abscissa_set(BPy_StrokeVertex *self, + PyObject *value, + void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->sv->setCurvilinearAbscissa(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && + PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->sv->setCurvilinearAbscissa(scalar); + return 0; } PyDoc_STRVAR(StrokeVertex_point_doc, -"2D point coordinates.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "2D point coordinates.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *StrokeVertex_point_get(BPy_StrokeVertex *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 2, StrokeVertex_mathutils_cb_index, 0); + return Vector_CreatePyObject_cb((PyObject *)self, 2, StrokeVertex_mathutils_cb_index, 0); } static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure)) { - float v[2]; - if (mathutils_array_parse(v, 2, 2, value, - "value must be a 2-dimensional vector") == -1) - { - return -1; - } - self->sv->setX(v[0]); - self->sv->setY(v[1]); - return 0; + float v[2]; + if (mathutils_array_parse(v, 2, 2, value, "value must be a 2-dimensional vector") == -1) { + return -1; + } + self->sv->setX(v[0]); + self->sv->setY(v[1]); + return 0; } PyDoc_STRVAR(StrokeVertex_stroke_length_doc, -"Stroke length (it is only a value retained by the StrokeVertex,\n" -"and it won't change the real stroke length).\n" -"\n" -":type: float"); + "Stroke length (it is only a value retained by the StrokeVertex,\n" + "and it won't change the real stroke length).\n" + "\n" + ":type: float"); static PyObject *StrokeVertex_stroke_length_get(BPy_StrokeVertex *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv->strokeLength()); + return PyFloat_FromDouble(self->sv->strokeLength()); } -static int StrokeVertex_stroke_length_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure)) +static int StrokeVertex_stroke_length_set(BPy_StrokeVertex *self, + PyObject *value, + void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->sv->setStrokeLength(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && + PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->sv->setStrokeLength(scalar); + return 0; } PyDoc_STRVAR(StrokeVertex_u_doc, -"Curvilinear abscissa of this StrokeVertex in the Stroke.\n" -"\n" -":type: float"); + "Curvilinear abscissa of this StrokeVertex in the Stroke.\n" + "\n" + ":type: float"); static PyObject *StrokeVertex_u_get(BPy_StrokeVertex *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv->u()); + return PyFloat_FromDouble(self->sv->u()); } static PyGetSetDef BPy_StrokeVertex_getseters[] = { - {(char *)"attribute", (getter)StrokeVertex_attribute_get, (setter)StrokeVertex_attribute_set, - (char *)StrokeVertex_attribute_doc, NULL}, - {(char *)"curvilinear_abscissa", (getter)StrokeVertex_curvilinear_abscissa_get, - (setter)StrokeVertex_curvilinear_abscissa_set, - (char *)StrokeVertex_curvilinear_abscissa_doc, NULL}, - {(char *)"point", (getter)StrokeVertex_point_get, (setter)StrokeVertex_point_set, - (char *)StrokeVertex_point_doc, NULL}, - {(char *)"stroke_length", (getter)StrokeVertex_stroke_length_get, (setter)StrokeVertex_stroke_length_set, - (char *)StrokeVertex_stroke_length_doc, NULL}, - {(char *)"u", (getter)StrokeVertex_u_get, (setter)NULL, (char *)StrokeVertex_u_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"attribute", + (getter)StrokeVertex_attribute_get, + (setter)StrokeVertex_attribute_set, + (char *)StrokeVertex_attribute_doc, + NULL}, + {(char *)"curvilinear_abscissa", + (getter)StrokeVertex_curvilinear_abscissa_get, + (setter)StrokeVertex_curvilinear_abscissa_set, + (char *)StrokeVertex_curvilinear_abscissa_doc, + NULL}, + {(char *)"point", + (getter)StrokeVertex_point_get, + (setter)StrokeVertex_point_set, + (char *)StrokeVertex_point_doc, + NULL}, + {(char *)"stroke_length", + (getter)StrokeVertex_stroke_length_get, + (setter)StrokeVertex_stroke_length_set, + (char *)StrokeVertex_stroke_length_doc, + NULL}, + {(char *)"u", (getter)StrokeVertex_u_get, (setter)NULL, (char *)StrokeVertex_u_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeVertex type definition ------------------------------*/ PyTypeObject StrokeVertex_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeVertex", /* tp_name */ - sizeof(BPy_StrokeVertex), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeVertex_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_StrokeVertex_getseters, /* tp_getset */ - &CurvePoint_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeVertex_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeVertex", /* tp_name */ + sizeof(BPy_StrokeVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeVertex_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_StrokeVertex_getseters, /* tp_getset */ + &CurvePoint_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeVertex_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h index a7bbae59c38..e2eab6ab887 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject StrokeVertex_Type; -#define BPy_StrokeVertex_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertex_Type)) +#define BPy_StrokeVertex_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertex_Type)) /*---------------------------Python BPy_StrokeVertex structure definition----------*/ typedef struct { - BPy_CurvePoint py_cp; - StrokeVertex *sv; + BPy_CurvePoint py_cp; + StrokeVertex *sv; } BPy_StrokeVertex; /*---------------------------Python BPy_StrokeVertex visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp index 49a1e7cc8b3..87873677189 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp @@ -32,112 +32,114 @@ extern "C" { /*----------------------NonTVertex methods ----------------------------*/ PyDoc_STRVAR(NonTVertex_doc, -"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`NonTVertex`\n" -"\n" -"View vertex for corners, cusps, etc. associated to a single SVertex.\n" -"Can be associated to 2 or more view edges.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(svertex)\n" -"\n" -" Build a NonTVertex from a SVertex.\n" -"\n" -" :arg svertex: An SVertex object.\n" -" :type svertex: :class:`SVertex`"); + "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`NonTVertex`\n" + "\n" + "View vertex for corners, cusps, etc. associated to a single SVertex.\n" + "Can be associated to 2 or more view edges.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(svertex)\n" + "\n" + " Build a NonTVertex from a SVertex.\n" + "\n" + " :arg svertex: An SVertex object.\n" + " :type svertex: :class:`SVertex`"); /* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int NonTVertex_init(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"svertex", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SVertex_Type, &obj)) - return -1; - if (!obj) - self->ntv = new NonTVertex(); - else - self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv); - self->py_vv.vv = self->ntv; - self->py_vv.py_if0D.if0D = self->ntv; - self->py_vv.py_if0D.borrowed = false; - return 0; + static const char *kwlist[] = {"svertex", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SVertex_Type, &obj)) + return -1; + if (!obj) + self->ntv = new NonTVertex(); + else + self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv); + self->py_vv.vv = self->ntv; + self->py_vv.py_if0D.if0D = self->ntv; + self->py_vv.py_if0D.borrowed = false; + return 0; } /*----------------------NonTVertex get/setters ----------------------------*/ PyDoc_STRVAR(NonTVertex_svertex_doc, -"The SVertex on top of which this NonTVertex is built.\n" -"\n" -":type: :class:`SVertex`"); + "The SVertex on top of which this NonTVertex is built.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *NonTVertex_svertex_get(BPy_NonTVertex *self, void *UNUSED(closure)) { - SVertex *v = self->ntv->svertex(); - if (v) - return BPy_SVertex_from_SVertex(*v); - Py_RETURN_NONE; + SVertex *v = self->ntv->svertex(); + if (v) + return BPy_SVertex_from_SVertex(*v); + Py_RETURN_NONE; } static int NonTVertex_svertex_set(BPy_NonTVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->ntv->setSVertex(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->ntv->setSVertex(((BPy_SVertex *)value)->sv); + return 0; } static PyGetSetDef BPy_NonTVertex_getseters[] = { - {(char *)"svertex", (getter)NonTVertex_svertex_get, (setter)NonTVertex_svertex_set, - (char *)NonTVertex_svertex_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"svertex", + (getter)NonTVertex_svertex_get, + (setter)NonTVertex_svertex_set, + (char *)NonTVertex_svertex_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_NonTVertex type definition ------------------------------*/ PyTypeObject NonTVertex_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "NonTVertex", /* tp_name */ - sizeof(BPy_NonTVertex), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - NonTVertex_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_NonTVertex_getseters, /* tp_getset */ - &ViewVertex_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)NonTVertex_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "NonTVertex", /* tp_name */ + sizeof(BPy_NonTVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + NonTVertex_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_NonTVertex_getseters, /* tp_getset */ + &ViewVertex_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)NonTVertex_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h index fc65dd3eb0f..fdea985a125 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h @@ -37,8 +37,8 @@ extern PyTypeObject NonTVertex_Type; /*---------------------------Python BPy_NonTVertex structure definition----------*/ typedef struct { - BPy_ViewVertex py_vv; - NonTVertex *ntv; + BPy_ViewVertex py_vv; + NonTVertex *ntv; } BPy_NonTVertex; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp index f24d551fad8..9a8592aaea5 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp @@ -35,205 +35,216 @@ extern "C" { /*----------------------TVertex methods ----------------------------*/ PyDoc_STRVAR(TVertex_doc, -"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n" -"\n" -"Class to define a T vertex, i.e. an intersection between two edges.\n" -"It points towards two SVertex and four ViewEdges. Among the\n" -"ViewEdges, two are front and the other two are back. Basically a\n" -"front edge hides part of a back edge. So, among the back edges, one\n" -"is of invisibility N and the other of invisibility N+1.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor."); + "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n" + "\n" + "Class to define a T vertex, i.e. an intersection between two edges.\n" + "It points towards two SVertex and four ViewEdges. Among the\n" + "ViewEdges, two are front and the other two are back. Basically a\n" + "front edge hides part of a back edge. So, among the back edges, one\n" + "is of invisibility N and the other of invisibility N+1.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor."); /* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->tv = new TVertex(); - self->py_vv.vv = self->tv; - self->py_vv.py_if0D.if0D = self->tv; - self->py_vv.py_if0D.borrowed = false; - return 0; + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->tv = new TVertex(); + self->py_vv.vv = self->tv; + self->py_vv.py_if0D.if0D = self->tv; + self->py_vv.py_if0D.borrowed = false; + return 0; } PyDoc_STRVAR(TVertex_get_svertex_doc, -".. method:: get_svertex(fedge)\n" -"\n" -" Returns the SVertex (among the 2) belonging to the given FEdge.\n" -"\n" -" :arg fedge: An FEdge object.\n" -" :type fedge: :class:`FEdge`\n" -" :return: The SVertex belonging to the given FEdge.\n" -" :rtype: :class:`SVertex`"); - -static PyObject *TVertex_get_svertex( BPy_TVertex *self, PyObject *args, PyObject *kwds) + ".. method:: get_svertex(fedge)\n" + "\n" + " Returns the SVertex (among the 2) belonging to the given FEdge.\n" + "\n" + " :arg fedge: An FEdge object.\n" + " :type fedge: :class:`FEdge`\n" + " :return: The SVertex belonging to the given FEdge.\n" + " :rtype: :class:`SVertex`"); + +static PyObject *TVertex_get_svertex(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"fedge", NULL}; - PyObject *py_fe; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) - return NULL; - SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe); - if (sv) - return BPy_SVertex_from_SVertex(*sv); - Py_RETURN_NONE; + static const char *kwlist[] = {"fedge", NULL}; + PyObject *py_fe; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) + return NULL; + SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe); + if (sv) + return BPy_SVertex_from_SVertex(*sv); + Py_RETURN_NONE; } PyDoc_STRVAR(TVertex_get_mate_doc, -".. method:: get_mate(viewedge)\n" -"\n" -" Returns the mate edge of the ViewEdge given as argument. If the\n" -" ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n" -" frontEdgeB, frontEdgeA is returned. Same for back edges.\n" -"\n" -" :arg viewedge: A ViewEdge object.\n" -" :type viewedge: :class:`ViewEdge`\n" -" :return: The mate edge of the given ViewEdge.\n" -" :rtype: :class:`ViewEdge`"); - -static PyObject *TVertex_get_mate( BPy_TVertex *self, PyObject *args, PyObject *kwds) + ".. method:: get_mate(viewedge)\n" + "\n" + " Returns the mate edge of the ViewEdge given as argument. If the\n" + " ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n" + " frontEdgeB, frontEdgeA is returned. Same for back edges.\n" + "\n" + " :arg viewedge: A ViewEdge object.\n" + " :type viewedge: :class:`ViewEdge`\n" + " :return: The mate edge of the given ViewEdge.\n" + " :rtype: :class:`ViewEdge`"); + +static PyObject *TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"viewedge", NULL}; - PyObject *py_ve; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) - return NULL; - ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + static const char *kwlist[] = {"viewedge", NULL}; + PyObject *py_ve; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) + return NULL; + ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } static PyMethodDef BPy_TVertex_methods[] = { - {"get_svertex", (PyCFunction)TVertex_get_svertex, METH_VARARGS | METH_KEYWORDS, TVertex_get_svertex_doc}, - {"get_mate", (PyCFunction)TVertex_get_mate, METH_VARARGS | METH_KEYWORDS, TVertex_get_mate_doc}, - {NULL, NULL, 0, NULL}, + {"get_svertex", + (PyCFunction)TVertex_get_svertex, + METH_VARARGS | METH_KEYWORDS, + TVertex_get_svertex_doc}, + {"get_mate", + (PyCFunction)TVertex_get_mate, + METH_VARARGS | METH_KEYWORDS, + TVertex_get_mate_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------TVertex get/setters ----------------------------*/ PyDoc_STRVAR(TVertex_front_svertex_doc, -"The SVertex that is closer to the viewpoint.\n" -"\n" -":type: :class:`SVertex`"); + "The SVertex that is closer to the viewpoint.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *TVertex_front_svertex_get(BPy_TVertex *self, void *UNUSED(closure)) { - SVertex *v = self->tv->frontSVertex(); - if (v) - return BPy_SVertex_from_SVertex(*v); - Py_RETURN_NONE; + SVertex *v = self->tv->frontSVertex(); + if (v) + return BPy_SVertex_from_SVertex(*v); + Py_RETURN_NONE; } static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(TVertex_back_svertex_doc, -"The SVertex that is further away from the viewpoint.\n" -"\n" -":type: :class:`SVertex`"); + "The SVertex that is further away from the viewpoint.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *TVertex_back_svertex_get(BPy_TVertex *self, void *UNUSED(closure)) { - SVertex *v = self->tv->backSVertex(); - if (v) - return BPy_SVertex_from_SVertex(*v); - Py_RETURN_NONE; + SVertex *v = self->tv->backSVertex(); + if (v) + return BPy_SVertex_from_SVertex(*v); + Py_RETURN_NONE; } static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->tv->setBackSVertex(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->tv->setBackSVertex(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(TVertex_id_doc, -"The Id of this TVertex.\n" -"\n" -":type: :class:`Id`"); + "The Id of this TVertex.\n" + "\n" + ":type: :class:`Id`"); static PyObject *TVertex_id_get(BPy_TVertex *self, void *UNUSED(closure)) { - Id id(self->tv->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->tv->getId()); + return BPy_Id_from_Id(id); // return a copy } static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->tv->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->tv->setId(*(((BPy_Id *)value)->id)); + return 0; } static PyGetSetDef BPy_TVertex_getseters[] = { - {(char *)"front_svertex", (getter)TVertex_front_svertex_get, (setter)TVertex_front_svertex_set, - (char *)TVertex_front_svertex_doc, NULL}, - {(char *)"back_svertex", (getter)TVertex_back_svertex_get, (setter)TVertex_back_svertex_set, - (char *)TVertex_back_svertex_doc, NULL}, - {(char *)"id", (getter)TVertex_id_get, (setter)TVertex_id_set, (char *)TVertex_id_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"front_svertex", + (getter)TVertex_front_svertex_get, + (setter)TVertex_front_svertex_set, + (char *)TVertex_front_svertex_doc, + NULL}, + {(char *)"back_svertex", + (getter)TVertex_back_svertex_get, + (setter)TVertex_back_svertex_set, + (char *)TVertex_back_svertex_doc, + NULL}, + {(char *)"id", (getter)TVertex_id_get, (setter)TVertex_id_set, (char *)TVertex_id_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_TVertex type definition ------------------------------*/ PyTypeObject TVertex_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TVertex", /* tp_name */ - sizeof(BPy_TVertex), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TVertex_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_TVertex_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_TVertex_getseters, /* tp_getset */ - &ViewVertex_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TVertex_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TVertex", /* tp_name */ + sizeof(BPy_TVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TVertex_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_TVertex_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_TVertex_getseters, /* tp_getset */ + &ViewVertex_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TVertex_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h index a7526ffd1c4..165ad976fdf 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h @@ -37,8 +37,8 @@ extern PyTypeObject TVertex_Type; /*---------------------------Python BPy_TVertex structure definition----------*/ typedef struct { - BPy_ViewVertex py_vv; - TVertex *tv; + BPy_ViewVertex py_vv; + TVertex *tv; } BPy_TVertex; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index 3bef47efd17..7ca783d9aa4 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -35,336 +35,364 @@ extern "C" { /*----------------------FEdge methods ----------------------------*/ PyDoc_STRVAR(FEdge_doc, -"Class hierarchy: :class:`Interface1D` > :class:`FEdge`\n" -"\n" -"Base Class for feature edges. This FEdge can represent a silhouette,\n" -"a crease, a ridge/valley, a border or a suggestive contour. For\n" -"silhouettes, the FEdge is oriented so that the visible face lies on\n" -"the left of the edge. For borders, the FEdge is oriented so that the\n" -"face lies on the left of the edge. An FEdge can represent an initial\n" -"edge of the mesh or runs across a face of the initial mesh depending\n" -"on the smoothness or sharpness of the mesh. This class is specialized\n" -"into a smooth and a sharp version since their properties slightly vary\n" -"from one to the other.\n" -"\n" -".. method:: FEdge()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: FEdge(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An FEdge object.\n" -" :type brother: :class:`FEdge`\n" -"\n" -".. method:: FEdge(first_vertex, second_vertex)\n" -"\n" -" Builds an FEdge going from the first vertex to the second.\n" -"\n" -" :arg first_vertex: The first SVertex.\n" -" :type first_vertex: :class:`SVertex`\n" -" :arg second_vertex: The second SVertex.\n" -" :type second_vertex: :class:`SVertex`"); + "Class hierarchy: :class:`Interface1D` > :class:`FEdge`\n" + "\n" + "Base Class for feature edges. This FEdge can represent a silhouette,\n" + "a crease, a ridge/valley, a border or a suggestive contour. For\n" + "silhouettes, the FEdge is oriented so that the visible face lies on\n" + "the left of the edge. For borders, the FEdge is oriented so that the\n" + "face lies on the left of the edge. An FEdge can represent an initial\n" + "edge of the mesh or runs across a face of the initial mesh depending\n" + "on the smoothness or sharpness of the mesh. This class is specialized\n" + "into a smooth and a sharp version since their properties slightly vary\n" + "from one to the other.\n" + "\n" + ".. method:: FEdge()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: FEdge(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An FEdge object.\n" + " :type brother: :class:`FEdge`\n" + "\n" + ".. method:: FEdge(first_vertex, second_vertex)\n" + "\n" + " Builds an FEdge going from the first vertex to the second.\n" + "\n" + " :arg first_vertex: The first SVertex.\n" + " :type first_vertex: :class:`SVertex`\n" + " :arg second_vertex: The second SVertex.\n" + " :type second_vertex: :class:`SVertex`"); static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdge_Type, &obj1)) { - if (!obj1) - self->fe = new FEdge(); - else - self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, - &SVertex_Type, &obj1, &SVertex_Type, &obj2)) - { - self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_if1D.if1D = self->fe; - self->py_if1D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdge_Type, &obj1)) { + if (!obj1) + self->fe = new FEdge(); + else + self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2)) { + self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_if1D.if1D = self->fe; + self->py_if1D.borrowed = false; + return 0; } /*----------------------FEdge sequence protocol ----------------------------*/ static Py_ssize_t FEdge_sq_length(BPy_FEdge * /*self*/) { - return 2; + return 2; } static PyObject *FEdge_sq_item(BPy_FEdge *self, int keynum) { - if (keynum < 0) - keynum += FEdge_sq_length(self); - if (keynum == 0 || keynum == 1) { - SVertex *v = self->fe->operator[](keynum); - if (v) - return BPy_SVertex_from_SVertex(*v); - Py_RETURN_NONE; - } - PyErr_Format(PyExc_IndexError, "FEdge[index]: index %d out of range", keynum); - return NULL; + if (keynum < 0) + keynum += FEdge_sq_length(self); + if (keynum == 0 || keynum == 1) { + SVertex *v = self->fe->operator[](keynum); + if (v) + return BPy_SVertex_from_SVertex(*v); + Py_RETURN_NONE; + } + PyErr_Format(PyExc_IndexError, "FEdge[index]: index %d out of range", keynum); + return NULL; } static PySequenceMethods BPy_FEdge_as_sequence = { - (lenfunc)FEdge_sq_length, /* sq_length */ - NULL, /* sq_concat */ - NULL, /* sq_repeat */ - (ssizeargfunc)FEdge_sq_item, /* sq_item */ - NULL, /* sq_slice */ - NULL, /* sq_ass_item */ - NULL, /* *was* sq_ass_slice */ - NULL, /* sq_contains */ - NULL, /* sq_inplace_concat */ - NULL, /* sq_inplace_repeat */ + (lenfunc)FEdge_sq_length, /* sq_length */ + NULL, /* sq_concat */ + NULL, /* sq_repeat */ + (ssizeargfunc)FEdge_sq_item, /* sq_item */ + NULL, /* sq_slice */ + NULL, /* sq_ass_item */ + NULL, /* *was* sq_ass_slice */ + NULL, /* sq_contains */ + NULL, /* sq_inplace_concat */ + NULL, /* sq_inplace_repeat */ }; /*----------------------FEdge get/setters ----------------------------*/ PyDoc_STRVAR(FEdge_first_svertex_doc, -"The first SVertex constituting this FEdge.\n" -"\n" -":type: :class:`SVertex`"); + "The first SVertex constituting this FEdge.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *FEdge_first_svertex_get(BPy_FEdge *self, void *UNUSED(closure)) { - SVertex *A = self->fe->vertexA(); - if (A) - return BPy_SVertex_from_SVertex(*A); - Py_RETURN_NONE; + SVertex *A = self->fe->vertexA(); + if (A) + return BPy_SVertex_from_SVertex(*A); + Py_RETURN_NONE; } static int FEdge_first_svertex_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->fe->setVertexA(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->fe->setVertexA(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(FEdge_second_svertex_doc, -"The second SVertex constituting this FEdge.\n" -"\n" -":type: :class:`SVertex`"); + "The second SVertex constituting this FEdge.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *FEdge_second_svertex_get(BPy_FEdge *self, void *UNUSED(closure)) { - SVertex *B = self->fe->vertexB(); - if (B) - return BPy_SVertex_from_SVertex(*B); - Py_RETURN_NONE; + SVertex *B = self->fe->vertexB(); + if (B) + return BPy_SVertex_from_SVertex(*B); + Py_RETURN_NONE; } static int FEdge_second_svertex_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_SVertex_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); - return -1; - } - self->fe->setVertexB(((BPy_SVertex *)value)->sv); - return 0; + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->fe->setVertexB(((BPy_SVertex *)value)->sv); + return 0; } PyDoc_STRVAR(FEdge_next_fedge_doc, -"The FEdge following this one in the ViewEdge. The value is None if\n" -"this FEdge is the last of the ViewEdge.\n" -"\n" -":type: :class:`FEdge`"); + "The FEdge following this one in the ViewEdge. The value is None if\n" + "this FEdge is the last of the ViewEdge.\n" + "\n" + ":type: :class:`FEdge`"); static PyObject *FEdge_next_fedge_get(BPy_FEdge *self, void *UNUSED(closure)) { - FEdge *fe = self->fe->nextEdge(); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + FEdge *fe = self->fe->nextEdge(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } static int FEdge_next_fedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_FEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); - return -1; - } - self->fe->setNextEdge(((BPy_FEdge *)value)->fe); - return 0; + if (!BPy_FEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); + return -1; + } + self->fe->setNextEdge(((BPy_FEdge *)value)->fe); + return 0; } PyDoc_STRVAR(FEdge_previous_fedge_doc, -"The FEdge preceding this one in the ViewEdge. The value is None if\n" -"this FEdge is the first one of the ViewEdge.\n" -"\n" -":type: :class:`FEdge`"); + "The FEdge preceding this one in the ViewEdge. The value is None if\n" + "this FEdge is the first one of the ViewEdge.\n" + "\n" + ":type: :class:`FEdge`"); static PyObject *FEdge_previous_fedge_get(BPy_FEdge *self, void *UNUSED(closure)) { - FEdge *fe = self->fe->previousEdge(); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + FEdge *fe = self->fe->previousEdge(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } static int FEdge_previous_fedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_FEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); - return -1; - } - self->fe->setPreviousEdge(((BPy_FEdge *)value)->fe); - return 0; + if (!BPy_FEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); + return -1; + } + self->fe->setPreviousEdge(((BPy_FEdge *)value)->fe); + return 0; } PyDoc_STRVAR(FEdge_viewedge_doc, -"The ViewEdge to which this FEdge belongs to.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge to which this FEdge belongs to.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *FEdge_viewedge_get(BPy_FEdge *self, void *UNUSED(closure)) { - ViewEdge *ve = self->fe->viewedge(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + ViewEdge *ve = self->fe->viewedge(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } static int FEdge_viewedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_ViewEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an ViewEdge"); - return -1; - } - self->fe->setViewEdge(((BPy_ViewEdge *)value)->ve); - return 0; + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an ViewEdge"); + return -1; + } + self->fe->setViewEdge(((BPy_ViewEdge *)value)->ve); + return 0; } PyDoc_STRVAR(FEdge_is_smooth_doc, -"True if this FEdge is a smooth FEdge.\n" -"\n" -":type: bool"); + "True if this FEdge is a smooth FEdge.\n" + "\n" + ":type: bool"); static PyObject *FEdge_is_smooth_get(BPy_FEdge *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->fe->isSmooth()); + return PyBool_from_bool(self->fe->isSmooth()); } static int FEdge_is_smooth_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!PyBool_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be boolean"); - return -1; - } - self->fe->setSmooth(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be boolean"); + return -1; + } + self->fe->setSmooth(bool_from_PyBool(value)); + return 0; } PyDoc_STRVAR(FEdge_id_doc, -"The Id of this FEdge.\n" -"\n" -":type: :class:`Id`"); + "The Id of this FEdge.\n" + "\n" + ":type: :class:`Id`"); static PyObject *FEdge_id_get(BPy_FEdge *self, void *UNUSED(closure)) { - Id id(self->fe->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->fe->getId()); + return BPy_Id_from_Id(id); // return a copy } static int FEdge_id_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->fe->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->fe->setId(*(((BPy_Id *)value)->id)); + return 0; } PyDoc_STRVAR(FEdge_nature_doc, -"The nature of this FEdge.\n" -"\n" -":type: :class:`Nature`"); + "The nature of this FEdge.\n" + "\n" + ":type: :class:`Nature`"); static PyObject *FEdge_nature_get(BPy_FEdge *self, void *UNUSED(closure)) { - return BPy_Nature_from_Nature(self->fe->getNature()); + return BPy_Nature_from_Nature(self->fe->getNature()); } static int FEdge_nature_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Nature_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a Nature"); - return -1; - } - self->fe->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); - return 0; + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->fe->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; } static PyGetSetDef BPy_FEdge_getseters[] = { - {(char *)"first_svertex", (getter)FEdge_first_svertex_get, (setter)FEdge_first_svertex_set, - (char *)FEdge_first_svertex_doc, NULL}, - {(char *)"second_svertex", (getter)FEdge_second_svertex_get, (setter)FEdge_second_svertex_set, - (char *)FEdge_second_svertex_doc, NULL}, - {(char *)"next_fedge", (getter)FEdge_next_fedge_get, (setter)FEdge_next_fedge_set, - (char *)FEdge_next_fedge_doc, NULL}, - {(char *)"previous_fedge", (getter)FEdge_previous_fedge_get, (setter)FEdge_previous_fedge_set, - (char *)FEdge_previous_fedge_doc, NULL}, - {(char *)"viewedge", (getter)FEdge_viewedge_get, (setter)FEdge_viewedge_set, (char *)FEdge_viewedge_doc, NULL}, - {(char *)"is_smooth", (getter)FEdge_is_smooth_get, (setter)FEdge_is_smooth_set, (char *)FEdge_is_smooth_doc, NULL}, - {(char *)"id", (getter)FEdge_id_get, (setter)FEdge_id_set, (char *)FEdge_id_doc, NULL}, - {(char *)"nature", (getter)FEdge_nature_get, (setter)FEdge_nature_set, (char *)FEdge_nature_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"first_svertex", + (getter)FEdge_first_svertex_get, + (setter)FEdge_first_svertex_set, + (char *)FEdge_first_svertex_doc, + NULL}, + {(char *)"second_svertex", + (getter)FEdge_second_svertex_get, + (setter)FEdge_second_svertex_set, + (char *)FEdge_second_svertex_doc, + NULL}, + {(char *)"next_fedge", + (getter)FEdge_next_fedge_get, + (setter)FEdge_next_fedge_set, + (char *)FEdge_next_fedge_doc, + NULL}, + {(char *)"previous_fedge", + (getter)FEdge_previous_fedge_get, + (setter)FEdge_previous_fedge_set, + (char *)FEdge_previous_fedge_doc, + NULL}, + {(char *)"viewedge", + (getter)FEdge_viewedge_get, + (setter)FEdge_viewedge_set, + (char *)FEdge_viewedge_doc, + NULL}, + {(char *)"is_smooth", + (getter)FEdge_is_smooth_get, + (setter)FEdge_is_smooth_set, + (char *)FEdge_is_smooth_doc, + NULL}, + {(char *)"id", (getter)FEdge_id_get, (setter)FEdge_id_set, (char *)FEdge_id_doc, NULL}, + {(char *)"nature", + (getter)FEdge_nature_get, + (setter)FEdge_nature_set, + (char *)FEdge_nature_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdge type definition ------------------------------*/ PyTypeObject FEdge_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FEdge", /* tp_name */ - sizeof(BPy_FEdge), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &BPy_FEdge_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdge_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_FEdge_getseters, /* tp_getset */ - &Interface1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FEdge_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FEdge", /* tp_name */ + sizeof(BPy_FEdge), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + &BPy_FEdge_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FEdge_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_FEdge_getseters, /* tp_getset */ + &Interface1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FEdge_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.h b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.h index 094f59f0908..3ab8c5f8273 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.h +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.h @@ -37,8 +37,8 @@ extern PyTypeObject FEdge_Type; /*---------------------------Python BPy_FEdge structure definition----------*/ typedef struct { - BPy_Interface1D py_if1D; - FEdge *fe; + BPy_Interface1D py_if1D; + FEdge *fe; } BPy_FEdge; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index 1932a2fd7ae..1d2d4f51028 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -34,192 +34,201 @@ extern "C" { /*----------------------CurvePoint methods ----------------------------*/ PyDoc_STRVAR(FrsCurve_doc, -"Class hierarchy: :class:`Interface1D` > :class:`Curve`\n" -"\n" -"Base class for curves made of CurvePoints. :class:`SVertex` is the\n" -"type of the initial curve vertices. A :class:`Chain` is a\n" -"specialization of a Curve.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default Constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy Constructor.\n" -"\n" -" :arg brother: A Curve object.\n" -" :type brother: :class:`Curve`\n" -"\n" -".. method:: __init__(id)\n" -"\n" -" Builds a Curve from its Id.\n" -"\n" -" :arg id: An Id object.\n" -" :type id: :class:`Id`"); + "Class hierarchy: :class:`Interface1D` > :class:`Curve`\n" + "\n" + "Base class for curves made of CurvePoints. :class:`SVertex` is the\n" + "type of the initial curve vertices. A :class:`Chain` is a\n" + "specialization of a Curve.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default Constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy Constructor.\n" + "\n" + " :arg brother: A Curve object.\n" + " :type brother: :class:`Curve`\n" + "\n" + ".. method:: __init__(id)\n" + "\n" + " Builds a Curve from its Id.\n" + "\n" + " :arg id: An Id object.\n" + " :type id: :class:`Id`"); static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"id", NULL}; - PyObject *obj = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) { - if (!obj) - self->c = new Curve(); - else - self->c = new Curve(*(((BPy_FrsCurve *)obj)->c)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) - { - self->c = new Curve(*(((BPy_Id *)obj)->id)); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_if1D.if1D = self->c; - self->py_if1D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"id", NULL}; + PyObject *obj = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) { + if (!obj) + self->c = new Curve(); + else + self->c = new Curve(*(((BPy_FrsCurve *)obj)->c)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) { + self->c = new Curve(*(((BPy_Id *)obj)->id)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_if1D.if1D = self->c; + self->py_if1D.borrowed = false; + return 0; } PyDoc_STRVAR(FrsCurve_push_vertex_back_doc, -".. method:: push_vertex_back(vertex)\n" -"\n" -" Adds a single vertex at the end of the Curve.\n" -"\n" -" :arg vertex: A vertex object.\n" -" :type vertex: :class:`SVertex` or :class:`CurvePoint`"); + ".. method:: push_vertex_back(vertex)\n" + "\n" + " Adds a single vertex at the end of the Curve.\n" + "\n" + " :arg vertex: A vertex object.\n" + " :type vertex: :class:`SVertex` or :class:`CurvePoint`"); static PyObject *FrsCurve_push_vertex_back(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"vertex", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) - return NULL; - - if (BPy_CurvePoint_Check(obj)) { - self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp); - } - else if (BPy_SVertex_Check(obj)) { - self->c->push_vertex_back(((BPy_SVertex *)obj)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"vertex", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) + return NULL; + + if (BPy_CurvePoint_Check(obj)) { + self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp); + } + else if (BPy_SVertex_Check(obj)) { + self->c->push_vertex_back(((BPy_SVertex *)obj)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(FrsCurve_push_vertex_front_doc, -".. method:: push_vertex_front(vertex)\n" -"\n" -" Adds a single vertex at the front of the Curve.\n" -"\n" -" :arg vertex: A vertex object.\n" -" :type vertex: :class:`SVertex` or :class:`CurvePoint`"); + ".. method:: push_vertex_front(vertex)\n" + "\n" + " Adds a single vertex at the front of the Curve.\n" + "\n" + " :arg vertex: A vertex object.\n" + " :type vertex: :class:`SVertex` or :class:`CurvePoint`"); static PyObject *FrsCurve_push_vertex_front(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"vertex", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) - return NULL; - - if (BPy_CurvePoint_Check(obj)) { - self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp); - } - else if (BPy_SVertex_Check(obj)) { - self->c->push_vertex_front(((BPy_SVertex *)obj)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"vertex", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) + return NULL; + + if (BPy_CurvePoint_Check(obj)) { + self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp); + } + else if (BPy_SVertex_Check(obj)) { + self->c->push_vertex_front(((BPy_SVertex *)obj)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } + Py_RETURN_NONE; } static PyMethodDef BPy_FrsCurve_methods[] = { - {"push_vertex_back", (PyCFunction)FrsCurve_push_vertex_back, METH_VARARGS | METH_KEYWORDS, - FrsCurve_push_vertex_back_doc}, - {"push_vertex_front", (PyCFunction)FrsCurve_push_vertex_front, METH_VARARGS | METH_KEYWORDS, - FrsCurve_push_vertex_front_doc}, - {NULL, NULL, 0, NULL}, + {"push_vertex_back", + (PyCFunction)FrsCurve_push_vertex_back, + METH_VARARGS | METH_KEYWORDS, + FrsCurve_push_vertex_back_doc}, + {"push_vertex_front", + (PyCFunction)FrsCurve_push_vertex_front, + METH_VARARGS | METH_KEYWORDS, + FrsCurve_push_vertex_front_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------CurvePoint get/setters ----------------------------*/ PyDoc_STRVAR(FrsCurve_is_empty_doc, -"True if the Curve doesn't have any Vertex yet.\n" -"\n" -":type: bool"); + "True if the Curve doesn't have any Vertex yet.\n" + "\n" + ":type: bool"); static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->c->empty()); + return PyBool_from_bool(self->c->empty()); } PyDoc_STRVAR(FrsCurve_segments_size_doc, -"The number of segments in the polyline constituting the Curve.\n" -"\n" -":type: int"); + "The number of segments in the polyline constituting the Curve.\n" + "\n" + ":type: int"); static PyObject *FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->c->nSegments()); + return PyLong_FromLong(self->c->nSegments()); } static PyGetSetDef BPy_FrsCurve_getseters[] = { - {(char *)"is_empty", (getter)FrsCurve_is_empty_get, (setter)NULL, (char *)FrsCurve_is_empty_doc, NULL}, - {(char *)"segments_size", (getter)FrsCurve_segments_size_get, (setter)NULL, - (char *)FrsCurve_segments_size_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"is_empty", + (getter)FrsCurve_is_empty_get, + (setter)NULL, + (char *)FrsCurve_is_empty_doc, + NULL}, + {(char *)"segments_size", + (getter)FrsCurve_segments_size_get, + (setter)NULL, + (char *)FrsCurve_segments_size_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FrsCurve type definition ------------------------------*/ PyTypeObject FrsCurve_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Curve", /* tp_name */ - sizeof(BPy_FrsCurve), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FrsCurve_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_FrsCurve_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_FrsCurve_getseters, /* tp_getset */ - &Interface1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FrsCurve_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Curve", /* tp_name */ + sizeof(BPy_FrsCurve), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FrsCurve_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_FrsCurve_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_FrsCurve_getseters, /* tp_getset */ + &Interface1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FrsCurve_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h index 05415662764..aa4fb409076 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h @@ -37,8 +37,8 @@ extern PyTypeObject FrsCurve_Type; /*---------------------------Python BPy_FrsCurve structure definition----------*/ typedef struct { - BPy_Interface1D py_if1D; - Curve *c; + BPy_Interface1D py_if1D; + Curve *c; } BPy_FrsCurve; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index 73907467f66..423a61c7f1d 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -42,457 +42,495 @@ extern "C" { // - is it even used ? not even in SWIG version PyDoc_STRVAR(Stroke_doc, -"Class hierarchy: :class:`Interface1D` > :class:`Stroke`\n" -"\n" -"Class to define a stroke. A stroke is made of a set of 2D vertices\n" -"(:class:`StrokeVertex`), regularly spaced out. This set of vertices\n" -"defines the stroke's backbone geometry. Each of these stroke vertices\n" -"defines the stroke's shape and appearance at this vertex position.\n" -"\n" -".. method:: Stroke()\n" -"\n" -" Default constructor\n" -"\n" -".. method:: Stroke(brother)\n" -"\n" -" Copy constructor"); + "Class hierarchy: :class:`Interface1D` > :class:`Stroke`\n" + "\n" + "Class to define a stroke. A stroke is made of a set of 2D vertices\n" + "(:class:`StrokeVertex`), regularly spaced out. This set of vertices\n" + "defines the stroke's backbone geometry. Each of these stroke vertices\n" + "defines the stroke's shape and appearance at this vertex position.\n" + "\n" + ".. method:: Stroke()\n" + "\n" + " Default constructor\n" + "\n" + ".. method:: Stroke(brother)\n" + "\n" + " Copy constructor"); static int Stroke_init(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"brother", NULL}; - PyObject *brother = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &Stroke_Type, &brother)) - return -1; - if (!brother) - self->s = new Stroke(); - else - self->s = new Stroke(*(((BPy_Stroke *)brother)->s)); - self->py_if1D.if1D = self->s; - self->py_if1D.borrowed = false; - return 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &Stroke_Type, &brother)) + return -1; + if (!brother) + self->s = new Stroke(); + else + self->s = new Stroke(*(((BPy_Stroke *)brother)->s)); + self->py_if1D.if1D = self->s; + self->py_if1D.borrowed = false; + return 0; } static PyObject *Stroke_iter(PyObject *self) { - StrokeInternal::StrokeVertexIterator sv_it( ((BPy_Stroke *)self)->s->strokeVerticesBegin() ); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, false); + StrokeInternal::StrokeVertexIterator sv_it(((BPy_Stroke *)self)->s->strokeVerticesBegin()); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, false); } static Py_ssize_t Stroke_sq_length(BPy_Stroke *self) { - return self->s->strokeVerticesSize(); + return self->s->strokeVerticesSize(); } static PyObject *Stroke_sq_item(BPy_Stroke *self, int keynum) { - if (keynum < 0) - keynum += Stroke_sq_length(self); - if (keynum < 0 || keynum >= Stroke_sq_length(self)) { - PyErr_Format(PyExc_IndexError, "Stroke[index]: index %d out of range", keynum); - return NULL; - } - return BPy_StrokeVertex_from_StrokeVertex(self->s->strokeVerticeAt(keynum)); + if (keynum < 0) + keynum += Stroke_sq_length(self); + if (keynum < 0 || keynum >= Stroke_sq_length(self)) { + PyErr_Format(PyExc_IndexError, "Stroke[index]: index %d out of range", keynum); + return NULL; + } + return BPy_StrokeVertex_from_StrokeVertex(self->s->strokeVerticeAt(keynum)); } PyDoc_STRVAR(Stroke_compute_sampling_doc, -".. method:: compute_sampling(n)\n" -"\n" -" Compute the sampling needed to get N vertices. If the\n" -" specified number of vertices is less than the actual number of\n" -" vertices, the actual sampling value is returned. (To remove Vertices,\n" -" use the RemoveVertex() method of this class.)\n" -"\n" -" :arg n: The number of stroke vertices we eventually want\n" -" in our Stroke.\n" -" :type n: int\n" -" :return: The sampling that must be used in the Resample(float)\n" -" method.\n" -" :rtype: float"); + ".. method:: compute_sampling(n)\n" + "\n" + " Compute the sampling needed to get N vertices. If the\n" + " specified number of vertices is less than the actual number of\n" + " vertices, the actual sampling value is returned. (To remove Vertices,\n" + " use the RemoveVertex() method of this class.)\n" + "\n" + " :arg n: The number of stroke vertices we eventually want\n" + " in our Stroke.\n" + " :type n: int\n" + " :return: The sampling that must be used in the Resample(float)\n" + " method.\n" + " :rtype: float"); static PyObject *Stroke_compute_sampling(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"n", NULL}; - int i; + static const char *kwlist[] = {"n", NULL}; + int i; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) - return NULL; - return PyFloat_FromDouble(self->s->ComputeSampling(i)); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) + return NULL; + return PyFloat_FromDouble(self->s->ComputeSampling(i)); } PyDoc_STRVAR(Stroke_resample_doc, -".. method:: resample(n)\n" -"\n" -" Resamples the stroke so that it eventually has N points. That means\n" -" it is going to add N-vertices_size, where vertices_size is the\n" -" number of points we already have. If vertices_size >= N, no\n" -" resampling is done.\n" -"\n" -" :arg n: The number of vertices we eventually want in our stroke.\n" -" :type n: int\n" -"\n" -".. method:: resample(sampling)\n" -"\n" -" Resamples the stroke with a given sampling. If the sampling is\n" -" smaller than the actual sampling value, no resampling is done.\n" -"\n" -" :arg sampling: The new sampling value.\n" -" :type sampling: float"); + ".. method:: resample(n)\n" + "\n" + " Resamples the stroke so that it eventually has N points. That means\n" + " it is going to add N-vertices_size, where vertices_size is the\n" + " number of points we already have. If vertices_size >= N, no\n" + " resampling is done.\n" + "\n" + " :arg n: The number of vertices we eventually want in our stroke.\n" + " :type n: int\n" + "\n" + ".. method:: resample(sampling)\n" + "\n" + " Resamples the stroke with a given sampling. If the sampling is\n" + " smaller than the actual sampling value, no resampling is done.\n" + "\n" + " :arg sampling: The new sampling value.\n" + " :type sampling: float"); static PyObject *Stroke_resample(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"n", NULL}; - static const char *kwlist_2[] = {"sampling", NULL}; - int i; - float f; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist_1, &i)) { - if (self->s->Resample(i) < 0) { - PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex count) failed"); - return NULL; - } - } - else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &f)) { - if (self->s->Resample(f) < 0) { - PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex interval) failed"); - return NULL; - } - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist_1[] = {"n", NULL}; + static const char *kwlist_2[] = {"sampling", NULL}; + int i; + float f; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist_1, &i)) { + if (self->s->Resample(i) < 0) { + PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex count) failed"); + return NULL; + } + } + else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &f)) { + if (self->s->Resample(f) < 0) { + PyErr_SetString(PyExc_RuntimeError, "Stroke resampling (by vertex interval) failed"); + return NULL; + } + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Stroke_insert_vertex_doc, -".. method:: insert_vertex(vertex, next)\n" -"\n" -" Inserts the StrokeVertex given as argument into the Stroke before the\n" -" point specified by next. The length and curvilinear abscissa are\n" -" updated consequently.\n" -"\n" -" :arg vertex: The StrokeVertex to insert in the Stroke.\n" -" :type vertex: :class:`StrokeVertex`\n" -" :arg next: A StrokeVertexIterator pointing to the StrokeVertex\n" -" before which vertex must be inserted.\n" -" :type next: :class:`StrokeVertexIterator`"); + ".. method:: insert_vertex(vertex, next)\n" + "\n" + " Inserts the StrokeVertex given as argument into the Stroke before the\n" + " point specified by next. The length and curvilinear abscissa are\n" + " updated consequently.\n" + "\n" + " :arg vertex: The StrokeVertex to insert in the Stroke.\n" + " :type vertex: :class:`StrokeVertex`\n" + " :arg next: A StrokeVertexIterator pointing to the StrokeVertex\n" + " before which vertex must be inserted.\n" + " :type next: :class:`StrokeVertexIterator`"); static PyObject *Stroke_insert_vertex(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"vertex", "next", NULL}; - PyObject *py_sv = 0, *py_sv_it = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &StrokeVertex_Type, &py_sv, &StrokeVertexIterator_Type, &py_sv_it)) - { - return NULL; - } - ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.borrowed = true; /* make the wrapped StrokeVertex internal */ - StrokeVertex *sv = ((BPy_StrokeVertex *)py_sv)->sv; - StrokeInternal::StrokeVertexIterator sv_it(*(((BPy_StrokeVertexIterator *)py_sv_it)->sv_it)); - self->s->InsertVertex(sv, sv_it); - Py_RETURN_NONE; + static const char *kwlist[] = {"vertex", "next", NULL}; + PyObject *py_sv = 0, *py_sv_it = 0; + + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist, + &StrokeVertex_Type, + &py_sv, + &StrokeVertexIterator_Type, + &py_sv_it)) { + return NULL; + } + ((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.borrowed = + true; /* make the wrapped StrokeVertex internal */ + StrokeVertex *sv = ((BPy_StrokeVertex *)py_sv)->sv; + StrokeInternal::StrokeVertexIterator sv_it(*(((BPy_StrokeVertexIterator *)py_sv_it)->sv_it)); + self->s->InsertVertex(sv, sv_it); + Py_RETURN_NONE; } PyDoc_STRVAR(Stroke_remove_vertex_doc, -".. method:: remove_vertex(vertex)\n" -"\n" -" Removes the StrokeVertex given as argument from the Stroke. The length\n" -" and curvilinear abscissa are updated consequently.\n" -"\n" -" :arg vertex: the StrokeVertex to remove from the Stroke.\n" -" :type vertex: :class:`StrokeVertex`"); - -static PyObject *Stroke_remove_vertex( BPy_Stroke *self, PyObject *args, PyObject *kwds) + ".. method:: remove_vertex(vertex)\n" + "\n" + " Removes the StrokeVertex given as argument from the Stroke. The length\n" + " and curvilinear abscissa are updated consequently.\n" + "\n" + " :arg vertex: the StrokeVertex to remove from the Stroke.\n" + " :type vertex: :class:`StrokeVertex`"); + +static PyObject *Stroke_remove_vertex(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"vertex", NULL}; - PyObject *py_sv = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &StrokeVertex_Type, &py_sv)) - return NULL; - if (((BPy_StrokeVertex *)py_sv)->sv) { - self->s->RemoveVertex(((BPy_StrokeVertex *)py_sv)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"vertex", NULL}; + PyObject *py_sv = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &StrokeVertex_Type, &py_sv)) + return NULL; + if (((BPy_StrokeVertex *)py_sv)->sv) { + self->s->RemoveVertex(((BPy_StrokeVertex *)py_sv)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return NULL; + } + Py_RETURN_NONE; } PyDoc_STRVAR(Stroke_remove_all_vertices_doc, -".. method:: remove_all_vertices()\n" -"\n" -" Removes all vertices from the Stroke."); + ".. method:: remove_all_vertices()\n" + "\n" + " Removes all vertices from the Stroke."); static PyObject *Stroke_remove_all_vertices(BPy_Stroke *self) { - self->s->RemoveAllVertices(); - Py_RETURN_NONE; + self->s->RemoveAllVertices(); + Py_RETURN_NONE; } PyDoc_STRVAR(Stroke_update_length_doc, -".. method:: update_length()\n" -"\n" -" Updates the 2D length of the Stroke."); + ".. method:: update_length()\n" + "\n" + " Updates the 2D length of the Stroke."); static PyObject *Stroke_update_length(BPy_Stroke *self) { - self->s->UpdateLength(); - Py_RETURN_NONE; + self->s->UpdateLength(); + Py_RETURN_NONE; } PyDoc_STRVAR(Stroke_stroke_vertices_begin_doc, -".. method:: stroke_vertices_begin(t=0.0)\n" -"\n" -" Returns a StrokeVertexIterator pointing on the first StrokeVertex of\n" -" the Stroke. One can specify a sampling value to resample the Stroke\n" -" on the fly if needed.\n" -"\n" -" :arg t: The resampling value with which we want our Stroke to be\n" -" resampled. If 0 is specified, no resampling is done.\n" -" :type t: float\n" -" :return: A StrokeVertexIterator pointing on the first StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: stroke_vertices_begin(t=0.0)\n" + "\n" + " Returns a StrokeVertexIterator pointing on the first StrokeVertex of\n" + " the Stroke. One can specify a sampling value to resample the Stroke\n" + " on the fly if needed.\n" + "\n" + " :arg t: The resampling value with which we want our Stroke to be\n" + " resampled. If 0 is specified, no resampling is done.\n" + " :type t: float\n" + " :return: A StrokeVertexIterator pointing on the first StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *Stroke_stroke_vertices_begin(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"t", NULL}; - float f = 0.0f; + static const char *kwlist[] = {"t", NULL}; + float f = 0.0f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) - return NULL; - StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesBegin(f)); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, false); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) + return NULL; + StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesBegin(f)); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, false); } PyDoc_STRVAR(Stroke_stroke_vertices_end_doc, -".. method:: stroke_vertices_end()\n" -"\n" -" Returns a StrokeVertexIterator pointing after the last StrokeVertex\n" -" of the Stroke.\n" -"\n" -" :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: stroke_vertices_end()\n" + "\n" + " Returns a StrokeVertexIterator pointing after the last StrokeVertex\n" + " of the Stroke.\n" + "\n" + " :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *Stroke_stroke_vertices_end(BPy_Stroke *self) { - StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd()); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true); + StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd()); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true); } PyDoc_STRVAR(Stroke_reversed_doc, -".. method:: __reversed__()\n" -"\n" -" Returns a StrokeVertexIterator iterating over the vertices of the Stroke\n" -" in the reversed order (from the last to the first).\n" -"\n" -" :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: __reversed__()\n" + "\n" + " Returns a StrokeVertexIterator iterating over the vertices of the Stroke\n" + " in the reversed order (from the last to the first).\n" + "\n" + " :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *Stroke_reversed(BPy_Stroke *self) { - StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd()); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true); + StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd()); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true); } PyDoc_STRVAR(Stroke_stroke_vertices_size_doc, -".. method:: stroke_vertices_size()\n" -"\n" -" Returns the number of StrokeVertex constituting the Stroke.\n" -"\n" -" :return: The number of stroke vertices.\n" -" :rtype: int"); + ".. method:: stroke_vertices_size()\n" + "\n" + " Returns the number of StrokeVertex constituting the Stroke.\n" + "\n" + " :return: The number of stroke vertices.\n" + " :rtype: int"); static PyObject *Stroke_stroke_vertices_size(BPy_Stroke *self) { - return PyLong_FromLong(self->s->strokeVerticesSize()); + return PyLong_FromLong(self->s->strokeVerticesSize()); } static PyMethodDef BPy_Stroke_methods[] = { - {"compute_sampling", (PyCFunction)Stroke_compute_sampling, METH_VARARGS | METH_KEYWORDS, - Stroke_compute_sampling_doc}, - {"resample", (PyCFunction)Stroke_resample, METH_VARARGS | METH_KEYWORDS, Stroke_resample_doc}, - {"remove_all_vertices", (PyCFunction)Stroke_remove_all_vertices, METH_NOARGS, Stroke_remove_all_vertices_doc}, - {"remove_vertex", (PyCFunction)Stroke_remove_vertex, METH_VARARGS | METH_KEYWORDS, Stroke_remove_vertex_doc}, - {"insert_vertex", (PyCFunction)Stroke_insert_vertex, METH_VARARGS | METH_KEYWORDS, Stroke_insert_vertex_doc}, - {"update_length", (PyCFunction)Stroke_update_length, METH_NOARGS, Stroke_update_length_doc}, - {"stroke_vertices_begin", (PyCFunction)Stroke_stroke_vertices_begin, METH_VARARGS | METH_KEYWORDS, - Stroke_stroke_vertices_begin_doc}, - {"stroke_vertices_end", (PyCFunction)Stroke_stroke_vertices_end, METH_NOARGS, Stroke_stroke_vertices_end_doc}, - {"__reversed__", (PyCFunction)Stroke_reversed, METH_NOARGS, Stroke_reversed_doc}, - {"stroke_vertices_size", (PyCFunction)Stroke_stroke_vertices_size, METH_NOARGS, Stroke_stroke_vertices_size_doc}, - {NULL, NULL, 0, NULL}, + {"compute_sampling", + (PyCFunction)Stroke_compute_sampling, + METH_VARARGS | METH_KEYWORDS, + Stroke_compute_sampling_doc}, + {"resample", (PyCFunction)Stroke_resample, METH_VARARGS | METH_KEYWORDS, Stroke_resample_doc}, + {"remove_all_vertices", + (PyCFunction)Stroke_remove_all_vertices, + METH_NOARGS, + Stroke_remove_all_vertices_doc}, + {"remove_vertex", + (PyCFunction)Stroke_remove_vertex, + METH_VARARGS | METH_KEYWORDS, + Stroke_remove_vertex_doc}, + {"insert_vertex", + (PyCFunction)Stroke_insert_vertex, + METH_VARARGS | METH_KEYWORDS, + Stroke_insert_vertex_doc}, + {"update_length", (PyCFunction)Stroke_update_length, METH_NOARGS, Stroke_update_length_doc}, + {"stroke_vertices_begin", + (PyCFunction)Stroke_stroke_vertices_begin, + METH_VARARGS | METH_KEYWORDS, + Stroke_stroke_vertices_begin_doc}, + {"stroke_vertices_end", + (PyCFunction)Stroke_stroke_vertices_end, + METH_NOARGS, + Stroke_stroke_vertices_end_doc}, + {"__reversed__", (PyCFunction)Stroke_reversed, METH_NOARGS, Stroke_reversed_doc}, + {"stroke_vertices_size", + (PyCFunction)Stroke_stroke_vertices_size, + METH_NOARGS, + Stroke_stroke_vertices_size_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------Stroke get/setters ----------------------------*/ PyDoc_STRVAR(Stroke_medium_type_doc, -"The MediumType used for this Stroke.\n" -"\n" -":type: :class:`MediumType`"); + "The MediumType used for this Stroke.\n" + "\n" + ":type: :class:`MediumType`"); static PyObject *Stroke_medium_type_get(BPy_Stroke *self, void *UNUSED(closure)) { - return BPy_MediumType_from_MediumType(self->s->getMediumType()); + return BPy_MediumType_from_MediumType(self->s->getMediumType()); } static int Stroke_medium_type_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_MediumType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a MediumType"); - return -1; - } - self->s->setMediumType(MediumType_from_BPy_MediumType(value)); - return 0; + if (!BPy_MediumType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a MediumType"); + return -1; + } + self->s->setMediumType(MediumType_from_BPy_MediumType(value)); + return 0; } PyDoc_STRVAR(Stroke_texture_id_doc, -"The ID of the texture used to simulate th marks system for this Stroke.\n" -"\n" -":type: int"); + "The ID of the texture used to simulate th marks system for this Stroke.\n" + "\n" + ":type: int"); static PyObject *Stroke_texture_id_get(BPy_Stroke *self, void *UNUSED(closure)) { - return PyLong_FromLong( self->s->getTextureId() ); + return PyLong_FromLong(self->s->getTextureId()); } static int Stroke_texture_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) { - unsigned int i = PyLong_AsUnsignedLong(value); - if (PyErr_Occurred()) - return -1; - self->s->setTextureId(i); - return 0; + unsigned int i = PyLong_AsUnsignedLong(value); + if (PyErr_Occurred()) + return -1; + self->s->setTextureId(i); + return 0; } PyDoc_STRVAR(Stroke_tips_doc, -"True if this Stroke uses a texture with tips, and false otherwise.\n" -"\n" -":type: bool"); + "True if this Stroke uses a texture with tips, and false otherwise.\n" + "\n" + ":type: bool"); static PyObject *Stroke_tips_get(BPy_Stroke *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->s->hasTips()); + return PyBool_from_bool(self->s->hasTips()); } static int Stroke_tips_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) { - if (!PyBool_Check(value)) - return -1; - self->s->setTips(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) + return -1; + self->s->setTips(bool_from_PyBool(value)); + return 0; } PyDoc_STRVAR(Stroke_length_2d_doc, -"The 2D length of the Stroke.\n" -"\n" -":type: float"); + "The 2D length of the Stroke.\n" + "\n" + ":type: float"); static PyObject *Stroke_length_2d_get(BPy_Stroke *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->s->getLength2D()); + return PyFloat_FromDouble(self->s->getLength2D()); } static int Stroke_length_2d_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) { - float scalar; - if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ - PyErr_SetString(PyExc_TypeError, "value must be a number"); - return -1; - } - self->s->setLength(scalar); - return 0; + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && + PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->s->setLength(scalar); + return 0; } PyDoc_STRVAR(Stroke_id_doc, -"The Id of this Stroke.\n" -"\n" -":type: :class:`Id`"); + "The Id of this Stroke.\n" + "\n" + ":type: :class:`Id`"); static PyObject *Stroke_id_get(BPy_Stroke *self, void *UNUSED(closure)) { - Id id(self->s->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->s->getId()); + return BPy_Id_from_Id(id); // return a copy } static int Stroke_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->s->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->s->setId(*(((BPy_Id *)value)->id)); + return 0; } static PyGetSetDef BPy_Stroke_getseters[] = { - {(char *)"medium_type", (getter)Stroke_medium_type_get, (setter)Stroke_medium_type_set, - (char *)Stroke_medium_type_doc, NULL}, - {(char *)"texture_id", (getter)Stroke_texture_id_get, (setter)Stroke_texture_id_set, - (char *)Stroke_texture_id_doc, NULL}, - {(char *)"tips", (getter)Stroke_tips_get, (setter)Stroke_tips_set, (char *)Stroke_tips_doc, NULL}, - {(char *)"length_2d", (getter)Stroke_length_2d_get, (setter)Stroke_length_2d_set, - (char *)Stroke_length_2d_doc, NULL}, - {(char *)"id", (getter)Stroke_id_get, (setter)Stroke_id_set, (char *)Stroke_id_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"medium_type", + (getter)Stroke_medium_type_get, + (setter)Stroke_medium_type_set, + (char *)Stroke_medium_type_doc, + NULL}, + {(char *)"texture_id", + (getter)Stroke_texture_id_get, + (setter)Stroke_texture_id_set, + (char *)Stroke_texture_id_doc, + NULL}, + {(char *)"tips", + (getter)Stroke_tips_get, + (setter)Stroke_tips_set, + (char *)Stroke_tips_doc, + NULL}, + {(char *)"length_2d", + (getter)Stroke_length_2d_get, + (setter)Stroke_length_2d_set, + (char *)Stroke_length_2d_doc, + NULL}, + {(char *)"id", (getter)Stroke_id_get, (setter)Stroke_id_set, (char *)Stroke_id_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Stroke type definition ------------------------------*/ static PySequenceMethods BPy_Stroke_as_sequence = { - (lenfunc)Stroke_sq_length, /* sq_length */ - NULL, /* sq_concat */ - NULL, /* sq_repeat */ - (ssizeargfunc)Stroke_sq_item, /* sq_item */ - NULL, /* sq_slice */ - NULL, /* sq_ass_item */ - NULL, /* *was* sq_ass_slice */ - NULL, /* sq_contains */ - NULL, /* sq_inplace_concat */ - NULL, /* sq_inplace_repeat */ + (lenfunc)Stroke_sq_length, /* sq_length */ + NULL, /* sq_concat */ + NULL, /* sq_repeat */ + (ssizeargfunc)Stroke_sq_item, /* sq_item */ + NULL, /* sq_slice */ + NULL, /* sq_ass_item */ + NULL, /* *was* sq_ass_slice */ + NULL, /* sq_contains */ + NULL, /* sq_inplace_concat */ + NULL, /* sq_inplace_repeat */ }; PyTypeObject Stroke_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Stroke", /* tp_name */ - sizeof(BPy_Stroke), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &BPy_Stroke_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Stroke_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)Stroke_iter, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Stroke_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_Stroke_getseters, /* tp_getset */ - &Interface1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Stroke_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Stroke", /* tp_name */ + sizeof(BPy_Stroke), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + &BPy_Stroke_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Stroke_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)Stroke_iter, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Stroke_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_Stroke_getseters, /* tp_getset */ + &Interface1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Stroke_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.h b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.h index 869ff7d07d5..a08905e6043 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.h +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.h @@ -33,12 +33,12 @@ extern "C" { extern PyTypeObject Stroke_Type; -#define BPy_Stroke_Check(v) (((PyObject *)v)->ob_type == &Stroke_Type) +#define BPy_Stroke_Check(v) (((PyObject *)v)->ob_type == &Stroke_Type) /*---------------------------Python BPy_Stroke structure definition----------*/ typedef struct { - BPy_Interface1D py_if1D; - Stroke *s; + BPy_Interface1D py_if1D; + Stroke *s; } BPy_Stroke; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp index c047b678a64..6331145974a 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp @@ -37,338 +37,381 @@ extern "C" { /*----------------------ViewEdge methods ----------------------------*/ PyDoc_STRVAR(ViewEdge_doc, -"Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n" -"\n" -"Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n" -"it connects two :class:`ViewVertex` objects. It is made by connecting\n" -"a set of FEdges.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ViewEdge object.\n" -" :type brother: :class:`ViewEdge`"); + "Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n" + "\n" + "Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n" + "it connects two :class:`ViewVertex` objects. It is made by connecting\n" + "a set of FEdges.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ViewEdge object.\n" + " :type brother: :class:`ViewEdge`"); static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"brother", NULL}; - PyObject *brother = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &ViewEdge_Type, &brother)) - return -1; - if (!brother) - self->ve = new ViewEdge(); - else - self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve)); - self->py_if1D.if1D = self->ve; - self->py_if1D.borrowed = false; - return 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &ViewEdge_Type, &brother)) + return -1; + if (!brother) + self->ve = new ViewEdge(); + else + self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve)); + self->py_if1D.if1D = self->ve; + self->py_if1D.borrowed = false; + return 0; } PyDoc_STRVAR(ViewEdge_update_fedges_doc, -".. method:: update_fedges()\n" -"\n" -" Sets Viewedge to this for all embedded fedges.\n"); + ".. method:: update_fedges()\n" + "\n" + " Sets Viewedge to this for all embedded fedges.\n"); static PyObject *ViewEdge_update_fedges(BPy_ViewEdge *self) { - self->ve->UpdateFEdges(); - Py_RETURN_NONE; + self->ve->UpdateFEdges(); + Py_RETURN_NONE; } static PyMethodDef BPy_ViewEdge_methods[] = { - {"update_fedges", (PyCFunction)ViewEdge_update_fedges, METH_NOARGS, ViewEdge_update_fedges_doc}, - {NULL, NULL, 0, NULL}, + {"update_fedges", + (PyCFunction)ViewEdge_update_fedges, + METH_NOARGS, + ViewEdge_update_fedges_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewEdge get/setters ----------------------------*/ PyDoc_STRVAR(ViewEdge_first_viewvertex_doc, -"The first ViewVertex.\n" -"\n" -":type: :class:`ViewVertex`"); + "The first ViewVertex.\n" + "\n" + ":type: :class:`ViewVertex`"); static PyObject *ViewEdge_first_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - ViewVertex *v = self->ve->A(); - if (v) - return Any_BPy_ViewVertex_from_ViewVertex(*v); - Py_RETURN_NONE; + ViewVertex *v = self->ve->A(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); + Py_RETURN_NONE; } -static int ViewEdge_first_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdge_first_viewvertex_set(BPy_ViewEdge *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_ViewVertex_Check(value)) - return -1; - self->ve->setA(((BPy_ViewVertex *)value)->vv); - return 0; + if (!BPy_ViewVertex_Check(value)) + return -1; + self->ve->setA(((BPy_ViewVertex *)value)->vv); + return 0; } PyDoc_STRVAR(ViewEdge_last_viewvertex_doc, -"The second ViewVertex.\n" -"\n" -":type: :class:`ViewVertex`"); + "The second ViewVertex.\n" + "\n" + ":type: :class:`ViewVertex`"); static PyObject *ViewEdge_last_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - ViewVertex *v = self->ve->B(); - if (v) - return Any_BPy_ViewVertex_from_ViewVertex(*v); - Py_RETURN_NONE; + ViewVertex *v = self->ve->B(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); + Py_RETURN_NONE; } static int ViewEdge_last_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_ViewVertex_Check(value)) - return -1; - self->ve->setB(((BPy_ViewVertex *)value)->vv); - return 0; + if (!BPy_ViewVertex_Check(value)) + return -1; + self->ve->setB(((BPy_ViewVertex *)value)->vv); + return 0; } PyDoc_STRVAR(ViewEdge_first_fedge_doc, -"The first FEdge that constitutes this ViewEdge.\n" -"\n" -":type: :class:`FEdge`"); + "The first FEdge that constitutes this ViewEdge.\n" + "\n" + ":type: :class:`FEdge`"); static PyObject *ViewEdge_first_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - FEdge *fe = self->ve->fedgeA(); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + FEdge *fe = self->ve->fedgeA(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } static int ViewEdge_first_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_FEdge_Check(value)) - return -1; - self->ve->setFEdgeA(((BPy_FEdge *)value)->fe); - return 0; + if (!BPy_FEdge_Check(value)) + return -1; + self->ve->setFEdgeA(((BPy_FEdge *)value)->fe); + return 0; } PyDoc_STRVAR(ViewEdge_last_fedge_doc, -"The last FEdge that constitutes this ViewEdge.\n" -"\n" -":type: :class:`FEdge`"); + "The last FEdge that constitutes this ViewEdge.\n" + "\n" + ":type: :class:`FEdge`"); static PyObject *ViewEdge_last_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - FEdge *fe = self->ve->fedgeB(); - if (fe) - return Any_BPy_FEdge_from_FEdge(*fe); - Py_RETURN_NONE; + FEdge *fe = self->ve->fedgeB(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } static int ViewEdge_last_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_FEdge_Check(value)) - return -1; - self->ve->setFEdgeB(((BPy_FEdge *)value)->fe); - return 0; + if (!BPy_FEdge_Check(value)) + return -1; + self->ve->setFEdgeB(((BPy_FEdge *)value)->fe); + return 0; } PyDoc_STRVAR(ViewEdge_viewshape_doc, -"The ViewShape to which this ViewEdge belongs to.\n" -"\n" -":type: :class:`ViewShape`"); + "The ViewShape to which this ViewEdge belongs to.\n" + "\n" + ":type: :class:`ViewShape`"); static PyObject *ViewEdge_viewshape_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - ViewShape *vs = self->ve->viewShape(); - if (vs) - return BPy_ViewShape_from_ViewShape(*vs); - Py_RETURN_NONE; + ViewShape *vs = self->ve->viewShape(); + if (vs) + return BPy_ViewShape_from_ViewShape(*vs); + Py_RETURN_NONE; } static int ViewEdge_viewshape_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_ViewShape_Check(value)) - return -1; - self->ve->setShape(((BPy_ViewShape *)value)->vs); - return 0; + if (!BPy_ViewShape_Check(value)) + return -1; + self->ve->setShape(((BPy_ViewShape *)value)->vs); + return 0; } PyDoc_STRVAR(ViewEdge_occludee_doc, -"The shape that is occluded by the ViewShape to which this ViewEdge\n" -"belongs to. If no object is occluded, this property is set to None.\n" -"\n" -":type: :class:`ViewShape`"); + "The shape that is occluded by the ViewShape to which this ViewEdge\n" + "belongs to. If no object is occluded, this property is set to None.\n" + "\n" + ":type: :class:`ViewShape`"); static PyObject *ViewEdge_occludee_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - ViewShape *vs = self->ve->aShape(); - if (vs) - return BPy_ViewShape_from_ViewShape(*vs); - Py_RETURN_NONE; + ViewShape *vs = self->ve->aShape(); + if (vs) + return BPy_ViewShape_from_ViewShape(*vs); + Py_RETURN_NONE; } static int ViewEdge_occludee_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_ViewShape_Check(value)) - return -1; - self->ve->setaShape(((BPy_ViewShape *)value)->vs); - return 0; + if (!BPy_ViewShape_Check(value)) + return -1; + self->ve->setaShape(((BPy_ViewShape *)value)->vs); + return 0; } PyDoc_STRVAR(ViewEdge_is_closed_doc, -"True if this ViewEdge forms a closed loop.\n" -"\n" -":type: bool"); + "True if this ViewEdge forms a closed loop.\n" + "\n" + ":type: bool"); static PyObject *ViewEdge_is_closed_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->ve->isClosed()); + return PyBool_from_bool(self->ve->isClosed()); } PyDoc_STRVAR(ViewEdge_id_doc, -"The Id of this ViewEdge.\n" -"\n" -":type: :class:`Id`"); + "The Id of this ViewEdge.\n" + "\n" + ":type: :class:`Id`"); static PyObject *ViewEdge_id_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - Id id(self->ve->getId()); - return BPy_Id_from_Id(id); // return a copy + Id id(self->ve->getId()); + return BPy_Id_from_Id(id); // return a copy } static int ViewEdge_id_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Id_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an Id"); - return -1; - } - self->ve->setId(*(((BPy_Id *)value)->id)); - return 0; + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->ve->setId(*(((BPy_Id *)value)->id)); + return 0; } PyDoc_STRVAR(ViewEdge_nature_doc, -"The nature of this ViewEdge.\n" -"\n" -":type: :class:`Nature`"); + "The nature of this ViewEdge.\n" + "\n" + ":type: :class:`Nature`"); static PyObject *ViewEdge_nature_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - return BPy_Nature_from_Nature(self->ve->getNature()); + return BPy_Nature_from_Nature(self->ve->getNature()); } static int ViewEdge_nature_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - if (!BPy_Nature_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a Nature"); - return -1; - } - self->ve->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); - return 0; + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->ve->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; } PyDoc_STRVAR(ViewEdge_qi_doc, -"The quantitative invisibility.\n" -"\n" -":type: int"); + "The quantitative invisibility.\n" + "\n" + ":type: int"); static PyObject *ViewEdge_qi_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->ve->qi()); + return PyLong_FromLong(self->ve->qi()); } static int ViewEdge_qi_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) { - int qi; + int qi; - if ((qi = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) - return -1; - self->ve->setQI(qi); - return 0; + if ((qi = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) + return -1; + self->ve->setQI(qi); + return 0; } PyDoc_STRVAR(ViewEdge_chaining_time_stamp_doc, -"The time stamp of this ViewEdge.\n" -"\n" -":type: int"); + "The time stamp of this ViewEdge.\n" + "\n" + ":type: int"); static PyObject *ViewEdge_chaining_time_stamp_get(BPy_ViewEdge *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->ve->getChainingTimeStamp()); + return PyLong_FromLong(self->ve->getChainingTimeStamp()); } -static int ViewEdge_chaining_time_stamp_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdge_chaining_time_stamp_set(BPy_ViewEdge *self, + PyObject *value, + void *UNUSED(closure)) { - int timestamp; + int timestamp; - if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) - return -1; - self->ve->setChainingTimeStamp(timestamp); - return 0; + if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) + return -1; + self->ve->setChainingTimeStamp(timestamp); + return 0; } static PyGetSetDef BPy_ViewEdge_getseters[] = { - {(char *)"first_viewvertex", (getter)ViewEdge_first_viewvertex_get, (setter)ViewEdge_first_viewvertex_set, - (char *)ViewEdge_first_viewvertex_doc, NULL}, - {(char *)"last_viewvertex", (getter)ViewEdge_last_viewvertex_get, (setter)ViewEdge_last_viewvertex_set, - (char *)ViewEdge_last_viewvertex_doc, NULL}, - {(char *)"first_fedge", (getter)ViewEdge_first_fedge_get, (setter)ViewEdge_first_fedge_set, - (char *)ViewEdge_first_fedge_doc, NULL}, - {(char *)"last_fedge", (getter)ViewEdge_last_fedge_get, (setter)ViewEdge_last_fedge_set, - (char *)ViewEdge_last_fedge_doc, NULL}, - {(char *)"viewshape", (getter)ViewEdge_viewshape_get, (setter)ViewEdge_viewshape_set, - (char *)ViewEdge_viewshape_doc, NULL}, - {(char *)"occludee", (getter)ViewEdge_occludee_get, (setter)ViewEdge_occludee_set, - (char *)ViewEdge_occludee_doc, NULL}, - {(char *)"is_closed", (getter)ViewEdge_is_closed_get, (setter)NULL, (char *)ViewEdge_is_closed_doc, NULL}, - {(char *)"id", (getter)ViewEdge_id_get, (setter)ViewEdge_id_set, (char *)ViewEdge_id_doc, NULL}, - {(char *)"nature", (getter)ViewEdge_nature_get, (setter)ViewEdge_nature_set, (char *)ViewEdge_nature_doc, NULL}, - {(char *)"qi", (getter)ViewEdge_qi_get, (setter)ViewEdge_qi_set, (char *)ViewEdge_qi_doc, NULL}, - {(char *)"chaining_time_stamp", (getter)ViewEdge_chaining_time_stamp_get, (setter)ViewEdge_chaining_time_stamp_set, - (char *)ViewEdge_chaining_time_stamp_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"first_viewvertex", + (getter)ViewEdge_first_viewvertex_get, + (setter)ViewEdge_first_viewvertex_set, + (char *)ViewEdge_first_viewvertex_doc, + NULL}, + {(char *)"last_viewvertex", + (getter)ViewEdge_last_viewvertex_get, + (setter)ViewEdge_last_viewvertex_set, + (char *)ViewEdge_last_viewvertex_doc, + NULL}, + {(char *)"first_fedge", + (getter)ViewEdge_first_fedge_get, + (setter)ViewEdge_first_fedge_set, + (char *)ViewEdge_first_fedge_doc, + NULL}, + {(char *)"last_fedge", + (getter)ViewEdge_last_fedge_get, + (setter)ViewEdge_last_fedge_set, + (char *)ViewEdge_last_fedge_doc, + NULL}, + {(char *)"viewshape", + (getter)ViewEdge_viewshape_get, + (setter)ViewEdge_viewshape_set, + (char *)ViewEdge_viewshape_doc, + NULL}, + {(char *)"occludee", + (getter)ViewEdge_occludee_get, + (setter)ViewEdge_occludee_set, + (char *)ViewEdge_occludee_doc, + NULL}, + {(char *)"is_closed", + (getter)ViewEdge_is_closed_get, + (setter)NULL, + (char *)ViewEdge_is_closed_doc, + NULL}, + {(char *)"id", + (getter)ViewEdge_id_get, + (setter)ViewEdge_id_set, + (char *)ViewEdge_id_doc, + NULL}, + {(char *)"nature", + (getter)ViewEdge_nature_get, + (setter)ViewEdge_nature_set, + (char *)ViewEdge_nature_doc, + NULL}, + {(char *)"qi", + (getter)ViewEdge_qi_get, + (setter)ViewEdge_qi_set, + (char *)ViewEdge_qi_doc, + NULL}, + {(char *)"chaining_time_stamp", + (getter)ViewEdge_chaining_time_stamp_get, + (setter)ViewEdge_chaining_time_stamp_set, + (char *)ViewEdge_chaining_time_stamp_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewEdge type definition ------------------------------*/ PyTypeObject ViewEdge_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewEdge", /* tp_name */ - sizeof(BPy_ViewEdge), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewEdge_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewEdge_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewEdge_getseters, /* tp_getset */ - &Interface1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewEdge_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewEdge", /* tp_name */ + sizeof(BPy_ViewEdge), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewEdge_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewEdge_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewEdge_getseters, /* tp_getset */ + &Interface1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewEdge_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.h b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.h index 81fd21fa092..c02d5d0f21b 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.h +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.h @@ -37,8 +37,8 @@ extern PyTypeObject ViewEdge_Type; /*---------------------------Python BPy_ViewEdge structure definition----------*/ typedef struct { - BPy_Interface1D py_if1D; - ViewEdge *ve; + BPy_Interface1D py_if1D; + ViewEdge *ve; } BPy_ViewEdge; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp index 0185fcc5ebe..7a6b2a01728 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp @@ -33,160 +33,160 @@ extern "C" { /*----------------------Chain methods ----------------------------*/ PyDoc_STRVAR(Chain_doc, -"Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n" -"\n" -"Class to represent a 1D elements issued from the chaining process. A\n" -"Chain is the last step before the :class:`Stroke` and is used in the\n" -"Splitting and Creation processes.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A Chain object.\n" -" :type brother: :class:`Chain`\n" -"\n" -".. method:: __init__(id)\n" -"\n" -" Builds a chain from its Id.\n" -"\n" -" :arg id: An Id object.\n" -" :type id: :class:`Id`"); + "Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n" + "\n" + "Class to represent a 1D elements issued from the chaining process. A\n" + "Chain is the last step before the :class:`Stroke` and is used in the\n" + "Splitting and Creation processes.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A Chain object.\n" + " :type brother: :class:`Chain`\n" + "\n" + ".. method:: __init__(id)\n" + "\n" + " Builds a chain from its Id.\n" + "\n" + " :arg id: An Id object.\n" + " :type id: :class:`Id`"); static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"id", NULL}; - PyObject *obj = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) { - if (!obj) - self->c = new Chain(); - else - self->c = new Chain(*(((BPy_Chain *)obj)->c)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) - { - self->c = new Chain(*(((BPy_Id *)obj)->id)); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_c.c = self->c; - self->py_c.py_if1D.if1D = self->c; - self->py_c.py_if1D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"id", NULL}; + PyObject *obj = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) { + if (!obj) + self->c = new Chain(); + else + self->c = new Chain(*(((BPy_Chain *)obj)->c)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) { + self->c = new Chain(*(((BPy_Id *)obj)->id)); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_c.c = self->c; + self->py_c.py_if1D.if1D = self->c; + self->py_c.py_if1D.borrowed = false; + return 0; } PyDoc_STRVAR(Chain_push_viewedge_back_doc, -".. method:: push_viewedge_back(viewedge, orientation)\n" -"\n" -" Adds a ViewEdge at the end of the Chain.\n" -"\n" -" :arg viewedge: The ViewEdge that must be added.\n" -" :type viewedge: :class:`ViewEdge`\n" -" :arg orientation: The orientation with which the ViewEdge must be\n" -" processed.\n" -" :type orientation: bool"); + ".. method:: push_viewedge_back(viewedge, orientation)\n" + "\n" + " Adds a ViewEdge at the end of the Chain.\n" + "\n" + " :arg viewedge: The ViewEdge that must be added.\n" + " :type viewedge: :class:`ViewEdge`\n" + " :arg orientation: The orientation with which the ViewEdge must be\n" + " processed.\n" + " :type orientation: bool"); static PyObject *Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"viewedge", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) - { - return NULL; - } - ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve; - bool orientation = bool_from_PyBool(obj2); - self->c->push_viewedge_back(ve, orientation); - Py_RETURN_NONE; + static const char *kwlist[] = {"viewedge", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) { + return NULL; + } + ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve; + bool orientation = bool_from_PyBool(obj2); + self->c->push_viewedge_back(ve, orientation); + Py_RETURN_NONE; } PyDoc_STRVAR(Chain_push_viewedge_front_doc, -".. method:: push_viewedge_front(viewedge, orientation)\n" -"\n" -" Adds a ViewEdge at the beginning of the Chain.\n" -"\n" -" :arg viewedge: The ViewEdge that must be added.\n" -" :type viewedge: :class:`ViewEdge`\n" -" :arg orientation: The orientation with which the ViewEdge must be\n" -" processed.\n" -" :type orientation: bool"); + ".. method:: push_viewedge_front(viewedge, orientation)\n" + "\n" + " Adds a ViewEdge at the beginning of the Chain.\n" + "\n" + " :arg viewedge: The ViewEdge that must be added.\n" + " :type viewedge: :class:`ViewEdge`\n" + " :arg orientation: The orientation with which the ViewEdge must be\n" + " processed.\n" + " :type orientation: bool"); static PyObject *Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"viewedge", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist, - &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) - { - return NULL; - } - ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve; - bool orientation = bool_from_PyBool(obj2); - self->c->push_viewedge_front(ve, orientation); - Py_RETURN_NONE; + static const char *kwlist[] = {"viewedge", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) { + return NULL; + } + ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve; + bool orientation = bool_from_PyBool(obj2); + self->c->push_viewedge_front(ve, orientation); + Py_RETURN_NONE; } static PyMethodDef BPy_Chain_methods[] = { - {"push_viewedge_back", (PyCFunction)Chain_push_viewedge_back, METH_VARARGS | METH_KEYWORDS, - Chain_push_viewedge_back_doc}, - {"push_viewedge_front", (PyCFunction)Chain_push_viewedge_front, METH_VARARGS | METH_KEYWORDS, - Chain_push_viewedge_front_doc}, - {NULL, NULL, 0, NULL}, + {"push_viewedge_back", + (PyCFunction)Chain_push_viewedge_back, + METH_VARARGS | METH_KEYWORDS, + Chain_push_viewedge_back_doc}, + {"push_viewedge_front", + (PyCFunction)Chain_push_viewedge_front, + METH_VARARGS | METH_KEYWORDS, + Chain_push_viewedge_front_doc}, + {NULL, NULL, 0, NULL}, }; /*-----------------------BPy_Chain type definition ------------------------------*/ PyTypeObject Chain_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Chain", /* tp_name */ - sizeof(BPy_Chain), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Chain_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_Chain_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &FrsCurve_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Chain_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Chain", /* tp_name */ + sizeof(BPy_Chain), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Chain_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_Chain_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &FrsCurve_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Chain_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h index 3356b0144d6..a9392cd81bf 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h @@ -37,8 +37,8 @@ extern PyTypeObject Chain_Type; /*---------------------------Python BPy_Chain structure definition----------*/ typedef struct { - BPy_FrsCurve py_c; - Chain *c; + BPy_FrsCurve py_c; + Chain *c; } BPy_Chain; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index 8d83c942d93..e91ae155929 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -32,396 +32,414 @@ extern "C" { /*----------------------FEdgeSharp methods ----------------------------*/ PyDoc_STRVAR(FEdgeSharp_doc, -"Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n" -"\n" -"Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n" -"edge of the input mesh. It can be a silhouette, a crease or a border.\n" -"If it is a crease edge, then it is borded by two faces of the mesh.\n" -"Face a lies on its right whereas Face b lies on its left. If it is a\n" -"border edge, then it doesn't have any face on its right, and thus Face\n" -"a is None.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An FEdgeSharp object.\n" -" :type brother: :class:`FEdgeSharp`\n" -"\n" -".. method:: __init__(first_vertex, second_vertex)\n" -"\n" -" Builds an FEdgeSharp going from the first vertex to the second.\n" -"\n" -" :arg first_vertex: The first SVertex object.\n" -" :type first_vertex: :class:`SVertex`\n" -" :arg second_vertex: The second SVertex object.\n" -" :type second_vertex: :class:`SVertex`"); + "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n" + "\n" + "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n" + "edge of the input mesh. It can be a silhouette, a crease or a border.\n" + "If it is a crease edge, then it is borded by two faces of the mesh.\n" + "Face a lies on its right whereas Face b lies on its left. If it is a\n" + "border edge, then it doesn't have any face on its right, and thus Face\n" + "a is None.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An FEdgeSharp object.\n" + " :type brother: :class:`FEdgeSharp`\n" + "\n" + ".. method:: __init__(first_vertex, second_vertex)\n" + "\n" + " Builds an FEdgeSharp going from the first vertex to the second.\n" + "\n" + " :arg first_vertex: The first SVertex object.\n" + " :type first_vertex: :class:`SVertex`\n" + " :arg second_vertex: The second SVertex object.\n" + " :type second_vertex: :class:`SVertex`"); static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) { - if (!obj1) - self->fes = new FEdgeSharp(); - else - self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, - &SVertex_Type, &obj1, &SVertex_Type, &obj2)) - { - self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_fe.fe = self->fes; - self->py_fe.py_if1D.if1D = self->fes; - self->py_fe.py_if1D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) { + if (!obj1) + self->fes = new FEdgeSharp(); + else + self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2)) { + self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_fe.fe = self->fes; + self->py_fe.py_if1D.if1D = self->fes; + self->py_fe.py_if1D.borrowed = false; + return 0; } /*----------------------mathutils callbacks ----------------------------*/ /* subtype */ -#define MATHUTILS_SUBTYPE_NORMAL_A 1 -#define MATHUTILS_SUBTYPE_NORMAL_B 2 +#define MATHUTILS_SUBTYPE_NORMAL_A 1 +#define MATHUTILS_SUBTYPE_NORMAL_B 2 static int FEdgeSharp_mathutils_check(BaseMathObject *bmo) { - if (!BPy_FEdgeSharp_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_FEdgeSharp_Check(bmo->cb_user)) + return -1; + return 0; } static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype) { - BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_NORMAL_A: - { - Vec3r p(self->fes->normalA()); - bmo->data[0] = p[0]; - bmo->data[1] = p[1]; - bmo->data[2] = p[2]; - } - break; - case MATHUTILS_SUBTYPE_NORMAL_B: - { - Vec3r p(self->fes->normalB()); - bmo->data[0] = p[0]; - bmo->data[1] = p[1]; - bmo->data[2] = p[2]; - } - break; - default: - return -1; - } - return 0; + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: { + Vec3r p(self->fes->normalA()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + } break; + case MATHUTILS_SUBTYPE_NORMAL_B: { + Vec3r p(self->fes->normalB()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + } break; + default: + return -1; + } + return 0; } static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype) { - BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_NORMAL_A: - { - Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); - self->fes->setNormalA(p); - } - break; - case MATHUTILS_SUBTYPE_NORMAL_B: - { - Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); - self->fes->setNormalB(p); - } - break; - default: - return -1; - } - return 0; + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormalA(p); + } break; + case MATHUTILS_SUBTYPE_NORMAL_B: { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormalB(p); + } break; + default: + return -1; + } + return 0; } static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) { - BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_NORMAL_A: - { - Vec3r p(self->fes->normalA()); - bmo->data[index] = p[index]; - } - break; - case MATHUTILS_SUBTYPE_NORMAL_B: - { - Vec3r p(self->fes->normalB()); - bmo->data[index] = p[index]; - } - break; - default: - return -1; - } - return 0; + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: { + Vec3r p(self->fes->normalA()); + bmo->data[index] = p[index]; + } break; + case MATHUTILS_SUBTYPE_NORMAL_B: { + Vec3r p(self->fes->normalB()); + bmo->data[index] = p[index]; + } break; + default: + return -1; + } + return 0; } static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) { - BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; - switch (subtype) { - case MATHUTILS_SUBTYPE_NORMAL_A: - { - Vec3r p(self->fes->normalA()); - p[index] = bmo->data[index]; - self->fes->setNormalA(p); - } - break; - case MATHUTILS_SUBTYPE_NORMAL_B: - { - Vec3r p(self->fes->normalB()); - p[index] = bmo->data[index]; - self->fes->setNormalB(p); - } - break; - default: - return -1; - } - return 0; + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: { + Vec3r p(self->fes->normalA()); + p[index] = bmo->data[index]; + self->fes->setNormalA(p); + } break; + case MATHUTILS_SUBTYPE_NORMAL_B: { + Vec3r p(self->fes->normalB()); + p[index] = bmo->data[index]; + self->fes->setNormalB(p); + } break; + default: + return -1; + } + return 0; } static Mathutils_Callback FEdgeSharp_mathutils_cb = { - FEdgeSharp_mathutils_check, - FEdgeSharp_mathutils_get, - FEdgeSharp_mathutils_set, - FEdgeSharp_mathutils_get_index, - FEdgeSharp_mathutils_set_index, + FEdgeSharp_mathutils_check, + FEdgeSharp_mathutils_get, + FEdgeSharp_mathutils_set, + FEdgeSharp_mathutils_get_index, + FEdgeSharp_mathutils_set_index, }; static unsigned char FEdgeSharp_mathutils_cb_index = -1; void FEdgeSharp_mathutils_register_callback() { - FEdgeSharp_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSharp_mathutils_cb); + FEdgeSharp_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSharp_mathutils_cb); } /*----------------------FEdgeSharp get/setters ----------------------------*/ PyDoc_STRVAR(FEdgeSharp_normal_right_doc, -"The normal to the face lying on the right of the FEdge. If this FEdge\n" -"is a border, it has no Face on its right and therefore no normal.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The normal to the face lying on the right of the FEdge. If this FEdge\n" + "is a border, it has no Face on its right and therefore no normal.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_A); + return Vector_CreatePyObject_cb( + (PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_A); } -static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, + PyObject *value, + void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - Vec3r p(v[0], v[1], v[2]); - self->fes->setNormalA(p); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormalA(p); + return 0; } PyDoc_STRVAR(FEdgeSharp_normal_left_doc, -"The normal to the face lying on the left of the FEdge.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The normal to the face lying on the left of the FEdge.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_B); + return Vector_CreatePyObject_cb( + (PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_B); } static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - Vec3r p(v[0], v[1], v[2]); - self->fes->setNormalB(p); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormalB(p); + return 0; } PyDoc_STRVAR(FEdgeSharp_material_index_right_doc, -"The index of the material of the face lying on the right of the FEdge.\n" -"If this FEdge is a border, it has no Face on its right and therefore\n" -"no material.\n" -"\n" -":type: int"); + "The index of the material of the face lying on the right of the FEdge.\n" + "If this FEdge is a border, it has no Face on its right and therefore\n" + "no material.\n" + "\n" + ":type: int"); static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->fes->aFrsMaterialIndex()); + return PyLong_FromLong(self->fes->aFrsMaterialIndex()); } -static int FEdgeSharp_material_index_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSharp_material_index_right_set(BPy_FEdgeSharp *self, + PyObject *value, + void *UNUSED(closure)) { - unsigned int i = PyLong_AsUnsignedLong(value); - if (PyErr_Occurred()) - return -1; - self->fes->setaFrsMaterialIndex(i); - return 0; + unsigned int i = PyLong_AsUnsignedLong(value); + if (PyErr_Occurred()) + return -1; + self->fes->setaFrsMaterialIndex(i); + return 0; } PyDoc_STRVAR(FEdgeSharp_material_index_left_doc, -"The index of the material of the face lying on the left of the FEdge.\n" -"\n" -":type: int"); + "The index of the material of the face lying on the left of the FEdge.\n" + "\n" + ":type: int"); static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->fes->bFrsMaterialIndex()); + return PyLong_FromLong(self->fes->bFrsMaterialIndex()); } -static int FEdgeSharp_material_index_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSharp_material_index_left_set(BPy_FEdgeSharp *self, + PyObject *value, + void *UNUSED(closure)) { - unsigned int i = PyLong_AsUnsignedLong(value); - if (PyErr_Occurred()) - return -1; - self->fes->setbFrsMaterialIndex(i); - return 0; + unsigned int i = PyLong_AsUnsignedLong(value); + if (PyErr_Occurred()) + return -1; + self->fes->setbFrsMaterialIndex(i); + return 0; } PyDoc_STRVAR(FEdgeSharp_material_right_doc, -"The material of the face lying on the right of the FEdge. If this FEdge\n" -"is a border, it has no Face on its right and therefore no material.\n" -"\n" -":type: :class:`Material`"); + "The material of the face lying on the right of the FEdge. If this FEdge\n" + "is a border, it has no Face on its right and therefore no material.\n" + "\n" + ":type: :class:`Material`"); static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial()); + return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial()); } PyDoc_STRVAR(FEdgeSharp_material_left_doc, -"The material of the face lying on the left of the FEdge.\n" -"\n" -":type: :class:`Material`"); + "The material of the face lying on the left of the FEdge.\n" + "\n" + ":type: :class:`Material`"); static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial()); + return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial()); } PyDoc_STRVAR(FEdgeSharp_face_mark_right_doc, -"The face mark of the face lying on the right of the FEdge. If this FEdge\n" -"is a border, it has no face on the right and thus this property is set to\n" -"false.\n" -"\n" -":type: bool"); + "The face mark of the face lying on the right of the FEdge. If this FEdge\n" + "is a border, it has no face on the right and thus this property is set to\n" + "false.\n" + "\n" + ":type: bool"); static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->fes->aFaceMark()); + return PyBool_from_bool(self->fes->aFaceMark()); } -static int FEdgeSharp_face_mark_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSharp_face_mark_right_set(BPy_FEdgeSharp *self, + PyObject *value, + void *UNUSED(closure)) { - if (!PyBool_Check(value)) - return -1; - self->fes->setaFaceMark(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) + return -1; + self->fes->setaFaceMark(bool_from_PyBool(value)); + return 0; } PyDoc_STRVAR(FEdgeSharp_face_mark_left_doc, -"The face mark of the face lying on the left of the FEdge.\n" -"\n" -":type: bool"); + "The face mark of the face lying on the left of the FEdge.\n" + "\n" + ":type: bool"); static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->fes->bFaceMark()); + return PyBool_from_bool(self->fes->bFaceMark()); } -static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, + PyObject *value, + void *UNUSED(closure)) { - if (!PyBool_Check(value)) - return -1; - self->fes->setbFaceMark(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) + return -1; + self->fes->setbFaceMark(bool_from_PyBool(value)); + return 0; } static PyGetSetDef BPy_FEdgeSharp_getseters[] = { - {(char *)"normal_right", (getter)FEdgeSharp_normal_right_get, (setter)FEdgeSharp_normal_right_set, - (char *)FEdgeSharp_normal_right_doc, NULL}, - {(char *)"normal_left", (getter)FEdgeSharp_normal_left_get, (setter)FEdgeSharp_normal_left_set, - (char *)FEdgeSharp_normal_left_doc, NULL}, - {(char *)"material_index_right", (getter)FEdgeSharp_material_index_right_get, - (setter)FEdgeSharp_material_index_right_set, - (char *)FEdgeSharp_material_index_right_doc, NULL}, - {(char *)"material_index_left", (getter)FEdgeSharp_material_index_left_get, - (setter)FEdgeSharp_material_index_left_set, - (char *)FEdgeSharp_material_index_left_doc, NULL}, - {(char *)"material_right", (getter)FEdgeSharp_material_right_get, (setter)NULL, - (char *)FEdgeSharp_material_right_doc, NULL}, - {(char *)"material_left", (getter)FEdgeSharp_material_left_get, (setter)NULL, - (char *)FEdgeSharp_material_left_doc, NULL}, - {(char *)"face_mark_right", (getter)FEdgeSharp_face_mark_right_get, (setter)FEdgeSharp_face_mark_right_set, - (char *)FEdgeSharp_face_mark_right_doc, NULL}, - {(char *)"face_mark_left", (getter)FEdgeSharp_face_mark_left_get, (setter)FEdgeSharp_face_mark_left_set, - (char *)FEdgeSharp_face_mark_left_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"normal_right", + (getter)FEdgeSharp_normal_right_get, + (setter)FEdgeSharp_normal_right_set, + (char *)FEdgeSharp_normal_right_doc, + NULL}, + {(char *)"normal_left", + (getter)FEdgeSharp_normal_left_get, + (setter)FEdgeSharp_normal_left_set, + (char *)FEdgeSharp_normal_left_doc, + NULL}, + {(char *)"material_index_right", + (getter)FEdgeSharp_material_index_right_get, + (setter)FEdgeSharp_material_index_right_set, + (char *)FEdgeSharp_material_index_right_doc, + NULL}, + {(char *)"material_index_left", + (getter)FEdgeSharp_material_index_left_get, + (setter)FEdgeSharp_material_index_left_set, + (char *)FEdgeSharp_material_index_left_doc, + NULL}, + {(char *)"material_right", + (getter)FEdgeSharp_material_right_get, + (setter)NULL, + (char *)FEdgeSharp_material_right_doc, + NULL}, + {(char *)"material_left", + (getter)FEdgeSharp_material_left_get, + (setter)NULL, + (char *)FEdgeSharp_material_left_doc, + NULL}, + {(char *)"face_mark_right", + (getter)FEdgeSharp_face_mark_right_get, + (setter)FEdgeSharp_face_mark_right_set, + (char *)FEdgeSharp_face_mark_right_doc, + NULL}, + {(char *)"face_mark_left", + (getter)FEdgeSharp_face_mark_left_get, + (setter)FEdgeSharp_face_mark_left_set, + (char *)FEdgeSharp_face_mark_left_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdgeSharp type definition ------------------------------*/ PyTypeObject FEdgeSharp_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FEdgeSharp", /* tp_name */ - sizeof(BPy_FEdgeSharp), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdgeSharp_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_FEdgeSharp_getseters, /* tp_getset */ - &FEdge_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FEdgeSharp_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FEdgeSharp", /* tp_name */ + sizeof(BPy_FEdgeSharp), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FEdgeSharp_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_FEdgeSharp_getseters, /* tp_getset */ + &FEdge_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FEdgeSharp_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h index be9adf311b6..450539acb16 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h @@ -37,8 +37,8 @@ extern PyTypeObject FEdgeSharp_Type; /*---------------------------Python BPy_FEdgeSharp structure definition----------*/ typedef struct { - BPy_FEdge py_fe; - FEdgeSharp *fes; + BPy_FEdge py_fe; + FEdgeSharp *fes; } BPy_FEdgeSharp; /*---------------------------Python BPy_FEdgeSharp visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp index 726fe97b3ea..08d18123172 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -32,243 +32,261 @@ extern "C" { /*----------------------FEdgeSmooth methods ----------------------------*/ PyDoc_STRVAR(FEdgeSmooth_doc, -"Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n" -"\n" -"Class defining a smooth edge. This kind of edge typically runs across\n" -"a face of the input mesh. It can be a silhouette, a ridge or valley,\n" -"a suggestive contour.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An FEdgeSmooth object.\n" -" :type brother: :class:`FEdgeSmooth`\n" -"\n" -".. method:: __init__(first_vertex, second_vertex)\n" -"\n" -" Builds an FEdgeSmooth going from the first to the second.\n" -"\n" -" :arg first_vertex: The first SVertex object.\n" -" :type first_vertex: :class:`SVertex`\n" -" :arg second_vertex: The second SVertex object.\n" -" :type second_vertex: :class:`SVertex`"); + "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n" + "\n" + "Class defining a smooth edge. This kind of edge typically runs across\n" + "a face of the input mesh. It can be a silhouette, a ridge or valley,\n" + "a suggestive contour.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An FEdgeSmooth object.\n" + " :type brother: :class:`FEdgeSmooth`\n" + "\n" + ".. method:: __init__(first_vertex, second_vertex)\n" + "\n" + " Builds an FEdgeSmooth going from the first to the second.\n" + "\n" + " :arg first_vertex: The first SVertex object.\n" + " :type first_vertex: :class:`SVertex`\n" + " :arg second_vertex: The second SVertex object.\n" + " :type second_vertex: :class:`SVertex`"); static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; - PyObject *obj1 = 0, *obj2 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) { - if (!obj1) - self->fes = new FEdgeSmooth(); - else - self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2, - &SVertex_Type, &obj1, &SVertex_Type, &obj2)) - { - self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_fe.fe = self->fes; - self->py_fe.py_if1D.if1D = self->fes; - self->py_fe.py_if1D.borrowed = false; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) { + if (!obj1) + self->fes = new FEdgeSmooth(); + else + self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2)) { + self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_fe.fe = self->fes; + self->py_fe.py_if1D.if1D = self->fes; + self->py_fe.py_if1D.borrowed = false; + return 0; } /*----------------------mathutils callbacks ----------------------------*/ static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo) { - if (!BPy_FEdgeSmooth_Check(bmo->cb_user)) - return -1; - return 0; + if (!BPy_FEdgeSmooth_Check(bmo->cb_user)) + return -1; + return 0; } static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int /*subtype*/) { - BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; - Vec3r p(self->fes->normal()); - bmo->data[0] = p[0]; - bmo->data[1] = p[1]; - bmo->data[2] = p[2]; - return 0; + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + return 0; } static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int /*subtype*/) { - BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; - Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); - self->fes->setNormal(p); - return 0; + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormal(p); + return 0; } static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int /*subtype*/, int index) { - BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; - Vec3r p(self->fes->normal()); - bmo->data[index] = p[index]; - return 0; + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + bmo->data[index] = p[index]; + return 0; } static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int /*subtype*/, int index) { - BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; - Vec3r p(self->fes->normal()); - p[index] = bmo->data[index]; - self->fes->setNormal(p); - return 0; + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + p[index] = bmo->data[index]; + self->fes->setNormal(p); + return 0; } static Mathutils_Callback FEdgeSmooth_mathutils_cb = { - FEdgeSmooth_mathutils_check, - FEdgeSmooth_mathutils_get, - FEdgeSmooth_mathutils_set, - FEdgeSmooth_mathutils_get_index, - FEdgeSmooth_mathutils_set_index, + FEdgeSmooth_mathutils_check, + FEdgeSmooth_mathutils_get, + FEdgeSmooth_mathutils_set, + FEdgeSmooth_mathutils_get_index, + FEdgeSmooth_mathutils_set_index, }; static unsigned char FEdgeSmooth_mathutils_cb_index = -1; void FEdgeSmooth_mathutils_register_callback() { - FEdgeSmooth_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSmooth_mathutils_cb); + FEdgeSmooth_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSmooth_mathutils_cb); } /*----------------------FEdgeSmooth get/setters ----------------------------*/ PyDoc_STRVAR(FEdgeSmooth_normal_doc, -"The normal of the face that this FEdge is running across.\n" -"\n" -":type: :class:`mathutils.Vector`"); + "The normal of the face that this FEdge is running across.\n" + "\n" + ":type: :class:`mathutils.Vector`"); static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) { - return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0); + return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0); } static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure)) { - float v[3]; - if (mathutils_array_parse(v, 3, 3, value, - "value must be a 3-dimensional vector") == -1) - { - return -1; - } - Vec3r p(v[0], v[1], v[2]); - self->fes->setNormal(p); - return 0; + float v[3]; + if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) { + return -1; + } + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormal(p); + return 0; } PyDoc_STRVAR(FEdgeSmooth_material_index_doc, -"The index of the material of the face that this FEdge is running across.\n" -"\n" -":type: int"); + "The index of the material of the face that this FEdge is running across.\n" + "\n" + ":type: int"); static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) { - return PyLong_FromLong(self->fes->frs_materialIndex()); + return PyLong_FromLong(self->fes->frs_materialIndex()); } -static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure)) +static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, + PyObject *value, + void *UNUSED(closure)) { - unsigned int i = PyLong_AsUnsignedLong(value); - if (PyErr_Occurred()) - return -1; - self->fes->setFrsMaterialIndex(i); - return 0; + unsigned int i = PyLong_AsUnsignedLong(value); + if (PyErr_Occurred()) + return -1; + self->fes->setFrsMaterialIndex(i); + return 0; } PyDoc_STRVAR(FEdgeSmooth_material_doc, -"The material of the face that this FEdge is running across.\n" -"\n" -":type: :class:`Material`"); + "The material of the face that this FEdge is running across.\n" + "\n" + ":type: :class:`Material`"); static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) { - return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material()); + return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material()); } PyDoc_STRVAR(FEdgeSmooth_face_mark_doc, -"The face mark of the face that this FEdge is running across.\n" -"\n" -":type: bool"); + "The face mark of the face that this FEdge is running across.\n" + "\n" + ":type: bool"); static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) { - return PyBool_from_bool(self->fes->faceMark()); + return PyBool_from_bool(self->fes->faceMark()); } static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure)) { - if (!PyBool_Check(value)) - return -1; - self->fes->setFaceMark(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) + return -1; + self->fes->setFaceMark(bool_from_PyBool(value)); + return 0; } static PyGetSetDef BPy_FEdgeSmooth_getseters[] = { - {(char *)"normal", (getter)FEdgeSmooth_normal_get, (setter)FEdgeSmooth_normal_set, - (char *)FEdgeSmooth_normal_doc, NULL}, - {(char *)"material_index", (getter)FEdgeSmooth_material_index_get, (setter)FEdgeSmooth_material_index_set, - (char *)FEdgeSmooth_material_index_doc, NULL}, - {(char *)"material", (getter)FEdgeSmooth_material_get, (setter)NULL, (char *)FEdgeSmooth_material_doc, NULL}, - {(char *)"face_mark", (getter)FEdgeSmooth_face_mark_get, (setter)FEdgeSmooth_face_mark_set, - (char *)FEdgeSmooth_face_mark_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"normal", + (getter)FEdgeSmooth_normal_get, + (setter)FEdgeSmooth_normal_set, + (char *)FEdgeSmooth_normal_doc, + NULL}, + {(char *)"material_index", + (getter)FEdgeSmooth_material_index_get, + (setter)FEdgeSmooth_material_index_set, + (char *)FEdgeSmooth_material_index_doc, + NULL}, + {(char *)"material", + (getter)FEdgeSmooth_material_get, + (setter)NULL, + (char *)FEdgeSmooth_material_doc, + NULL}, + {(char *)"face_mark", + (getter)FEdgeSmooth_face_mark_get, + (setter)FEdgeSmooth_face_mark_set, + (char *)FEdgeSmooth_face_mark_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/ PyTypeObject FEdgeSmooth_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FEdgeSmooth", /* tp_name */ - sizeof(BPy_FEdgeSmooth), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdgeSmooth_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_FEdgeSmooth_getseters, /* tp_getset */ - &FEdge_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FEdgeSmooth_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FEdgeSmooth", /* tp_name */ + sizeof(BPy_FEdgeSmooth), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FEdgeSmooth_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_FEdgeSmooth_getseters, /* tp_getset */ + &FEdge_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FEdgeSmooth_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h index b460795228c..901741a76ff 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject FEdgeSmooth_Type; -#define BPy_FEdgeSmooth_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&FEdgeSmooth_Type)) +#define BPy_FEdgeSmooth_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&FEdgeSmooth_Type)) /*---------------------------Python BPy_FEdgeSmooth structure definition----------*/ typedef struct { - BPy_FEdge py_fe; - FEdgeSmooth *fes; + BPy_FEdge py_fe; + FEdgeSmooth *fes; } BPy_FEdgeSmooth; /*---------------------------Python BPy_FEdgeSmooth visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index f8bae0e5aca..6b23ffadffb 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -31,179 +31,198 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(AdjacencyIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" -"\n" -"Class for representing adjacency iterators used in the chaining\n" -"process. An AdjacencyIterator is created in the increment() and\n" -"decrement() methods of a :class:`ChainingIterator` and passed to the\n" -"traverse() method of the ChainingIterator.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An AdjacencyIterator object.\n" -" :type brother: :class:`AdjacencyIterator`\n" -"\n" -".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" -"\n" -" Builds a AdjacencyIterator object.\n" -"\n" -" :arg vertex: The vertex which is the next crossing.\n" -" :type vertex: :class:`ViewVertex`\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool"); +PyDoc_STRVAR( + AdjacencyIterator_doc, + "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" + "\n" + "Class for representing adjacency iterators used in the chaining\n" + "process. An AdjacencyIterator is created in the increment() and\n" + "decrement() methods of a :class:`ChainingIterator` and passed to the\n" + "traverse() method of the ChainingIterator.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An AdjacencyIterator object.\n" + " :type brother: :class:`AdjacencyIterator`\n" + "\n" + ".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" + "\n" + " Builds a AdjacencyIterator object.\n" + "\n" + " :arg vertex: The vertex which is the next crossing.\n" + " :type vertex: :class:`ViewVertex`\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool"); static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"vertex", "restrict_to_selection", "restrict_to_unvisited", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { - if (!obj1) { - self->a_it = new AdjacencyIterator(); - self->at_start = true; - } - else { - self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it)); - self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; - } - } - else if (PyErr_Clear(), (obj2 = obj3 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!O!", (char **)kwlist_2, - &ViewVertex_Type, &obj1, &PyBool_Type, &obj2, &PyBool_Type, &obj3)) - { - bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2); - bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3); - self->a_it = new AdjacencyIterator(((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited); - self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->a_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = { + "vertex", "restrict_to_selection", "restrict_to_unvisited", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { + if (!obj1) { + self->a_it = new AdjacencyIterator(); + self->at_start = true; + } + else { + self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it)); + self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; + } + } + else if (PyErr_Clear(), + (obj2 = obj3 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!|O!O!", + (char **)kwlist_2, + &ViewVertex_Type, + &obj1, + &PyBool_Type, + &obj2, + &PyBool_Type, + &obj3)) { + bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2); + bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3); + self->a_it = new AdjacencyIterator( + ((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited); + self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->a_it; + return 0; } static PyObject *AdjacencyIterator_iter(BPy_AdjacencyIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + Py_INCREF(self); + self->at_start = true; + return (PyObject *)self; } static PyObject *AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) { - if (self->a_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - if (self->at_start) - self->at_start = false; - else { - self->a_it->increment(); - if (self->a_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - } - ViewEdge *ve = self->a_it->operator->(); - return BPy_ViewEdge_from_ViewEdge(*ve); + if (self->a_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if (self->at_start) + self->at_start = false; + else { + self->a_it->increment(); + if (self->a_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + ViewEdge *ve = self->a_it->operator->(); + return BPy_ViewEdge_from_ViewEdge(*ve); } /*----------------------AdjacencyIterator get/setters ----------------------------*/ PyDoc_STRVAR(AdjacencyIterator_object_doc, -"The ViewEdge object currently pointed to by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed to by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { - if (self->a_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->a_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->a_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, -"True if the current ViewEdge is coming towards the iteration vertex, and\n" -"False otherwise.\n" -"\n" -":type: bool"); + "True if the current ViewEdge is coming towards the iteration vertex, and\n" + "False otherwise.\n" + "\n" + ":type: bool"); -static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) +static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, + void *UNUSED(closure)) { - if (self->a_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return PyBool_from_bool(self->a_it->isIncoming()); + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return PyBool_from_bool(self->a_it->isIncoming()); } static PyGetSetDef BPy_AdjacencyIterator_getseters[] = { - {(char *)"is_incoming", (getter)AdjacencyIterator_is_incoming_get, (setter)NULL, - (char *)AdjacencyIterator_is_incoming_doc, NULL}, - {(char *)"object", (getter)AdjacencyIterator_object_get, (setter)NULL, (char *)AdjacencyIterator_object_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"is_incoming", + (getter)AdjacencyIterator_is_incoming_get, + (setter)NULL, + (char *)AdjacencyIterator_is_incoming_doc, + NULL}, + {(char *)"object", + (getter)AdjacencyIterator_object_get, + (setter)NULL, + (char *)AdjacencyIterator_object_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/ PyTypeObject AdjacencyIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "AdjacencyIterator", /* tp_name */ - sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - AdjacencyIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)AdjacencyIterator_iter, /* tp_iter */ - (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_AdjacencyIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)AdjacencyIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "AdjacencyIterator", /* tp_name */ + sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + AdjacencyIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)AdjacencyIterator_iter, /* tp_iter */ + (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_AdjacencyIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)AdjacencyIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h index 775f8a2628d..9a360f23f0a 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h @@ -33,13 +33,14 @@ extern "C" { extern PyTypeObject AdjacencyIterator_Type; -#define BPy_AdjacencyIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&AdjacencyIterator_Type)) +#define BPy_AdjacencyIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&AdjacencyIterator_Type)) /*---------------------------Python BPy_AdjacencyIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - AdjacencyIterator *a_it; - bool at_start; + BPy_Iterator py_it; + AdjacencyIterator *a_it; + bool at_start; } BPy_AdjacencyIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index 994eb715fe3..f25435b421c 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -35,152 +35,172 @@ extern "C" { PyDoc_STRVAR(ChainPredicateIterator_doc, -"Class hierarchy: :class:`freestyle.types.Iterator` >\n" -":class:`freestyle.types.ViewEdgeIterator` >\n" -":class:`freestyle.types.ChainingIterator` >\n" -":class:`ChainPredicateIterator`\n" -"\n" -"A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" -"particular built from a unary predicate and a binary predicate.\n" -"First, the unary predicate is evaluated for all potential next\n" -"ViewEdges in order to only keep the ones respecting a certain\n" -"constraint. Then, the binary predicate is evaluated on the current\n" -"ViewEdge together with each ViewEdge of the previous selection. The\n" -"first ViewEdge respecting both the unary predicate and the binary\n" -"predicate is kept as the next one. If none of the potential next\n" -"ViewEdge respects these two predicates, None is returned.\n" -"\n" -".. method:: __init__(upred, bpred, restrict_to_selection=True, restrict_to_unvisited=True, begin=None, " -"orientation=True)\n" -"\n" -" Builds a ChainPredicateIterator from a unary predicate, a binary\n" -" predicate, a starting ViewEdge and its orientation.\n" -"\n" -" :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" -" :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" -" :arg bpred: The binary predicate that the next ViewEdge must\n" -" satisfy together with the actual pointed ViewEdge.\n" -" :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`freestyle.types.ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ChainPredicateIterator object.\n" -" :type brother: :class:`ChainPredicateIterator`"); + "Class hierarchy: :class:`freestyle.types.Iterator` >\n" + ":class:`freestyle.types.ViewEdgeIterator` >\n" + ":class:`freestyle.types.ChainingIterator` >\n" + ":class:`ChainPredicateIterator`\n" + "\n" + "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" + "particular built from a unary predicate and a binary predicate.\n" + "First, the unary predicate is evaluated for all potential next\n" + "ViewEdges in order to only keep the ones respecting a certain\n" + "constraint. Then, the binary predicate is evaluated on the current\n" + "ViewEdge together with each ViewEdge of the previous selection. The\n" + "first ViewEdge respecting both the unary predicate and the binary\n" + "predicate is kept as the next one. If none of the potential next\n" + "ViewEdge respects these two predicates, None is returned.\n" + "\n" + ".. method:: __init__(upred, bpred, restrict_to_selection=True, " + "restrict_to_unvisited=True, begin=None, " + "orientation=True)\n" + "\n" + " Builds a ChainPredicateIterator from a unary predicate, a binary\n" + " predicate, a starting ViewEdge and its orientation.\n" + "\n" + " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" + " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" + " :arg bpred: The binary predicate that the next ViewEdge must\n" + " satisfy together with the actual pointed ViewEdge.\n" + " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`freestyle.types.ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ChainPredicateIterator object.\n" + " :type brother: :class:`ChainPredicateIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } -static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds) +static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"upred", "bpred", "restrict_to_selection", "restrict_to_unvisited", "begin", - "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) { - self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it)); - self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred; - self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred; - Py_INCREF(self->upred); - Py_INCREF(self->bpred); - } - else if (PyErr_Clear(), (obj3 = obj4 = obj5 = obj6 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|O!O!O&O!", (char **)kwlist_2, - &UnaryPredicate1D_Type, &obj1, &BinaryPredicate1D_Type, &obj2, - &PyBool_Type, &obj3, &PyBool_Type, &obj4, check_begin, &obj5, - &PyBool_Type, &obj6)) - { - UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D; - BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D; - bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3); - bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4); - ViewEdge *begin = (!obj5 || obj5 == Py_None) ? NULL : ((BPy_ViewEdge *)obj5)->ve; - bool orientation = (!obj6) ? true : bool_from_PyBool(obj6); - self->cp_it = new ChainPredicateIterator(*up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, - orientation); - self->upred = obj1; - self->bpred = obj2; - Py_INCREF(self->upred); - Py_INCREF(self->bpred); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_c_it.c_it = self->cp_it; - self->py_c_it.py_ve_it.ve_it = self->cp_it; - self->py_c_it.py_ve_it.py_it.it = self->cp_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"upred", + "bpred", + "restrict_to_selection", + "restrict_to_unvisited", + "begin", + "orientation", + NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) { + self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it)); + self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred; + self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred; + Py_INCREF(self->upred); + Py_INCREF(self->bpred); + } + else if (PyErr_Clear(), + (obj3 = obj4 = obj5 = obj6 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!|O!O!O&O!", + (char **)kwlist_2, + &UnaryPredicate1D_Type, + &obj1, + &BinaryPredicate1D_Type, + &obj2, + &PyBool_Type, + &obj3, + &PyBool_Type, + &obj4, + check_begin, + &obj5, + &PyBool_Type, + &obj6)) { + UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D; + BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D; + bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3); + bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4); + ViewEdge *begin = (!obj5 || obj5 == Py_None) ? NULL : ((BPy_ViewEdge *)obj5)->ve; + bool orientation = (!obj6) ? true : bool_from_PyBool(obj6); + self->cp_it = new ChainPredicateIterator( + *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation); + self->upred = obj1; + self->bpred = obj2; + Py_INCREF(self->upred); + Py_INCREF(self->bpred); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_c_it.c_it = self->cp_it; + self->py_c_it.py_ve_it.ve_it = self->cp_it; + self->py_c_it.py_ve_it.py_it.it = self->cp_it; + return 0; } static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self) { - Py_XDECREF(self->upred); - Py_XDECREF(self->bpred); - ChainingIterator_Type.tp_dealloc((PyObject *)self); + Py_XDECREF(self->upred); + Py_XDECREF(self->bpred); + ChainingIterator_Type.tp_dealloc((PyObject *)self); } /*-----------------------BPy_ChainPredicateIterator type definition ------------------------------*/ PyTypeObject ChainPredicateIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainPredicateIterator", /* tp_name */ - sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainPredicateIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &ChainingIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainPredicateIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainPredicateIterator", /* tp_name */ + sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainPredicateIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainPredicateIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h index 2fab8671239..645e6573257 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h @@ -34,14 +34,14 @@ extern "C" { extern PyTypeObject ChainPredicateIterator_Type; #define BPy_ChainPredicateIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainPredicateIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainPredicateIterator_Type)) /*---------------------------Python BPy_ChainPredicateIterator structure definition----------*/ typedef struct { - BPy_ChainingIterator py_c_it; - ChainPredicateIterator *cp_it; - PyObject *upred; - PyObject *bpred; + BPy_ChainingIterator py_c_it; + ChainPredicateIterator *cp_it; + PyObject *upred; + PyObject *bpred; } BPy_ChainPredicateIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index 73e178a6706..6a4af0f8053 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -35,118 +35,128 @@ extern "C" { // ChainSilhouetteIterator (const ChainSilhouetteIterator &brother) PyDoc_STRVAR(ChainSilhouetteIterator_doc, -"Class hierarchy: :class:`freestyle.types.Iterator` >\n" -":class:`freestyle.types.ViewEdgeIterator` >\n" -":class:`freestyle.types.ChainingIterator` >\n" -":class:`ChainSilhouetteIterator`\n" -"\n" -"A ViewEdge Iterator used to follow ViewEdges the most naturally. For\n" -"example, it will follow visible ViewEdges of same nature. As soon, as\n" -"the nature or the visibility changes, the iteration stops (by setting\n" -"the pointed ViewEdge to 0). In the case of an iteration over a set of\n" -"ViewEdge that are both Silhouette and Crease, there will be a\n" -"precedence of the silhouette over the crease criterion.\n" -"\n" -".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n" -"\n" -" Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" -" iteration and its orientation.\n" -"\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`freestyle.types.ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ChainSilhouetteIterator object.\n" -" :type brother: :class:`ChainSilhouetteIterator`"); + "Class hierarchy: :class:`freestyle.types.Iterator` >\n" + ":class:`freestyle.types.ViewEdgeIterator` >\n" + ":class:`freestyle.types.ChainingIterator` >\n" + ":class:`ChainSilhouetteIterator`\n" + "\n" + "A ViewEdge Iterator used to follow ViewEdges the most naturally. For\n" + "example, it will follow visible ViewEdges of same nature. As soon, as\n" + "the nature or the visibility changes, the iteration stops (by setting\n" + "the pointed ViewEdge to 0). In the case of an iteration over a set of\n" + "ViewEdge that are both Silhouette and Crease, there will be a\n" + "precedence of the silhouette over the crease criterion.\n" + "\n" + ".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n" + "\n" + " Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" + " iteration and its orientation.\n" + "\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`freestyle.types.ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ChainSilhouetteIterator object.\n" + " :type brother: :class:`ChainSilhouetteIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } -static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args, PyObject *kwds) +static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) { - self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = obj3 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!O&O!", (char **)kwlist_2, - &PyBool_Type, &obj1, check_begin, &obj2, &PyBool_Type, &obj3)) - { - bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); - ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve; - bool orientation = (!obj3) ? true : bool_from_PyBool(obj3); - self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_c_it.c_it = self->cs_it; - self->py_c_it.py_ve_it.ve_it = self->cs_it; - self->py_c_it.py_ve_it.py_it.it = self->cs_it; - return 0; + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) { + self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = obj3 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "|O!O&O!", + (char **)kwlist_2, + &PyBool_Type, + &obj1, + check_begin, + &obj2, + &PyBool_Type, + &obj3)) { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve; + bool orientation = (!obj3) ? true : bool_from_PyBool(obj3); + self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_c_it.c_it = self->cs_it; + self->py_c_it.py_ve_it.ve_it = self->cs_it; + self->py_c_it.py_ve_it.py_it.it = self->cs_it; + return 0; } /*-----------------------BPy_ChainSilhouetteIterator type definition ------------------------------*/ PyTypeObject ChainSilhouetteIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainSilhouetteIterator", /* tp_name */ - sizeof(BPy_ChainSilhouetteIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainSilhouetteIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &ChainingIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainSilhouetteIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainSilhouetteIterator", /* tp_name */ + sizeof(BPy_ChainSilhouetteIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainSilhouetteIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainSilhouetteIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h index 7c5974ec218..72823832441 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h @@ -34,12 +34,12 @@ extern "C" { extern PyTypeObject ChainSilhouetteIterator_Type; #define BPy_ChainSilhouetteIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainSilhouetteIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainSilhouetteIterator_Type)) /*---------------------------Python BPy_ChainSilhouetteIterator structure definition----------*/ typedef struct { - BPy_ChainingIterator py_c_it; - ChainSilhouetteIterator *cs_it; + BPy_ChainingIterator py_c_it; + ChainSilhouetteIterator *cs_it; } BPy_ChainSilhouetteIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index afd7f6f69c6..370ef23d8ef 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -33,229 +33,260 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(ChainingIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" -"\n" -"Base class for chaining iterators. This class is designed to be\n" -"overloaded in order to describe chaining rules. It makes the\n" -"description of chaining rules easier. The two main methods that need\n" -"to overloaded are traverse() and init(). traverse() tells which\n" -":class:`ViewEdge` to follow, among the adjacent ones. If you specify\n" -"restriction rules (such as \"Chain only ViewEdges of the selection\"),\n" -"they will be included in the adjacency iterator (i.e, the adjacent\n" -"iterator will only stop on \"valid\" edges).\n" -"\n" -".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" -"\n" -" Builds a Chaining Iterator from the first ViewEdge used for\n" -" iteration and its orientation.\n" -"\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool\n" -" :arg begin: The ViewEdge from which to start the chain.\n" -" :type begin: :class:`ViewEdge` or None\n" -" :arg orientation: The direction to follow to explore the graph. If\n" -" true, the direction indicated by the first ViewEdge is used.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: \n" -" :type brother: ChainingIterator"); +PyDoc_STRVAR( + ChainingIterator_doc, + "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" + "\n" + "Base class for chaining iterators. This class is designed to be\n" + "overloaded in order to describe chaining rules. It makes the\n" + "description of chaining rules easier. The two main methods that need\n" + "to overloaded are traverse() and init(). traverse() tells which\n" + ":class:`ViewEdge` to follow, among the adjacent ones. If you specify\n" + "restriction rules (such as \"Chain only ViewEdges of the selection\"),\n" + "they will be included in the adjacency iterator (i.e, the adjacent\n" + "iterator will only stop on \"valid\" edges).\n" + "\n" + ".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, " + "orientation=True)\n" + "\n" + " Builds a Chaining Iterator from the first ViewEdge used for\n" + " iteration and its orientation.\n" + "\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool\n" + " :arg begin: The ViewEdge from which to start the chain.\n" + " :type begin: :class:`ViewEdge` or None\n" + " :arg orientation: The direction to follow to explore the graph. If\n" + " true, the direction indicated by the first ViewEdge is used.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: \n" + " :type brother: ChainingIterator"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { - self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = obj3 = obj4 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!O&O!", (char **)kwlist_2, - &PyBool_Type, &obj1, &PyBool_Type, &obj2, check_begin, &obj3, - &PyBool_Type, &obj4)) - { - bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); - bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); - ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; - bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); - self->c_it = new ChainingIterator(restrict_to_selection, restrict_to_unvisited, begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_ve_it.ve_it = self->c_it; - self->py_ve_it.py_it.it = self->c_it; - - self->c_it->py_c_it = (PyObject *)self; - - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = { + "restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { + self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = obj3 = obj4 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "|O!O!O&O!", + (char **)kwlist_2, + &PyBool_Type, + &obj1, + &PyBool_Type, + &obj2, + check_begin, + &obj3, + &PyBool_Type, + &obj4)) { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); + ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; + bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); + self->c_it = new ChainingIterator( + restrict_to_selection, restrict_to_unvisited, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_ve_it.ve_it = self->c_it; + self->py_ve_it.py_it.it = self->c_it; + + self->c_it->py_c_it = (PyObject *)self; + + return 0; } PyDoc_STRVAR(ChainingIterator_init_doc, -".. method:: init()\n" -"\n" -" Initializes the iterator context. This method is called each\n" -" time a new chain is started. It can be used to reset some\n" -" history information that you might want to keep."); + ".. method:: init()\n" + "\n" + " Initializes the iterator context. This method is called each\n" + " time a new chain is started. It can be used to reset some\n" + " history information that you might want to keep."); static PyObject *ChainingIterator_init(BPy_ChainingIterator *self) { - if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { - PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); - return NULL; - } - self->c_it->init(); - Py_RETURN_NONE; + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { + PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); + return NULL; + } + self->c_it->init(); + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_traverse_doc, -".. method:: traverse(it)\n" -"\n" -" This method iterates over the potential next ViewEdges and returns\n" -" the one that will be followed next. Returns the next ViewEdge to\n" -" follow or None when the end of the chain is reached.\n" -"\n" -" :arg it: The iterator over the ViewEdges adjacent to the end vertex\n" -" of the current ViewEdge. The adjacency iterator reflects the\n" -" restriction rules by only iterating over the valid ViewEdges.\n" -" :type it: :class:`AdjacencyIterator`\n" -" :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" -" :rtype: :class:`ViewEdge` or None"); - -static PyObject *ChainingIterator_traverse(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) + ".. method:: traverse(it)\n" + "\n" + " This method iterates over the potential next ViewEdges and returns\n" + " the one that will be followed next. Returns the next ViewEdge to\n" + " follow or None when the end of the chain is reached.\n" + "\n" + " :arg it: The iterator over the ViewEdges adjacent to the end vertex\n" + " of the current ViewEdge. The adjacency iterator reflects the\n" + " restriction rules by only iterating over the valid ViewEdges.\n" + " :type it: :class:`AdjacencyIterator`\n" + " :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" + " :rtype: :class:`ViewEdge` or None"); + +static PyObject *ChainingIterator_traverse(BPy_ChainingIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *py_a_it; - - if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { - PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); - return NULL; - } - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &AdjacencyIterator_Type, &py_a_it)) - return NULL; - if (((BPy_AdjacencyIterator *)py_a_it)->a_it) - self->c_it->traverse(*(((BPy_AdjacencyIterator *)py_a_it)->a_it)); - Py_RETURN_NONE; + static const char *kwlist[] = {"it", NULL}; + PyObject *py_a_it; + + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { + PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); + return NULL; + } + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &AdjacencyIterator_Type, &py_a_it)) + return NULL; + if (((BPy_AdjacencyIterator *)py_a_it)->a_it) + self->c_it->traverse(*(((BPy_AdjacencyIterator *)py_a_it)->a_it)); + Py_RETURN_NONE; } static PyMethodDef BPy_ChainingIterator_methods[] = { - {"init", (PyCFunction) ChainingIterator_init, METH_NOARGS, ChainingIterator_init_doc}, - {"traverse", (PyCFunction) ChainingIterator_traverse, METH_VARARGS | METH_KEYWORDS, ChainingIterator_traverse_doc}, - {NULL, NULL, 0, NULL}, + {"init", (PyCFunction)ChainingIterator_init, METH_NOARGS, ChainingIterator_init_doc}, + {"traverse", + (PyCFunction)ChainingIterator_traverse, + METH_VARARGS | METH_KEYWORDS, + ChainingIterator_traverse_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ChainingIterator get/setters ----------------------------*/ PyDoc_STRVAR(ChainingIterator_object_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ChainingIterator_object_get(BPy_ChainingIterator *self, void *UNUSED(closure)) { - if (self->c_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->c_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - - Py_RETURN_NONE; + if (self->c_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->c_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_next_vertex_doc, -"The ViewVertex that is the next crossing.\n" -"\n" -":type: :class:`ViewVertex`"); + "The ViewVertex that is the next crossing.\n" + "\n" + ":type: :class:`ViewVertex`"); -static PyObject *ChainingIterator_next_vertex_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +static PyObject *ChainingIterator_next_vertex_get(BPy_ChainingIterator *self, + void *UNUSED(closure)) { - ViewVertex *v = self->c_it->getVertex(); - if (v) - return Any_BPy_ViewVertex_from_ViewVertex(*v); + ViewVertex *v = self->c_it->getVertex(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_is_incrementing_doc, -"True if the current iteration is an incrementation.\n" -"\n" -":type: bool"); + "True if the current iteration is an incrementation.\n" + "\n" + ":type: bool"); -static PyObject *ChainingIterator_is_incrementing_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +static PyObject *ChainingIterator_is_incrementing_get(BPy_ChainingIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->c_it->isIncrementing()); + return PyBool_from_bool(self->c_it->isIncrementing()); } static PyGetSetDef BPy_ChainingIterator_getseters[] = { - {(char *)"object", (getter)ChainingIterator_object_get, (setter)NULL, (char *)ChainingIterator_object_doc, NULL}, - {(char *)"next_vertex", (getter)ChainingIterator_next_vertex_get, (setter)NULL, - (char *)ChainingIterator_next_vertex_doc, NULL}, - {(char *)"is_incrementing", (getter)ChainingIterator_is_incrementing_get, (setter)NULL, - (char *)ChainingIterator_is_incrementing_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)ChainingIterator_object_get, + (setter)NULL, + (char *)ChainingIterator_object_doc, + NULL}, + {(char *)"next_vertex", + (getter)ChainingIterator_next_vertex_get, + (setter)NULL, + (char *)ChainingIterator_next_vertex_doc, + NULL}, + {(char *)"is_incrementing", + (getter)ChainingIterator_is_incrementing_get, + (setter)NULL, + (char *)ChainingIterator_is_incrementing_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ChainingIterator type definition ------------------------------*/ PyTypeObject ChainingIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainingIterator", /* tp_name */ - sizeof(BPy_ChainingIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainingIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ChainingIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ChainingIterator_getseters, /* tp_getset */ - &ViewEdgeIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainingIterator___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainingIterator", /* tp_name */ + sizeof(BPy_ChainingIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainingIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ChainingIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ChainingIterator_getseters, /* tp_getset */ + &ViewEdgeIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainingIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h index 898662c4f09..7e3be0bc6cd 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject ChainingIterator_Type; -#define BPy_ChainingIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingIterator_Type)) +#define BPy_ChainingIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingIterator_Type)) /*---------------------------Python BPy_ChainingIterator structure definition----------*/ typedef struct { - BPy_ViewEdgeIterator py_ve_it; - ChainingIterator *c_it; + BPy_ViewEdgeIterator py_ve_it; + ChainingIterator *c_it; } BPy_ChainingIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index 1caf0e9eb58..5b287433c13 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -32,143 +32,153 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(CurvePointIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" -"\n" -"Class representing an iterator on a curve. Allows an iterating\n" -"outside initial vertices. A CurvePoint is instanciated and returned\n" -"through the .object attribute.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A CurvePointIterator object.\n" -" :type brother: :class:`CurvePointIterator`\n" -"\n" -".. method:: __init__(step=0.0)\n" -"\n" -" Builds a CurvePointIterator object.\n" -"\n" -" :arg step: A resampling resolution with which the curve is resampled.\n" -" If zero, no resampling is done (i.e., the iterator iterates over\n" -" initial vertices).\n" -" :type step: float"); + "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" + "\n" + "Class representing an iterator on a curve. Allows an iterating\n" + "outside initial vertices. A CurvePoint is instanciated and returned\n" + "through the .object attribute.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A CurvePointIterator object.\n" + " :type brother: :class:`CurvePointIterator`\n" + "\n" + ".. method:: __init__(step=0.0)\n" + "\n" + " Builds a CurvePointIterator object.\n" + "\n" + " :arg step: A resampling resolution with which the curve is resampled.\n" + " If zero, no resampling is done (i.e., the iterator iterates over\n" + " initial vertices).\n" + " :type step: float"); static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"step", NULL}; - PyObject *brother = 0; - float step; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) { - if (!brother) - self->cp_it = new CurveInternal::CurvePointIterator(); - else - self->cp_it = new CurveInternal::CurvePointIterator(*(((BPy_CurvePointIterator *)brother)->cp_it)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) - { - self->cp_it = new CurveInternal::CurvePointIterator(step); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->cp_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"step", NULL}; + PyObject *brother = 0; + float step; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) { + if (!brother) + self->cp_it = new CurveInternal::CurvePointIterator(); + else + self->cp_it = new CurveInternal::CurvePointIterator( + *(((BPy_CurvePointIterator *)brother)->cp_it)); + } + else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) { + self->cp_it = new CurveInternal::CurvePointIterator(step); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->cp_it; + return 0; } /*----------------------CurvePointIterator get/setters ----------------------------*/ PyDoc_STRVAR(CurvePointIterator_object_doc, -"The CurvePoint object currently pointed by this iterator.\n" -"\n" -":type: :class:`CurvePoint`"); + "The CurvePoint object currently pointed by this iterator.\n" + "\n" + ":type: :class:`CurvePoint`"); static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - if (self->cp_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); + if (self->cp_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); } PyDoc_STRVAR(CurvePointIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->cp_it->t()); + return PyFloat_FromDouble(self->cp_it->t()); } PyDoc_STRVAR(CurvePointIterator_u_doc, -"The point parameter at the current point in the stroke (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the stroke (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->cp_it->u()); + return PyFloat_FromDouble(self->cp_it->u()); } static PyGetSetDef BPy_CurvePointIterator_getseters[] = { - {(char *)"object", (getter)CurvePointIterator_object_get, (setter)NULL, - (char *)CurvePointIterator_object_doc, NULL}, - {(char *)"t", (getter)CurvePointIterator_t_get, (setter)NULL, (char *)CurvePointIterator_t_doc, NULL}, - {(char *)"u", (getter)CurvePointIterator_u_get, (setter)NULL, (char *)CurvePointIterator_u_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)CurvePointIterator_object_get, + (setter)NULL, + (char *)CurvePointIterator_object_doc, + NULL}, + {(char *)"t", + (getter)CurvePointIterator_t_get, + (setter)NULL, + (char *)CurvePointIterator_t_doc, + NULL}, + {(char *)"u", + (getter)CurvePointIterator_u_get, + (setter)NULL, + (char *)CurvePointIterator_u_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_CurvePointIterator type definition ------------------------------*/ PyTypeObject CurvePointIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CurvePointIterator", /* tp_name */ - sizeof(BPy_CurvePointIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurvePointIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_CurvePointIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CurvePointIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CurvePointIterator", /* tp_name */ + sizeof(BPy_CurvePointIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurvePointIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_CurvePointIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurvePointIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h index 41a3007d12c..aa84b1020ce 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject CurvePointIterator_Type; -#define BPy_CurvePointIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurvePointIterator_Type)) +#define BPy_CurvePointIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurvePointIterator_Type)) /*---------------------------Python BPy_CurvePointIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - CurveInternal::CurvePointIterator *cp_it; + BPy_Iterator py_it; + CurveInternal::CurvePointIterator *cp_it; } BPy_CurvePointIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 6e3606c0041..6218541df9b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -32,210 +32,227 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Interface0DIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" -"\n" -"Class defining an iterator over Interface0D elements. An instance of\n" -"this iterator is always obtained from a 1D element.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An Interface0DIterator object.\n" -" :type brother: :class:`Interface0DIterator`\n" -"\n" -".. method:: __init__(it)\n" -"\n" -" Construct a nested Interface0DIterator that can be the argument of\n" -" a Function0D.\n" -"\n" -" :arg it: An iterator object to be nested.\n" -" :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" -" :class:`StrokeVertexIterator`"); + "Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" + "\n" + "Class defining an iterator over Interface0D elements. An instance of\n" + "this iterator is always obtained from a 1D element.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An Interface0DIterator object.\n" + " :type brother: :class:`Interface0DIterator`\n" + "\n" + ".. method:: __init__(it)\n" + "\n" + " Construct a nested Interface0DIterator that can be the argument of\n" + " a Function0D.\n" + "\n" + " :arg it: An iterator object to be nested.\n" + " :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" + " :class:`StrokeVertexIterator`"); static int convert_nested_it(PyObject *obj, void *v) { - if (!obj || !BPy_Iterator_Check(obj)) - return 0; - Interface0DIteratorNested *nested_it = dynamic_cast(((BPy_Iterator *)obj)->it); - if (!nested_it) - return 0; - *((Interface0DIteratorNested **)v) = nested_it; - return 1; + if (!obj || !BPy_Iterator_Check(obj)) + return 0; + Interface0DIteratorNested *nested_it = dynamic_cast( + ((BPy_Iterator *)obj)->it); + if (!nested_it) + return 0; + *((Interface0DIteratorNested **)v) = nested_it; + return 1; } static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"it", NULL}; - static const char *kwlist_2[] = {"inter", NULL}; - static const char *kwlist_3[] = {"brother", NULL}; - Interface0DIteratorNested *nested_it; - PyObject *brother, *inter; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) { - self->if0D_it = new Interface0DIterator(nested_it->copy()); - self->at_start = true; - self->reversed = false; - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Interface1D_Type, &inter)) - { - self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin()); - self->at_start = true; - self->reversed = false; - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &Interface0DIterator_Type, &brother)) - { - self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it)); - self->at_start = ((BPy_Interface0DIterator *)brother)->at_start; - self->reversed = ((BPy_Interface0DIterator *)brother)->reversed; - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->if0D_it; - return 0; + static const char *kwlist_1[] = {"it", NULL}; + static const char *kwlist_2[] = {"inter", NULL}; + static const char *kwlist_3[] = {"brother", NULL}; + Interface0DIteratorNested *nested_it; + PyObject *brother, *inter; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) { + self->if0D_it = new Interface0DIterator(nested_it->copy()); + self->at_start = true; + self->reversed = false; + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_2, &Interface1D_Type, &inter)) { + self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin()); + self->at_start = true; + self->reversed = false; + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_3, &Interface0DIterator_Type, &brother)) { + self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it)); + self->at_start = ((BPy_Interface0DIterator *)brother)->at_start; + self->reversed = ((BPy_Interface0DIterator *)brother)->reversed; + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->if0D_it; + return 0; } static PyObject *Interface0DIterator_iter(BPy_Interface0DIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + Py_INCREF(self); + self->at_start = true; + return (PyObject *)self; } static PyObject *Interface0DIterator_iternext(BPy_Interface0DIterator *self) { - if (self->reversed) { - if (self->if0D_it->isBegin()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - self->if0D_it->decrement(); - } - else { - if (self->if0D_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else if (self->at_start) { - self->at_start = false; - } - else if (self->if0D_it->atLast()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else { - self->if0D_it->increment(); - } - } - Interface0D *if0D = self->if0D_it->operator->(); - return Any_BPy_Interface0D_from_Interface0D(*if0D); + if (self->reversed) { + if (self->if0D_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->if0D_it->decrement(); + } + else { + if (self->if0D_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else if (self->at_start) { + self->at_start = false; + } + else if (self->if0D_it->atLast()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else { + self->if0D_it->increment(); + } + } + Interface0D *if0D = self->if0D_it->operator->(); + return Any_BPy_Interface0D_from_Interface0D(*if0D); } /*----------------------Interface0DIterator get/setters ----------------------------*/ PyDoc_STRVAR(Interface0DIterator_object_doc, -"The 0D object currently pointed to by this iterator. Note that the object\n" -"may be an instance of an Interface0D subclass. For example if the iterator\n" -"has been created from the `vertices_begin()` method of the :class:`Stroke`\n" -"class, the .object property refers to a :class:`StrokeVertex` object.\n" -"\n" -":type: :class:`Interface0D` or one of its subclasses."); - -static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) + "The 0D object currently pointed to by this iterator. Note that the object\n" + "may be an instance of an Interface0D subclass. For example if the iterator\n" + "has been created from the `vertices_begin()` method of the :class:`Stroke`\n" + "class, the .object property refers to a :class:`StrokeVertex` object.\n" + "\n" + ":type: :class:`Interface0D` or one of its subclasses."); + +static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, + void *UNUSED(closure)) { - if (self->if0D_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); + if (self->if0D_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); } PyDoc_STRVAR(Interface0DIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *Interface0DIterator_t_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->if0D_it->t()); + return PyFloat_FromDouble(self->if0D_it->t()); } PyDoc_STRVAR(Interface0DIterator_u_doc, -"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the 1D element (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *Interface0DIterator_u_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->if0D_it->u()); + return PyFloat_FromDouble(self->if0D_it->u()); } PyDoc_STRVAR(Interface0DIterator_at_last_doc, -"True if the interator points to the last valid element.\n" -"For its counterpart (pointing to the first valid element), use it.is_begin.\n" -"\n" -":type: bool"); + "True if the interator points to the last valid element.\n" + "For its counterpart (pointing to the first valid element), use it.is_begin.\n" + "\n" + ":type: bool"); -static PyObject *Interface0DIterator_at_last_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) +static PyObject *Interface0DIterator_at_last_get(BPy_Interface0DIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->if0D_it->atLast()); + return PyBool_from_bool(self->if0D_it->atLast()); } static PyGetSetDef BPy_Interface0DIterator_getseters[] = { - {(char *)"object", (getter)Interface0DIterator_object_get, (setter)NULL, - (char *)Interface0DIterator_object_doc, NULL}, - {(char *)"t", (getter)Interface0DIterator_t_get, (setter)NULL, (char *)Interface0DIterator_t_doc, NULL}, - {(char *)"u", (getter)Interface0DIterator_u_get, (setter)NULL, (char *)Interface0DIterator_u_doc, NULL}, - {(char *)"at_last", (getter)Interface0DIterator_at_last_get, (setter)NULL, - (char *)Interface0DIterator_at_last_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)Interface0DIterator_object_get, + (setter)NULL, + (char *)Interface0DIterator_object_doc, + NULL}, + {(char *)"t", + (getter)Interface0DIterator_t_get, + (setter)NULL, + (char *)Interface0DIterator_t_doc, + NULL}, + {(char *)"u", + (getter)Interface0DIterator_u_get, + (setter)NULL, + (char *)Interface0DIterator_u_doc, + NULL}, + {(char *)"at_last", + (getter)Interface0DIterator_at_last_get, + (setter)NULL, + (char *)Interface0DIterator_at_last_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Interface0DIterator type definition ------------------------------*/ PyTypeObject Interface0DIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Interface0DIterator", /* tp_name */ - sizeof(BPy_Interface0DIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Interface0DIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)Interface0DIterator_iter, /* tp_iter */ - (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_Interface0DIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Interface0DIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Interface0DIterator", /* tp_name */ + sizeof(BPy_Interface0DIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Interface0DIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)Interface0DIterator_iter, /* tp_iter */ + (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_Interface0DIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Interface0DIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h index 7379ec5112d..3695cda6c76 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h @@ -33,14 +33,15 @@ extern "C" { extern PyTypeObject Interface0DIterator_Type; -#define BPy_Interface0DIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0DIterator_Type)) +#define BPy_Interface0DIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0DIterator_Type)) /*---------------------------Python BPy_Interface0DIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - Interface0DIterator *if0D_it; - bool reversed; - bool at_start; + BPy_Iterator py_it; + Interface0DIterator *if0D_it; + bool reversed; + bool at_start; } BPy_Interface0DIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index ef8e1135139..2a860976d7f 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -33,162 +33,179 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(SVertexIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" -"\n" -"Class representing an iterator over :class:`SVertex` of a\n" -":class:`ViewEdge`. An instance of an SVertexIterator can be obtained\n" -"from a ViewEdge by calling verticesBegin() or verticesEnd().\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An SVertexIterator object.\n" -" :type brother: :class:`SVertexIterator`\n" -"\n" -".. method:: __init__(vertex, begin, previous_edge, next_edge, t)\n" -"\n" -" Build an SVertexIterator that starts iteration from an SVertex\n" -" object v.\n" -"\n" -" :arg vertex: The SVertex from which the iterator starts iteration.\n" -" :type vertex: :class:`SVertex`\n" -" :arg begin: The first SVertex of a ViewEdge.\n" -" :type begin: :class:`SVertex`\n" -" :arg previous_edge: The previous FEdge coming to vertex.\n" -" :type previous_edge: :class:`FEdge`\n" -" :arg next_edge: The next FEdge going out from vertex.\n" -" :type next_edge: :class:`FEdge`\n" -" :arg t: The curvilinear abscissa at vertex.\n" -" :type t: float"); + "Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" + "\n" + "Class representing an iterator over :class:`SVertex` of a\n" + ":class:`ViewEdge`. An instance of an SVertexIterator can be obtained\n" + "from a ViewEdge by calling verticesBegin() or verticesEnd().\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An SVertexIterator object.\n" + " :type brother: :class:`SVertexIterator`\n" + "\n" + ".. method:: __init__(vertex, begin, previous_edge, next_edge, t)\n" + "\n" + " Build an SVertexIterator that starts iteration from an SVertex\n" + " object v.\n" + "\n" + " :arg vertex: The SVertex from which the iterator starts iteration.\n" + " :type vertex: :class:`SVertex`\n" + " :arg begin: The first SVertex of a ViewEdge.\n" + " :type begin: :class:`SVertex`\n" + " :arg previous_edge: The previous FEdge coming to vertex.\n" + " :type previous_edge: :class:`FEdge`\n" + " :arg next_edge: The next FEdge going out from vertex.\n" + " :type next_edge: :class:`FEdge`\n" + " :arg t: The curvilinear abscissa at vertex.\n" + " :type t: float"); static int SVertexIterator_init(BPy_SVertexIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"vertex", "begin", "previous_edge", "next_edge", "t", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - float t; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertexIterator_Type, &obj1)) { - if (!obj1) - self->sv_it = new ViewEdgeInternal::SVertexIterator(); - else - self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!f", (char **)kwlist_2, - &SVertex_Type, &obj1, - &SVertex_Type, &obj2, - &FEdge_Type, &obj3, - &FEdge_Type, &obj4, - &t)) - { - self->sv_it = new ViewEdgeInternal::SVertexIterator( - ((BPy_SVertex *)obj1)->sv, - ((BPy_SVertex *)obj2)->sv, - ((BPy_FEdge *)obj3)->fe, - ((BPy_FEdge *)obj4)->fe, - t); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->sv_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"vertex", "begin", "previous_edge", "next_edge", "t", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + float t; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &SVertexIterator_Type, &obj1)) { + if (!obj1) + self->sv_it = new ViewEdgeInternal::SVertexIterator(); + else + self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!O!O!f", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2, + &FEdge_Type, + &obj3, + &FEdge_Type, + &obj4, + &t)) { + self->sv_it = new ViewEdgeInternal::SVertexIterator(((BPy_SVertex *)obj1)->sv, + ((BPy_SVertex *)obj2)->sv, + ((BPy_FEdge *)obj3)->fe, + ((BPy_FEdge *)obj4)->fe, + t); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->sv_it; + return 0; } /*----------------------SVertexIterator get/setters ----------------------------*/ PyDoc_STRVAR(SVertexIterator_object_doc, -"The SVertex object currently pointed by this iterator.\n" -"\n" -":type: :class:`SVertex`"); + "The SVertex object currently pointed by this iterator.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *SVertexIterator_object_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - if (self->sv_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - SVertex *sv = self->sv_it->operator->(); - if (sv) - return BPy_SVertex_from_SVertex(*sv); - Py_RETURN_NONE; + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + SVertex *sv = self->sv_it->operator->(); + if (sv) + return BPy_SVertex_from_SVertex(*sv); + Py_RETURN_NONE; } PyDoc_STRVAR(SVertexIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *SVertexIterator_t_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->t()); + return PyFloat_FromDouble(self->sv_it->t()); } PyDoc_STRVAR(SVertexIterator_u_doc, -"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the 1D element (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *SVertexIterator_u_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->u()); + return PyFloat_FromDouble(self->sv_it->u()); } static PyGetSetDef BPy_SVertexIterator_getseters[] = { - {(char *)"object", (getter)SVertexIterator_object_get, (setter)NULL, (char *)SVertexIterator_object_doc, NULL}, - {(char *)"t", (getter)SVertexIterator_t_get, (setter)NULL, (char *)SVertexIterator_t_doc, NULL}, - {(char *)"u", (getter)SVertexIterator_u_get, (setter)NULL, (char *)SVertexIterator_u_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)SVertexIterator_object_get, + (setter)NULL, + (char *)SVertexIterator_object_doc, + NULL}, + {(char *)"t", + (getter)SVertexIterator_t_get, + (setter)NULL, + (char *)SVertexIterator_t_doc, + NULL}, + {(char *)"u", + (getter)SVertexIterator_u_get, + (setter)NULL, + (char *)SVertexIterator_u_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SVertexIterator type definition ------------------------------*/ PyTypeObject SVertexIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SVertexIterator", /* tp_name */ - sizeof(BPy_SVertexIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SVertexIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_SVertexIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SVertexIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SVertexIterator", /* tp_name */ + sizeof(BPy_SVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SVertexIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_SVertexIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SVertexIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h index 43e67af1183..2a3bfa6baf9 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject SVertexIterator_Type; -#define BPy_SVertexIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SVertexIterator_Type)) +#define BPy_SVertexIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SVertexIterator_Type)) /*---------------------------Python BPy_SVertexIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewEdgeInternal::SVertexIterator *sv_it; + BPy_Iterator py_it; + ViewEdgeInternal::SVertexIterator *sv_it; } BPy_SVertexIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index f39f95fda2d..5727ac2e461 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -33,271 +33,298 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(StrokeVertexIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" -"\n" -"Class defining an iterator designed to iterate over the\n" -":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" -"StrokeVertexIterator can be obtained from a Stroke by calling\n" -"iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n" -"over the same vertices as an :class:`Interface0DIterator`. The difference\n" -"resides in the object access: an Interface0DIterator only allows\n" -"access to an Interface0D while one might need to access the\n" -"specialized StrokeVertex type. In this case, one should use a\n" -"StrokeVertexIterator. To call functions of the UnaryFuntion0D type,\n" -"a StrokeVertexIterator can be converted to an Interface0DIterator by\n" -"by calling Interface0DIterator(it).\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A StrokeVertexIterator object.\n" -" :type brother: :class:`StrokeVertexIterator`"); - -static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" + "\n" + "Class defining an iterator designed to iterate over the\n" + ":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" + "StrokeVertexIterator can be obtained from a Stroke by calling\n" + "iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n" + "over the same vertices as an :class:`Interface0DIterator`. The difference\n" + "resides in the object access: an Interface0DIterator only allows\n" + "access to an Interface0D while one might need to access the\n" + "specialized StrokeVertex type. In this case, one should use a\n" + "StrokeVertexIterator. To call functions of the UnaryFuntion0D type,\n" + "a StrokeVertexIterator can be converted to an Interface0DIterator by\n" + "by calling Interface0DIterator(it).\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A StrokeVertexIterator object.\n" + " :type brother: :class:`StrokeVertexIterator`"); + +static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"stroke", NULL}; - PyObject *brother = 0, *stroke = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &StrokeVertexIterator_Type, &brother)) { - self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)brother)->sv_it)); - self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed; - self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start; - } - - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_2, &Stroke_Type, &stroke)) - { - if (!stroke) - self->sv_it = new StrokeInternal::StrokeVertexIterator(); - else - self->sv_it = new StrokeInternal::StrokeVertexIterator(((BPy_Stroke *)stroke)->s->strokeVerticesBegin()); - self->reversed = false; - self->at_start = true; - } - else { - PyErr_SetString(PyExc_TypeError, "argument 1 must be StrokeVertexIterator or Stroke"); - return -1; - } - self->py_it.it = self->sv_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"stroke", NULL}; + PyObject *brother = 0, *stroke = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &StrokeVertexIterator_Type, &brother)) { + self->sv_it = new StrokeInternal::StrokeVertexIterator( + *(((BPy_StrokeVertexIterator *)brother)->sv_it)); + self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed; + self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start; + } + + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_2, &Stroke_Type, &stroke)) { + if (!stroke) + self->sv_it = new StrokeInternal::StrokeVertexIterator(); + else + self->sv_it = new StrokeInternal::StrokeVertexIterator( + ((BPy_Stroke *)stroke)->s->strokeVerticesBegin()); + self->reversed = false; + self->at_start = true; + } + else { + PyErr_SetString(PyExc_TypeError, "argument 1 must be StrokeVertexIterator or Stroke"); + return -1; + } + self->py_it.it = self->sv_it; + return 0; } static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + Py_INCREF(self); + self->at_start = true; + return (PyObject *)self; } static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) { - /* Because Freestyle iterators for which it.isEnd() holds true have no valid object - * (they point to the past-the-end element and can't be dereferenced), we have to check - * iterators for validity. - * Additionally, the at_start attribute is used to keep Freestyle iterator objects - * and Python for loops in sync. */ - - if (self->reversed) { - if (self->sv_it->isBegin()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - self->sv_it->decrement(); - } - else { - /* If sv_it.isEnd() is true, the iterator can't be incremented. */ - if (self->sv_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - /* If at the start of the iterator, only return the object - * and don't increment, to keep for-loops in sync */ - else if (self->at_start) { - self->at_start = false; - } - /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element. - * Incrementing it further would lead to a state that the iterator can't be dereferenced. */ - else if (self->sv_it->atLast()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else { - self->sv_it->increment(); - } - } - StrokeVertex *sv = self->sv_it->operator->(); - return BPy_StrokeVertex_from_StrokeVertex(*sv); + /* Because Freestyle iterators for which it.isEnd() holds true have no valid object + * (they point to the past-the-end element and can't be dereferenced), we have to check + * iterators for validity. + * Additionally, the at_start attribute is used to keep Freestyle iterator objects + * and Python for loops in sync. */ + + if (self->reversed) { + if (self->sv_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->sv_it->decrement(); + } + else { + /* If sv_it.isEnd() is true, the iterator can't be incremented. */ + if (self->sv_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + /* If at the start of the iterator, only return the object + * and don't increment, to keep for-loops in sync */ + else if (self->at_start) { + self->at_start = false; + } + /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element. + * Incrementing it further would lead to a state that the iterator can't be dereferenced. */ + else if (self->sv_it->atLast()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else { + self->sv_it->increment(); + } + } + StrokeVertex *sv = self->sv_it->operator->(); + return BPy_StrokeVertex_from_StrokeVertex(*sv); } /*----------------------StrokeVertexIterator methods ----------------------------*/ PyDoc_STRVAR(StrokeVertexIterator_incremented_doc, -".. method:: incremented()\n" -"\n" -" Returns a copy of an incremented StrokeVertexIterator.\n" -"\n" -" :return: A StrokeVertexIterator pointing the next StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: incremented()\n" + "\n" + " Returns a copy of an incremented StrokeVertexIterator.\n" + "\n" + " :return: A StrokeVertexIterator pointing the next StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *StrokeVertexIterator_incremented(BPy_StrokeVertexIterator *self) { - if (self->sv_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); - return NULL; - } - StrokeInternal::StrokeVertexIterator copy(*self->sv_it); - copy.increment(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); + return NULL; + } + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.increment(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_decremented_doc, -".. method:: decremented()\n" -"\n" -" Returns a copy of a decremented StrokeVertexIterator.\n" -"\n" -" :return: A StrokeVertexIterator pointing the previous StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: decremented()\n" + "\n" + " Returns a copy of a decremented StrokeVertexIterator.\n" + "\n" + " :return: A StrokeVertexIterator pointing the previous StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *StrokeVertexIterator_decremented(BPy_StrokeVertexIterator *self) { - if (self->sv_it->isBegin()) { - PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); - return NULL; - } - StrokeInternal::StrokeVertexIterator copy(*self->sv_it); - copy.decrement(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); + if (self->sv_it->isBegin()) { + PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); + return NULL; + } + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.decrement(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, -".. method:: reversed()\n" -"\n" -" Returns a StrokeVertexIterator that traverses stroke vertices in the\n" -" reversed order.\n" -"\n" -" :return: A StrokeVertexIterator traversing stroke vertices backward.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: reversed()\n" + "\n" + " Returns a StrokeVertexIterator that traverses stroke vertices in the\n" + " reversed order.\n" + "\n" + " :return: A StrokeVertexIterator traversing stroke vertices backward.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self) { - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); } static PyMethodDef BPy_StrokeVertexIterator_methods[] = { - {"incremented", (PyCFunction)StrokeVertexIterator_incremented, METH_NOARGS, StrokeVertexIterator_incremented_doc}, - {"decremented", (PyCFunction)StrokeVertexIterator_decremented, METH_NOARGS, StrokeVertexIterator_decremented_doc}, - {"reversed", (PyCFunction)StrokeVertexIterator_reversed, METH_NOARGS, StrokeVertexIterator_reversed_doc}, - {NULL, NULL, 0, NULL}, + {"incremented", + (PyCFunction)StrokeVertexIterator_incremented, + METH_NOARGS, + StrokeVertexIterator_incremented_doc}, + {"decremented", + (PyCFunction)StrokeVertexIterator_decremented, + METH_NOARGS, + StrokeVertexIterator_decremented_doc}, + {"reversed", + (PyCFunction)StrokeVertexIterator_reversed, + METH_NOARGS, + StrokeVertexIterator_reversed_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------StrokeVertexIterator get/setters ----------------------------*/ PyDoc_STRVAR(StrokeVertexIterator_object_doc, -"The StrokeVertex object currently pointed to by this iterator.\n" -"\n" -":type: :class:`StrokeVertex`"); + "The StrokeVertex object currently pointed to by this iterator.\n" + "\n" + ":type: :class:`StrokeVertex`"); -static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) +static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, + void *UNUSED(closure)) { - if (self->sv_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - StrokeVertex *sv = self->sv_it->operator->(); - if (sv) - return BPy_StrokeVertex_from_StrokeVertex(*sv); - Py_RETURN_NONE; + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + StrokeVertex *sv = self->sv_it->operator->(); + if (sv) + return BPy_StrokeVertex_from_StrokeVertex(*sv); + Py_RETURN_NONE; } PyDoc_STRVAR(StrokeVertexIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *StrokeVertexIterator_t_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->t()); + return PyFloat_FromDouble(self->sv_it->t()); } PyDoc_STRVAR(StrokeVertexIterator_u_doc, -"The point parameter at the current point in the stroke (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the stroke (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->u()); + return PyFloat_FromDouble(self->sv_it->u()); } PyDoc_STRVAR(StrokeVertexIterator_at_last_doc, -"True if the interator points to the last valid element.\n" -"For its counterpart (pointing to the first valid element), use it.is_begin.\n" -"\n" -":type: bool"); + "True if the interator points to the last valid element.\n" + "For its counterpart (pointing to the first valid element), use it.is_begin.\n" + "\n" + ":type: bool"); static PyObject *StrokeVertexIterator_at_last_get(BPy_StrokeVertexIterator *self) { - return PyBool_from_bool(self->sv_it->atLast()); - + return PyBool_from_bool(self->sv_it->atLast()); } static PyGetSetDef BPy_StrokeVertexIterator_getseters[] = { - {(char *)"object", (getter)StrokeVertexIterator_object_get, (setter)NULL, - (char *)StrokeVertexIterator_object_doc, NULL}, - {(char *)"t", (getter)StrokeVertexIterator_t_get, (setter)NULL, (char *)StrokeVertexIterator_t_doc, NULL}, - {(char *)"u", (getter)StrokeVertexIterator_u_get, (setter)NULL, (char *)StrokeVertexIterator_u_doc, NULL}, - {(char *)"at_last", (getter)StrokeVertexIterator_at_last_get, (setter)NULL, - (char *)StrokeVertexIterator_at_last_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)StrokeVertexIterator_object_get, + (setter)NULL, + (char *)StrokeVertexIterator_object_doc, + NULL}, + {(char *)"t", + (getter)StrokeVertexIterator_t_get, + (setter)NULL, + (char *)StrokeVertexIterator_t_doc, + NULL}, + {(char *)"u", + (getter)StrokeVertexIterator_u_get, + (setter)NULL, + (char *)StrokeVertexIterator_u_doc, + NULL}, + {(char *)"at_last", + (getter)StrokeVertexIterator_at_last_get, + (setter)NULL, + (char *)StrokeVertexIterator_at_last_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeVertexIterator type definition ------------------------------*/ PyTypeObject StrokeVertexIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeVertexIterator", /* tp_name */ - sizeof(BPy_StrokeVertexIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeVertexIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ - (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ - BPy_StrokeVertexIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_StrokeVertexIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeVertexIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeVertexIterator", /* tp_name */ + sizeof(BPy_StrokeVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeVertexIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ + (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ + BPy_StrokeVertexIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_StrokeVertexIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeVertexIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h index 22bdf3341c4..04bca16337d 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h @@ -33,15 +33,16 @@ extern "C" { extern PyTypeObject StrokeVertexIterator_Type; -#define BPy_StrokeVertexIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertexIterator_Type)) +#define BPy_StrokeVertexIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertexIterator_Type)) /*---------------------------Python BPy_StrokeVertexIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - StrokeInternal::StrokeVertexIterator *sv_it; - bool reversed; - /* attribute to make next() work correctly */ - bool at_start; + BPy_Iterator py_it; + StrokeInternal::StrokeVertexIterator *sv_it; + bool reversed; + /* attribute to make next() work correctly */ + bool at_start; } BPy_StrokeVertexIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index efd0aafbc17..525df5dd89b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -32,224 +32,247 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(ViewEdgeIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" -"\n" -"Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" -"Basically the increment() operator of this class should be able to\n" -"take the decision of \"where\" (on which ViewEdge) to go when pointing\n" -"on a given ViewEdge.\n" -"\n" -".. method:: __init__(begin=None, orientation=True)\n" -"\n" -" Builds a ViewEdgeIterator from a starting ViewEdge and its\n" -" orientation.\n" -"\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ViewEdgeIterator object.\n" -" :type brother: :class:`ViewEdgeIterator`"); + "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" + "\n" + "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" + "Basically the increment() operator of this class should be able to\n" + "take the decision of \"where\" (on which ViewEdge) to go when pointing\n" + "on a given ViewEdge.\n" + "\n" + ".. method:: __init__(begin=None, orientation=True)\n" + "\n" + " Builds a ViewEdgeIterator from a starting ViewEdge and its\n" + " orientation.\n" + "\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ViewEdgeIterator object.\n" + " :type brother: :class:`ViewEdgeIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) { - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O&O!", (char **)kwlist_2, - check_begin, &obj1, &PyBool_Type, &obj2)) - { - ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve; - bool orientation = (!obj2) ? true : bool_from_PyBool(obj2); - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->ve_it; - return 0; + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) { + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = 0), + PyArg_ParseTupleAndKeywords( + args, kwds, "|O&O!", (char **)kwlist_2, check_begin, &obj1, &PyBool_Type, &obj2)) { + ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve; + bool orientation = (!obj2) ? true : bool_from_PyBool(obj2); + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->ve_it; + return 0; } PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc, -".. method:: change_orientation()\n" -"\n" -" Changes the current orientation."); + ".. method:: change_orientation()\n" + "\n" + " Changes the current orientation."); static PyObject *ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self) { - self->ve_it->changeOrientation(); - Py_RETURN_NONE; + self->ve_it->changeOrientation(); + Py_RETURN_NONE; } static PyMethodDef BPy_ViewEdgeIterator_methods[] = { - {"change_orientation", (PyCFunction) ViewEdgeIterator_change_orientation, METH_NOARGS, - ViewEdgeIterator_change_orientation_doc}, - {NULL, NULL, 0, NULL}, + {"change_orientation", + (PyCFunction)ViewEdgeIterator_change_orientation, + METH_NOARGS, + ViewEdgeIterator_change_orientation_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewEdgeIterator get/setters ----------------------------*/ PyDoc_STRVAR(ViewEdgeIterator_object_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { - if (!self->ve_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->ve_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + if (!self->ve_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->ve_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); -static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, + void *UNUSED(closure)) { - ViewEdge *ve = self->ve_it->getCurrentEdge(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + ViewEdge *ve = self->ve_it->getCurrentEdge(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } -static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_ViewEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); - return -1; - } - self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve); - return 0; + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve); + return 0; } PyDoc_STRVAR(ViewEdgeIterator_orientation_doc, -"The orientation of the pointed ViewEdge in the iteration.\n" -"If true, the iterator looks for the next ViewEdge among those ViewEdges\n" -"that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n" -"the iterator searches over the ViewEdges surrounding the ending ViewVertex\n" -"of the \"begin\" ViewEdge.\n" -"\n" -":type: bool"); + "The orientation of the pointed ViewEdge in the iteration.\n" + "If true, the iterator looks for the next ViewEdge among those ViewEdges\n" + "that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n" + "the iterator searches over the ViewEdges surrounding the ending ViewVertex\n" + "of the \"begin\" ViewEdge.\n" + "\n" + ":type: bool"); -static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->ve_it->getOrientation()); + return PyBool_from_bool(self->ve_it->getOrientation()); } -static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!PyBool_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a boolean"); - return -1; - } - self->ve_it->setOrientation(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a boolean"); + return -1; + } + self->ve_it->setOrientation(bool_from_PyBool(value)); + return 0; } PyDoc_STRVAR(ViewEdgeIterator_begin_doc, -"The first ViewEdge used for the iteration.\n" -"\n" -":type: :class:`ViewEdge`"); + "The first ViewEdge used for the iteration.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { - ViewEdge *ve = self->ve_it->getBegin(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + ViewEdge *ve = self->ve_it->getBegin(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } -static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_ViewEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); - return -1; - } - self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve); - return 0; + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve); + return 0; } static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = { - {(char *)"object", (getter)ViewEdgeIterator_object_get, (setter)NULL, (char *)ViewEdgeIterator_object_doc, NULL}, - {(char *)"current_edge", (getter)ViewEdgeIterator_current_edge_get, (setter)ViewEdgeIterator_current_edge_set, - (char *)ViewEdgeIterator_current_edge_doc, NULL}, - {(char *)"orientation", (getter)ViewEdgeIterator_orientation_get, (setter)ViewEdgeIterator_orientation_set, - (char *)ViewEdgeIterator_orientation_doc, NULL}, - {(char *)"begin", (getter)ViewEdgeIterator_begin_get, (setter)ViewEdgeIterator_begin_set, - (char *)ViewEdgeIterator_begin_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)ViewEdgeIterator_object_get, + (setter)NULL, + (char *)ViewEdgeIterator_object_doc, + NULL}, + {(char *)"current_edge", + (getter)ViewEdgeIterator_current_edge_get, + (setter)ViewEdgeIterator_current_edge_set, + (char *)ViewEdgeIterator_current_edge_doc, + NULL}, + {(char *)"orientation", + (getter)ViewEdgeIterator_orientation_get, + (setter)ViewEdgeIterator_orientation_set, + (char *)ViewEdgeIterator_orientation_doc, + NULL}, + {(char *)"begin", + (getter)ViewEdgeIterator_begin_get, + (setter)ViewEdgeIterator_begin_set, + (char *)ViewEdgeIterator_begin_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/ PyTypeObject ViewEdgeIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewEdgeIterator", /* tp_name */ - sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewEdgeIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewEdgeIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewEdgeIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewEdgeIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewEdgeIterator", /* tp_name */ + sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewEdgeIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewEdgeIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewEdgeIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewEdgeIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h index 83c1512e239..c9061d30e07 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject ViewEdgeIterator_Type; -#define BPy_ViewEdgeIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewEdgeIterator_Type)) +#define BPy_ViewEdgeIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewEdgeIterator_Type)) /*---------------------------Python BPy_ViewEdgeIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewEdgeInternal::ViewEdgeIterator *ve_it; + BPy_Iterator py_it; + ViewEdgeInternal::ViewEdgeIterator *ve_it; } BPy_ViewEdgeIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index 4ef1eca4e0a..3cb114a0037 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -31,145 +31,152 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(orientedViewEdgeIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" -"\n" -"Class representing an iterator over oriented ViewEdges around a\n" -":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" -"plane). An instance of an orientedViewEdgeIterator can only be\n" -"obtained from a ViewVertex by calling edges_begin() or edges_end().\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: An orientedViewEdgeIterator object.\n" -" :type iBrother: :class:`orientedViewEdgeIterator`"); - -static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" + "\n" + "Class representing an iterator over oriented ViewEdges around a\n" + ":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" + "plane). An instance of an orientedViewEdgeIterator can only be\n" + "obtained from a ViewVertex by calling edges_begin() or edges_end().\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(iBrother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg iBrother: An orientedViewEdgeIterator object.\n" + " :type iBrother: :class:`orientedViewEdgeIterator`"); + +static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"brother", NULL}; - PyObject *brother = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) - return -1; - if (!brother) { - self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); - self->at_start = true; - self->reversed = false; - } - else { - self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); - self->at_start = ((BPy_orientedViewEdgeIterator *)brother)->at_start; - self->reversed = ((BPy_orientedViewEdgeIterator *)brother)->reversed; - } - self->py_it.it = self->ove_it; - return 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) + return -1; + if (!brother) { + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); + self->at_start = true; + self->reversed = false; + } + else { + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( + *(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); + self->at_start = ((BPy_orientedViewEdgeIterator *)brother)->at_start; + self->reversed = ((BPy_orientedViewEdgeIterator *)brother)->reversed; + } + self->py_it.it = self->ove_it; + return 0; } static PyObject *orientedViewEdgeIterator_iter(BPy_orientedViewEdgeIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + Py_INCREF(self); + self->at_start = true; + return (PyObject *)self; } static PyObject *orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self) { - if (self->reversed) { - if (self->ove_it->isBegin()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - self->ove_it->decrement(); - } - else { - if (self->ove_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - if (self->at_start) - self->at_start = false; - else { - self->ove_it->increment(); - if (self->ove_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - } - } - ViewVertex::directedViewEdge *dve = self->ove_it->operator->(); - return BPy_directedViewEdge_from_directedViewEdge(*dve); + if (self->reversed) { + if (self->ove_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->ove_it->decrement(); + } + else { + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if (self->at_start) + self->at_start = false; + else { + self->ove_it->increment(); + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + } + ViewVertex::directedViewEdge *dve = self->ove_it->operator->(); + return BPy_directedViewEdge_from_directedViewEdge(*dve); } /*----------------------orientedViewEdgeIterator get/setters ----------------------------*/ PyDoc_STRVAR(orientedViewEdgeIterator_object_doc, -"The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n" -"value) currently pointed to by this iterator. If the boolean value is true,\n" -"the ViewEdge is incoming.\n" -"\n" -":type: (:class:`ViewEdge`, bool)"); - -static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure)) + "The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n" + "value) currently pointed to by this iterator. If the boolean value is true,\n" + "the ViewEdge is incoming.\n" + "\n" + ":type: (:class:`ViewEdge`, bool)"); + +static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, + void *UNUSED(closure)) { - if (self->ove_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); + if (self->ove_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); } static PyGetSetDef BPy_orientedViewEdgeIterator_getseters[] = { - {(char *)"object", (getter)orientedViewEdgeIterator_object_get, (setter)NULL, - (char *)orientedViewEdgeIterator_object_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)orientedViewEdgeIterator_object_get, + (setter)NULL, + (char *)orientedViewEdgeIterator_object_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_orientedViewEdgeIterator type definition ------------------------------*/ PyTypeObject orientedViewEdgeIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "orientedViewEdgeIterator", /* tp_name */ - sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - orientedViewEdgeIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */ - (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_orientedViewEdgeIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)orientedViewEdgeIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "orientedViewEdgeIterator", /* tp_name */ + sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + orientedViewEdgeIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */ + (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_orientedViewEdgeIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)orientedViewEdgeIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h index 226535e3882..179e315b1be 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h @@ -34,14 +34,14 @@ extern "C" { extern PyTypeObject orientedViewEdgeIterator_Type; #define BPy_orientedViewEdgeIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&orientedViewEdgeIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&orientedViewEdgeIterator_Type)) /*---------------------------Python BPy_orientedViewEdgeIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewVertexInternal::orientedViewEdgeIterator *ove_it; - bool reversed; - bool at_start; + BPy_Iterator py_it; + ViewVertexInternal::orientedViewEdgeIterator *ove_it; + bool reversed; + bool at_start; } BPy_orientedViewEdgeIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.cpp index 1fa26efdbce..7ee1372aa22 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.cpp @@ -31,77 +31,78 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char BackboneStretcherShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BackboneStretcherShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(amount=2.0)\n" -"\n" -" Builds a BackboneStretcherShader object.\n" -"\n" -" :arg amount: The stretching amount value.\n" -" :type amount: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Stretches the stroke at its two extremities and following the\n" -" respective directions: v(1)v(0) and v(n-1)v(n).\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BackboneStretcherShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(amount=2.0)\n" + "\n" + " Builds a BackboneStretcherShader object.\n" + "\n" + " :arg amount: The stretching amount value.\n" + " :type amount: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Stretches the stroke at its two extremities and following the\n" + " respective directions: v(1)v(0) and v(n-1)v(n).\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int BackboneStretcherShader___init__(BPy_BackboneStretcherShader *self, PyObject *args, PyObject *kwds) +static int BackboneStretcherShader___init__(BPy_BackboneStretcherShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"amount", NULL}; - float f = 2.0; + static const char *kwlist[] = {"amount", NULL}; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::BackboneStretcherShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::BackboneStretcherShader(f); + return 0; } /*-----------------------BPy_BackboneStretcherShader type definition ------------------------------*/ PyTypeObject BackboneStretcherShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BackboneStretcherShader", /* tp_name */ - sizeof(BPy_BackboneStretcherShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BackboneStretcherShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BackboneStretcherShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BackboneStretcherShader", /* tp_name */ + sizeof(BPy_BackboneStretcherShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BackboneStretcherShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BackboneStretcherShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.h index 037a06725c1..c37d330e4a7 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BackboneStretcherShader.h @@ -32,19 +32,17 @@ extern "C" { extern PyTypeObject BackboneStretcherShader_Type; #define BPy_BackboneStretcherShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&BackboneStretcherShader_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&BackboneStretcherShader_Type)) /*---------------------------Python BPy_BackboneStretcherShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_BackboneStretcherShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_BACKBONESTRETCHERSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.cpp index 4bb86a0bb0e..ff5b98cf912 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.cpp @@ -31,79 +31,78 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char BezierCurveShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BezierCurveShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(error=4.0)\n" -"\n" -" Builds a BezierCurveShader object.\n" -"\n" -" :arg error: The error we're allowing for the approximation. This\n" -" error is the max distance allowed between the new curve and the\n" -" original geometry.\n" -" :type error: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Transforms the stroke backbone geometry so that it corresponds to a\n" -" Bezier Curve approximation of the original backbone geometry.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BezierCurveShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(error=4.0)\n" + "\n" + " Builds a BezierCurveShader object.\n" + "\n" + " :arg error: The error we're allowing for the approximation. This\n" + " error is the max distance allowed between the new curve and the\n" + " original geometry.\n" + " :type error: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Transforms the stroke backbone geometry so that it corresponds to a\n" + " Bezier Curve approximation of the original backbone geometry.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; static int BezierCurveShader___init__(BPy_BezierCurveShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"error", NULL}; - float f = 4.0; + static const char *kwlist[] = {"error", NULL}; + float f = 4.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::BezierCurveShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::BezierCurveShader(f); + return 0; } /*-----------------------BPy_BezierCurveShader type definition ------------------------------*/ PyTypeObject BezierCurveShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BezierCurveShader", /* tp_name */ - sizeof(BPy_BezierCurveShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BezierCurveShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BezierCurveShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BezierCurveShader", /* tp_name */ + sizeof(BPy_BezierCurveShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BezierCurveShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BezierCurveShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.h index ea289bbbf62..b38fcec838d 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BezierCurveShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject BezierCurveShader_Type; -#define BPy_BezierCurveShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&BezierCurveShader_Type)) +#define BPy_BezierCurveShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&BezierCurveShader_Type)) /*---------------------------Python BPy_BezierCurveShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_BezierCurveShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_BEZIERCURVESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.cpp index 91a95d054cd..2984f52203d 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.cpp @@ -33,94 +33,96 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char BlenderTextureShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BlenderTextureShader`\n" -"\n" -"[Texture shader]\n" -"\n" -".. method:: __init__(texture)\n" -"\n" -" Builds a BlenderTextureShader object.\n" -"\n" -" :arg texture: A line style texture slot or a shader node tree to define\n" -" a set of textures.\n" -" :type texture: :class:`bpy.types.LineStyleTextureSlot` or\n" -" :class:`bpy.types.ShaderNodeTree`\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a blender texture slot to the stroke shading in order to\n" -" simulate marks.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`BlenderTextureShader`\n" + "\n" + "[Texture shader]\n" + "\n" + ".. method:: __init__(texture)\n" + "\n" + " Builds a BlenderTextureShader object.\n" + "\n" + " :arg texture: A line style texture slot or a shader node tree to define\n" + " a set of textures.\n" + " :type texture: :class:`bpy.types.LineStyleTextureSlot` or\n" + " :class:`bpy.types.ShaderNodeTree`\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns a blender texture slot to the stroke shading in order to\n" + " simulate marks.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int BlenderTextureShader___init__(BPy_BlenderTextureShader *self, PyObject *args, PyObject *kwds) +static int BlenderTextureShader___init__(BPy_BlenderTextureShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"texture", NULL}; - PyObject *obj; - MTex *_mtex; - bNodeTree *_nodetree; + static const char *kwlist[] = {"texture", NULL}; + PyObject *obj; + MTex *_mtex; + bNodeTree *_nodetree; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) - return -1; - _mtex = (MTex *)PyC_RNA_AsPointer(obj, "LineStyleTextureSlot"); - if (_mtex) { - self->py_ss.ss = new StrokeShaders::BlenderTextureShader(_mtex); - return 0; - } - PyErr_Clear(); - _nodetree = (bNodeTree *)PyC_RNA_AsPointer(obj, "ShaderNodeTree"); - if (_nodetree) { - self->py_ss.ss = new StrokeShaders::BlenderTextureShader(_nodetree); - return 0; - } - PyErr_Format(PyExc_TypeError, - "expected either 'LineStyleTextureSlot' or 'ShaderNodeTree', " - "found '%.200s' instead", Py_TYPE(obj)->tp_name); - return -1; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) + return -1; + _mtex = (MTex *)PyC_RNA_AsPointer(obj, "LineStyleTextureSlot"); + if (_mtex) { + self->py_ss.ss = new StrokeShaders::BlenderTextureShader(_mtex); + return 0; + } + PyErr_Clear(); + _nodetree = (bNodeTree *)PyC_RNA_AsPointer(obj, "ShaderNodeTree"); + if (_nodetree) { + self->py_ss.ss = new StrokeShaders::BlenderTextureShader(_nodetree); + return 0; + } + PyErr_Format(PyExc_TypeError, + "expected either 'LineStyleTextureSlot' or 'ShaderNodeTree', " + "found '%.200s' instead", + Py_TYPE(obj)->tp_name); + return -1; } /*-----------------------BPy_BlenderTextureShader type definition ------------------------------*/ PyTypeObject BlenderTextureShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "BlenderTextureShader", /* tp_name */ - sizeof(BPy_BlenderTextureShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - BlenderTextureShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)BlenderTextureShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "BlenderTextureShader", /* tp_name */ + sizeof(BPy_BlenderTextureShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + BlenderTextureShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)BlenderTextureShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h index 7fdc3b4f9fd..35335ffc023 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h @@ -27,26 +27,24 @@ extern "C" { #endif - /////////////////////////////////////////////////////////////////////////////////////////// #include extern PyTypeObject BlenderTextureShader_Type; -#define BPy_BlenderTextureShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&BlenderTextureShader_Type)) +#define BPy_BlenderTextureShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&BlenderTextureShader_Type)) /*---------------------------Python BPy_BlenderTextureShader structure definition-----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_BlenderTextureShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_BLENDERTEXTURESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp index 33734313857..98b50f2112c 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp @@ -32,95 +32,95 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char CalligraphicShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`CalligraphicShader`\n" -"\n" -"[Thickness Shader]\n" -"\n" -".. method:: __init__(thickness_min, thickness_max, orientation, clamp)\n" -"\n" -" Builds a CalligraphicShader object.\n" -"\n" -" :arg thickness_min: The minimum thickness in the direction\n" -" perpendicular to the main direction.\n" -" :type thickness_min: float\n" -" :arg thickness_max: The maximum thickness in the main direction.\n" -" :type thickness_max: float\n" -" :arg orientation: The 2D vector giving the main direction.\n" -" :type orientation: :class:`mathutils.Vector`\n" -" :arg clamp: If true, the strokes are drawn in black when the stroke\n" -" direction is between -90 and 90 degrees with respect to the main\n" -" direction and drawn in white otherwise. If false, the strokes\n" -" are always drawn in black.\n" -" :type clamp: bool\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns thicknesses to the stroke vertices so that the stroke looks\n" -" like made with a calligraphic tool, i.e. the stroke will be the\n" -" thickest in a main direction, and the thinest in the direction\n" -" perpendicular to this one, and an interpolation inbetween.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`CalligraphicShader`\n" + "\n" + "[Thickness Shader]\n" + "\n" + ".. method:: __init__(thickness_min, thickness_max, orientation, clamp)\n" + "\n" + " Builds a CalligraphicShader object.\n" + "\n" + " :arg thickness_min: The minimum thickness in the direction\n" + " perpendicular to the main direction.\n" + " :type thickness_min: float\n" + " :arg thickness_max: The maximum thickness in the main direction.\n" + " :type thickness_max: float\n" + " :arg orientation: The 2D vector giving the main direction.\n" + " :type orientation: :class:`mathutils.Vector`\n" + " :arg clamp: If true, the strokes are drawn in black when the stroke\n" + " direction is between -90 and 90 degrees with respect to the main\n" + " direction and drawn in white otherwise. If false, the strokes\n" + " are always drawn in black.\n" + " :type clamp: bool\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns thicknesses to the stroke vertices so that the stroke looks\n" + " like made with a calligraphic tool, i.e. the stroke will be the\n" + " thickest in a main direction, and the thinest in the direction\n" + " perpendicular to this one, and an interpolation inbetween.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int CalligraphicShader___init__(BPy_CalligraphicShader *self, PyObject *args, PyObject *kwds) +static int CalligraphicShader___init__(BPy_CalligraphicShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"thickness_min", "thickness_max", "orientation", "clamp", NULL}; - double d1, d2; - float f3[2]; - PyObject *obj4 = 0; + static const char *kwlist[] = {"thickness_min", "thickness_max", "orientation", "clamp", NULL}; + double d1, d2; + float f3[2]; + PyObject *obj4 = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ddO&O!", (char **)kwlist, - &d1, &d2, convert_v2, f3, &PyBool_Type, &obj4)) - { - return -1; - } - Vec2f v(f3[0], f3[1]); - self->py_ss.ss = new CalligraphicShader(d1, d2, v, bool_from_PyBool(obj4)); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "ddO&O!", (char **)kwlist, &d1, &d2, convert_v2, f3, &PyBool_Type, &obj4)) { + return -1; + } + Vec2f v(f3[0], f3[1]); + self->py_ss.ss = new CalligraphicShader(d1, d2, v, bool_from_PyBool(obj4)); + return 0; } /*-----------------------BPy_CalligraphicShader type definition ------------------------------*/ PyTypeObject CalligraphicShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CalligraphicShader", /* tp_name */ - sizeof(BPy_CalligraphicShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CalligraphicShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CalligraphicShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CalligraphicShader", /* tp_name */ + sizeof(BPy_CalligraphicShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CalligraphicShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CalligraphicShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.h index 1932e5e4dc2..8acb1215980 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.h @@ -35,15 +35,13 @@ extern PyTypeObject CalligraphicShader_Type; /*---------------------------Python BPy_CalligraphicShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_CalligraphicShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_CALLIGRAPHICSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.cpp index 3e5da7289fa..8de33188639 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.cpp @@ -31,78 +31,77 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ColorNoiseShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ColorNoiseShader`\n" -"\n" -"[Color shader]\n" -"\n" -".. method:: __init__(amplitude, period)\n" -"\n" -" Builds a ColorNoiseShader object.\n" -"\n" -" :arg amplitude: The amplitude of the noise signal.\n" -" :type amplitude: float\n" -" :arg period: The period of the noise signal.\n" -" :type period: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Shader to add noise to the stroke colors.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ColorNoiseShader`\n" + "\n" + "[Color shader]\n" + "\n" + ".. method:: __init__(amplitude, period)\n" + "\n" + " Builds a ColorNoiseShader object.\n" + "\n" + " :arg amplitude: The amplitude of the noise signal.\n" + " :type amplitude: float\n" + " :arg period: The period of the noise signal.\n" + " :type period: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Shader to add noise to the stroke colors.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; static int ColorNoiseShader___init__(BPy_ColorNoiseShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"amplitude", "period", NULL}; - float f1, f2; + static const char *kwlist[] = {"amplitude", "period", NULL}; + float f1, f2; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) - return -1; - self->py_ss.ss = new StrokeShaders::ColorNoiseShader(f1, f2); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) + return -1; + self->py_ss.ss = new StrokeShaders::ColorNoiseShader(f1, f2); + return 0; } /*-----------------------BPy_ColorNoiseShader type definition ------------------------------*/ PyTypeObject ColorNoiseShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ColorNoiseShader", /* tp_name */ - sizeof(BPy_ColorNoiseShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ColorNoiseShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ColorNoiseShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ColorNoiseShader", /* tp_name */ + sizeof(BPy_ColorNoiseShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ColorNoiseShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ColorNoiseShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.h index 0ee5964641d..054479d916d 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorNoiseShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject ColorNoiseShader_Type; -#define BPy_ColorNoiseShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ColorNoiseShader_Type)) +#define BPy_ColorNoiseShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ColorNoiseShader_Type)) /*---------------------------Python BPy_ColorNoiseShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_ColorNoiseShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_COLORNOISESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.cpp index 99dc4a07370..6dbbd1396d9 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.cpp @@ -31,82 +31,83 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ConstantColorShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ConstantColorShader`\n" -"\n" -"[Color shader]\n" -"\n" -".. method:: __init__(red, green, blue, alpha=1.0)\n" -"\n" -" Builds a ConstantColorShader object.\n" -"\n" -" :arg red: The red component.\n" -" :type red: float\n" -" :arg green: The green component.\n" -" :type green: float\n" -" :arg blue: The blue component.\n" -" :type blue: float\n" -" :arg alpha: The alpha value.\n" -" :type alpha: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a constant color to every vertex of the Stroke.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ConstantColorShader`\n" + "\n" + "[Color shader]\n" + "\n" + ".. method:: __init__(red, green, blue, alpha=1.0)\n" + "\n" + " Builds a ConstantColorShader object.\n" + "\n" + " :arg red: The red component.\n" + " :type red: float\n" + " :arg green: The green component.\n" + " :type green: float\n" + " :arg blue: The blue component.\n" + " :type blue: float\n" + " :arg alpha: The alpha value.\n" + " :type alpha: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns a constant color to every vertex of the Stroke.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int ConstantColorShader___init__(BPy_ConstantColorShader *self, PyObject *args, PyObject *kwds) +static int ConstantColorShader___init__(BPy_ConstantColorShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"red", "green", "blue", "alpha", NULL}; - float f1, f2, f3, f4 = 1.0; + static const char *kwlist[] = {"red", "green", "blue", "alpha", NULL}; + float f1, f2, f3, f4 = 1.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff|f", (char **)kwlist, &f1, &f2, &f3, &f4)) - return -1; - self->py_ss.ss = new StrokeShaders::ConstantColorShader(f1, f2, f3, f4); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff|f", (char **)kwlist, &f1, &f2, &f3, &f4)) + return -1; + self->py_ss.ss = new StrokeShaders::ConstantColorShader(f1, f2, f3, f4); + return 0; } /*-----------------------BPy_ConstantColorShader type definition ------------------------------*/ PyTypeObject ConstantColorShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ConstantColorShader", /* tp_name */ - sizeof(BPy_ConstantColorShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ConstantColorShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ConstantColorShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ConstantColorShader", /* tp_name */ + sizeof(BPy_ConstantColorShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ConstantColorShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ConstantColorShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.h index ad0ddeb23f2..36b59e6493e 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantColorShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject ConstantColorShader_Type; -#define BPy_ConstantColorShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstantColorShader_Type)) +#define BPy_ConstantColorShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstantColorShader_Type)) /*---------------------------Python BPy_ConstantColorShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_ConstantColorShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_CONSTANTCOLORSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp index 511ac47b74b..c226cc0df25 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.cpp @@ -31,76 +31,77 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ConstantThicknessShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ConstantThicknessShader`\n" -"\n" -"[Thickness shader]\n" -"\n" -".. method:: __init__(thickness)\n" -"\n" -" Builds a ConstantThicknessShader object.\n" -"\n" -" :arg thickness: The thickness that must be assigned to the stroke.\n" -" :type thickness: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns an absolute constant thickness to every vertex of the Stroke.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ConstantThicknessShader`\n" + "\n" + "[Thickness shader]\n" + "\n" + ".. method:: __init__(thickness)\n" + "\n" + " Builds a ConstantThicknessShader object.\n" + "\n" + " :arg thickness: The thickness that must be assigned to the stroke.\n" + " :type thickness: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns an absolute constant thickness to every vertex of the Stroke.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int ConstantThicknessShader___init__(BPy_ConstantThicknessShader *self, PyObject *args, PyObject *kwds) +static int ConstantThicknessShader___init__(BPy_ConstantThicknessShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"thickness", NULL}; - float f; + static const char *kwlist[] = {"thickness", NULL}; + float f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::ConstantThicknessShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::ConstantThicknessShader(f); + return 0; } /*-----------------------BPy_ConstantThicknessShader type definition ------------------------------*/ PyTypeObject ConstantThicknessShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ConstantThicknessShader", /* tp_name */ - sizeof(BPy_ConstantThicknessShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ConstantThicknessShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ConstantThicknessShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ConstantThicknessShader", /* tp_name */ + sizeof(BPy_ConstantThicknessShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ConstantThicknessShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ConstantThicknessShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.h index d07ab7250f9..3a11ab9c9a0 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstantThicknessShader.h @@ -32,19 +32,17 @@ extern "C" { extern PyTypeObject ConstantThicknessShader_Type; #define BPy_ConstantThicknessShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstantThicknessShader_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstantThicknessShader_Type)) /*---------------------------Python BPy_ConstantThicknessShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_ConstantThicknessShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_CONSTANTTHICKNESSSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.cpp index f50d496b03a..22a67c65df8 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.cpp @@ -31,83 +31,83 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ConstrainedIncreasingThicknessShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ConstrainedIncreasingThicknessShader`\n" -"\n" -"[Thickness shader]\n" -"\n" -".. method:: __init__(thickness_min, thickness_max, ratio)\n" -"\n" -" Builds a ConstrainedIncreasingThicknessShader object.\n" -"\n" -" :arg thickness_min: The minimum thickness.\n" -" :type thickness_min: float\n" -" :arg thickness_max: The maximum thickness.\n" -" :type thickness_max: float\n" -" :arg ratio: The thickness/length ratio that we don't want to exceed. \n" -" :type ratio: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Same as the :class:`IncreasingThicknessShader`, but here we allow\n" -" the user to control the thickness/length ratio so that we don't get\n" -" fat short lines.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > " + ":class:`ConstrainedIncreasingThicknessShader`\n" + "\n" + "[Thickness shader]\n" + "\n" + ".. method:: __init__(thickness_min, thickness_max, ratio)\n" + "\n" + " Builds a ConstrainedIncreasingThicknessShader object.\n" + "\n" + " :arg thickness_min: The minimum thickness.\n" + " :type thickness_min: float\n" + " :arg thickness_max: The maximum thickness.\n" + " :type thickness_max: float\n" + " :arg ratio: The thickness/length ratio that we don't want to exceed. \n" + " :type ratio: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Same as the :class:`IncreasingThicknessShader`, but here we allow\n" + " the user to control the thickness/length ratio so that we don't get\n" + " fat short lines.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int ConstrainedIncreasingThicknessShader___init__(BPy_ConstrainedIncreasingThicknessShader *self, - PyObject *args, PyObject *kwds) +static int ConstrainedIncreasingThicknessShader___init__( + BPy_ConstrainedIncreasingThicknessShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"thickness_min", "thickness_max", "ratio", NULL}; - float f1, f2, f3; + static const char *kwlist[] = {"thickness_min", "thickness_max", "ratio", NULL}; + float f1, f2, f3; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff", (char **)kwlist, &f1, &f2, &f3)) - return -1; - self->py_ss.ss = new StrokeShaders::ConstrainedIncreasingThicknessShader(f1, f2, f3); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "fff", (char **)kwlist, &f1, &f2, &f3)) + return -1; + self->py_ss.ss = new StrokeShaders::ConstrainedIncreasingThicknessShader(f1, f2, f3); + return 0; } /*-----------------------BPy_ConstrainedIncreasingThicknessShader type definition ------------------------------*/ PyTypeObject ConstrainedIncreasingThicknessShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ConstrainedIncreasingThicknessShader", /* tp_name */ - sizeof(BPy_ConstrainedIncreasingThicknessShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ConstrainedIncreasingThicknessShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ConstrainedIncreasingThicknessShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ConstrainedIncreasingThicknessShader", /* tp_name */ + sizeof(BPy_ConstrainedIncreasingThicknessShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ConstrainedIncreasingThicknessShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ConstrainedIncreasingThicknessShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.h index 2c53ee40db4..907355ea69c 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ConstrainedIncreasingThicknessShader.h @@ -32,19 +32,17 @@ extern "C" { extern PyTypeObject ConstrainedIncreasingThicknessShader_Type; #define BPy_ConstrainedIncreasingThicknessShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstrainedIncreasingThicknessShader_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ConstrainedIncreasingThicknessShader_Type)) /*---------------------------Python BPy_ConstrainedIncreasingThicknessShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_ConstrainedIncreasingThicknessShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_CONSTRAINEDINCREASINGTHICKNESSSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.cpp index 79566195633..a3cf272a1ab 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.cpp @@ -31,84 +31,85 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GuidingLinesShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`GuidingLinesShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(offset)\n" -"\n" -" Builds a GuidingLinesShader object.\n" -"\n" -" :arg offset: The line that replaces the stroke is initially in the\n" -" middle of the initial stroke bounding box. offset is the value\n" -" of the displacement which is applied to this line along its\n" -" normal.\n" -" :type offset: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Shader to modify the Stroke geometry so that it corresponds to its\n" -" main direction line. This shader must be used together with the\n" -" splitting operator using the curvature criterion. Indeed, the\n" -" precision of the approximation will depend on the size of the\n" -" stroke's pieces. The bigger the pieces are, the rougher the\n" -" approximation is.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`GuidingLinesShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(offset)\n" + "\n" + " Builds a GuidingLinesShader object.\n" + "\n" + " :arg offset: The line that replaces the stroke is initially in the\n" + " middle of the initial stroke bounding box. offset is the value\n" + " of the displacement which is applied to this line along its\n" + " normal.\n" + " :type offset: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Shader to modify the Stroke geometry so that it corresponds to its\n" + " main direction line. This shader must be used together with the\n" + " splitting operator using the curvature criterion. Indeed, the\n" + " precision of the approximation will depend on the size of the\n" + " stroke's pieces. The bigger the pieces are, the rougher the\n" + " approximation is.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int GuidingLinesShader___init__(BPy_GuidingLinesShader *self, PyObject *args, PyObject *kwds) +static int GuidingLinesShader___init__(BPy_GuidingLinesShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"offset", NULL}; - float f; + static const char *kwlist[] = {"offset", NULL}; + float f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::GuidingLinesShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::GuidingLinesShader(f); + return 0; } /*-----------------------BPy_GuidingLinesShader type definition ------------------------------*/ PyTypeObject GuidingLinesShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GuidingLinesShader", /* tp_name */ - sizeof(BPy_GuidingLinesShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GuidingLinesShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GuidingLinesShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GuidingLinesShader", /* tp_name */ + sizeof(BPy_GuidingLinesShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GuidingLinesShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GuidingLinesShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.h index 1603efce35a..217acbc4648 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_GuidingLinesShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject GuidingLinesShader_Type; -#define BPy_GuidingLinesShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GuidingLinesShader_Type)) +#define BPy_GuidingLinesShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GuidingLinesShader_Type)) /*---------------------------Python BPy_GuidingLinesShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_GuidingLinesShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_GUIDINGLINESSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.cpp index a27092d9c61..bc0bc5bd721 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.cpp @@ -31,93 +31,103 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char IncreasingColorShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`IncreasingColorShader`\n" -"\n" -"[Color shader]\n" -"\n" -".. method:: __init__(red_min, green_min, blue_min, alpha_min, red_max, green_max, blue_max, alpha_max)\n" -"\n" -" Builds an IncreasingColorShader object.\n" -"\n" -" :arg red_min: The first color red component.\n" -" :type red_min: float\n" -" :arg green_min: The first color green component.\n" -" :type green_min: float\n" -" :arg blue_min: The first color blue component.\n" -" :type blue_min: float\n" -" :arg alpha_min: The first color alpha value.\n" -" :type alpha_min: float\n" -" :arg red_max: The second color red component.\n" -" :type red_max: float\n" -" :arg green_max: The second color green component.\n" -" :type green_max: float\n" -" :arg blue_max: The second color blue component.\n" -" :type blue_max: float\n" -" :arg alpha_max: The second color alpha value.\n" -" :type alpha_max: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a varying color to the stroke. The user specifies two\n" -" colors A and B. The stroke color will change linearly from A to B\n" -" between the first and the last vertex.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`IncreasingColorShader`\n" + "\n" + "[Color shader]\n" + "\n" + ".. method:: __init__(red_min, green_min, blue_min, alpha_min, red_max, green_max, blue_max, " + "alpha_max)\n" + "\n" + " Builds an IncreasingColorShader object.\n" + "\n" + " :arg red_min: The first color red component.\n" + " :type red_min: float\n" + " :arg green_min: The first color green component.\n" + " :type green_min: float\n" + " :arg blue_min: The first color blue component.\n" + " :type blue_min: float\n" + " :arg alpha_min: The first color alpha value.\n" + " :type alpha_min: float\n" + " :arg red_max: The second color red component.\n" + " :type red_max: float\n" + " :arg green_max: The second color green component.\n" + " :type green_max: float\n" + " :arg blue_max: The second color blue component.\n" + " :type blue_max: float\n" + " :arg alpha_max: The second color alpha value.\n" + " :type alpha_max: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns a varying color to the stroke. The user specifies two\n" + " colors A and B. The stroke color will change linearly from A to B\n" + " between the first and the last vertex.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int IncreasingColorShader___init__(BPy_IncreasingColorShader *self, PyObject *args, PyObject *kwds) +static int IncreasingColorShader___init__(BPy_IncreasingColorShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"red_min", "green_min", "blue_min", "alpha_min", - "red_max", "green_max", "blue_max", "alpha_max", NULL}; - float f1, f2, f3, f4, f5, f6, f7, f8; + static const char *kwlist[] = {"red_min", + "green_min", + "blue_min", + "alpha_min", + "red_max", + "green_max", + "blue_max", + "alpha_max", + NULL}; + float f1, f2, f3, f4, f5, f6, f7, f8; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffffff", (char **)kwlist, &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8)) - return -1; - self->py_ss.ss = new StrokeShaders::IncreasingColorShader(f1, f2, f3, f4, f5, f6, f7, f8); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "ffffffff", (char **)kwlist, &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8)) + return -1; + self->py_ss.ss = new StrokeShaders::IncreasingColorShader(f1, f2, f3, f4, f5, f6, f7, f8); + return 0; } /*-----------------------BPy_IncreasingColorShader type definition ------------------------------*/ PyTypeObject IncreasingColorShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "IncreasingColorShader", /* tp_name */ - sizeof(BPy_IncreasingColorShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - IncreasingColorShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)IncreasingColorShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "IncreasingColorShader", /* tp_name */ + sizeof(BPy_IncreasingColorShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + IncreasingColorShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)IncreasingColorShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.h index 812b8df1271..d7d1d053efd 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingColorShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject IncreasingColorShader_Type; -#define BPy_IncreasingColorShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncreasingColorShader_Type)) +#define BPy_IncreasingColorShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncreasingColorShader_Type)) /*---------------------------Python BPy_IncreasingColorShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_IncreasingColorShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_INCREASINGCOLORSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.cpp index 34b62b02a39..324f1c1a40b 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.cpp @@ -31,82 +31,83 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char IncreasingThicknessShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`IncreasingThicknessShader`\n" -"\n" -"[Thickness shader]\n" -"\n" -".. method:: __init__(thickness_A, thickness_B)\n" -"\n" -" Builds an IncreasingThicknessShader object.\n" -"\n" -" :arg thickness_A: The first thickness value.\n" -" :type thickness_A: float\n" -" :arg thickness_B: The second thickness value.\n" -" :type thickness_B: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns thicknesses values such as the thickness increases from a\n" -" thickness value A to a thickness value B between the first vertex\n" -" to the midpoint vertex and then decreases from B to a A between\n" -" this midpoint vertex and the last vertex. The thickness is\n" -" linearly interpolated from A to B.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`IncreasingThicknessShader`\n" + "\n" + "[Thickness shader]\n" + "\n" + ".. method:: __init__(thickness_A, thickness_B)\n" + "\n" + " Builds an IncreasingThicknessShader object.\n" + "\n" + " :arg thickness_A: The first thickness value.\n" + " :type thickness_A: float\n" + " :arg thickness_B: The second thickness value.\n" + " :type thickness_B: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns thicknesses values such as the thickness increases from a\n" + " thickness value A to a thickness value B between the first vertex\n" + " to the midpoint vertex and then decreases from B to a A between\n" + " this midpoint vertex and the last vertex. The thickness is\n" + " linearly interpolated from A to B.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int IncreasingThicknessShader___init__(BPy_IncreasingThicknessShader *self, PyObject *args, PyObject *kwds) +static int IncreasingThicknessShader___init__(BPy_IncreasingThicknessShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"thickness_A", "thickness_B", NULL}; - float f1, f2; + static const char *kwlist[] = {"thickness_A", "thickness_B", NULL}; + float f1, f2; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) - return -1; - self->py_ss.ss = new StrokeShaders::IncreasingThicknessShader(f1, f2); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) + return -1; + self->py_ss.ss = new StrokeShaders::IncreasingThicknessShader(f1, f2); + return 0; } /*-----------------------BPy_IncreasingThicknessShader type definition ------------------------------*/ PyTypeObject IncreasingThicknessShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "IncreasingThicknessShader", /* tp_name */ - sizeof(BPy_IncreasingThicknessShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - IncreasingThicknessShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)IncreasingThicknessShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "IncreasingThicknessShader", /* tp_name */ + sizeof(BPy_IncreasingThicknessShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + IncreasingThicknessShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)IncreasingThicknessShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.h index 08c2a067d13..28636263813 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_IncreasingThicknessShader.h @@ -32,19 +32,17 @@ extern "C" { extern PyTypeObject IncreasingThicknessShader_Type; #define BPy_IncreasingThicknessShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncreasingThicknessShader_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncreasingThicknessShader_Type)) /*---------------------------Python BPy_IncreasingThicknessShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_IncreasingThicknessShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_INCREASINGTHICKNESSSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.cpp index 3444272d77a..273e41a7b9f 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.cpp @@ -31,83 +31,84 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char PolygonalizationShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`PolygonalizationShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(error)\n" -"\n" -" Builds a PolygonalizationShader object.\n" -"\n" -" :arg error: The error we want our polygonal approximation to have\n" -" with respect to the original geometry. The smaller, the closer\n" -" the new stroke is to the orinal one. This error corresponds to\n" -" the maximum distance between the new stroke and the old one.\n" -" :type error: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Modifies the Stroke geometry so that it looks more \"polygonal\".\n" -" The basic idea is to start from the minimal stroke approximation\n" -" consisting in a line joining the first vertex to the last one and\n" -" to subdivide using the original stroke vertices until a certain\n" -" error is reached.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`PolygonalizationShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(error)\n" + "\n" + " Builds a PolygonalizationShader object.\n" + "\n" + " :arg error: The error we want our polygonal approximation to have\n" + " with respect to the original geometry. The smaller, the closer\n" + " the new stroke is to the orinal one. This error corresponds to\n" + " the maximum distance between the new stroke and the old one.\n" + " :type error: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Modifies the Stroke geometry so that it looks more \"polygonal\".\n" + " The basic idea is to start from the minimal stroke approximation\n" + " consisting in a line joining the first vertex to the last one and\n" + " to subdivide using the original stroke vertices until a certain\n" + " error is reached.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int PolygonalizationShader___init__(BPy_PolygonalizationShader *self, PyObject *args, PyObject *kwds) +static int PolygonalizationShader___init__(BPy_PolygonalizationShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"error", NULL}; - float f; + static const char *kwlist[] = {"error", NULL}; + float f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::PolygonalizationShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::PolygonalizationShader(f); + return 0; } /*-----------------------BPy_PolygonalizationShader type definition ------------------------------*/ PyTypeObject PolygonalizationShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "PolygonalizationShader", /* tp_name */ - sizeof(BPy_PolygonalizationShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - PolygonalizationShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PolygonalizationShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "PolygonalizationShader", /* tp_name */ + sizeof(BPy_PolygonalizationShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + PolygonalizationShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PolygonalizationShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.h index dc314c29294..e44ca1caa51 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_PolygonalizationShader.h @@ -32,19 +32,17 @@ extern "C" { extern PyTypeObject PolygonalizationShader_Type; #define BPy_PolygonalizationShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&PolygonalizationShader_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&PolygonalizationShader_Type)) /*---------------------------Python BPy_PolygonalizationShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_PolygonalizationShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_POLYGONALIZATIONSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.cpp index cb8af522798..8769433123a 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.cpp @@ -31,76 +31,75 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char SamplingShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SamplingShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(sampling)\n" -"\n" -" Builds a SamplingShader object.\n" -"\n" -" :arg sampling: The sampling to use for the stroke resampling.\n" -" :type sampling: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Resamples the stroke.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SamplingShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(sampling)\n" + "\n" + " Builds a SamplingShader object.\n" + "\n" + " :arg sampling: The sampling to use for the stroke resampling.\n" + " :type sampling: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Resamples the stroke.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; static int SamplingShader___init__(BPy_SamplingShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"sampling", NULL}; - float f; + static const char *kwlist[] = {"sampling", NULL}; + float f; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) - return -1; - self->py_ss.ss = new StrokeShaders::SamplingShader(f); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &f)) + return -1; + self->py_ss.ss = new StrokeShaders::SamplingShader(f); + return 0; } /*-----------------------BPy_SamplingShader type definition ------------------------------*/ PyTypeObject SamplingShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SamplingShader", /* tp_name */ - sizeof(BPy_SamplingShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SamplingShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SamplingShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SamplingShader", /* tp_name */ + sizeof(BPy_SamplingShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SamplingShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SamplingShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.h index e474e836f11..50dbae6916e 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SamplingShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject SamplingShader_Type; -#define BPy_SamplingShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SamplingShader_Type)) +#define BPy_SamplingShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SamplingShader_Type)) /*---------------------------Python BPy_SamplingShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_SamplingShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_SAMPLINGSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.cpp index 870af96caf2..72d5799412f 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.cpp @@ -31,102 +31,106 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char SmoothingShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SmoothingShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(num_iterations=100, factor_point=0.1,\n" -" factor_curvature=0.0, factor_curvature_difference=0.2,\n" -" aniso_point=0.0, aniso_normal=0.0, aniso_curvature=0.0,\n" -" carricature_factor=1.0)\n" -"\n" -" Builds a SmoothingShader object.\n" -"\n" -" :arg num_iterations: The number of iterations.\n" -" :type num_iterations: int\n" -" :arg factor_point: 0.1\n" -" :type factor_point: float\n" -" :arg factor_curvature: 0.0\n" -" :type factor_curvature: float\n" -" :arg factor_curvature_difference: 0.2\n" -" :type factor_curvature_difference: float\n" -" :arg aniso_point: 0.0\n" -" :type aniso_point: float\n" -" :arg aniso_normal: 0.0\n" -" :type aniso_normal: float\n" -" :arg aniso_curvature: 0.0\n" -" :type aniso_curvature: float\n" -" :arg carricature_factor: 1.0\n" -" :type carricature_factor: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Smoothes the stroke by moving the vertices to make the stroke\n" -" smoother. Uses curvature flow to converge towards a curve of\n" -" constant curvature. The diffusion method we use is anisotropic to\n" -" prevent the diffusion across corners.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SmoothingShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(num_iterations=100, factor_point=0.1,\n" + " factor_curvature=0.0, factor_curvature_difference=0.2,\n" + " aniso_point=0.0, aniso_normal=0.0, aniso_curvature=0.0,\n" + " carricature_factor=1.0)\n" + "\n" + " Builds a SmoothingShader object.\n" + "\n" + " :arg num_iterations: The number of iterations.\n" + " :type num_iterations: int\n" + " :arg factor_point: 0.1\n" + " :type factor_point: float\n" + " :arg factor_curvature: 0.0\n" + " :type factor_curvature: float\n" + " :arg factor_curvature_difference: 0.2\n" + " :type factor_curvature_difference: float\n" + " :arg aniso_point: 0.0\n" + " :type aniso_point: float\n" + " :arg aniso_normal: 0.0\n" + " :type aniso_normal: float\n" + " :arg aniso_curvature: 0.0\n" + " :type aniso_curvature: float\n" + " :arg carricature_factor: 1.0\n" + " :type carricature_factor: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Smoothes the stroke by moving the vertices to make the stroke\n" + " smoother. Uses curvature flow to converge towards a curve of\n" + " constant curvature. The diffusion method we use is anisotropic to\n" + " prevent the diffusion across corners.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; static int SmoothingShader___init__(BPy_SmoothingShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"num_iterations", "factor_point", "factor_curvature", - "factor_curvature_difference", "aniso_point", "aniso_normal", - "aniso_curvature", "carricature_factor", NULL}; - int i1 = 100; - double d2 = 0.1, d3 = 0.0, d4 = 0.2, d5 = 0.0, d6 = 0.0, d7 = 0.0, d8 = 1.0; + static const char *kwlist[] = {"num_iterations", + "factor_point", + "factor_curvature", + "factor_curvature_difference", + "aniso_point", + "aniso_normal", + "aniso_curvature", + "carricature_factor", + NULL}; + int i1 = 100; + double d2 = 0.1, d3 = 0.0, d4 = 0.2, d5 = 0.0, d6 = 0.0, d7 = 0.0, d8 = 1.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iddddddd", (char **)kwlist, - &i1, &d2, &d3, &d4, &d5, &d6, &d7, &d8)) - { - return -1; - } - self->py_ss.ss = new SmoothingShader(i1, d2, d3, d4, d5, d6, d7, d8); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|iddddddd", (char **)kwlist, &i1, &d2, &d3, &d4, &d5, &d6, &d7, &d8)) { + return -1; + } + self->py_ss.ss = new SmoothingShader(i1, d2, d3, d4, d5, d6, d7, d8); + return 0; } /*-----------------------BPy_SmoothingShader type definition ------------------------------*/ PyTypeObject SmoothingShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SmoothingShader", /* tp_name */ - sizeof(BPy_SmoothingShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SmoothingShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SmoothingShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SmoothingShader", /* tp_name */ + sizeof(BPy_SmoothingShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SmoothingShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SmoothingShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.h index 35f046a6d4f..4b553d76770 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SmoothingShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject SmoothingShader_Type; -#define BPy_SmoothingShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SmoothingShader_Type)) +#define BPy_SmoothingShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SmoothingShader_Type)) /*---------------------------Python BPy_SmoothingShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_SmoothingShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHONSMOOTHINGSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp index 5f1c1cb7b0d..f45d97047eb 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.cpp @@ -32,90 +32,100 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char SpatialNoiseShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SpatialNoiseShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(amount, scale, num_octaves, smooth, pure_random)\n" -"\n" -" Builds a SpatialNoiseShader object.\n" -"\n" -" :arg amount: The amplitude of the noise.\n" -" :type amount: float\n" -" :arg scale: The noise frequency.\n" -" :type scale: float\n" -" :arg num_octaves: The number of octaves\n" -" :type num_octaves: int\n" -" :arg smooth: True if you want the noise to be smooth.\n" -" :type smooth: bool\n" -" :arg pure_random: True if you don't want any coherence.\n" -" :type pure_random: bool\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Spatial Noise stroke shader. Moves the vertices to make the stroke\n" -" more noisy.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`SpatialNoiseShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(amount, scale, num_octaves, smooth, pure_random)\n" + "\n" + " Builds a SpatialNoiseShader object.\n" + "\n" + " :arg amount: The amplitude of the noise.\n" + " :type amount: float\n" + " :arg scale: The noise frequency.\n" + " :type scale: float\n" + " :arg num_octaves: The number of octaves\n" + " :type num_octaves: int\n" + " :arg smooth: True if you want the noise to be smooth.\n" + " :type smooth: bool\n" + " :arg pure_random: True if you don't want any coherence.\n" + " :type pure_random: bool\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Spatial Noise stroke shader. Moves the vertices to make the stroke\n" + " more noisy.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int SpatialNoiseShader___init__(BPy_SpatialNoiseShader *self, PyObject *args, PyObject *kwds) +static int SpatialNoiseShader___init__(BPy_SpatialNoiseShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"amount", "scale", "num_octaves", "smooth", "pure_random", NULL}; - float f1, f2; - int i3; - PyObject *obj4 = 0, *obj5 = 0; + static const char *kwlist[] = {"amount", "scale", "num_octaves", "smooth", "pure_random", NULL}; + float f1, f2; + int i3; + PyObject *obj4 = 0, *obj5 = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffiO!O!", (char **)kwlist, - &f1, &f2, &i3, &PyBool_Type, &obj4, &PyBool_Type, &obj5)) - { - return -1; - } - self->py_ss.ss = new SpatialNoiseShader(f1, f2, i3, bool_from_PyBool(obj4), bool_from_PyBool(obj5)); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, + kwds, + "ffiO!O!", + (char **)kwlist, + &f1, + &f2, + &i3, + &PyBool_Type, + &obj4, + &PyBool_Type, + &obj5)) { + return -1; + } + self->py_ss.ss = new SpatialNoiseShader( + f1, f2, i3, bool_from_PyBool(obj4), bool_from_PyBool(obj5)); + return 0; } /*-----------------------BPy_SpatialNoiseShader type definition ------------------------------*/ PyTypeObject SpatialNoiseShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SpatialNoiseShader", /* tp_name */ - sizeof(BPy_SpatialNoiseShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SpatialNoiseShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SpatialNoiseShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SpatialNoiseShader", /* tp_name */ + sizeof(BPy_SpatialNoiseShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SpatialNoiseShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SpatialNoiseShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.h index 73fd0c32f45..7e5e644c46f 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_SpatialNoiseShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject SpatialNoiseShader_Type; -#define BPy_SpatialNoiseShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SpatialNoiseShader_Type)) +#define BPy_SpatialNoiseShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SpatialNoiseShader_Type)) /*---------------------------Python BPy_SpatialNoiseShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_SpatialNoiseShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_SPATIALNOISESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.cpp index 8f7c3728be4..3d76d71bab6 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.cpp @@ -31,76 +31,77 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char StrokeTextureStepShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`StrokeTextureStepShader`\n" -"\n" -"[Texture shader]\n" -"\n" -".. method:: __init__(step)\n" -"\n" -" Builds a StrokeTextureStepShader object.\n" -"\n" -" :arg step: The spacing along the stroke.\n" -" :type step: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a spacing factor to the texture coordinates of the Stroke.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`StrokeTextureStepShader`\n" + "\n" + "[Texture shader]\n" + "\n" + ".. method:: __init__(step)\n" + "\n" + " Builds a StrokeTextureStepShader object.\n" + "\n" + " :arg step: The spacing along the stroke.\n" + " :type step: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Assigns a spacing factor to the texture coordinates of the Stroke.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int StrokeTextureStepShader___init__(BPy_StrokeTextureStepShader *self, PyObject *args, PyObject *kwds) +static int StrokeTextureStepShader___init__(BPy_StrokeTextureStepShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"step", NULL}; - float step = 0.1; + static const char *kwlist[] = {"step", NULL}; + float step = 0.1; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &step)) - return -1; - self->py_ss.ss = new StrokeShaders::StrokeTextureStepShader(step); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist, &step)) + return -1; + self->py_ss.ss = new StrokeShaders::StrokeTextureStepShader(step); + return 0; } /*-----------------------BPy_StrokeTextureStepShader type definition ------------------------------*/ PyTypeObject StrokeTextureStepShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeTextureStepShader", /* tp_name */ - sizeof(BPy_StrokeTextureStepShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeTextureStepShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeTextureStepShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeTextureStepShader", /* tp_name */ + sizeof(BPy_StrokeTextureStepShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeTextureStepShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeTextureStepShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.h index 97522da52fd..d53ca139b2b 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureStepShader.h @@ -33,19 +33,18 @@ extern "C" { extern PyTypeObject StrokeTextureStepShader_Type; -#define BPy_StrokeTextureStepShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeTextureStepShader_Type)) +#define BPy_StrokeTextureStepShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeTextureStepShader_Type)) /*---------------------------Python BPy_StrokeTextureStepShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_StrokeTextureStepShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_STROKETEXTURESTEPSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.cpp index 3ba2cec4dae..56f04fb9c88 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.cpp @@ -31,78 +31,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ThicknessNoiseShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ThicknessNoiseShader`\n" -"\n" -"[Thickness shader]\n" -"\n" -".. method:: __init__(amplitude, period)\n" -"\n" -" Builds a ThicknessNoiseShader object.\n" -"\n" -" :arg amplitude: The amplitude of the noise signal.\n" -" :type amplitude: float\n" -" :arg period: The period of the noise signal.\n" -" :type period: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Adds some noise to the stroke thickness.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ThicknessNoiseShader`\n" + "\n" + "[Thickness shader]\n" + "\n" + ".. method:: __init__(amplitude, period)\n" + "\n" + " Builds a ThicknessNoiseShader object.\n" + "\n" + " :arg amplitude: The amplitude of the noise signal.\n" + " :type amplitude: float\n" + " :arg period: The period of the noise signal.\n" + " :type period: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Adds some noise to the stroke thickness.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; -static int ThicknessNoiseShader___init__(BPy_ThicknessNoiseShader *self, PyObject *args, PyObject *kwds) +static int ThicknessNoiseShader___init__(BPy_ThicknessNoiseShader *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"amplitude", "period", NULL}; - float f1, f2; + static const char *kwlist[] = {"amplitude", "period", NULL}; + float f1, f2; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) - return -1; - self->py_ss.ss = new StrokeShaders::ThicknessNoiseShader(f1, f2); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", (char **)kwlist, &f1, &f2)) + return -1; + self->py_ss.ss = new StrokeShaders::ThicknessNoiseShader(f1, f2); + return 0; } /*-----------------------BPy_ThicknessNoiseShader type definition ------------------------------*/ PyTypeObject ThicknessNoiseShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ThicknessNoiseShader", /* tp_name */ - sizeof(BPy_ThicknessNoiseShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ThicknessNoiseShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ThicknessNoiseShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ThicknessNoiseShader", /* tp_name */ + sizeof(BPy_ThicknessNoiseShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ThicknessNoiseShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ThicknessNoiseShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.h index ec18ae24966..1a42985b245 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessNoiseShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject ThicknessNoiseShader_Type; -#define BPy_ThicknessNoiseShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ThicknessNoiseShader_Type)) +#define BPy_ThicknessNoiseShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ThicknessNoiseShader_Type)) /*---------------------------Python BPy_ThicknessNoiseShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_ThicknessNoiseShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_THICKNESSNOISESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.cpp index 1d33aeb559b..3c3c31f4a70 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.cpp @@ -31,77 +31,76 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char TipRemoverShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`TipRemoverShader`\n" -"\n" -"[Geometry shader]\n" -"\n" -".. method:: __init__(tip_length)\n" -"\n" -" Builds a TipRemoverShader object.\n" -"\n" -" :arg tip_length: The length of the piece of stroke we want to remove\n" -" at each extremity.\n" -" :type tip_length: float\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Removes the stroke's extremities.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; + "Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`TipRemoverShader`\n" + "\n" + "[Geometry shader]\n" + "\n" + ".. method:: __init__(tip_length)\n" + "\n" + " Builds a TipRemoverShader object.\n" + "\n" + " :arg tip_length: The length of the piece of stroke we want to remove\n" + " at each extremity.\n" + " :type tip_length: float\n" + "\n" + ".. method:: shade(stroke)\n" + "\n" + " Removes the stroke's extremities.\n" + "\n" + " :arg stroke: A Stroke object.\n" + " :type stroke: :class:`freestyle.types.Stroke`\n"; static int TipRemoverShader___init__(BPy_TipRemoverShader *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"tip_length", NULL}; - double d; + static const char *kwlist[] = {"tip_length", NULL}; + double d; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", (char **)kwlist, &d)) - return -1; - self->py_ss.ss = new StrokeShaders::TipRemoverShader(d); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "d", (char **)kwlist, &d)) + return -1; + self->py_ss.ss = new StrokeShaders::TipRemoverShader(d); + return 0; } /*-----------------------BPy_TipRemoverShader type definition ------------------------------*/ PyTypeObject TipRemoverShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TipRemoverShader", /* tp_name */ - sizeof(BPy_TipRemoverShader), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TipRemoverShader___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &StrokeShader_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TipRemoverShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TipRemoverShader", /* tp_name */ + sizeof(BPy_TipRemoverShader), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TipRemoverShader___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &StrokeShader_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TipRemoverShader___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.h index 9615c4caff8..a82be691c81 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_TipRemoverShader.h @@ -31,19 +31,18 @@ extern "C" { extern PyTypeObject TipRemoverShader_Type; -#define BPy_TipRemoverShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&TipRemoverShader_Type)) +#define BPy_TipRemoverShader_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&TipRemoverShader_Type)) /*---------------------------Python BPy_TipRemoverShader structure definition----------*/ typedef struct { - BPy_StrokeShader py_ss; + BPy_StrokeShader py_ss; } BPy_TipRemoverShader; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif - #endif /* __FREESTYLE_PYTHON_TIPREMOVERSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp index ebd67c124ea..2b3aaf6f3cd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp @@ -44,165 +44,169 @@ extern "C" { int UnaryFunction0DDouble_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction0DDouble_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DDouble_Type); - PyModule_AddObject(module, "UnaryFunction0DDouble", (PyObject *)&UnaryFunction0DDouble_Type); - - if (PyType_Ready(&DensityF0D_Type) < 0) - return -1; - Py_INCREF(&DensityF0D_Type); - PyModule_AddObject(module, "DensityF0D", (PyObject *)&DensityF0D_Type); - - if (PyType_Ready(&LocalAverageDepthF0D_Type) < 0) - return -1; - Py_INCREF(&LocalAverageDepthF0D_Type); - PyModule_AddObject(module, "LocalAverageDepthF0D", (PyObject *)&LocalAverageDepthF0D_Type); - - if (PyType_Ready(&Curvature2DAngleF0D_Type) < 0) - return -1; - Py_INCREF(&Curvature2DAngleF0D_Type); - PyModule_AddObject(module, "Curvature2DAngleF0D", (PyObject *)&Curvature2DAngleF0D_Type); - - if (PyType_Ready(&GetProjectedXF0D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedXF0D_Type); - PyModule_AddObject(module, "GetProjectedXF0D", (PyObject *)&GetProjectedXF0D_Type); - - if (PyType_Ready(&GetProjectedYF0D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedYF0D_Type); - PyModule_AddObject(module, "GetProjectedYF0D", (PyObject *)&GetProjectedYF0D_Type); - - if (PyType_Ready(&GetProjectedZF0D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedZF0D_Type); - PyModule_AddObject(module, "GetProjectedZF0D", (PyObject *)&GetProjectedZF0D_Type); - - if (PyType_Ready(&GetXF0D_Type) < 0) - return -1; - Py_INCREF(&GetXF0D_Type); - PyModule_AddObject(module, "GetXF0D", (PyObject *)&GetXF0D_Type); - - if (PyType_Ready(&GetYF0D_Type) < 0) - return -1; - Py_INCREF(&GetYF0D_Type); - PyModule_AddObject(module, "GetYF0D", (PyObject *)&GetYF0D_Type); - - if (PyType_Ready(&GetZF0D_Type) < 0) - return -1; - Py_INCREF(&GetZF0D_Type); - PyModule_AddObject(module, "GetZF0D", (PyObject *)&GetZF0D_Type); - - if (PyType_Ready(&ZDiscontinuityF0D_Type) < 0) - return -1; - Py_INCREF(&ZDiscontinuityF0D_Type); - PyModule_AddObject(module, "ZDiscontinuityF0D", (PyObject *)&ZDiscontinuityF0D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction0DDouble_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DDouble_Type); + PyModule_AddObject(module, "UnaryFunction0DDouble", (PyObject *)&UnaryFunction0DDouble_Type); + + if (PyType_Ready(&DensityF0D_Type) < 0) + return -1; + Py_INCREF(&DensityF0D_Type); + PyModule_AddObject(module, "DensityF0D", (PyObject *)&DensityF0D_Type); + + if (PyType_Ready(&LocalAverageDepthF0D_Type) < 0) + return -1; + Py_INCREF(&LocalAverageDepthF0D_Type); + PyModule_AddObject(module, "LocalAverageDepthF0D", (PyObject *)&LocalAverageDepthF0D_Type); + + if (PyType_Ready(&Curvature2DAngleF0D_Type) < 0) + return -1; + Py_INCREF(&Curvature2DAngleF0D_Type); + PyModule_AddObject(module, "Curvature2DAngleF0D", (PyObject *)&Curvature2DAngleF0D_Type); + + if (PyType_Ready(&GetProjectedXF0D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedXF0D_Type); + PyModule_AddObject(module, "GetProjectedXF0D", (PyObject *)&GetProjectedXF0D_Type); + + if (PyType_Ready(&GetProjectedYF0D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedYF0D_Type); + PyModule_AddObject(module, "GetProjectedYF0D", (PyObject *)&GetProjectedYF0D_Type); + + if (PyType_Ready(&GetProjectedZF0D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedZF0D_Type); + PyModule_AddObject(module, "GetProjectedZF0D", (PyObject *)&GetProjectedZF0D_Type); + + if (PyType_Ready(&GetXF0D_Type) < 0) + return -1; + Py_INCREF(&GetXF0D_Type); + PyModule_AddObject(module, "GetXF0D", (PyObject *)&GetXF0D_Type); + + if (PyType_Ready(&GetYF0D_Type) < 0) + return -1; + Py_INCREF(&GetYF0D_Type); + PyModule_AddObject(module, "GetYF0D", (PyObject *)&GetYF0D_Type); + + if (PyType_Ready(&GetZF0D_Type) < 0) + return -1; + Py_INCREF(&GetZF0D_Type); + PyModule_AddObject(module, "GetZF0D", (PyObject *)&GetZF0D_Type); + + if (PyType_Ready(&ZDiscontinuityF0D_Type) < 0) + return -1; + Py_INCREF(&ZDiscontinuityF0D_Type); + PyModule_AddObject(module, "ZDiscontinuityF0D", (PyObject *)&ZDiscontinuityF0D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DDouble___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DDouble`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a float value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DDouble___init__(BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DDouble`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a float value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DDouble___init__(BPy_UnaryFunction0DDouble *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_double = new UnaryFunction0D(); - self->uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_double = new UnaryFunction0D(); + self->uf0D_double->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DDouble___dealloc__(BPy_UnaryFunction0DDouble *self) { - if (self->uf0D_double) - delete self->uf0D_double; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_double) + delete self->uf0D_double; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DDouble___repr__(BPy_UnaryFunction0DDouble *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_double); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_double); } -static PyObject *UnaryFunction0DDouble___call__(BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DDouble___call__(BPy_UnaryFunction0DDouble *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_double)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_double->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyFloat_FromDouble(self->uf0D_double->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_double)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_double->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyFloat_FromDouble(self->uf0D_double->result); } /*-----------------------BPy_UnaryFunction0DDouble type definition ------------------------------*/ PyTypeObject UnaryFunction0DDouble_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DDouble", /* tp_name */ - sizeof(BPy_UnaryFunction0DDouble), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DDouble___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DDouble___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DDouble___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DDouble___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DDouble___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DDouble", /* tp_name */ + sizeof(BPy_UnaryFunction0DDouble), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DDouble___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DDouble___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DDouble___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DDouble___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DDouble___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.h index b31297394e6..8abccd27591 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.h @@ -31,18 +31,18 @@ extern "C" { extern PyTypeObject UnaryFunction0DDouble_Type; -#define BPy_UnaryFunction0DDouble_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DDouble_Type)) +#define BPy_UnaryFunction0DDouble_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DDouble_Type)) /*---------------------------Python BPy_UnaryFunction0DDouble structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_double; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_double; } BPy_UnaryFunction0DDouble; /*---------------------------Python BPy_UnaryFunction0DDouble visible prototypes-----------*/ int UnaryFunction0DDouble_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp index 816fd622927..76dbe2ef023 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp @@ -35,121 +35,126 @@ extern "C" { int UnaryFunction0DEdgeNature_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DEdgeNature_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DEdgeNature_Type); - PyModule_AddObject(module, "UnaryFunction0DEdgeNature", (PyObject *)&UnaryFunction0DEdgeNature_Type); + if (PyType_Ready(&UnaryFunction0DEdgeNature_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DEdgeNature_Type); + PyModule_AddObject( + module, "UnaryFunction0DEdgeNature", (PyObject *)&UnaryFunction0DEdgeNature_Type); - if (PyType_Ready(&CurveNatureF0D_Type) < 0) - return -1; - Py_INCREF(&CurveNatureF0D_Type); - PyModule_AddObject(module, "CurveNatureF0D", (PyObject *)&CurveNatureF0D_Type); + if (PyType_Ready(&CurveNatureF0D_Type) < 0) + return -1; + Py_INCREF(&CurveNatureF0D_Type); + PyModule_AddObject(module, "CurveNatureF0D", (PyObject *)&CurveNatureF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DEdgeNature___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DEdgeNature`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a :class:`Nature` object.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DEdgeNature___init__(BPy_UnaryFunction0DEdgeNature *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DEdgeNature`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a :class:`Nature` object.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DEdgeNature___init__(BPy_UnaryFunction0DEdgeNature *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_edgenature = new UnaryFunction0D(); - self->uf0D_edgenature->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_edgenature = new UnaryFunction0D(); + self->uf0D_edgenature->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DEdgeNature___dealloc__(BPy_UnaryFunction0DEdgeNature *self) { - if (self->uf0D_edgenature) - delete self->uf0D_edgenature; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_edgenature) + delete self->uf0D_edgenature; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DEdgeNature___repr__(BPy_UnaryFunction0DEdgeNature *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_edgenature); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_edgenature); } static PyObject *UnaryFunction0DEdgeNature___call__(BPy_UnaryFunction0DEdgeNature *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_edgenature)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_edgenature->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return BPy_Nature_from_Nature(self->uf0D_edgenature->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_edgenature)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_edgenature->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return BPy_Nature_from_Nature(self->uf0D_edgenature->result); } /*-----------------------BPy_UnaryFunction0DEdgeNature type definition ------------------------------*/ PyTypeObject UnaryFunction0DEdgeNature_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DEdgeNature", /* tp_name */ - sizeof(BPy_UnaryFunction0DEdgeNature), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DEdgeNature___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DEdgeNature___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DEdgeNature___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DEdgeNature___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DEdgeNature___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DEdgeNature", /* tp_name */ + sizeof(BPy_UnaryFunction0DEdgeNature), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DEdgeNature___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DEdgeNature___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DEdgeNature___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DEdgeNature___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DEdgeNature___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.h index f178c8eff39..5a92142c88a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.h @@ -34,18 +34,17 @@ extern "C" { extern PyTypeObject UnaryFunction0DEdgeNature_Type; #define BPy_UnaryFunction0DEdgeNature_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DEdgeNature_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DEdgeNature_Type)) /*---------------------------Python BPy_UnaryFunction0DEdgeNature structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_edgenature; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_edgenature; } BPy_UnaryFunction0DEdgeNature; /*---------------------------Python BPy_UnaryFunction0DEdgeNature visible prototypes-----------*/ int UnaryFunction0DEdgeNature_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp index 4ee2057bafa..150b8f4e553 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp @@ -40,145 +40,153 @@ extern "C" { int UnaryFunction0DFloat_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction0DFloat_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DFloat_Type); - PyModule_AddObject(module, "UnaryFunction0DFloat", (PyObject *)&UnaryFunction0DFloat_Type); - - if (PyType_Ready(&GetCurvilinearAbscissaF0D_Type) < 0) - return -1; - Py_INCREF(&GetCurvilinearAbscissaF0D_Type); - PyModule_AddObject(module, "GetCurvilinearAbscissaF0D", (PyObject *)&GetCurvilinearAbscissaF0D_Type); - - if (PyType_Ready(&GetParameterF0D_Type) < 0) - return -1; - Py_INCREF(&GetParameterF0D_Type); - PyModule_AddObject(module, "GetParameterF0D", (PyObject *)&GetParameterF0D_Type); - - if (PyType_Ready(&GetViewMapGradientNormF0D_Type) < 0) - return -1; - Py_INCREF(&GetViewMapGradientNormF0D_Type); - PyModule_AddObject(module, "GetViewMapGradientNormF0D", (PyObject *)&GetViewMapGradientNormF0D_Type); - - if (PyType_Ready(&ReadCompleteViewMapPixelF0D_Type) < 0) - return -1; - Py_INCREF(&ReadCompleteViewMapPixelF0D_Type); - PyModule_AddObject(module, "ReadCompleteViewMapPixelF0D", (PyObject *)&ReadCompleteViewMapPixelF0D_Type); - - if (PyType_Ready(&ReadMapPixelF0D_Type) < 0) - return -1; - Py_INCREF(&ReadMapPixelF0D_Type); - PyModule_AddObject(module, "ReadMapPixelF0D", (PyObject *)&ReadMapPixelF0D_Type); - - if (PyType_Ready(&ReadSteerableViewMapPixelF0D_Type) < 0) - return -1; - Py_INCREF(&ReadSteerableViewMapPixelF0D_Type); - PyModule_AddObject(module, "ReadSteerableViewMapPixelF0D", (PyObject *)&ReadSteerableViewMapPixelF0D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction0DFloat_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DFloat_Type); + PyModule_AddObject(module, "UnaryFunction0DFloat", (PyObject *)&UnaryFunction0DFloat_Type); + + if (PyType_Ready(&GetCurvilinearAbscissaF0D_Type) < 0) + return -1; + Py_INCREF(&GetCurvilinearAbscissaF0D_Type); + PyModule_AddObject( + module, "GetCurvilinearAbscissaF0D", (PyObject *)&GetCurvilinearAbscissaF0D_Type); + + if (PyType_Ready(&GetParameterF0D_Type) < 0) + return -1; + Py_INCREF(&GetParameterF0D_Type); + PyModule_AddObject(module, "GetParameterF0D", (PyObject *)&GetParameterF0D_Type); + + if (PyType_Ready(&GetViewMapGradientNormF0D_Type) < 0) + return -1; + Py_INCREF(&GetViewMapGradientNormF0D_Type); + PyModule_AddObject( + module, "GetViewMapGradientNormF0D", (PyObject *)&GetViewMapGradientNormF0D_Type); + + if (PyType_Ready(&ReadCompleteViewMapPixelF0D_Type) < 0) + return -1; + Py_INCREF(&ReadCompleteViewMapPixelF0D_Type); + PyModule_AddObject( + module, "ReadCompleteViewMapPixelF0D", (PyObject *)&ReadCompleteViewMapPixelF0D_Type); + + if (PyType_Ready(&ReadMapPixelF0D_Type) < 0) + return -1; + Py_INCREF(&ReadMapPixelF0D_Type); + PyModule_AddObject(module, "ReadMapPixelF0D", (PyObject *)&ReadMapPixelF0D_Type); + + if (PyType_Ready(&ReadSteerableViewMapPixelF0D_Type) < 0) + return -1; + Py_INCREF(&ReadSteerableViewMapPixelF0D_Type); + PyModule_AddObject( + module, "ReadSteerableViewMapPixelF0D", (PyObject *)&ReadSteerableViewMapPixelF0D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DFloat___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DFloat`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a float value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DFloat`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a float value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_float = new UnaryFunction0D(); - self->uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_float = new UnaryFunction0D(); + self->uf0D_float->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat *self) { - if (self->uf0D_float) - delete self->uf0D_float; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_float) + delete self->uf0D_float; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DFloat___repr__(BPy_UnaryFunction0DFloat *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_float); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_float); } -static PyObject *UnaryFunction0DFloat___call__(BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DFloat___call__(BPy_UnaryFunction0DFloat *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_float)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_float->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyFloat_FromDouble(self->uf0D_float->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_float)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_float->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyFloat_FromDouble(self->uf0D_float->result); } /*-----------------------BPy_UnaryFunction0DFloat type definition ------------------------------*/ PyTypeObject UnaryFunction0DFloat_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DFloat", /* tp_name */ - sizeof(BPy_UnaryFunction0DFloat), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DFloat___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DFloat___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DFloat___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DFloat___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DFloat___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DFloat", /* tp_name */ + sizeof(BPy_UnaryFunction0DFloat), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DFloat___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DFloat___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DFloat___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DFloat___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DFloat___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.h index a36b6046a6f..53dc88d0e21 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.h @@ -31,18 +31,18 @@ extern "C" { extern PyTypeObject UnaryFunction0DFloat_Type; -#define BPy_UnaryFunction0DFloat_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DFloat_Type)) +#define BPy_UnaryFunction0DFloat_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DFloat_Type)) /*---------------------------Python BPy_UnaryFunction0DFloat structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_float; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_float; } BPy_UnaryFunction0DFloat; /*---------------------------Python BPy_UnaryFunction0DFloat visible prototypes-----------*/ int UnaryFunction0DFloat_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp index 43f73a3fedc..e9455f3dd39 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp @@ -35,120 +35,122 @@ extern "C" { int UnaryFunction0DId_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DId_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DId_Type); - PyModule_AddObject(module, "UnaryFunction0DId", (PyObject *)&UnaryFunction0DId_Type); + if (PyType_Ready(&UnaryFunction0DId_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DId_Type); + PyModule_AddObject(module, "UnaryFunction0DId", (PyObject *)&UnaryFunction0DId_Type); - if (PyType_Ready(&ShapeIdF0D_Type) < 0) - return -1; - Py_INCREF(&ShapeIdF0D_Type); - PyModule_AddObject(module, "ShapeIdF0D", (PyObject *)&ShapeIdF0D_Type); + if (PyType_Ready(&ShapeIdF0D_Type) < 0) + return -1; + Py_INCREF(&ShapeIdF0D_Type); + PyModule_AddObject(module, "ShapeIdF0D", (PyObject *)&ShapeIdF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DId___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DId`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return an :class:`Id` object.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DId`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return an :class:`Id` object.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; static int UnaryFunction0DId___init__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_id = new UnaryFunction0D(); - self->uf0D_id->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_id = new UnaryFunction0D(); + self->uf0D_id->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DId___dealloc__(BPy_UnaryFunction0DId *self) { - if (self->uf0D_id) - delete self->uf0D_id; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_id) + delete self->uf0D_id; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DId___repr__(BPy_UnaryFunction0DId *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_id); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_id); } -static PyObject *UnaryFunction0DId___call__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DId___call__(BPy_UnaryFunction0DId *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_id)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_id->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return BPy_Id_from_Id(self->uf0D_id->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_id)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_id->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return BPy_Id_from_Id(self->uf0D_id->result); } /*-----------------------BPy_UnaryFunction0DId type definition ------------------------------*/ PyTypeObject UnaryFunction0DId_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DId", /* tp_name */ - sizeof(BPy_UnaryFunction0DId), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DId___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DId___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DId___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DId___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DId___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DId", /* tp_name */ + sizeof(BPy_UnaryFunction0DId), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DId___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DId___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DId___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DId___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DId___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.h index b0c07db56e8..a8887b081ce 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.h @@ -33,18 +33,18 @@ extern "C" { extern PyTypeObject UnaryFunction0DId_Type; -#define BPy_UnaryFunction0DId_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DId_Type)) +#define BPy_UnaryFunction0DId_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DId_Type)) /*---------------------------Python BPy_UnaryFunction0DId structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_id; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_id; } BPy_UnaryFunction0DId; /*---------------------------Python BPy_UnaryFunction0DId visible prototypes-----------*/ int UnaryFunction0DId_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp index 1cfdcd23ad6..a375ac506f0 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp @@ -35,120 +35,125 @@ extern "C" { int UnaryFunction0DMaterial_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DMaterial_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DMaterial_Type); - PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type); + if (PyType_Ready(&UnaryFunction0DMaterial_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DMaterial_Type); + PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type); - if (PyType_Ready(&MaterialF0D_Type) < 0) - return -1; - Py_INCREF(&MaterialF0D_Type); - PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type); + if (PyType_Ready(&MaterialF0D_Type) < 0) + return -1; + Py_INCREF(&MaterialF0D_Type); + PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DMaterial___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DMaterial`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a :class:`Material` object.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DMaterial`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a :class:`Material` object.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_material = new UnaryFunction0D(); - self->uf0D_material->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_material = new UnaryFunction0D(); + self->uf0D_material->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial *self) { - if (self->uf0D_material) - delete self->uf0D_material; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_material) + delete self->uf0D_material; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_material); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_material); } -static PyObject *UnaryFunction0DMaterial___call__(BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DMaterial___call__(BPy_UnaryFunction0DMaterial *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_material)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_material->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return BPy_FrsMaterial_from_FrsMaterial(self->uf0D_material->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_material)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_material->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return BPy_FrsMaterial_from_FrsMaterial(self->uf0D_material->result); } /*-----------------------BPy_UnaryFunction0DMaterial type definition ------------------------------*/ PyTypeObject UnaryFunction0DMaterial_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DMaterial", /* tp_name */ - sizeof(BPy_UnaryFunction0DMaterial), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DMaterial___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DMaterial___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DMaterial___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DMaterial___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DMaterial___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DMaterial", /* tp_name */ + sizeof(BPy_UnaryFunction0DMaterial), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DMaterial___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DMaterial___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DMaterial___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DMaterial___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DMaterial___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.h index 53035601ef2..558719032f8 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.h @@ -34,18 +34,17 @@ extern "C" { extern PyTypeObject UnaryFunction0DMaterial_Type; #define BPy_UnaryFunction0DMaterial_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DMaterial_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DMaterial_Type)) /*---------------------------Python BPy_UnaryFunction0DMaterial structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_material; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_material; } BPy_UnaryFunction0DMaterial; /*---------------------------Python BPy_UnaryFunction0DMaterial visible prototypes-----------*/ int UnaryFunction0DMaterial_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp index 3aa1edb70a8..756e5cde3ce 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp @@ -35,120 +35,126 @@ extern "C" { int UnaryFunction0DUnsigned_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DUnsigned_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DUnsigned_Type); - PyModule_AddObject(module, "UnaryFunction0DUnsigned", (PyObject *)&UnaryFunction0DUnsigned_Type); + if (PyType_Ready(&UnaryFunction0DUnsigned_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DUnsigned_Type); + PyModule_AddObject(module, "UnaryFunction0DUnsigned", (PyObject *)&UnaryFunction0DUnsigned_Type); - if (PyType_Ready(&QuantitativeInvisibilityF0D_Type) < 0) - return -1; - Py_INCREF(&QuantitativeInvisibilityF0D_Type); - PyModule_AddObject(module, "QuantitativeInvisibilityF0D", (PyObject *)&QuantitativeInvisibilityF0D_Type); + if (PyType_Ready(&QuantitativeInvisibilityF0D_Type) < 0) + return -1; + Py_INCREF(&QuantitativeInvisibilityF0D_Type); + PyModule_AddObject( + module, "QuantitativeInvisibilityF0D", (PyObject *)&QuantitativeInvisibilityF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DUnsigned___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DUnsigned`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return an int value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DUnsigned___init__(BPy_UnaryFunction0DUnsigned *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DUnsigned`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return an int value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DUnsigned___init__(BPy_UnaryFunction0DUnsigned *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_unsigned = new UnaryFunction0D(); - self->uf0D_unsigned->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_unsigned = new UnaryFunction0D(); + self->uf0D_unsigned->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DUnsigned___dealloc__(BPy_UnaryFunction0DUnsigned *self) { - if (self->uf0D_unsigned) - delete self->uf0D_unsigned; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_unsigned) + delete self->uf0D_unsigned; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DUnsigned___repr__(BPy_UnaryFunction0DUnsigned *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_unsigned); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_unsigned); } -static PyObject *UnaryFunction0DUnsigned___call__(BPy_UnaryFunction0DUnsigned *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DUnsigned___call__(BPy_UnaryFunction0DUnsigned *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_unsigned)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_unsigned->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyLong_FromLong(self->uf0D_unsigned->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_unsigned)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_unsigned->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyLong_FromLong(self->uf0D_unsigned->result); } /*-----------------------BPy_UnaryFunction0DUnsigned type definition ------------------------------*/ PyTypeObject UnaryFunction0DUnsigned_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DUnsigned", /* tp_name */ - sizeof(BPy_UnaryFunction0DUnsigned), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DUnsigned___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DUnsigned___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DUnsigned___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DUnsigned___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DUnsigned___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DUnsigned", /* tp_name */ + sizeof(BPy_UnaryFunction0DUnsigned), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DUnsigned___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DUnsigned___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DUnsigned___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DUnsigned___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DUnsigned___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.h index 3205a2a01dc..ac09b51eceb 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.h @@ -32,18 +32,17 @@ extern "C" { extern PyTypeObject UnaryFunction0DUnsigned_Type; #define BPy_UnaryFunction0DUnsigned_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DUnsigned_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DUnsigned_Type)) /*---------------------------Python BPy_UnaryFunction0DUnsigned structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_unsigned; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_unsigned; } BPy_UnaryFunction0DUnsigned; /*---------------------------Python BPy_UnaryFunction0DUnsigned visible prototypes-----------*/ int UnaryFunction0DUnsigned_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp index 025d2801fbf..48cb3453ea8 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp @@ -36,125 +36,129 @@ extern "C" { int UnaryFunction0DVec2f_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DVec2f_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DVec2f_Type); - PyModule_AddObject(module, "UnaryFunction0DVec2f", (PyObject *)&UnaryFunction0DVec2f_Type); + if (PyType_Ready(&UnaryFunction0DVec2f_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DVec2f_Type); + PyModule_AddObject(module, "UnaryFunction0DVec2f", (PyObject *)&UnaryFunction0DVec2f_Type); - if (PyType_Ready(&Normal2DF0D_Type) < 0) - return -1; - Py_INCREF(&Normal2DF0D_Type); - PyModule_AddObject(module, "Normal2DF0D", (PyObject *)&Normal2DF0D_Type); + if (PyType_Ready(&Normal2DF0D_Type) < 0) + return -1; + Py_INCREF(&Normal2DF0D_Type); + PyModule_AddObject(module, "Normal2DF0D", (PyObject *)&Normal2DF0D_Type); - if (PyType_Ready(&VertexOrientation2DF0D_Type) < 0) - return -1; - Py_INCREF(&VertexOrientation2DF0D_Type); - PyModule_AddObject(module, "VertexOrientation2DF0D", (PyObject *)&VertexOrientation2DF0D_Type); + if (PyType_Ready(&VertexOrientation2DF0D_Type) < 0) + return -1; + Py_INCREF(&VertexOrientation2DF0D_Type); + PyModule_AddObject(module, "VertexOrientation2DF0D", (PyObject *)&VertexOrientation2DF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DVec2f___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec2f`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a 2D vector.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec2f`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a 2D vector.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_vec2f = new UnaryFunction0D(); - self->uf0D_vec2f->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_vec2f = new UnaryFunction0D(); + self->uf0D_vec2f->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DVec2f___dealloc__(BPy_UnaryFunction0DVec2f *self) { - if (self->uf0D_vec2f) - delete self->uf0D_vec2f; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_vec2f) + delete self->uf0D_vec2f; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DVec2f___repr__(BPy_UnaryFunction0DVec2f *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec2f); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec2f); } -static PyObject *UnaryFunction0DVec2f___call__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DVec2f___call__(BPy_UnaryFunction0DVec2f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_vec2f)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_vec2f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return Vector_from_Vec2f(self->uf0D_vec2f->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_vec2f)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_vec2f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return Vector_from_Vec2f(self->uf0D_vec2f->result); } /*-----------------------BPy_UnaryFunction0DVec2f type definition ------------------------------*/ PyTypeObject UnaryFunction0DVec2f_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DVec2f", /* tp_name */ - sizeof(BPy_UnaryFunction0DVec2f), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DVec2f___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DVec2f___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DVec2f___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DVec2f___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DVec2f___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DVec2f", /* tp_name */ + sizeof(BPy_UnaryFunction0DVec2f), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DVec2f___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DVec2f___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DVec2f___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DVec2f___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DVec2f___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.h index 974298c290b..1639e1a5356 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.h @@ -34,18 +34,18 @@ extern "C" { extern PyTypeObject UnaryFunction0DVec2f_Type; -#define BPy_UnaryFunction0DVec2f_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVec2f_Type)) +#define BPy_UnaryFunction0DVec2f_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVec2f_Type)) /*---------------------------Python BPy_UnaryFunction0DVec2f structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_vec2f; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_vec2f; } BPy_UnaryFunction0DVec2f; /*---------------------------Python BPy_UnaryFunction0DVec2f visible prototypes-----------*/ int UnaryFunction0DVec2f_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp index 53b3610ea2d..6b12136693f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp @@ -35,120 +35,124 @@ extern "C" { int UnaryFunction0DVec3f_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DVec3f_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DVec3f_Type); - PyModule_AddObject(module, "UnaryFunction0DVec3f", (PyObject *)&UnaryFunction0DVec3f_Type); + if (PyType_Ready(&UnaryFunction0DVec3f_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DVec3f_Type); + PyModule_AddObject(module, "UnaryFunction0DVec3f", (PyObject *)&UnaryFunction0DVec3f_Type); - if (PyType_Ready(&VertexOrientation3DF0D_Type) < 0) - return -1; - Py_INCREF(&VertexOrientation3DF0D_Type); - PyModule_AddObject(module, "VertexOrientation3DF0D", (PyObject *)&VertexOrientation3DF0D_Type); + if (PyType_Ready(&VertexOrientation3DF0D_Type) < 0) + return -1; + Py_INCREF(&VertexOrientation3DF0D_Type); + PyModule_AddObject(module, "VertexOrientation3DF0D", (PyObject *)&VertexOrientation3DF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DVec3f___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec3f`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a 3D vector.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DVec3f___init__(BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec3f`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a 3D vector.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DVec3f___init__(BPy_UnaryFunction0DVec3f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_vec3f = new UnaryFunction0D(); - self->uf0D_vec3f->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_vec3f = new UnaryFunction0D(); + self->uf0D_vec3f->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DVec3f___dealloc__(BPy_UnaryFunction0DVec3f *self) { - if (self->uf0D_vec3f) - delete self->uf0D_vec3f; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_vec3f) + delete self->uf0D_vec3f; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DVec3f___repr__(BPy_UnaryFunction0DVec3f *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec3f); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec3f); } -static PyObject *UnaryFunction0DVec3f___call__(BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DVec3f___call__(BPy_UnaryFunction0DVec3f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_vec3f)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_vec3f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return Vector_from_Vec3f(self->uf0D_vec3f->result); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_vec3f)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_vec3f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return Vector_from_Vec3f(self->uf0D_vec3f->result); } /*-----------------------BPy_UnaryFunction0DVec3f type definition ------------------------------*/ PyTypeObject UnaryFunction0DVec3f_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DVec3f", /* tp_name */ - sizeof(BPy_UnaryFunction0DVec3f), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DVec3f___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DVec3f___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DVec3f___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DVec3f___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DVec3f___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DVec3f", /* tp_name */ + sizeof(BPy_UnaryFunction0DVec3f), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DVec3f___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DVec3f___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DVec3f___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DVec3f___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DVec3f___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.h index fb938f019ad..0f3bcc51f2e 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.h @@ -34,18 +34,18 @@ extern "C" { extern PyTypeObject UnaryFunction0DVec3f_Type; -#define BPy_UnaryFunction0DVec3f_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVec3f_Type)) +#define BPy_UnaryFunction0DVec3f_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVec3f_Type)) /*---------------------------Python BPy_UnaryFunction0DVec3f structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_vec3f; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_vec3f; } BPy_UnaryFunction0DVec3f; /*---------------------------Python BPy_UnaryFunction0DVec3f visible prototypes-----------*/ int UnaryFunction0DVec3f_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp index ac3eb72038c..039727f4fab 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp @@ -35,131 +35,135 @@ extern "C" { int UnaryFunction0DVectorViewShape_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction0DVectorViewShape_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DVectorViewShape_Type); - PyModule_AddObject(module, "UnaryFunction0DVectorViewShape", (PyObject *)&UnaryFunction0DVectorViewShape_Type); + if (PyType_Ready(&UnaryFunction0DVectorViewShape_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DVectorViewShape_Type); + PyModule_AddObject( + module, "UnaryFunction0DVectorViewShape", (PyObject *)&UnaryFunction0DVectorViewShape_Type); - if (PyType_Ready(&GetOccludersF0D_Type) < 0) - return -1; - Py_INCREF(&GetOccludersF0D_Type); - PyModule_AddObject(module, "GetOccludersF0D", (PyObject *)&GetOccludersF0D_Type); + if (PyType_Ready(&GetOccludersF0D_Type) < 0) + return -1; + Py_INCREF(&GetOccludersF0D_Type); + PyModule_AddObject(module, "GetOccludersF0D", (PyObject *)&GetOccludersF0D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DVectorViewShape___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVectorViewShape`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a list of :class:`ViewShape`\n" -"objects.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVectorViewShape`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a list of :class:`ViewShape`\n" + "objects.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; static int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorViewShape *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_vectorviewshape = new UnaryFunction0D< std::vector >(); - self->uf0D_vectorviewshape->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_vectorviewshape = new UnaryFunction0D>(); + self->uf0D_vectorviewshape->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVectorViewShape *self) { - if (self->uf0D_vectorviewshape) - delete self->uf0D_vectorviewshape; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_vectorviewshape) + delete self->uf0D_vectorviewshape; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVectorViewShape *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vectorviewshape); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vectorviewshape); } static PyObject *UnaryFunction0DVectorViewShape___call__(BPy_UnaryFunction0DVectorViewShape *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_vectorviewshape)) == typeid(UnaryFunction0D< std::vector >)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_vectorviewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - - const unsigned int list_len = self->uf0D_vectorviewshape->result.size(); - PyObject *list = PyList_New(list_len); - for (unsigned int i = 0; i < list_len; i++) { - ViewShape *v = self->uf0D_vectorviewshape->result[i]; - PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); - } - - return list; + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_vectorviewshape)) == typeid(UnaryFunction0D>)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_vectorviewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + + const unsigned int list_len = self->uf0D_vectorviewshape->result.size(); + PyObject *list = PyList_New(list_len); + for (unsigned int i = 0; i < list_len; i++) { + ViewShape *v = self->uf0D_vectorviewshape->result[i]; + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); + } + + return list; } /*-----------------------BPy_UnaryFunction0DVectorViewShape type definition ------------------------------*/ PyTypeObject UnaryFunction0DVectorViewShape_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DVectorViewShape", /* tp_name */ - sizeof(BPy_UnaryFunction0DVectorViewShape), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DVectorViewShape___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DVectorViewShape___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DVectorViewShape___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DVectorViewShape___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DVectorViewShape___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DVectorViewShape", /* tp_name */ + sizeof(BPy_UnaryFunction0DVectorViewShape), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DVectorViewShape___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DVectorViewShape___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DVectorViewShape___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DVectorViewShape___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DVectorViewShape___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.h index bbcef5add69..22cf50ce5a2 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.h @@ -35,18 +35,17 @@ extern "C" { extern PyTypeObject UnaryFunction0DVectorViewShape_Type; #define BPy_UnaryFunction0DVectorViewShape_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVectorViewShape_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DVectorViewShape_Type)) /*---------------------------Python BPy_UnaryFunction0DVectorViewShape structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D< std::vector > *uf0D_vectorviewshape; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D> *uf0D_vectorviewshape; } BPy_UnaryFunction0DVectorViewShape; /*---------------------------Python BPy_UnaryFunction0DVectorViewShape visible prototypes-----------*/ int UnaryFunction0DVectorViewShape_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp index 9ee302e4a5c..1df3be084c0 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp @@ -36,125 +36,131 @@ extern "C" { int UnaryFunction0DViewShape_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction0DViewShape_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction0DViewShape_Type); - PyModule_AddObject(module, "UnaryFunction0DViewShape", (PyObject *)&UnaryFunction0DViewShape_Type); - - if (PyType_Ready(&GetOccludeeF0D_Type) < 0) - return -1; - Py_INCREF(&GetOccludeeF0D_Type); - PyModule_AddObject(module, "GetOccludeeF0D", (PyObject *)&GetOccludeeF0D_Type); - - if (PyType_Ready(&GetShapeF0D_Type) < 0) - return -1; - Py_INCREF(&GetShapeF0D_Type); - PyModule_AddObject(module, "GetShapeF0D", (PyObject *)&GetShapeF0D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction0DViewShape_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction0DViewShape_Type); + PyModule_AddObject( + module, "UnaryFunction0DViewShape", (PyObject *)&UnaryFunction0DViewShape_Type); + + if (PyType_Ready(&GetOccludeeF0D_Type) < 0) + return -1; + Py_INCREF(&GetOccludeeF0D_Type); + PyModule_AddObject(module, "GetOccludeeF0D", (PyObject *)&GetOccludeeF0D_Type); + + if (PyType_Ready(&GetShapeF0D_Type) < 0) + return -1; + Py_INCREF(&GetShapeF0D_Type); + PyModule_AddObject(module, "GetShapeF0D", (PyObject *)&GetShapeF0D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction0DViewShape___doc__[] = -"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DViewShape`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface0DIterator` and return a :class:`ViewShape` object.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n"; - -static int UnaryFunction0DViewShape___init__(BPy_UnaryFunction0DViewShape *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DViewShape`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface0DIterator` and return a :class:`ViewShape` object.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n"; + +static int UnaryFunction0DViewShape___init__(BPy_UnaryFunction0DViewShape *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->uf0D_viewshape = new UnaryFunction0D(); - self->uf0D_viewshape->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->uf0D_viewshape = new UnaryFunction0D(); + self->uf0D_viewshape->py_uf0D = (PyObject *)self; + return 0; } static void UnaryFunction0DViewShape___dealloc__(BPy_UnaryFunction0DViewShape *self) { - if (self->uf0D_viewshape) - delete self->uf0D_viewshape; - UnaryFunction0D_Type.tp_dealloc((PyObject *)self); + if (self->uf0D_viewshape) + delete self->uf0D_viewshape; + UnaryFunction0D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction0DViewShape___repr__(BPy_UnaryFunction0DViewShape *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_viewshape); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_viewshape); } -static PyObject *UnaryFunction0DViewShape___call__(BPy_UnaryFunction0DViewShape *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction0DViewShape___call__(BPy_UnaryFunction0DViewShape *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *obj; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) - return NULL; - - if (typeid(*(self->uf0D_viewshape)) == typeid(UnaryFunction0D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf0D_viewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return BPy_ViewShape_from_ViewShape(*(self->uf0D_viewshape->result)); + static const char *kwlist[] = {"it", NULL}; + PyObject *obj; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) + return NULL; + + if (typeid(*(self->uf0D_viewshape)) == typeid(UnaryFunction0D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf0D_viewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return BPy_ViewShape_from_ViewShape(*(self->uf0D_viewshape->result)); } /*-----------------------BPy_UnaryFunction0DViewShape type definition ------------------------------*/ PyTypeObject UnaryFunction0DViewShape_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction0DViewShape", /* tp_name */ - sizeof(BPy_UnaryFunction0DViewShape), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction0DViewShape___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction0DViewShape___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction0DViewShape___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction0DViewShape___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction0DViewShape___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DViewShape", /* tp_name */ + sizeof(BPy_UnaryFunction0DViewShape), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction0DViewShape___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction0DViewShape___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction0DViewShape___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction0DViewShape___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction0DViewShape___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.h b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.h index d94cc89c3fc..af3661669bd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.h @@ -34,18 +34,17 @@ extern "C" { extern PyTypeObject UnaryFunction0DViewShape_Type; #define BPy_UnaryFunction0DViewShape_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DViewShape_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction0DViewShape_Type)) /*---------------------------Python BPy_UnaryFunction0DViewShape structure definition----------*/ typedef struct { - BPy_UnaryFunction0D py_uf0D; - UnaryFunction0D *uf0D_viewshape; + BPy_UnaryFunction0D py_uf0D; + UnaryFunction0D *uf0D_viewshape; } BPy_UnaryFunction0DViewShape; /*---------------------------Python BPy_UnaryFunction0DViewShape visible prototypes-----------*/ int UnaryFunction0DViewShape_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.cpp index 1019c2495a2..6529c4f435b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.cpp @@ -31,81 +31,81 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ShapeIdF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DId` > :class:`ShapeIdF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a ShapeIdF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the :class:`freestyle.types.Id` of the Shape the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator belongs to. This evaluation can be ambiguous (in\n" -" the case of a :class:`freestyle.types.TVertex` for example). This\n" -" functor tries to remove this ambiguity using the context offered by\n" -" the 1D element to which the Interface0DIterator belongs to. However,\n" -" there still can be problematic cases, and the user willing to deal\n" -" with this cases in a specific way should implement its own\n" -" getShapeIdF0D functor.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The Id of the Shape the pointed Interface0D belongs to.\n" -" :rtype: :class:`freestyle.types.Id`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DId` > :class:`ShapeIdF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a ShapeIdF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the :class:`freestyle.types.Id` of the Shape the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator belongs to. This evaluation can be ambiguous (in\n" + " the case of a :class:`freestyle.types.TVertex` for example). This\n" + " functor tries to remove this ambiguity using the context offered by\n" + " the 1D element to which the Interface0DIterator belongs to. However,\n" + " there still can be problematic cases, and the user willing to deal\n" + " with this cases in a specific way should implement its own\n" + " getShapeIdF0D functor.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The Id of the Shape the pointed Interface0D belongs to.\n" + " :rtype: :class:`freestyle.types.Id`\n"; static int ShapeIdF0D___init__(BPy_ShapeIdF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_id.uf0D_id = new Functions0D::ShapeIdF0D(); - self->py_uf0D_id.uf0D_id->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_id.uf0D_id = new Functions0D::ShapeIdF0D(); + self->py_uf0D_id.uf0D_id->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_ShapeIdF0D type definition ------------------------------*/ PyTypeObject ShapeIdF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ShapeIdF0D", /* tp_name */ - sizeof(BPy_ShapeIdF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ShapeIdF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DId_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ShapeIdF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ShapeIdF0D", /* tp_name */ + sizeof(BPy_ShapeIdF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ShapeIdF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DId_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ShapeIdF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.h index c4794e7cbda..1aea0736c9b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Id/BPy_ShapeIdF0D.h @@ -35,10 +35,9 @@ extern PyTypeObject ShapeIdF0D_Type; /*---------------------------Python BPy_ShapeIdF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DId py_uf0D_id; + BPy_UnaryFunction0DId py_uf0D_id; } BPy_ShapeIdF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.cpp index 8333a7dad74..6fb65b8f132 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.cpp @@ -31,84 +31,84 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char MaterialF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DMaterial` > :class:`MaterialF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a MaterialF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the material of the object evaluated at the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator. This evaluation can be ambiguous (in the case of\n" -" a :class:`freestyle.types.TVertex` for example. This functor tries to\n" -" remove this ambiguity using the context offered by the 1D element to\n" -" which the Interface0DIterator belongs to and by arbitrary choosing the\n" -" material of the face that lies on its left when following the 1D\n" -" element if there are two different materials on each side of the\n" -" point. However, there still can be problematic cases, and the user\n" -" willing to deal with this cases in a specific way should implement its\n" -" own getMaterial functor.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The material of the object evaluated at the pointed\n" -" Interface0D.\n" -" :rtype: :class:`freestyle.types.Material`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DMaterial` > :class:`MaterialF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a MaterialF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the material of the object evaluated at the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator. This evaluation can be ambiguous (in the case of\n" + " a :class:`freestyle.types.TVertex` for example. This functor tries to\n" + " remove this ambiguity using the context offered by the 1D element to\n" + " which the Interface0DIterator belongs to and by arbitrary choosing the\n" + " material of the face that lies on its left when following the 1D\n" + " element if there are two different materials on each side of the\n" + " point. However, there still can be problematic cases, and the user\n" + " willing to deal with this cases in a specific way should implement its\n" + " own getMaterial functor.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The material of the object evaluated at the pointed\n" + " Interface0D.\n" + " :rtype: :class:`freestyle.types.Material`\n"; static int MaterialF0D___init__(BPy_MaterialF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_material.uf0D_material = new Functions0D::MaterialF0D(); - self->py_uf0D_material.uf0D_material->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_material.uf0D_material = new Functions0D::MaterialF0D(); + self->py_uf0D_material.uf0D_material->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_MaterialF0D type definition ------------------------------*/ PyTypeObject MaterialF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "MaterialF0D", /* tp_name */ - sizeof(BPy_MaterialF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - MaterialF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DMaterial_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)MaterialF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "MaterialF0D", /* tp_name */ + sizeof(BPy_MaterialF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + MaterialF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DMaterial_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)MaterialF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.h index 10f7b11eb32..f1520fa63ee 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Material/BPy_MaterialF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject MaterialF0D_Type; -#define BPy_MaterialF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&MaterialF0D_Type)) +#define BPy_MaterialF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&MaterialF0D_Type)) /*---------------------------Python BPy_MaterialF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DMaterial py_uf0D_material; + BPy_UnaryFunction0DMaterial py_uf0D_material; } BPy_MaterialF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.cpp index c67a7efc92f..a3e5871b20d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.cpp @@ -31,75 +31,75 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char CurveNatureF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DEdgeNature` > :class:`CurveNatureF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a CurveNatureF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the :class:`freestyle.types.Nature` of the 1D element the\n" -" Interface0D pointed by the Interface0DIterator belongs to.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The nature of the 1D element to which the pointed Interface0D\n" -" belongs.\n" -" :rtype: :class:`freestyle.types.Nature`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DEdgeNature` > :class:`CurveNatureF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a CurveNatureF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the :class:`freestyle.types.Nature` of the 1D element the\n" + " Interface0D pointed by the Interface0DIterator belongs to.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The nature of the 1D element to which the pointed Interface0D\n" + " belongs.\n" + " :rtype: :class:`freestyle.types.Nature`\n"; static int CurveNatureF0D___init__(BPy_CurveNatureF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_edgenature.uf0D_edgenature = new Functions0D::CurveNatureF0D(); - self->py_uf0D_edgenature.uf0D_edgenature->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_edgenature.uf0D_edgenature = new Functions0D::CurveNatureF0D(); + self->py_uf0D_edgenature.uf0D_edgenature->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_CurveNatureF0D type definition ------------------------------*/ PyTypeObject CurveNatureF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CurveNatureF0D", /* tp_name */ - sizeof(BPy_CurveNatureF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurveNatureF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DEdgeNature_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CurveNatureF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CurveNatureF0D", /* tp_name */ + sizeof(BPy_CurveNatureF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurveNatureF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DEdgeNature_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurveNatureF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.h index 8a60c28beaa..f24e63d09f9 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject CurveNatureF0D_Type; -#define BPy_CurveNatureF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurveNatureF0D_Type)) +#define BPy_CurveNatureF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurveNatureF0D_Type)) /*---------------------------Python BPy_CurveNatureF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DEdgeNature py_uf0D_edgenature; + BPy_UnaryFunction0DEdgeNature py_uf0D_edgenature; } BPy_CurveNatureF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.cpp index 5cd92790ea5..cd50e23f1d7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.cpp @@ -31,77 +31,77 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Normal2DF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DVec2f` > :class:`Normal2DF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a Normal2DF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a two-dimensional vector giving the normalized 2D normal to\n" -" the 1D element to which the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator belongs. The normal is evaluated\n" -" at the pointed Interface0D.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The 2D normal of the 1D element evaluated at the pointed\n" -" Interface0D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DVec2f` > :class:`Normal2DF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a Normal2DF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a two-dimensional vector giving the normalized 2D normal to\n" + " the 1D element to which the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator belongs. The normal is evaluated\n" + " at the pointed Interface0D.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The 2D normal of the 1D element evaluated at the pointed\n" + " Interface0D.\n" + " :rtype: :class:`mathutils.Vector`\n"; static int Normal2DF0D___init__(BPy_Normal2DF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_vec2f.uf0D_vec2f = new Functions0D::Normal2DF0D(); - self->py_uf0D_vec2f.uf0D_vec2f->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_vec2f.uf0D_vec2f = new Functions0D::Normal2DF0D(); + self->py_uf0D_vec2f.uf0D_vec2f->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_Normal2DF0D type definition ------------------------------*/ PyTypeObject Normal2DF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Normal2DF0D", /* tp_name */ - sizeof(BPy_Normal2DF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Normal2DF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DVec2f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Normal2DF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Normal2DF0D", /* tp_name */ + sizeof(BPy_Normal2DF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Normal2DF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DVec2f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Normal2DF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h index 590b8f201eb..45a4ec3124d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Normal2DF0D_Type; -#define BPy_Normal2DF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Normal2DF0D_Type)) +#define BPy_Normal2DF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Normal2DF0D_Type)) /*---------------------------Python BPy_Normal2DF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DVec2f py_uf0D_vec2f; + BPy_UnaryFunction0DVec2f py_uf0D_vec2f; } BPy_Normal2DF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.cpp index 52aabb351ad..623ec4db50e 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.cpp @@ -31,77 +31,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char VertexOrientation2DF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DVec2f` > :class:`VertexOrientation2DF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a VertexOrientation2DF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a two-dimensional vector giving the 2D oriented tangent to the\n" -" 1D element to which the :class:`freestyle.types.Interface0D` pointed\n" -" by the Interface0DIterator belongs. The 2D oriented tangent is\n" -" evaluated at the pointed Interface0D.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The 2D oriented tangent to the 1D element evaluated at the\n" -" pointed Interface0D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DVec2f` > :class:`VertexOrientation2DF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a VertexOrientation2DF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a two-dimensional vector giving the 2D oriented tangent to the\n" + " 1D element to which the :class:`freestyle.types.Interface0D` pointed\n" + " by the Interface0DIterator belongs. The 2D oriented tangent is\n" + " evaluated at the pointed Interface0D.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The 2D oriented tangent to the 1D element evaluated at the\n" + " pointed Interface0D.\n" + " :rtype: :class:`mathutils.Vector`\n"; -static int VertexOrientation2DF0D___init__(BPy_VertexOrientation2DF0D *self, PyObject *args, PyObject *kwds) +static int VertexOrientation2DF0D___init__(BPy_VertexOrientation2DF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_vec2f.uf0D_vec2f = new Functions0D::VertexOrientation2DF0D(); - self->py_uf0D_vec2f.uf0D_vec2f->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_vec2f.uf0D_vec2f = new Functions0D::VertexOrientation2DF0D(); + self->py_uf0D_vec2f.uf0D_vec2f->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_VertexOrientation2DF0D type definition ------------------------------*/ PyTypeObject VertexOrientation2DF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "VertexOrientation2DF0D", /* tp_name */ - sizeof(BPy_VertexOrientation2DF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - VertexOrientation2DF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DVec2f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)VertexOrientation2DF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "VertexOrientation2DF0D", /* tp_name */ + sizeof(BPy_VertexOrientation2DF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + VertexOrientation2DF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DVec2f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)VertexOrientation2DF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h index 157737e3f4d..8e76c31ff27 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject VertexOrientation2DF0D_Type; #define BPy_VertexOrientation2DF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&VertexOrientation2DF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&VertexOrientation2DF0D_Type)) /*---------------------------Python BPy_VertexOrientation2DF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DVec2f py_uf0D_vec2f; + BPy_UnaryFunction0DVec2f py_uf0D_vec2f; } BPy_VertexOrientation2DF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.cpp index c3d30d9b7e5..6ed52014719 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.cpp @@ -31,77 +31,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char VertexOrientation3DF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DVec3f` > :class:`VertexOrientation3DF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a VertexOrientation3DF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a three-dimensional vector giving the 3D oriented tangent to\n" -" the 1D element to which the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator belongs. The 3D oriented tangent\n" -" is evaluated at the pointed Interface0D.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The 3D oriented tangent to the 1D element evaluated at the\n" -" pointed Interface0D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DVec3f` > :class:`VertexOrientation3DF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a VertexOrientation3DF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a three-dimensional vector giving the 3D oriented tangent to\n" + " the 1D element to which the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator belongs. The 3D oriented tangent\n" + " is evaluated at the pointed Interface0D.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The 3D oriented tangent to the 1D element evaluated at the\n" + " pointed Interface0D.\n" + " :rtype: :class:`mathutils.Vector`\n"; -static int VertexOrientation3DF0D___init__(BPy_VertexOrientation3DF0D *self, PyObject *args, PyObject *kwds) +static int VertexOrientation3DF0D___init__(BPy_VertexOrientation3DF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_vec3f.uf0D_vec3f = new Functions0D::VertexOrientation3DF0D(); - self->py_uf0D_vec3f.uf0D_vec3f->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_vec3f.uf0D_vec3f = new Functions0D::VertexOrientation3DF0D(); + self->py_uf0D_vec3f.uf0D_vec3f->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_VertexOrientation3DF0D type definition ------------------------------*/ PyTypeObject VertexOrientation3DF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "VertexOrientation3DF0D", /* tp_name */ - sizeof(BPy_VertexOrientation3DF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - VertexOrientation3DF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DVec3f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)VertexOrientation3DF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "VertexOrientation3DF0D", /* tp_name */ + sizeof(BPy_VertexOrientation3DF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + VertexOrientation3DF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DVec3f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)VertexOrientation3DF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.h index 0254de71b68..391f7c9536b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_Vec3f/BPy_VertexOrientation3DF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject VertexOrientation3DF0D_Type; #define BPy_VertexOrientation3DF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&VertexOrientation3DF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&VertexOrientation3DF0D_Type)) /*---------------------------Python BPy_VertexOrientation3DF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DVec3f py_uf0D_vec3f; + BPy_UnaryFunction0DVec3f py_uf0D_vec3f; } BPy_VertexOrientation3DF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.cpp index 3636ecead72..88f4b9d32ec 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetOccludeeF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DViewShape` > :class:`GetOccludeeF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetOccludeeF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the :class:`freestyle.types.ViewShape` that the Interface0D\n" -" pointed by the Interface0DIterator occludes.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The ViewShape occluded by the pointed Interface0D.\n" -" :rtype: :class:`freestyle.types.ViewShape`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DViewShape` > :class:`GetOccludeeF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetOccludeeF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the :class:`freestyle.types.ViewShape` that the Interface0D\n" + " pointed by the Interface0DIterator occludes.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The ViewShape occluded by the pointed Interface0D.\n" + " :rtype: :class:`freestyle.types.ViewShape`\n"; static int GetOccludeeF0D___init__(BPy_GetOccludeeF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_viewshape.uf0D_viewshape = new Functions0D::GetOccludeeF0D(); - self->py_uf0D_viewshape.uf0D_viewshape->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_viewshape.uf0D_viewshape = new Functions0D::GetOccludeeF0D(); + self->py_uf0D_viewshape.uf0D_viewshape->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetOccludeeF0D type definition ------------------------------*/ PyTypeObject GetOccludeeF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetOccludeeF0D", /* tp_name */ - sizeof(BPy_GetOccludeeF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetOccludeeF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetOccludeeF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetOccludeeF0D", /* tp_name */ + sizeof(BPy_GetOccludeeF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetOccludeeF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetOccludeeF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h index 606049b1461..45c9524e185 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetOccludeeF0D_Type; -#define BPy_GetOccludeeF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludeeF0D_Type)) +#define BPy_GetOccludeeF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludeeF0D_Type)) /*---------------------------Python BPy_GetOccludeeF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DViewShape py_uf0D_viewshape; + BPy_UnaryFunction0DViewShape py_uf0D_viewshape; } BPy_GetOccludeeF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.cpp index f3f8c028a96..558e403d09c 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetShapeF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DViewShape` > :class:`GetShapeF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetShapeF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the :class:`freestyle.types.ViewShape` containing the\n" -" Interface0D pointed by the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The ViewShape containing the pointed Interface0D.\n" -" :rtype: :class:`freestyle.types.ViewShape`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DViewShape` > :class:`GetShapeF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetShapeF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the :class:`freestyle.types.ViewShape` containing the\n" + " Interface0D pointed by the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The ViewShape containing the pointed Interface0D.\n" + " :rtype: :class:`freestyle.types.ViewShape`\n"; static int GetShapeF0D___init__(BPy_GetShapeF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_viewshape.uf0D_viewshape = new Functions0D::GetShapeF0D(); - self->py_uf0D_viewshape.uf0D_viewshape->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_viewshape.uf0D_viewshape = new Functions0D::GetShapeF0D(); + self->py_uf0D_viewshape.uf0D_viewshape->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetShapeF0D type definition ------------------------------*/ PyTypeObject GetShapeF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetShapeF0D", /* tp_name */ - sizeof(BPy_GetShapeF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetShapeF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetShapeF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetShapeF0D", /* tp_name */ + sizeof(BPy_GetShapeF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetShapeF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetShapeF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h index 3033c98671c..c1db8c1219a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetShapeF0D_Type; -#define BPy_GetShapeF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetShapeF0D_Type)) +#define BPy_GetShapeF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetShapeF0D_Type)) /*---------------------------Python BPy_GetShapeF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DViewShape py_uf0D_viewshape; + BPy_UnaryFunction0DViewShape py_uf0D_viewshape; } BPy_GetShapeF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.cpp index e0c2582e841..0205adada46 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.cpp @@ -31,77 +31,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Curvature2DAngleF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`Curvature2DAngleF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a Curvature2DAngleF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a real value giving the 2D curvature (as an angle) of the 1D\n" -" element to which the :class:`freestyle.types.Interface0D` pointed by\n" -" the Interface0DIterator belongs. The 2D curvature is evaluated at the\n" -" Interface0D.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The 2D curvature of the 1D element evaluated at the\n" -" pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`Curvature2DAngleF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a Curvature2DAngleF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a real value giving the 2D curvature (as an angle) of the 1D\n" + " element to which the :class:`freestyle.types.Interface0D` pointed by\n" + " the Interface0DIterator belongs. The 2D curvature is evaluated at the\n" + " Interface0D.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The 2D curvature of the 1D element evaluated at the\n" + " pointed Interface0D.\n" + " :rtype: float\n"; -static int Curvature2DAngleF0D___init__(BPy_Curvature2DAngleF0D *self, PyObject *args, PyObject *kwds) +static int Curvature2DAngleF0D___init__(BPy_Curvature2DAngleF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::Curvature2DAngleF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::Curvature2DAngleF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_Curvature2DAngleF0D type definition ------------------------------*/ PyTypeObject Curvature2DAngleF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Curvature2DAngleF0D", /* tp_name */ - sizeof(BPy_Curvature2DAngleF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Curvature2DAngleF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Curvature2DAngleF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Curvature2DAngleF0D", /* tp_name */ + sizeof(BPy_Curvature2DAngleF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Curvature2DAngleF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Curvature2DAngleF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.h index 9f7e5f54c6a..b57119257b9 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_Curvature2DAngleF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Curvature2DAngleF0D_Type; -#define BPy_Curvature2DAngleF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Curvature2DAngleF0D_Type)) +#define BPy_Curvature2DAngleF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Curvature2DAngleF0D_Type)) /*---------------------------Python BPy_Curvature2DAngleF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_Curvature2DAngleF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.cpp index 912b56d5555..c18a4e1ab40 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.cpp @@ -31,84 +31,84 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char DensityF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`DensityF0D`\n" -"\n" -".. method:: __init__(sigma=2.0)\n" -"\n" -" Builds a DensityF0D object.\n" -"\n" -" :arg sigma: The gaussian sigma value indicating the X value for\n" -" which the gaussian function is 0.5. It leads to the window size\n" -" value (the larger, the smoother).\n" -" :type sigma: float\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the density of the (result) image evaluated at the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator. This density is evaluated using a pixels square\n" -" window around the evaluation point and integrating these values using\n" -" a gaussian.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The density of the image evaluated at the pointed\n" -" Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`DensityF0D`\n" + "\n" + ".. method:: __init__(sigma=2.0)\n" + "\n" + " Builds a DensityF0D object.\n" + "\n" + " :arg sigma: The gaussian sigma value indicating the X value for\n" + " which the gaussian function is 0.5. It leads to the window size\n" + " value (the larger, the smoother).\n" + " :type sigma: float\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the density of the (result) image evaluated at the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator. This density is evaluated using a pixels square\n" + " window around the evaluation point and integrating these values using\n" + " a gaussian.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The density of the image evaluated at the pointed\n" + " Interface0D.\n" + " :rtype: float\n"; static int DensityF0D___init__(BPy_DensityF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"sigma", NULL}; - double d = 2; + static const char *kwlist[] = {"sigma", NULL}; + double d = 2; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|d", (char **)kwlist, &d)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::DensityF0D(d); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|d", (char **)kwlist, &d)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::DensityF0D(d); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_DensityF0D type definition ------------------------------*/ PyTypeObject DensityF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "DensityF0D", /* tp_name */ - sizeof(BPy_DensityF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - DensityF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)DensityF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "DensityF0D", /* tp_name */ + sizeof(BPy_DensityF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + DensityF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)DensityF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.h index 55fd8042654..34bbd8331fb 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_DensityF0D.h @@ -35,10 +35,9 @@ extern PyTypeObject DensityF0D_Type; /*---------------------------Python BPy_DensityF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_DensityF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.cpp index 7c75b96c2ec..6bf7fd3895c 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedXF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedXF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetProjectedXF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the X 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The X 3D projected coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedXF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetProjectedXF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the X 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The X 3D projected coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetProjectedXF0D___init__(BPy_GetProjectedXF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedXF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedXF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetProjectedXF0D type definition ------------------------------*/ PyTypeObject GetProjectedXF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedXF0D", /* tp_name */ - sizeof(BPy_GetProjectedXF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedXF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedXF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedXF0D", /* tp_name */ + sizeof(BPy_GetProjectedXF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedXF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedXF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.h index 7fedc2eedf8..ddd500f617e 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedXF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedXF0D_Type; -#define BPy_GetProjectedXF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedXF0D_Type)) +#define BPy_GetProjectedXF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedXF0D_Type)) /*---------------------------Python BPy_GetProjectedXF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetProjectedXF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.cpp index c3c42372361..af2b05bcc02 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedYF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedYF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetProjectedYF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the Y 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The Y 3D projected coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedYF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetProjectedYF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the Y 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The Y 3D projected coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetProjectedYF0D___init__(BPy_GetProjectedYF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedYF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedYF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetProjectedYF0D type definition ------------------------------*/ PyTypeObject GetProjectedYF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedYF0D", /* tp_name */ - sizeof(BPy_GetProjectedYF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedYF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedYF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedYF0D", /* tp_name */ + sizeof(BPy_GetProjectedYF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedYF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedYF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.h index d1a5d754103..8fccf14971f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedYF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedYF0D_Type; -#define BPy_GetProjectedYF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedYF0D_Type)) +#define BPy_GetProjectedYF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedYF0D_Type)) /*---------------------------Python BPy_GetProjectedYF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetProjectedYF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.cpp index 3a3cfb96404..db066f445f5 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedZF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedZF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetProjectedZF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the Z 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The Z 3D projected coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetProjectedZF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetProjectedZF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the Z 3D projected coordinate of the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The Z 3D projected coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetProjectedZF0D___init__(BPy_GetProjectedZF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedZF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetProjectedZF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetProjectedZF0D type definition ------------------------------*/ PyTypeObject GetProjectedZF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedZF0D", /* tp_name */ - sizeof(BPy_GetProjectedZF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedZF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedZF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedZF0D", /* tp_name */ + sizeof(BPy_GetProjectedZF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedZF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedZF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.h index 00e933ba88e..eecf69adb12 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetProjectedZF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedZF0D_Type; -#define BPy_GetProjectedZF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedZF0D_Type)) +#define BPy_GetProjectedZF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedZF0D_Type)) /*---------------------------Python BPy_GetProjectedZF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetProjectedZF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.cpp index 063d1470bb7..e95b9146248 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetXF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetXF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetXF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the X 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" -" the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The X 3D coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetXF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetXF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the X 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" + " the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The X 3D coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetXF0D___init__(BPy_GetXF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetXF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetXF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetXF0D type definition ------------------------------*/ PyTypeObject GetXF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetXF0D", /* tp_name */ - sizeof(BPy_GetXF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetXF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetXF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetXF0D", /* tp_name */ + sizeof(BPy_GetXF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetXF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetXF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.h index 8d29f401faf..745bd5c628d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetXF0D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetXF0D_Type; /*---------------------------Python BPy_GetXF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetXF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.cpp index 9c22ac1acbc..c4ce2dc6140 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetYF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetYF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetYF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the Y 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" -" the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The Y 3D coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetYF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetYF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the Y 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" + " the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The Y 3D coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetYF0D___init__(BPy_GetYF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetYF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetYF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetYF0D type definition ------------------------------*/ PyTypeObject GetYF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetYF0D", /* tp_name */ - sizeof(BPy_GetYF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetYF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetYF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetYF0D", /* tp_name */ + sizeof(BPy_GetYF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetYF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetYF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.h index 56cf07992d7..437ec573585 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetYF0D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetYF0D_Type; /*---------------------------Python BPy_GetYF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetYF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.cpp index 5c280d74d59..1b93a295f53 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetZF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetZF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetZF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the Z 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" -" the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The Z 3D coordinate of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`GetZF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetZF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the Z 3D coordinate of the :class:`freestyle.types.Interface0D` pointed by\n" + " the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The Z 3D coordinate of the pointed Interface0D.\n" + " :rtype: float\n"; static int GetZF0D___init__(BPy_GetZF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::GetZF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::GetZF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetZF0D type definition ------------------------------*/ PyTypeObject GetZF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetZF0D", /* tp_name */ - sizeof(BPy_GetZF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetZF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetZF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetZF0D", /* tp_name */ + sizeof(BPy_GetZF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetZF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetZF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.h index 944e575937f..840303fa59d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_GetZF0D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetZF0D_Type; /*---------------------------Python BPy_GetZF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_GetZF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.cpp index 775c058e882..dc304574c7f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.cpp @@ -31,80 +31,82 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char LocalAverageDepthF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`LocalAverageDepthF0D`\n" -"\n" -".. method:: __init__(mask_size=5.0)\n" -"\n" -" Builds a LocalAverageDepthF0D object.\n" -"\n" -" :arg mask_size: The size of the mask.\n" -" :type mask_size: float\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the average depth around the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator. The result is obtained by querying the depth\n" -" buffer on a window around that point.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The average depth around the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`LocalAverageDepthF0D`\n" + "\n" + ".. method:: __init__(mask_size=5.0)\n" + "\n" + " Builds a LocalAverageDepthF0D object.\n" + "\n" + " :arg mask_size: The size of the mask.\n" + " :type mask_size: float\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the average depth around the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator. The result is obtained by querying the depth\n" + " buffer on a window around that point.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The average depth around the pointed Interface0D.\n" + " :rtype: float\n"; -static int LocalAverageDepthF0D___init__(BPy_LocalAverageDepthF0D *self, PyObject *args, PyObject *kwds) +static int LocalAverageDepthF0D___init__(BPy_LocalAverageDepthF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"mask_size", NULL}; - double d = 5.0; + static const char *kwlist[] = {"mask_size", NULL}; + double d = 5.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|d", (char **)kwlist, &d)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::LocalAverageDepthF0D(d); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|d", (char **)kwlist, &d)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::LocalAverageDepthF0D(d); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_LocalAverageDepthF0D type definition ------------------------------*/ PyTypeObject LocalAverageDepthF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "LocalAverageDepthF0D", /* tp_name */ - sizeof(BPy_LocalAverageDepthF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - LocalAverageDepthF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)LocalAverageDepthF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "LocalAverageDepthF0D", /* tp_name */ + sizeof(BPy_LocalAverageDepthF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + LocalAverageDepthF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)LocalAverageDepthF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.h index 951b036f72a..f8072427d47 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_LocalAverageDepthF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject LocalAverageDepthF0D_Type; -#define BPy_LocalAverageDepthF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&LocalAverageDepthF0D_Type)) +#define BPy_LocalAverageDepthF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&LocalAverageDepthF0D_Type)) /*---------------------------Python BPy_LocalAverageDepthF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_LocalAverageDepthF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.cpp index 7b3a2f568d2..d2ae0f0fa31 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.cpp @@ -31,79 +31,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ZDiscontinuityF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DDouble` > :class:`ZDiscontinuityF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a ZDiscontinuityF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a real value giving the distance between the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator and the shape that lies behind (occludee). This\n" -" distance is evaluated in the camera space and normalized between 0 and\n" -" 1. Therefore, if no object is occluded by the shape to which the\n" -" Interface0D belongs to, 1 is returned.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The normalized distance between the pointed Interface0D\n" -" and the occludee.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DDouble` > :class:`ZDiscontinuityF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a ZDiscontinuityF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a real value giving the distance between the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator and the shape that lies behind (occludee). This\n" + " distance is evaluated in the camera space and normalized between 0 and\n" + " 1. Therefore, if no object is occluded by the shape to which the\n" + " Interface0D belongs to, 1 is returned.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The normalized distance between the pointed Interface0D\n" + " and the occludee.\n" + " :rtype: float\n"; static int ZDiscontinuityF0D___init__(BPy_ZDiscontinuityF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_double.uf0D_double = new Functions0D::ZDiscontinuityF0D(); - self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_double.uf0D_double = new Functions0D::ZDiscontinuityF0D(); + self->py_uf0D_double.uf0D_double->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_ZDiscontinuityF0D type definition ------------------------------*/ PyTypeObject ZDiscontinuityF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ZDiscontinuityF0D", /* tp_name */ - sizeof(BPy_ZDiscontinuityF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ZDiscontinuityF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ZDiscontinuityF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ZDiscontinuityF0D", /* tp_name */ + sizeof(BPy_ZDiscontinuityF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ZDiscontinuityF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ZDiscontinuityF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h index ccfb186fb28..d0aed95fc1a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject ZDiscontinuityF0D_Type; -#define BPy_ZDiscontinuityF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ZDiscontinuityF0D_Type)) +#define BPy_ZDiscontinuityF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ZDiscontinuityF0D_Type)) /*---------------------------Python BPy_ZDiscontinuityF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DDouble py_uf0D_double; + BPy_UnaryFunction0DDouble py_uf0D_double; } BPy_ZDiscontinuityF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.cpp index 726412428a6..ce8852a2b6c 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.cpp @@ -31,75 +31,77 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetCurvilinearAbscissaF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetCurvilinearAbscissaF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetCurvilinearAbscissaF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the curvilinear abscissa of the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator in the context of its 1D element.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The curvilinear abscissa of the pointed Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetCurvilinearAbscissaF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetCurvilinearAbscissaF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the curvilinear abscissa of the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator in the context of its 1D element.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The curvilinear abscissa of the pointed Interface0D.\n" + " :rtype: float\n"; -static int GetCurvilinearAbscissaF0D___init__(BPy_GetCurvilinearAbscissaF0D *self, PyObject *args, PyObject *kwds) +static int GetCurvilinearAbscissaF0D___init__(BPy_GetCurvilinearAbscissaF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::GetCurvilinearAbscissaF0D(); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::GetCurvilinearAbscissaF0D(); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetCurvilinearAbscissaF0D type definition ------------------------------*/ PyTypeObject GetCurvilinearAbscissaF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetCurvilinearAbscissaF0D", /* tp_name */ - sizeof(BPy_GetCurvilinearAbscissaF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetCurvilinearAbscissaF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetCurvilinearAbscissaF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetCurvilinearAbscissaF0D", /* tp_name */ + sizeof(BPy_GetCurvilinearAbscissaF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetCurvilinearAbscissaF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetCurvilinearAbscissaF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h index 33d268afce2..72238cfc255 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject GetCurvilinearAbscissaF0D_Type; #define BPy_GetCurvilinearAbscissaF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetCurvilinearAbscissaF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetCurvilinearAbscissaF0D_Type)) /*---------------------------Python BPy_GetCurvilinearAbscissaF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_GetCurvilinearAbscissaF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.cpp index c6c3d351f8f..bc67c4dd91d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.cpp @@ -31,74 +31,74 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetParameterF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetParameterF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetParameterF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the parameter of the :class:`freestyle.types.Interface0D`\n" -" pointed by the Interface0DIterator in the context of its 1D element.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The parameter of an Interface0D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetParameterF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetParameterF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the parameter of the :class:`freestyle.types.Interface0D`\n" + " pointed by the Interface0DIterator in the context of its 1D element.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The parameter of an Interface0D.\n" + " :rtype: float\n"; static int GetParameterF0D___init__(BPy_GetParameterF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::GetParameterF0D(); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::GetParameterF0D(); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetParameterF0D type definition ------------------------------*/ PyTypeObject GetParameterF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetParameterF0D", /* tp_name */ - sizeof(BPy_GetParameterF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetParameterF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetParameterF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetParameterF0D", /* tp_name */ + sizeof(BPy_GetParameterF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetParameterF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetParameterF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.h index 3917c27db77..4fdb6419f21 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetParameterF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetParameterF0D_Type; -#define BPy_GetParameterF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetParameterF0D_Type)) +#define BPy_GetParameterF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetParameterF0D_Type)) /*---------------------------Python BPy_GetParameterF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_GetParameterF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.cpp index d56fc8fb321..3cf5efc59d7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.cpp @@ -31,80 +31,82 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetViewMapGradientNormF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetViewMapGradientNormF0D`\n" -"\n" -".. method:: __init__(level)\n" -"\n" -" Builds a GetViewMapGradientNormF0D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the norm of the gradient of the global viewmap density\n" -" image.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The norm of the gradient of the global viewmap density\n" -" image.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`GetViewMapGradientNormF0D`\n" + "\n" + ".. method:: __init__(level)\n" + "\n" + " Builds a GetViewMapGradientNormF0D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the norm of the gradient of the global viewmap density\n" + " image.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The norm of the gradient of the global viewmap density\n" + " image.\n" + " :rtype: float\n"; -static int GetViewMapGradientNormF0D___init__(BPy_GetViewMapGradientNormF0D *self, PyObject *args, PyObject *kwds) +static int GetViewMapGradientNormF0D___init__(BPy_GetViewMapGradientNormF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", NULL}; - int i; + static const char *kwlist[] = {"level", NULL}; + int i; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::GetViewMapGradientNormF0D(i); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::GetViewMapGradientNormF0D(i); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetViewMapGradientNormF0D type definition ------------------------------*/ PyTypeObject GetViewMapGradientNormF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetViewMapGradientNormF0D", /* tp_name */ - sizeof(BPy_GetViewMapGradientNormF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetViewMapGradientNormF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetViewMapGradientNormF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetViewMapGradientNormF0D", /* tp_name */ + sizeof(BPy_GetViewMapGradientNormF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetViewMapGradientNormF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetViewMapGradientNormF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h index 24a8bef6277..6ed42ee8019 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject GetViewMapGradientNormF0D_Type; #define BPy_GetViewMapGradientNormF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetViewMapGradientNormF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetViewMapGradientNormF0D_Type)) /*---------------------------Python BPy_GetViewMapGradientNormF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_GetViewMapGradientNormF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.cpp index f04284cdb22..a70cf817b46 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.cpp @@ -31,78 +31,80 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ReadCompleteViewMapPixelF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadCompleteViewMapPixelF0D`\n" -"\n" -".. method:: __init__(level)\n" -"\n" -" Builds a ReadCompleteViewMapPixelF0D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Reads a pixel in one of the level of the complete viewmap.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: A pixel in one of the level of the complete viewmap.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadCompleteViewMapPixelF0D`\n" + "\n" + ".. method:: __init__(level)\n" + "\n" + " Builds a ReadCompleteViewMapPixelF0D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Reads a pixel in one of the level of the complete viewmap.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: A pixel in one of the level of the complete viewmap.\n" + " :rtype: float\n"; -static int ReadCompleteViewMapPixelF0D___init__(BPy_ReadCompleteViewMapPixelF0D *self, PyObject *args, PyObject *kwds) +static int ReadCompleteViewMapPixelF0D___init__(BPy_ReadCompleteViewMapPixelF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", NULL}; - int i; + static const char *kwlist[] = {"level", NULL}; + int i; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::ReadCompleteViewMapPixelF0D(i); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::ReadCompleteViewMapPixelF0D(i); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_ReadCompleteViewMapPixelF0D type definition ------------------------------*/ PyTypeObject ReadCompleteViewMapPixelF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ReadCompleteViewMapPixelF0D", /* tp_name */ - sizeof(BPy_ReadCompleteViewMapPixelF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ReadCompleteViewMapPixelF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ReadCompleteViewMapPixelF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ReadCompleteViewMapPixelF0D", /* tp_name */ + sizeof(BPy_ReadCompleteViewMapPixelF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ReadCompleteViewMapPixelF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ReadCompleteViewMapPixelF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h index 53afad75533..6ccfd9764c5 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject ReadCompleteViewMapPixelF0D_Type; #define BPy_ReadCompleteViewMapPixelF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadCompleteViewMapPixelF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadCompleteViewMapPixelF0D_Type)) /*---------------------------Python BPy_ReadCompleteViewMapPixelF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_ReadCompleteViewMapPixelF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.cpp index eb1e8c8c068..dea8923777b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.cpp @@ -31,81 +31,81 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ReadMapPixelF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadMapPixelF0D`\n" -"\n" -".. method:: __init__(map_name, level)\n" -"\n" -" Builds a ReadMapPixelF0D object.\n" -"\n" -" :arg map_name: The name of the map to be read.\n" -" :type map_name: str\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Reads a pixel in a map.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: A pixel in a map.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadMapPixelF0D`\n" + "\n" + ".. method:: __init__(map_name, level)\n" + "\n" + " Builds a ReadMapPixelF0D object.\n" + "\n" + " :arg map_name: The name of the map to be read.\n" + " :type map_name: str\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Reads a pixel in a map.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: A pixel in a map.\n" + " :rtype: float\n"; static int ReadMapPixelF0D___init__(BPy_ReadMapPixelF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"map_name", "level", NULL}; - const char *s; - int i; + static const char *kwlist[] = {"map_name", "level", NULL}; + const char *s; + int i; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "si", (char **)kwlist, &s, &i)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::ReadMapPixelF0D(s, i); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "si", (char **)kwlist, &s, &i)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::ReadMapPixelF0D(s, i); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_ReadMapPixelF0D type definition ------------------------------*/ PyTypeObject ReadMapPixelF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ReadMapPixelF0D", /* tp_name */ - sizeof(BPy_ReadMapPixelF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ReadMapPixelF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ReadMapPixelF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ReadMapPixelF0D", /* tp_name */ + sizeof(BPy_ReadMapPixelF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ReadMapPixelF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ReadMapPixelF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.h index 3c6a05d8233..014a4aa2b8e 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadMapPixelF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject ReadMapPixelF0D_Type; -#define BPy_ReadMapPixelF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadMapPixelF0D_Type)) +#define BPy_ReadMapPixelF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadMapPixelF0D_Type)) /*---------------------------Python BPy_ReadMapPixelF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_ReadMapPixelF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.cpp index 99f87dfcdee..3dec389f1f1 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.cpp @@ -31,82 +31,84 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ReadSteerableViewMapPixelF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadSteerableViewMapPixelF0D`\n" -"\n" -".. method:: __init__(orientation, level)\n" -"\n" -" Builds a ReadSteerableViewMapPixelF0D object.\n" -"\n" -" :arg orientation: The integer belonging to [0, 4] indicating the\n" -" orientation (E, NE, N, NW) we are interested in.\n" -" :type orientation: int\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Reads a pixel in one of the level of one of the steerable viewmaps.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: A pixel in one of the level of one of the steerable viewmaps.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DFloat` > :class:`ReadSteerableViewMapPixelF0D`\n" + "\n" + ".. method:: __init__(orientation, level)\n" + "\n" + " Builds a ReadSteerableViewMapPixelF0D object.\n" + "\n" + " :arg orientation: The integer belonging to [0, 4] indicating the\n" + " orientation (E, NE, N, NW) we are interested in.\n" + " :type orientation: int\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Reads a pixel in one of the level of one of the steerable viewmaps.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: A pixel in one of the level of one of the steerable viewmaps.\n" + " :rtype: float\n"; -static int ReadSteerableViewMapPixelF0D___init__(BPy_ReadSteerableViewMapPixelF0D *self, PyObject *args, PyObject *kwds) +static int ReadSteerableViewMapPixelF0D___init__(BPy_ReadSteerableViewMapPixelF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"orientation", "level", NULL}; - unsigned int u; - int i; + static const char *kwlist[] = {"orientation", "level", NULL}; + unsigned int u; + int i; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ii", (char **)kwlist, &u, &i)) - return -1; - self->py_uf0D_float.uf0D_float = new Functions0D::ReadSteerableViewMapPixelF0D(u, i); - self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ii", (char **)kwlist, &u, &i)) + return -1; + self->py_uf0D_float.uf0D_float = new Functions0D::ReadSteerableViewMapPixelF0D(u, i); + self->py_uf0D_float.uf0D_float->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_ReadSteerableViewMapPixelF0D type definition ------------------------------*/ PyTypeObject ReadSteerableViewMapPixelF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ReadSteerableViewMapPixelF0D", /* tp_name */ - sizeof(BPy_ReadSteerableViewMapPixelF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ReadSteerableViewMapPixelF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DFloat_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ReadSteerableViewMapPixelF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ReadSteerableViewMapPixelF0D", /* tp_name */ + sizeof(BPy_ReadSteerableViewMapPixelF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ReadSteerableViewMapPixelF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DFloat_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ReadSteerableViewMapPixelF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h index 07d9b4996de..c0c62a50941 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject ReadSteerableViewMapPixelF0D_Type; #define BPy_ReadSteerableViewMapPixelF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadSteerableViewMapPixelF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ReadSteerableViewMapPixelF0D_Type)) /*---------------------------Python BPy_ReadSteerableViewMapPixelF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DFloat py_uf0D_float; + BPy_UnaryFunction0DFloat py_uf0D_float; } BPy_ReadSteerableViewMapPixelF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.cpp index 6569c8a8c1f..f35f6ad7814 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.cpp @@ -31,80 +31,82 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char QuantitativeInvisibilityF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DUnsigned` > :class:`QuantitativeInvisibilityF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a QuantitativeInvisibilityF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns the quantitative invisibility of the\n" -" :class:`freestyle.types.Interface0D` pointed by the\n" -" Interface0DIterator. This evaluation can be ambiguous (in the case of\n" -" a :class:`freestyle.types.TVertex` for example). This functor tries\n" -" to remove this ambiguity using the context offered by the 1D element\n" -" to which the Interface0D belongs to. However, there still can be\n" -" problematic cases, and the user willing to deal with this cases in a\n" -" specific way should implement its own getQIF0D functor.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: The quantitative invisibility of the pointed Interface0D.\n" -" :rtype: int\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DUnsigned` > :class:`QuantitativeInvisibilityF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a QuantitativeInvisibilityF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns the quantitative invisibility of the\n" + " :class:`freestyle.types.Interface0D` pointed by the\n" + " Interface0DIterator. This evaluation can be ambiguous (in the case of\n" + " a :class:`freestyle.types.TVertex` for example). This functor tries\n" + " to remove this ambiguity using the context offered by the 1D element\n" + " to which the Interface0D belongs to. However, there still can be\n" + " problematic cases, and the user willing to deal with this cases in a\n" + " specific way should implement its own getQIF0D functor.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: The quantitative invisibility of the pointed Interface0D.\n" + " :rtype: int\n"; -static int QuantitativeInvisibilityF0D___init__(BPy_QuantitativeInvisibilityF0D *self, PyObject *args, PyObject *kwds) +static int QuantitativeInvisibilityF0D___init__(BPy_QuantitativeInvisibilityF0D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_unsigned.uf0D_unsigned = new Functions0D::QuantitativeInvisibilityF0D(); - self->py_uf0D_unsigned.uf0D_unsigned->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_unsigned.uf0D_unsigned = new Functions0D::QuantitativeInvisibilityF0D(); + self->py_uf0D_unsigned.uf0D_unsigned->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_QuantitativeInvisibilityF0D type definition ------------------------------*/ PyTypeObject QuantitativeInvisibilityF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "QuantitativeInvisibilityF0D", /* tp_name */ - sizeof(BPy_QuantitativeInvisibilityF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - QuantitativeInvisibilityF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DUnsigned_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)QuantitativeInvisibilityF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "QuantitativeInvisibilityF0D", /* tp_name */ + sizeof(BPy_QuantitativeInvisibilityF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + QuantitativeInvisibilityF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DUnsigned_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)QuantitativeInvisibilityF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.h index cf2bfaac9b6..933deb706ee 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_unsigned_int/BPy_QuantitativeInvisibilityF0D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject QuantitativeInvisibilityF0D_Type; #define BPy_QuantitativeInvisibilityF0D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityF0D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityF0D_Type)) /*---------------------------Python BPy_QuantitativeInvisibilityF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DUnsigned py_uf0D_unsigned; + BPy_UnaryFunction0DUnsigned py_uf0D_unsigned; } BPy_QuantitativeInvisibilityF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.cpp index e0753337d1b..37f8f82978f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.cpp @@ -31,75 +31,75 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetOccludersF0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > :class:`freestyle.types.UnaryFunction0DVectorViewShape` > :class:`GetOccludersF0D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetOccludersF0D object.\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Returns a list of :class:`freestyle.types.ViewShape` objects occluding the\n" -" :class:`freestyle.types.Interface0D` pointed by the Interface0DIterator.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: A list of ViewShape objects occluding the pointed\n" -" Interface0D.\n" -" :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction0D` > " + ":class:`freestyle.types.UnaryFunction0DVectorViewShape` > :class:`GetOccludersF0D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetOccludersF0D object.\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Returns a list of :class:`freestyle.types.ViewShape` objects occluding the\n" + " :class:`freestyle.types.Interface0D` pointed by the Interface0DIterator.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: A list of ViewShape objects occluding the pointed\n" + " Interface0D.\n" + " :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; static int GetOccludersF0D___init__(BPy_GetOccludersF0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf0D_vectorviewshape.uf0D_vectorviewshape = new Functions0D::GetOccludersF0D(); - self->py_uf0D_vectorviewshape.uf0D_vectorviewshape->py_uf0D = (PyObject *)self; - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf0D_vectorviewshape.uf0D_vectorviewshape = new Functions0D::GetOccludersF0D(); + self->py_uf0D_vectorviewshape.uf0D_vectorviewshape->py_uf0D = (PyObject *)self; + return 0; } /*-----------------------BPy_GetOccludersF0D type definition ------------------------------*/ PyTypeObject GetOccludersF0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetOccludersF0D", /* tp_name */ - sizeof(BPy_GetOccludersF0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetOccludersF0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction0DVectorViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetOccludersF0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetOccludersF0D", /* tp_name */ + sizeof(BPy_GetOccludersF0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetOccludersF0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction0DVectorViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetOccludersF0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h index 0c74fcd5234..82889b64aba 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetOccludersF0D_Type; -#define BPy_GetOccludersF0D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludersF0D_Type)) +#define BPy_GetOccludersF0D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludersF0D_Type)) /*---------------------------Python BPy_GetOccludersF0D structure definition----------*/ typedef struct { - BPy_UnaryFunction0DVectorViewShape py_uf0D_vectorviewshape; + BPy_UnaryFunction0DVectorViewShape py_uf0D_vectorviewshape; } BPy_GetOccludersF0D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp index 5d6863d4e8e..84aa10098ee 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp @@ -49,229 +49,243 @@ extern "C" { int UnaryFunction1DDouble_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction1DDouble_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DDouble_Type); - PyModule_AddObject(module, "UnaryFunction1DDouble", (PyObject *)&UnaryFunction1DDouble_Type); - - if (PyType_Ready(&DensityF1D_Type) < 0) - return -1; - Py_INCREF(&DensityF1D_Type); - PyModule_AddObject(module, "DensityF1D", (PyObject *)&DensityF1D_Type); - - if (PyType_Ready(&Curvature2DAngleF1D_Type) < 0) - return -1; - Py_INCREF(&Curvature2DAngleF1D_Type); - PyModule_AddObject(module, "Curvature2DAngleF1D", (PyObject *)&Curvature2DAngleF1D_Type); - - if (PyType_Ready(&GetCompleteViewMapDensityF1D_Type) < 0) - return -1; - Py_INCREF(&GetCompleteViewMapDensityF1D_Type); - PyModule_AddObject(module, "GetCompleteViewMapDensityF1D", (PyObject *)&GetCompleteViewMapDensityF1D_Type); - - if (PyType_Ready(&GetDirectionalViewMapDensityF1D_Type) < 0) - return -1; - Py_INCREF(&GetDirectionalViewMapDensityF1D_Type); - PyModule_AddObject(module, "GetDirectionalViewMapDensityF1D", (PyObject *)&GetDirectionalViewMapDensityF1D_Type); - - if (PyType_Ready(&GetProjectedXF1D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedXF1D_Type); - PyModule_AddObject(module, "GetProjectedXF1D", (PyObject *)&GetProjectedXF1D_Type); - - if (PyType_Ready(&GetProjectedYF1D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedYF1D_Type); - PyModule_AddObject(module, "GetProjectedYF1D", (PyObject *)&GetProjectedYF1D_Type); - - if (PyType_Ready(&GetProjectedZF1D_Type) < 0) - return -1; - Py_INCREF(&GetProjectedZF1D_Type); - PyModule_AddObject(module, "GetProjectedZF1D", (PyObject *)&GetProjectedZF1D_Type); - - if (PyType_Ready(&GetSteerableViewMapDensityF1D_Type) < 0) - return -1; - Py_INCREF(&GetSteerableViewMapDensityF1D_Type); - PyModule_AddObject(module, "GetSteerableViewMapDensityF1D", (PyObject *)&GetSteerableViewMapDensityF1D_Type); - - if (PyType_Ready(&GetViewMapGradientNormF1D_Type) < 0) - return -1; - Py_INCREF(&GetViewMapGradientNormF1D_Type); - PyModule_AddObject(module, "GetViewMapGradientNormF1D", (PyObject *)&GetViewMapGradientNormF1D_Type); - - if (PyType_Ready(&GetXF1D_Type) < 0) - return -1; - Py_INCREF(&GetXF1D_Type); - PyModule_AddObject(module, "GetXF1D", (PyObject *)&GetXF1D_Type); - - if (PyType_Ready(&GetYF1D_Type) < 0) - return -1; - Py_INCREF(&GetYF1D_Type); - PyModule_AddObject(module, "GetYF1D", (PyObject *)&GetYF1D_Type); - - if (PyType_Ready(&GetZF1D_Type) < 0) - return -1; - Py_INCREF(&GetZF1D_Type); - PyModule_AddObject(module, "GetZF1D", (PyObject *)&GetZF1D_Type); - - if (PyType_Ready(&LocalAverageDepthF1D_Type) < 0) - return -1; - Py_INCREF(&LocalAverageDepthF1D_Type); - PyModule_AddObject(module, "LocalAverageDepthF1D", (PyObject *)&LocalAverageDepthF1D_Type); - - if (PyType_Ready(&ZDiscontinuityF1D_Type) < 0) - return -1; - Py_INCREF(&ZDiscontinuityF1D_Type); - PyModule_AddObject(module, "ZDiscontinuityF1D", (PyObject *)&ZDiscontinuityF1D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction1DDouble_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DDouble_Type); + PyModule_AddObject(module, "UnaryFunction1DDouble", (PyObject *)&UnaryFunction1DDouble_Type); + + if (PyType_Ready(&DensityF1D_Type) < 0) + return -1; + Py_INCREF(&DensityF1D_Type); + PyModule_AddObject(module, "DensityF1D", (PyObject *)&DensityF1D_Type); + + if (PyType_Ready(&Curvature2DAngleF1D_Type) < 0) + return -1; + Py_INCREF(&Curvature2DAngleF1D_Type); + PyModule_AddObject(module, "Curvature2DAngleF1D", (PyObject *)&Curvature2DAngleF1D_Type); + + if (PyType_Ready(&GetCompleteViewMapDensityF1D_Type) < 0) + return -1; + Py_INCREF(&GetCompleteViewMapDensityF1D_Type); + PyModule_AddObject( + module, "GetCompleteViewMapDensityF1D", (PyObject *)&GetCompleteViewMapDensityF1D_Type); + + if (PyType_Ready(&GetDirectionalViewMapDensityF1D_Type) < 0) + return -1; + Py_INCREF(&GetDirectionalViewMapDensityF1D_Type); + PyModule_AddObject(module, + "GetDirectionalViewMapDensityF1D", + (PyObject *)&GetDirectionalViewMapDensityF1D_Type); + + if (PyType_Ready(&GetProjectedXF1D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedXF1D_Type); + PyModule_AddObject(module, "GetProjectedXF1D", (PyObject *)&GetProjectedXF1D_Type); + + if (PyType_Ready(&GetProjectedYF1D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedYF1D_Type); + PyModule_AddObject(module, "GetProjectedYF1D", (PyObject *)&GetProjectedYF1D_Type); + + if (PyType_Ready(&GetProjectedZF1D_Type) < 0) + return -1; + Py_INCREF(&GetProjectedZF1D_Type); + PyModule_AddObject(module, "GetProjectedZF1D", (PyObject *)&GetProjectedZF1D_Type); + + if (PyType_Ready(&GetSteerableViewMapDensityF1D_Type) < 0) + return -1; + Py_INCREF(&GetSteerableViewMapDensityF1D_Type); + PyModule_AddObject( + module, "GetSteerableViewMapDensityF1D", (PyObject *)&GetSteerableViewMapDensityF1D_Type); + + if (PyType_Ready(&GetViewMapGradientNormF1D_Type) < 0) + return -1; + Py_INCREF(&GetViewMapGradientNormF1D_Type); + PyModule_AddObject( + module, "GetViewMapGradientNormF1D", (PyObject *)&GetViewMapGradientNormF1D_Type); + + if (PyType_Ready(&GetXF1D_Type) < 0) + return -1; + Py_INCREF(&GetXF1D_Type); + PyModule_AddObject(module, "GetXF1D", (PyObject *)&GetXF1D_Type); + + if (PyType_Ready(&GetYF1D_Type) < 0) + return -1; + Py_INCREF(&GetYF1D_Type); + PyModule_AddObject(module, "GetYF1D", (PyObject *)&GetYF1D_Type); + + if (PyType_Ready(&GetZF1D_Type) < 0) + return -1; + Py_INCREF(&GetZF1D_Type); + PyModule_AddObject(module, "GetZF1D", (PyObject *)&GetZF1D_Type); + + if (PyType_Ready(&LocalAverageDepthF1D_Type) < 0) + return -1; + Py_INCREF(&LocalAverageDepthF1D_Type); + PyModule_AddObject(module, "LocalAverageDepthF1D", (PyObject *)&LocalAverageDepthF1D_Type); + + if (PyType_Ready(&ZDiscontinuityF1D_Type) < 0) + return -1; + Py_INCREF(&ZDiscontinuityF1D_Type); + PyModule_AddObject(module, "ZDiscontinuityF1D", (PyObject *)&ZDiscontinuityF1D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DDouble___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a float value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DDouble___init__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a float value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DDouble___init__(BPy_UnaryFunction1DDouble *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_double = new UnaryFunction1D(); - else { - self->uf1D_double = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_double = new UnaryFunction1D(); + else { + self->uf1D_double = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_double->py_uf1D = (PyObject *)self; + self->uf1D_double->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DDouble___dealloc__(BPy_UnaryFunction1DDouble *self) { - if (self->uf1D_double) - delete self->uf1D_double; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_double) + delete self->uf1D_double; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DDouble___repr__(BPy_UnaryFunction1DDouble *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double); } -static PyObject *UnaryFunction1DDouble___call__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DDouble___call__(BPy_UnaryFunction1DDouble *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_double->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyFloat_FromDouble(self->uf1D_double->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyFloat_FromDouble(self->uf1D_double->result); } /*----------------------UnaryFunction1DDouble get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DDouble *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DDouble *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DDouble_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/ PyTypeObject UnaryFunction1DDouble_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DDouble", /* tp_name */ - sizeof(BPy_UnaryFunction1DDouble), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DDouble___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DDouble___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DDouble___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DDouble___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DDouble_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DDouble___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DDouble", /* tp_name */ + sizeof(BPy_UnaryFunction1DDouble), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DDouble___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DDouble___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DDouble___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DDouble___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DDouble_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DDouble___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.h index 0335356e207..cfd7f954b54 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.h @@ -31,18 +31,18 @@ extern "C" { extern PyTypeObject UnaryFunction1DDouble_Type; -#define BPy_UnaryFunction1DDouble_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DDouble_Type)) +#define BPy_UnaryFunction1DDouble_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DDouble_Type)) /*---------------------------Python BPy_UnaryFunction1DDouble structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_double; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_double; } BPy_UnaryFunction1DDouble; /*---------------------------Python BPy_UnaryFunction1DDouble visible prototypes-----------*/ int UnaryFunction1DDouble_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp index 41fcab32746..2bcda9718c3 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp @@ -36,165 +36,176 @@ extern "C" { int UnaryFunction1DEdgeNature_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction1DEdgeNature_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DEdgeNature_Type); - PyModule_AddObject(module, "UnaryFunction1DEdgeNature", (PyObject *)&UnaryFunction1DEdgeNature_Type); + if (PyType_Ready(&UnaryFunction1DEdgeNature_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DEdgeNature_Type); + PyModule_AddObject( + module, "UnaryFunction1DEdgeNature", (PyObject *)&UnaryFunction1DEdgeNature_Type); - if (PyType_Ready(&CurveNatureF1D_Type) < 0) - return -1; - Py_INCREF(&CurveNatureF1D_Type); - PyModule_AddObject(module, "CurveNatureF1D", (PyObject *)&CurveNatureF1D_Type); + if (PyType_Ready(&CurveNatureF1D_Type) < 0) + return -1; + Py_INCREF(&CurveNatureF1D_Type); + PyModule_AddObject(module, "CurveNatureF1D", (PyObject *)&CurveNatureF1D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DEdgeNature___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DEdgeNature`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a :class:`Nature` object.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DEdgeNature___init__(BPy_UnaryFunction1DEdgeNature *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DEdgeNature`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a :class:`Nature` object.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DEdgeNature___init__(BPy_UnaryFunction1DEdgeNature *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_edgenature = new UnaryFunction1D(); - else { - self->uf1D_edgenature = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_edgenature = new UnaryFunction1D(); + else { + self->uf1D_edgenature = new UnaryFunction1D( + IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_edgenature->py_uf1D = (PyObject *)self; + self->uf1D_edgenature->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DEdgeNature___dealloc__(BPy_UnaryFunction1DEdgeNature *self) { - if (self->uf1D_edgenature) - delete self->uf1D_edgenature; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_edgenature) + delete self->uf1D_edgenature; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DEdgeNature___repr__(BPy_UnaryFunction1DEdgeNature *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_edgenature); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_edgenature); } static PyObject *UnaryFunction1DEdgeNature___call__(BPy_UnaryFunction1DEdgeNature *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_edgenature)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_edgenature->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return BPy_Nature_from_Nature(self->uf1D_edgenature->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_edgenature)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_edgenature->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return BPy_Nature_from_Nature(self->uf1D_edgenature->result); } /*----------------------UnaryFunction1DEdgeNature get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DEdgeNature *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_edgenature->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_edgenature->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DEdgeNature *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DEdgeNature *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_edgenature->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_edgenature->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DEdgeNature_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DEdgeNature type definition ------------------------------*/ PyTypeObject UnaryFunction1DEdgeNature_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DEdgeNature", /* tp_name */ - sizeof(BPy_UnaryFunction1DEdgeNature), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DEdgeNature___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DEdgeNature___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DEdgeNature___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DEdgeNature___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DEdgeNature_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DEdgeNature___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DEdgeNature", /* tp_name */ + sizeof(BPy_UnaryFunction1DEdgeNature), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DEdgeNature___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DEdgeNature___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DEdgeNature___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DEdgeNature___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DEdgeNature_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DEdgeNature___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.h index fbe3759d48a..1a7a5a2d7ee 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.h @@ -34,18 +34,17 @@ extern "C" { extern PyTypeObject UnaryFunction1DEdgeNature_Type; #define BPy_UnaryFunction1DEdgeNature_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DEdgeNature_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DEdgeNature_Type)) /*---------------------------Python BPy_UnaryFunction1DEdgeNature structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_edgenature; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_edgenature; } BPy_UnaryFunction1DEdgeNature; /*---------------------------Python BPy_UnaryFunction1DEdgeNature visible prototypes-----------*/ int UnaryFunction1DEdgeNature_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp index 4e0ac9fac12..fcd670ea1e7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp @@ -34,159 +34,168 @@ extern "C" { int UnaryFunction1DFloat_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction1DFloat_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DFloat_Type); - PyModule_AddObject(module, "UnaryFunction1DFloat", (PyObject *)&UnaryFunction1DFloat_Type); + if (PyType_Ready(&UnaryFunction1DFloat_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DFloat_Type); + PyModule_AddObject(module, "UnaryFunction1DFloat", (PyObject *)&UnaryFunction1DFloat_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DFloat___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a float value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DFloat___init__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a float value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DFloat___init__(BPy_UnaryFunction1DFloat *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_float = new UnaryFunction1D(); - else { - self->uf1D_float = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_float = new UnaryFunction1D(); + else { + self->uf1D_float = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_float->py_uf1D = (PyObject *)self; + self->uf1D_float->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DFloat___dealloc__(BPy_UnaryFunction1DFloat *self) { - if (self->uf1D_float) - delete self->uf1D_float; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_float) + delete self->uf1D_float; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DFloat___repr__(BPy_UnaryFunction1DFloat *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float); } -static PyObject *UnaryFunction1DFloat___call__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DFloat___call__(BPy_UnaryFunction1DFloat *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_float->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyFloat_FromDouble(self->uf1D_float->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_float->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyFloat_FromDouble(self->uf1D_float->result); } /*----------------------UnaryFunction1DFloat get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DFloat *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_float->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_float->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DFloat *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DFloat *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_float->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_float->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DFloat_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DFloat type definition ------------------------------*/ PyTypeObject UnaryFunction1DFloat_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DFloat", /* tp_name */ - sizeof(BPy_UnaryFunction1DFloat), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DFloat___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DFloat___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DFloat___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DFloat___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DFloat_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DFloat___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DFloat", /* tp_name */ + sizeof(BPy_UnaryFunction1DFloat), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DFloat___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DFloat___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DFloat___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DFloat___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DFloat_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DFloat___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.h index 4b269783712..8a5a329b0bf 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.h @@ -31,18 +31,18 @@ extern "C" { extern PyTypeObject UnaryFunction1DFloat_Type; -#define BPy_UnaryFunction1DFloat_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DFloat_Type)) +#define BPy_UnaryFunction1DFloat_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DFloat_Type)) /*---------------------------Python BPy_UnaryFunction1DFloat structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_float; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_float; } BPy_UnaryFunction1DFloat; /*---------------------------Python BPy_UnaryFunction1DFloat visible prototypes-----------*/ int UnaryFunction1DFloat_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp index 8bb551de823..a28448314cd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp @@ -36,164 +36,176 @@ extern "C" { int UnaryFunction1DUnsigned_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction1DUnsigned_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DUnsigned_Type); - PyModule_AddObject(module, "UnaryFunction1DUnsigned", (PyObject *)&UnaryFunction1DUnsigned_Type); + if (PyType_Ready(&UnaryFunction1DUnsigned_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DUnsigned_Type); + PyModule_AddObject(module, "UnaryFunction1DUnsigned", (PyObject *)&UnaryFunction1DUnsigned_Type); - if (PyType_Ready(&QuantitativeInvisibilityF1D_Type) < 0) - return -1; - Py_INCREF(&QuantitativeInvisibilityF1D_Type); - PyModule_AddObject(module, "QuantitativeInvisibilityF1D", (PyObject *)&QuantitativeInvisibilityF1D_Type); + if (PyType_Ready(&QuantitativeInvisibilityF1D_Type) < 0) + return -1; + Py_INCREF(&QuantitativeInvisibilityF1D_Type); + PyModule_AddObject( + module, "QuantitativeInvisibilityF1D", (PyObject *)&QuantitativeInvisibilityF1D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DUnsigned___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DUnsigned`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return an int value.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DUnsigned___init__(BPy_UnaryFunction1DUnsigned *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DUnsigned`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return an int value.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DUnsigned___init__(BPy_UnaryFunction1DUnsigned *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_unsigned = new UnaryFunction1D(); - else { - self->uf1D_unsigned = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_unsigned = new UnaryFunction1D(); + else { + self->uf1D_unsigned = new UnaryFunction1D( + IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_unsigned->py_uf1D = (PyObject *)self; + self->uf1D_unsigned->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DUnsigned___dealloc__(BPy_UnaryFunction1DUnsigned *self) { - if (self->uf1D_unsigned) - delete self->uf1D_unsigned; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_unsigned) + delete self->uf1D_unsigned; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DUnsigned___repr__(BPy_UnaryFunction1DUnsigned *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_unsigned); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_unsigned); } -static PyObject *UnaryFunction1DUnsigned___call__(BPy_UnaryFunction1DUnsigned *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DUnsigned___call__(BPy_UnaryFunction1DUnsigned *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_unsigned)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_unsigned->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return PyLong_FromLong(self->uf1D_unsigned->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_unsigned)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_unsigned->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return PyLong_FromLong(self->uf1D_unsigned->result); } /*----------------------UnaryFunction1DUnsigned get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DUnsigned *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_unsigned->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_unsigned->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DUnsigned *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DUnsigned *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_unsigned->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_unsigned->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DUnsigned_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DUnsigned type definition ------------------------------*/ PyTypeObject UnaryFunction1DUnsigned_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DUnsigned", /* tp_name */ - sizeof(BPy_UnaryFunction1DUnsigned), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DUnsigned___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DUnsigned___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DUnsigned___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DUnsigned___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DUnsigned_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DUnsigned___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DUnsigned", /* tp_name */ + sizeof(BPy_UnaryFunction1DUnsigned), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DUnsigned___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DUnsigned___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DUnsigned___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DUnsigned___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DUnsigned_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DUnsigned___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.h index 28f2bd7270c..b18bf34b27e 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.h @@ -32,18 +32,17 @@ extern "C" { extern PyTypeObject UnaryFunction1DUnsigned_Type; #define BPy_UnaryFunction1DUnsigned_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DUnsigned_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DUnsigned_Type)) /*---------------------------Python BPy_UnaryFunction1DUnsigned structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_unsigned; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_unsigned; } BPy_UnaryFunction1DUnsigned; /*---------------------------Python BPy_UnaryFunction1DUnsigned visible prototypes-----------*/ int UnaryFunction1DUnsigned_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp index 525218374a7..d41f035af3f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp @@ -37,169 +37,178 @@ extern "C" { int UnaryFunction1DVec2f_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction1DVec2f_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DVec2f_Type); - PyModule_AddObject(module, "UnaryFunction1DVec2f", (PyObject *)&UnaryFunction1DVec2f_Type); + if (PyType_Ready(&UnaryFunction1DVec2f_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DVec2f_Type); + PyModule_AddObject(module, "UnaryFunction1DVec2f", (PyObject *)&UnaryFunction1DVec2f_Type); - if (PyType_Ready(&Normal2DF1D_Type) < 0) - return -1; - Py_INCREF(&Normal2DF1D_Type); - PyModule_AddObject(module, "Normal2DF1D", (PyObject *)&Normal2DF1D_Type); + if (PyType_Ready(&Normal2DF1D_Type) < 0) + return -1; + Py_INCREF(&Normal2DF1D_Type); + PyModule_AddObject(module, "Normal2DF1D", (PyObject *)&Normal2DF1D_Type); - if (PyType_Ready(&Orientation2DF1D_Type) < 0) - return -1; - Py_INCREF(&Orientation2DF1D_Type); - PyModule_AddObject(module, "Orientation2DF1D", (PyObject *)&Orientation2DF1D_Type); + if (PyType_Ready(&Orientation2DF1D_Type) < 0) + return -1; + Py_INCREF(&Orientation2DF1D_Type); + PyModule_AddObject(module, "Orientation2DF1D", (PyObject *)&Orientation2DF1D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DVec2f___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec2f`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a 2D vector.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DVec2f___init__(BPy_UnaryFunction1DVec2f *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec2f`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a 2D vector.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DVec2f___init__(BPy_UnaryFunction1DVec2f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_vec2f = new UnaryFunction1D(); - else { - self->uf1D_vec2f = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_vec2f = new UnaryFunction1D(); + else { + self->uf1D_vec2f = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_vec2f->py_uf1D = (PyObject *)self; + self->uf1D_vec2f->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DVec2f___dealloc__(BPy_UnaryFunction1DVec2f *self) { - if (self->uf1D_vec2f) - delete self->uf1D_vec2f; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_vec2f) + delete self->uf1D_vec2f; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DVec2f___repr__(BPy_UnaryFunction1DVec2f *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec2f); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec2f); } -static PyObject *UnaryFunction1DVec2f___call__(BPy_UnaryFunction1DVec2f *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DVec2f___call__(BPy_UnaryFunction1DVec2f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_vec2f)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_vec2f->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return Vector_from_Vec2f(self->uf1D_vec2f->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_vec2f)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_vec2f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return Vector_from_Vec2f(self->uf1D_vec2f->result); } /*----------------------UnaryFunction1DVec2f get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DVec2f *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec2f->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec2f->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DVec2f *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DVec2f *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_vec2f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_vec2f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DVec2f_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DVec2f type definition ------------------------------*/ PyTypeObject UnaryFunction1DVec2f_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DVec2f", /* tp_name */ - sizeof(BPy_UnaryFunction1DVec2f), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DVec2f___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DVec2f___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DVec2f___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DVec2f___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DVec2f_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DVec2f___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DVec2f", /* tp_name */ + sizeof(BPy_UnaryFunction1DVec2f), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DVec2f___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DVec2f___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DVec2f___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DVec2f___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DVec2f_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DVec2f___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.h index 56a10d8c1eb..f4cad92334f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.h @@ -34,18 +34,18 @@ extern "C" { extern PyTypeObject UnaryFunction1DVec2f_Type; -#define BPy_UnaryFunction1DVec2f_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVec2f_Type)) +#define BPy_UnaryFunction1DVec2f_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVec2f_Type)) /*---------------------------Python BPy_UnaryFunction1DVec2f structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_vec2f; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_vec2f; } BPy_UnaryFunction1DVec2f; /*---------------------------Python BPy_UnaryFunction1DVec2f visible prototypes-----------*/ int UnaryFunction1DVec2f_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp index ace1fb7f153..61b393cd732 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp @@ -36,164 +36,173 @@ extern "C" { int UnaryFunction1DVec3f_Init(PyObject *module) { - if (module == NULL) - return -1; + if (module == NULL) + return -1; - if (PyType_Ready(&UnaryFunction1DVec3f_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DVec3f_Type); - PyModule_AddObject(module, "UnaryFunction1DVec3f", (PyObject *)&UnaryFunction1DVec3f_Type); + if (PyType_Ready(&UnaryFunction1DVec3f_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DVec3f_Type); + PyModule_AddObject(module, "UnaryFunction1DVec3f", (PyObject *)&UnaryFunction1DVec3f_Type); - if (PyType_Ready(&Orientation3DF1D_Type) < 0) - return -1; - Py_INCREF(&Orientation3DF1D_Type); - PyModule_AddObject(module, "Orientation3DF1D", (PyObject *)&Orientation3DF1D_Type); + if (PyType_Ready(&Orientation3DF1D_Type) < 0) + return -1; + Py_INCREF(&Orientation3DF1D_Type); + PyModule_AddObject(module, "Orientation3DF1D", (PyObject *)&Orientation3DF1D_Type); - return 0; + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DVec3f___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec3f`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a 3D vector.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec3f`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a 3D vector.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_vec3f = new UnaryFunction1D(); - else { - self->uf1D_vec3f = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_vec3f = new UnaryFunction1D(); + else { + self->uf1D_vec3f = new UnaryFunction1D(IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_vec3f->py_uf1D = (PyObject *)self; + self->uf1D_vec3f->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DVec3f___dealloc__(BPy_UnaryFunction1DVec3f *self) { - if (self->uf1D_vec3f) - delete self->uf1D_vec3f; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_vec3f) + delete self->uf1D_vec3f; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DVec3f___repr__(BPy_UnaryFunction1DVec3f *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec3f); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec3f); } -static PyObject *UnaryFunction1DVec3f___call__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DVec3f___call__(BPy_UnaryFunction1DVec3f *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_vec3f->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - return Vector_from_Vec3f(self->uf1D_vec3f->result); + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_vec3f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + return Vector_from_Vec3f(self->uf1D_vec3f->result); } /*----------------------UnaryFunction1DVec3f get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DVec3f *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec3f->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec3f->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DVec3f *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DVec3f *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_vec3f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_vec3f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DVec3f_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DVec3f type definition ------------------------------*/ PyTypeObject UnaryFunction1DVec3f_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DVec3f", /* tp_name */ - sizeof(BPy_UnaryFunction1DVec3f), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DVec3f___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DVec3f___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DVec3f___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DVec3f___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DVec3f_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DVec3f___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DVec3f", /* tp_name */ + sizeof(BPy_UnaryFunction1DVec3f), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DVec3f___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DVec3f___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DVec3f___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DVec3f___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DVec3f_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DVec3f___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.h index 57257bec850..253a8d550e3 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.h @@ -34,18 +34,18 @@ extern "C" { extern PyTypeObject UnaryFunction1DVec3f_Type; -#define BPy_UnaryFunction1DVec3f_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVec3f_Type)) +#define BPy_UnaryFunction1DVec3f_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVec3f_Type)) /*---------------------------Python BPy_UnaryFunction1DVec3f structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D *uf1D_vec3f; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D *uf1D_vec3f; } BPy_UnaryFunction1DVec3f; /*---------------------------Python BPy_UnaryFunction1DVec3f visible prototypes-----------*/ int UnaryFunction1DVec3f_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp index 1be830c2e89..f7a80a270b6 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp @@ -38,186 +38,198 @@ extern "C" { int UnaryFunction1DVectorViewShape_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction1DVectorViewShape_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DVectorViewShape_Type); - PyModule_AddObject(module, "UnaryFunction1DVectorViewShape", (PyObject *)&UnaryFunction1DVectorViewShape_Type); - - if (PyType_Ready(&GetOccludeeF1D_Type) < 0) - return -1; - Py_INCREF(&GetOccludeeF1D_Type); - PyModule_AddObject(module, "GetOccludeeF1D", (PyObject *)&GetOccludeeF1D_Type); - - if (PyType_Ready(&GetOccludersF1D_Type) < 0) - return -1; - Py_INCREF(&GetOccludersF1D_Type); - PyModule_AddObject(module, "GetOccludersF1D", (PyObject *)&GetOccludersF1D_Type); - - if (PyType_Ready(&GetShapeF1D_Type) < 0) - return -1; - Py_INCREF(&GetShapeF1D_Type); - PyModule_AddObject(module, "GetShapeF1D", (PyObject *)&GetShapeF1D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction1DVectorViewShape_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DVectorViewShape_Type); + PyModule_AddObject( + module, "UnaryFunction1DVectorViewShape", (PyObject *)&UnaryFunction1DVectorViewShape_Type); + + if (PyType_Ready(&GetOccludeeF1D_Type) < 0) + return -1; + Py_INCREF(&GetOccludeeF1D_Type); + PyModule_AddObject(module, "GetOccludeeF1D", (PyObject *)&GetOccludeeF1D_Type); + + if (PyType_Ready(&GetOccludersF1D_Type) < 0) + return -1; + Py_INCREF(&GetOccludersF1D_Type); + PyModule_AddObject(module, "GetOccludersF1D", (PyObject *)&GetOccludersF1D_Type); + + if (PyType_Ready(&GetShapeF1D_Type) < 0) + return -1; + Py_INCREF(&GetShapeF1D_Type); + PyModule_AddObject(module, "GetShapeF1D", (PyObject *)&GetShapeF1D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DVectorViewShape___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVectorViewShape`\n" -"\n" -"Base class for unary functions (functors) that work on\n" -":class:`Interface1D` and return a list of :class:`ViewShape`\n" -"objects.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVectorViewShape`\n" + "\n" + "Base class for unary functions (functors) that work on\n" + ":class:`Interface1D` and return a list of :class:`ViewShape`\n" + "objects.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; static int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) { - self->uf1D_vectorviewshape = new UnaryFunction1D< std::vector >(); - } - else { - self->uf1D_vectorviewshape = new UnaryFunction1D< std::vector >(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) { + self->uf1D_vectorviewshape = new UnaryFunction1D>(); + } + else { + self->uf1D_vectorviewshape = new UnaryFunction1D>( + IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self; + self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape *self) { - if (self->uf1D_vectorviewshape) - delete self->uf1D_vectorviewshape; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_vectorviewshape) + delete self->uf1D_vectorviewshape; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vectorviewshape); + return PyUnicode_FromFormat( + "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vectorviewshape); } static PyObject *UnaryFunction1DVectorViewShape___call__(BPy_UnaryFunction1DVectorViewShape *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D< std::vector >)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_vectorviewshape->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - - const unsigned int list_len = self->uf1D_vectorviewshape->result.size(); - PyObject *list = PyList_New(list_len); - for (unsigned int i = 0; i < list_len; i++) { - ViewShape *v = self->uf1D_vectorviewshape->result[i]; - PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); - } - - return list; + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D>)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_vectorviewshape->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + + const unsigned int list_len = self->uf1D_vectorviewshape->result.size(); + PyObject *list = PyList_New(list_len); + for (unsigned int i = 0; i < list_len; i++) { + ViewShape *v = self->uf1D_vectorviewshape->result[i]; + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); + } + + return list; } /*----------------------UnaryFunction1DVectorViewShape get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); -static PyObject *integration_type_get(BPy_UnaryFunction1DVectorViewShape *self, void *UNUSED(closure)) +static PyObject *integration_type_get(BPy_UnaryFunction1DVectorViewShape *self, + void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_vectorviewshape->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType( + self->uf1D_vectorviewshape->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DVectorViewShape *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DVectorViewShape *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_vectorviewshape->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_vectorviewshape->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DVectorViewShape_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DVectorViewShape type definition ------------------------------*/ PyTypeObject UnaryFunction1DVectorViewShape_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DVectorViewShape", /* tp_name */ - sizeof(BPy_UnaryFunction1DVectorViewShape), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DVectorViewShape___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DVectorViewShape___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DVectorViewShape___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DVectorViewShape___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DVectorViewShape_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DVectorViewShape___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DVectorViewShape", /* tp_name */ + sizeof(BPy_UnaryFunction1DVectorViewShape), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DVectorViewShape___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DVectorViewShape___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DVectorViewShape___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DVectorViewShape___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DVectorViewShape_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DVectorViewShape___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.h index 575d0a272c8..92889ddbfd9 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.h @@ -35,18 +35,17 @@ extern "C" { extern PyTypeObject UnaryFunction1DVectorViewShape_Type; #define BPy_UnaryFunction1DVectorViewShape_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVectorViewShape_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVectorViewShape_Type)) /*---------------------------Python BPy_UnaryFunction1DVectorViewShape structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D< std::vector > *uf1D_vectorviewshape; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D> *uf1D_vectorviewshape; } BPy_UnaryFunction1DVectorViewShape; /*---------------------------Python BPy_UnaryFunction1DVectorViewShape visible prototypes-----------*/ int UnaryFunction1DVectorViewShape_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp index 01636d76084..c9009dc6889 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp @@ -28,7 +28,6 @@ #include "UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.h" #include "UnaryFunction1D_void/BPy_TimeStampF1D.h" - #ifdef __cplusplus extern "C" { #endif @@ -39,174 +38,184 @@ extern "C" { int UnaryFunction1DVoid_Init(PyObject *module) { - if (module == NULL) - return -1; - - if (PyType_Ready(&UnaryFunction1DVoid_Type) < 0) - return -1; - Py_INCREF(&UnaryFunction1DVoid_Type); - PyModule_AddObject(module, "UnaryFunction1DVoid", (PyObject *)&UnaryFunction1DVoid_Type); - - if (PyType_Ready(&ChainingTimeStampF1D_Type) < 0) - return -1; - Py_INCREF(&ChainingTimeStampF1D_Type); - PyModule_AddObject(module, "ChainingTimeStampF1D", (PyObject *)&ChainingTimeStampF1D_Type); - - if (PyType_Ready(&IncrementChainingTimeStampF1D_Type) < 0) - return -1; - Py_INCREF(&IncrementChainingTimeStampF1D_Type); - PyModule_AddObject(module, "IncrementChainingTimeStampF1D", (PyObject *)&IncrementChainingTimeStampF1D_Type); - - if (PyType_Ready(&TimeStampF1D_Type) < 0) - return -1; - Py_INCREF(&TimeStampF1D_Type); - PyModule_AddObject(module, "TimeStampF1D", (PyObject *)&TimeStampF1D_Type); - - return 0; + if (module == NULL) + return -1; + + if (PyType_Ready(&UnaryFunction1DVoid_Type) < 0) + return -1; + Py_INCREF(&UnaryFunction1DVoid_Type); + PyModule_AddObject(module, "UnaryFunction1DVoid", (PyObject *)&UnaryFunction1DVoid_Type); + + if (PyType_Ready(&ChainingTimeStampF1D_Type) < 0) + return -1; + Py_INCREF(&ChainingTimeStampF1D_Type); + PyModule_AddObject(module, "ChainingTimeStampF1D", (PyObject *)&ChainingTimeStampF1D_Type); + + if (PyType_Ready(&IncrementChainingTimeStampF1D_Type) < 0) + return -1; + Py_INCREF(&IncrementChainingTimeStampF1D_Type); + PyModule_AddObject( + module, "IncrementChainingTimeStampF1D", (PyObject *)&IncrementChainingTimeStampF1D_Type); + + if (PyType_Ready(&TimeStampF1D_Type) < 0) + return -1; + Py_INCREF(&TimeStampF1D_Type); + PyModule_AddObject(module, "TimeStampF1D", (PyObject *)&TimeStampF1D_Type); + + return 0; } //------------------------INSTANCE METHODS ---------------------------------- static char UnaryFunction1DVoid___doc__[] = -"Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n" -"\n" -"Base class for unary functions (functors) working on\n" -":class:`Interface1D`.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(integration_type)\n" -"\n" -" Builds a unary 1D function using the integration method given as\n" -" argument.\n" -"\n" -" :arg integration_type: An integration method.\n" -" :type integration_type: :class:`IntegrationType`\n"; - -static int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n" + "\n" + "Base class for unary functions (functors) working on\n" + ":class:`Interface1D`.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(integration_type)\n" + "\n" + " Builds a unary 1D function using the integration method given as\n" + " argument.\n" + "\n" + " :arg integration_type: An integration method.\n" + " :type integration_type: :class:`IntegrationType`\n"; + +static int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; - if (!obj) - self->uf1D_void = new UnaryFunction1D_void(); - else { - self->uf1D_void = new UnaryFunction1D_void(IntegrationType_from_BPy_IntegrationType(obj)); - } + if (!obj) + self->uf1D_void = new UnaryFunction1D_void(); + else { + self->uf1D_void = new UnaryFunction1D_void(IntegrationType_from_BPy_IntegrationType(obj)); + } - self->uf1D_void->py_uf1D = (PyObject *)self; + self->uf1D_void->py_uf1D = (PyObject *)self; - return 0; + return 0; } static void UnaryFunction1DVoid___dealloc__(BPy_UnaryFunction1DVoid *self) { - if (self->uf1D_void) - delete self->uf1D_void; - UnaryFunction1D_Type.tp_dealloc((PyObject *)self); + if (self->uf1D_void) + delete self->uf1D_void; + UnaryFunction1D_Type.tp_dealloc((PyObject *)self); } static PyObject *UnaryFunction1DVoid___repr__(BPy_UnaryFunction1DVoid *self) { - return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void); + return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void); } -static PyObject *UnaryFunction1DVoid___call__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds) +static PyObject *UnaryFunction1DVoid___call__(BPy_UnaryFunction1DVoid *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"inter", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) - return NULL; - - if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) { - PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); - return NULL; - } - if (self->uf1D_void->operator()(*(((BPy_Interface1D *) obj)->if1D)) < 0) { - if (!PyErr_Occurred()) { - string class_name(Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); - } - return NULL; - } - Py_RETURN_NONE; + static const char *kwlist[] = {"inter", NULL}; + PyObject *obj = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) + return NULL; + + if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) { + PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden"); + return NULL; + } + if (self->uf1D_void->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) { + if (!PyErr_Occurred()) { + string class_name(Py_TYPE(self)->tp_name); + PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); + } + return NULL; + } + Py_RETURN_NONE; } /*----------------------UnaryFunction1DVoid get/setters ----------------------------*/ PyDoc_STRVAR(integration_type_doc, -"The integration method.\n" -"\n" -":type: :class:`IntegrationType`"); + "The integration method.\n" + "\n" + ":type: :class:`IntegrationType`"); static PyObject *integration_type_get(BPy_UnaryFunction1DVoid *self, void *UNUSED(closure)) { - return BPy_IntegrationType_from_IntegrationType(self->uf1D_void->getIntegrationType()); + return BPy_IntegrationType_from_IntegrationType(self->uf1D_void->getIntegrationType()); } -static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void *UNUSED(closure)) +static int integration_type_set(BPy_UnaryFunction1DVoid *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_IntegrationType_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); - return -1; - } - self->uf1D_void->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); - return 0; + if (!BPy_IntegrationType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType"); + return -1; + } + self->uf1D_void->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value)); + return 0; } static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[] = { - {(char *)"integration_type", (getter)integration_type_get, (setter)integration_type_set, - (char *)integration_type_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"integration_type", + (getter)integration_type_get, + (setter)integration_type_set, + (char *)integration_type_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_UnaryFunction1DVoid type definition ------------------------------*/ PyTypeObject UnaryFunction1DVoid_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "UnaryFunction1DVoid", /* tp_name */ - sizeof(BPy_UnaryFunction1DVoid), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)UnaryFunction1DVoid___dealloc__, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)UnaryFunction1DVoid___repr__, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - (ternaryfunc)UnaryFunction1DVoid___call__, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - UnaryFunction1DVoid___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_UnaryFunction1DVoid_getseters, /* tp_getset */ - &UnaryFunction1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)UnaryFunction1DVoid___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction1DVoid", /* tp_name */ + sizeof(BPy_UnaryFunction1DVoid), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)UnaryFunction1DVoid___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + (reprfunc)UnaryFunction1DVoid___repr__, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + (ternaryfunc)UnaryFunction1DVoid___call__, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + UnaryFunction1DVoid___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_UnaryFunction1DVoid_getseters, /* tp_getset */ + &UnaryFunction1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)UnaryFunction1DVoid___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.h b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.h index cbc74bda99b..03d949f879d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.h @@ -31,18 +31,18 @@ extern "C" { extern PyTypeObject UnaryFunction1DVoid_Type; -#define BPy_UnaryFunction1DVoid_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVoid_Type)) +#define BPy_UnaryFunction1DVoid_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&UnaryFunction1DVoid_Type)) /*---------------------------Python BPy_UnaryFunction1DVoid structure definition----------*/ typedef struct { - BPy_UnaryFunction1D py_uf1D; - UnaryFunction1D_void *uf1D_void; + BPy_UnaryFunction1D py_uf1D; + UnaryFunction1D_void *uf1D_void; } BPy_UnaryFunction1DVoid; /*---------------------------Python BPy_UnaryFunction1DVoid visible prototypes-----------*/ int UnaryFunction1DVoid_Init(PyObject *module); - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.cpp index 77c8d48305d..248f1cc0ca1 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.cpp @@ -33,84 +33,85 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char CurveNatureF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DEdgeNature` > :class:`CurveNatureF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a CurveNatureF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the nature of the Interface1D (silhouette, ridge, crease, and\n" -" so on). Except if the Interface1D is a\n" -" :class:`freestyle.types.ViewEdge`, this result might be ambiguous.\n" -" Indeed, the Interface1D might result from the gathering of several 1D\n" -" elements, each one being of a different nature. An integration\n" -" method, such as the MEAN, might give, in this case, irrelevant\n" -" results.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The nature of the Interface1D.\n" -" :rtype: :class:`freestyle.types.Nature`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DEdgeNature` > :class:`CurveNatureF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a CurveNatureF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the nature of the Interface1D (silhouette, ridge, crease, and\n" + " so on). Except if the Interface1D is a\n" + " :class:`freestyle.types.ViewEdge`, this result might be ambiguous.\n" + " Indeed, the Interface1D might result from the gathering of several 1D\n" + " elements, each one being of a different nature. An integration\n" + " method, such as the MEAN, might give, in this case, irrelevant\n" + " results.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The nature of the Interface1D.\n" + " :rtype: :class:`freestyle.types.Nature`\n"; static int CurveNatureF1D___init__(BPy_CurveNatureF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_edgenature.uf1D_edgenature = new Functions1D::CurveNatureF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_edgenature.uf1D_edgenature = new Functions1D::CurveNatureF1D(t); + return 0; } /*-----------------------BPy_CurveNatureF1D type definition ------------------------------*/ PyTypeObject CurveNatureF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CurveNatureF1D", /* tp_name */ - sizeof(BPy_CurveNatureF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurveNatureF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DEdgeNature_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CurveNatureF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CurveNatureF1D", /* tp_name */ + sizeof(BPy_CurveNatureF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurveNatureF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DEdgeNature_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurveNatureF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.h index 211f7148fef..15c381eb279 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Nature_EdgeNature/BPy_CurveNatureF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject CurveNatureF1D_Type; -#define BPy_CurveNatureF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurveNatureF1D_Type)) +#define BPy_CurveNatureF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurveNatureF1D_Type)) /*---------------------------Python BPy_CurveNatureF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DEdgeNature py_uf1D_edgenature; + BPy_UnaryFunction1DEdgeNature py_uf1D_edgenature; } BPy_CurveNatureF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.cpp index e77a05c1373..530f76ee706 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Normal2DF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVec2f` > :class:`Normal2DF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a Normal2DF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the 2D normal for the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The 2D normal for the Interface1D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVec2f` > :class:`Normal2DF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a Normal2DF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the 2D normal for the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The 2D normal for the Interface1D.\n" + " :rtype: :class:`mathutils.Vector`\n"; static int Normal2DF1D___init__(BPy_Normal2DF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_vec2f.uf1D_vec2f = new Functions1D::Normal2DF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_vec2f.uf1D_vec2f = new Functions1D::Normal2DF1D(t); + return 0; } /*-----------------------BPy_Normal2DF1D type definition ------------------------------*/ PyTypeObject Normal2DF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Normal2DF1D", /* tp_name */ - sizeof(BPy_Normal2DF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Normal2DF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVec2f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Normal2DF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Normal2DF1D", /* tp_name */ + sizeof(BPy_Normal2DF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Normal2DF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVec2f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Normal2DF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.h index 00bb526e92d..343c4379b4a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Normal2DF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Normal2DF1D_Type; -#define BPy_Normal2DF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Normal2DF1D_Type)) +#define BPy_Normal2DF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Normal2DF1D_Type)) /*---------------------------Python BPy_Normal2DF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVec2f py_uf1D_vec2f; + BPy_UnaryFunction1DVec2f py_uf1D_vec2f; } BPy_Normal2DF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.cpp index a216b19dacc..6449ab95611 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Orientation2DF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVec2f` > :class:`Orientation2DF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds an Orientation2DF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the 2D orientation of the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The 2D orientation of the Interface1D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVec2f` > :class:`Orientation2DF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds an Orientation2DF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the 2D orientation of the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The 2D orientation of the Interface1D.\n" + " :rtype: :class:`mathutils.Vector`\n"; static int Orientation2DF1D___init__(BPy_Orientation2DF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_vec2f.uf1D_vec2f = new Functions1D::Orientation2DF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_vec2f.uf1D_vec2f = new Functions1D::Orientation2DF1D(t); + return 0; } /*-----------------------BPy_Orientation2DF1D type definition ------------------------------*/ PyTypeObject Orientation2DF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Orientation2DF1D", /* tp_name */ - sizeof(BPy_Orientation2DF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Orientation2DF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVec2f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Orientation2DF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Orientation2DF1D", /* tp_name */ + sizeof(BPy_Orientation2DF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Orientation2DF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVec2f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Orientation2DF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.h index fb0c00c0277..5b453cbe714 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec2f/BPy_Orientation2DF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Orientation2DF1D_Type; -#define BPy_Orientation2DF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Orientation2DF1D_Type)) +#define BPy_Orientation2DF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Orientation2DF1D_Type)) /*---------------------------Python BPy_Orientation2DF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVec2f py_uf1D_vec2f; + BPy_UnaryFunction1DVec2f py_uf1D_vec2f; } BPy_Orientation2DF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.cpp index 80f1bac5d41..adfe7b0961b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Orientation3DF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVec3f` > :class:`Orientation3DF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds an Orientation3DF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the 3D orientation of the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The 3D orientation of the Interface1D.\n" -" :rtype: :class:`mathutils.Vector`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVec3f` > :class:`Orientation3DF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds an Orientation3DF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the 3D orientation of the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The 3D orientation of the Interface1D.\n" + " :rtype: :class:`mathutils.Vector`\n"; static int Orientation3DF1D___init__(BPy_Orientation3DF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_vec3f.uf1D_vec3f = new Functions1D::Orientation3DF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_vec3f.uf1D_vec3f = new Functions1D::Orientation3DF1D(t); + return 0; } /*-----------------------BPy_Orientation3DF1D type definition ------------------------------*/ PyTypeObject Orientation3DF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Orientation3DF1D", /* tp_name */ - sizeof(BPy_Orientation3DF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Orientation3DF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVec3f_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Orientation3DF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Orientation3DF1D", /* tp_name */ + sizeof(BPy_Orientation3DF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Orientation3DF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVec3f_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Orientation3DF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h index 592337052f7..26c6cd845db 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Orientation3DF1D_Type; -#define BPy_Orientation3DF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Orientation3DF1D_Type)) +#define BPy_Orientation3DF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Orientation3DF1D_Type)) /*---------------------------Python BPy_Orientation3DF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVec3f py_uf1D_vec3f; + BPy_UnaryFunction1DVec3f py_uf1D_vec3f; } BPy_Orientation3DF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.cpp index f780e15a578..d1e893a1550 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.cpp @@ -33,78 +33,80 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char Curvature2DAngleF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`Curvature2DAngleF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a Curvature2DAngleF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the 2D curvature as an angle for an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The 2D curvature as an angle.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`Curvature2DAngleF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a Curvature2DAngleF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the 2D curvature as an angle for an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The 2D curvature as an angle.\n" + " :rtype: float\n"; -static int Curvature2DAngleF1D___init__(BPy_Curvature2DAngleF1D *self, PyObject *args, PyObject *kwds) +static int Curvature2DAngleF1D___init__(BPy_Curvature2DAngleF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::Curvature2DAngleF1D(t); - return 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::Curvature2DAngleF1D(t); + return 0; } /*-----------------------BPy_Curvature2DAngleF1D type definition ------------------------------*/ PyTypeObject Curvature2DAngleF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Curvature2DAngleF1D", /* tp_name */ - sizeof(BPy_Curvature2DAngleF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Curvature2DAngleF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Curvature2DAngleF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Curvature2DAngleF1D", /* tp_name */ + sizeof(BPy_Curvature2DAngleF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Curvature2DAngleF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Curvature2DAngleF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.h index a5f81f6d99f..7a3a3fcff4b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_Curvature2DAngleF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject Curvature2DAngleF1D_Type; -#define BPy_Curvature2DAngleF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Curvature2DAngleF1D_Type)) +#define BPy_Curvature2DAngleF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Curvature2DAngleF1D_Type)) /*---------------------------Python BPy_Curvature2DAngleF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_Curvature2DAngleF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.cpp index 9059516e8fc..6218eed5b70 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.cpp @@ -33,92 +33,93 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char DensityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`DensityF1D`\n" -"\n" -".. method:: __init__(sigma=2.0, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a DensityF1D object.\n" -"\n" -" :arg sigma: The sigma used in DensityF0D and determining the window size\n" -" used in each density query.\n" -" :type sigma: float\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain: the\n" -" corresponding 0D function is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the density evaluated for an Interface1D. The density is\n" -" evaluated for a set of points along the Interface1D (using the\n" -" :class:`freestyle.functions.DensityF0D` functor) with a user-defined\n" -" sampling and then integrated into a single value using a user-defined\n" -" integration method.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The density evaluated for an Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`DensityF1D`\n" + "\n" + ".. method:: __init__(sigma=2.0, integration_type=IntegrationType.MEAN, sampling=2.0)\n" + "\n" + " Builds a DensityF1D object.\n" + "\n" + " :arg sigma: The sigma used in DensityF0D and determining the window size\n" + " used in each density query.\n" + " :type sigma: float\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain: the\n" + " corresponding 0D function is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the density evaluated for an Interface1D. The density is\n" + " evaluated for a set of points along the Interface1D (using the\n" + " :class:`freestyle.functions.DensityF0D` functor) with a user-defined\n" + " sampling and then integrated into a single value using a user-defined\n" + " integration method.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The density evaluated for an Interface1D.\n" + " :rtype: float\n"; static int DensityF1D___init__(BPy_DensityF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"sigma", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - double d = 2.0; - float f = 2.0; + static const char *kwlist[] = {"sigma", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + double d = 2.0; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|dO!f", (char **)kwlist, &d, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::DensityF1D(d, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|dO!f", (char **)kwlist, &d, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::DensityF1D(d, t, f); + return 0; } /*-----------------------BPy_DensityF1D type definition ------------------------------*/ PyTypeObject DensityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "DensityF1D", /* tp_name */ - sizeof(BPy_DensityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - DensityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)DensityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "DensityF1D", /* tp_name */ + sizeof(BPy_DensityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + DensityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)DensityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.h index 6483a3fb87c..71daa14069a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_DensityF1D.h @@ -35,10 +35,9 @@ extern PyTypeObject DensityF1D_Type; /*---------------------------Python BPy_DensityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_DensityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.cpp index 62039c8df87..419ea1f54a9 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.cpp @@ -33,94 +33,97 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetCompleteViewMapDensityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetCompleteViewMapDensityF1D`\n" -"\n" -".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a GetCompleteViewMapDensityF1D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain: the\n" -" corresponding 0D function is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the density evaluated for an Interface1D in the complete\n" -" viewmap image. The density is evaluated for a set of points along the\n" -" Interface1D (using the\n" -" :class:`freestyle.functions.ReadCompleteViewMapPixelF0D` functor) and\n" -" then integrated into a single value using a user-defined integration\n" -" method.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The density evaluated for the Interface1D in the complete\n" -" viewmap image.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetCompleteViewMapDensityF1D`\n" + "\n" + ".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" + "\n" + " Builds a GetCompleteViewMapDensityF1D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain: the\n" + " corresponding 0D function is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the density evaluated for an Interface1D in the complete\n" + " viewmap image. The density is evaluated for a set of points along the\n" + " Interface1D (using the\n" + " :class:`freestyle.functions.ReadCompleteViewMapPixelF0D` functor) and\n" + " then integrated into a single value using a user-defined integration\n" + " method.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The density evaluated for the Interface1D in the complete\n" + " viewmap image.\n" + " :rtype: float\n"; -static int GetCompleteViewMapDensityF1D___init__(BPy_GetCompleteViewMapDensityF1D *self, PyObject *args, PyObject *kwds) +static int GetCompleteViewMapDensityF1D___init__(BPy_GetCompleteViewMapDensityF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - int i; - float f = 2.0; + static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + int i; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetCompleteViewMapDensityF1D(i, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetCompleteViewMapDensityF1D(i, t, f); + return 0; } /*-----------------------BPy_GetCompleteViewMapDensityF1D type definition ------------------------------*/ PyTypeObject GetCompleteViewMapDensityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetCompleteViewMapDensityF1D", /* tp_name */ - sizeof(BPy_GetCompleteViewMapDensityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetCompleteViewMapDensityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetCompleteViewMapDensityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetCompleteViewMapDensityF1D", /* tp_name */ + sizeof(BPy_GetCompleteViewMapDensityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetCompleteViewMapDensityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetCompleteViewMapDensityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.h index 5b05aed0d06..c0a78e89551 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetCompleteViewMapDensityF1D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject GetCompleteViewMapDensityF1D_Type; #define BPy_GetCompleteViewMapDensityF1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetCompleteViewMapDensityF1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetCompleteViewMapDensityF1D_Type)) /*---------------------------Python BPy_GetCompleteViewMapDensityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetCompleteViewMapDensityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.cpp index 4fd2b3c9d3f..58290f6b45f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.cpp @@ -33,100 +33,104 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetDirectionalViewMapDensityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` " -"> :class:`GetDirectionalViewMapDensityF1D`\n" -"\n" -".. method:: __init__(orientation, level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a GetDirectionalViewMapDensityF1D object.\n" -"\n" -" :arg orientation: The number of the directional map we must work\n" -" with.\n" -" :type orientation: int\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain: the\n" -" corresponding 0D function is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the density evaluated for an Interface1D in of the steerable\n" -" viewmaps image. The direction telling which Directional map to choose\n" -" is explicitly specified by the user. The density is evaluated for a\n" -" set of points along the Interface1D (using the\n" -" :class:`freestyle.functions.ReadSteerableViewMapPixelF0D` functor) and\n" -" then integrated into a single value using a user-defined integration\n" -" method.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: the density evaluated for an Interface1D in of the\n" -" steerable viewmaps image.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` " + "> :class:`GetDirectionalViewMapDensityF1D`\n" + "\n" + ".. method:: __init__(orientation, level, integration_type=IntegrationType.MEAN, " + "sampling=2.0)\n" + "\n" + " Builds a GetDirectionalViewMapDensityF1D object.\n" + "\n" + " :arg orientation: The number of the directional map we must work\n" + " with.\n" + " :type orientation: int\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain: the\n" + " corresponding 0D function is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the density evaluated for an Interface1D in of the steerable\n" + " viewmaps image. The direction telling which Directional map to choose\n" + " is explicitly specified by the user. The density is evaluated for a\n" + " set of points along the Interface1D (using the\n" + " :class:`freestyle.functions.ReadSteerableViewMapPixelF0D` functor) and\n" + " then integrated into a single value using a user-defined integration\n" + " method.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: the density evaluated for an Interface1D in of the\n" + " steerable viewmaps image.\n" + " :rtype: float\n"; static int GetDirectionalViewMapDensityF1D___init__(BPy_GetDirectionalViewMapDensityF1D *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"orientation", "level", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - unsigned int u1, u2; - float f = 2.0; + static const char *kwlist[] = {"orientation", "level", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + unsigned int u1, u2; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|O!f", (char **)kwlist, &u1, &u2, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetDirectionalViewMapDensityF1D(u1, u2, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "II|O!f", (char **)kwlist, &u1, &u2, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetDirectionalViewMapDensityF1D( + u1, u2, t, f); + return 0; } /*-----------------------BPy_GetDirectionalViewMapDensityF1D type definition ------------------------------*/ PyTypeObject GetDirectionalViewMapDensityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetDirectionalViewMapDensityF1D", /* tp_name */ - sizeof(BPy_GetDirectionalViewMapDensityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetDirectionalViewMapDensityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetDirectionalViewMapDensityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetDirectionalViewMapDensityF1D", /* tp_name */ + sizeof(BPy_GetDirectionalViewMapDensityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetDirectionalViewMapDensityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetDirectionalViewMapDensityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.h index cf91eed1a70..d78ffe84381 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetDirectionalViewMapDensityF1D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject GetDirectionalViewMapDensityF1D_Type; #define BPy_GetDirectionalViewMapDensityF1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetDirectionalViewMapDensityF1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetDirectionalViewMapDensityF1D_Type)) /*---------------------------Python BPy_GetDirectionalViewMapDensityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetDirectionalViewMapDensityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.cpp index 421a5eae8dd..bbd6dfd2701 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedXF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedXF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetProjectedXF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values. \n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the projected X 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The projected X 3D coordinate of an Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedXF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetProjectedXF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values. \n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the projected X 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The projected X 3D coordinate of an Interface1D.\n" + " :rtype: float\n"; static int GetProjectedXF1D___init__(BPy_GetProjectedXF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedXF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedXF1D(t); + return 0; } /*-----------------------BPy_GetProjectedXF1D type definition ------------------------------*/ PyTypeObject GetProjectedXF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedXF1D", /* tp_name */ - sizeof(BPy_GetProjectedXF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedXF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedXF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedXF1D", /* tp_name */ + sizeof(BPy_GetProjectedXF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedXF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedXF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.h index 4f66a3db389..febb3265f97 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedXF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedXF1D_Type; -#define BPy_GetProjectedXF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedXF1D_Type)) +#define BPy_GetProjectedXF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedXF1D_Type)) /*---------------------------Python BPy_GetProjectedXF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetProjectedXF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.cpp index 4e45c29ac1a..8cfd958ba29 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedYF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedYF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetProjectedYF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values. \n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the projected Y 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The projected Y 3D coordinate of an Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedYF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetProjectedYF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values. \n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the projected Y 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The projected Y 3D coordinate of an Interface1D.\n" + " :rtype: float\n"; static int GetProjectedYF1D___init__(BPy_GetProjectedYF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedYF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedYF1D(t); + return 0; } /*-----------------------BPy_GetProjectedYF1D type definition ------------------------------*/ PyTypeObject GetProjectedYF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedYF1D", /* tp_name */ - sizeof(BPy_GetProjectedYF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedYF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedYF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedYF1D", /* tp_name */ + sizeof(BPy_GetProjectedYF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedYF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedYF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.h index 6869aa4a7fc..5a0a5f42cb0 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedYF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedYF1D_Type; -#define BPy_GetProjectedYF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedYF1D_Type)) +#define BPy_GetProjectedYF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedYF1D_Type)) /*---------------------------Python BPy_GetProjectedYF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetProjectedYF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.cpp index 5f7ee3456e7..e5bd864fcfd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetProjectedZF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedZF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetProjectedZF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values. \n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the projected Z 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The projected Z 3D coordinate of an Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetProjectedZF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetProjectedZF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values. \n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the projected Z 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The projected Z 3D coordinate of an Interface1D.\n" + " :rtype: float\n"; static int GetProjectedZF1D___init__(BPy_GetProjectedZF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedZF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetProjectedZF1D(t); + return 0; } /*-----------------------BPy_GetProjectedZF1D type definition ------------------------------*/ PyTypeObject GetProjectedZF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetProjectedZF1D", /* tp_name */ - sizeof(BPy_GetProjectedZF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetProjectedZF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetProjectedZF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetProjectedZF1D", /* tp_name */ + sizeof(BPy_GetProjectedZF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetProjectedZF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetProjectedZF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.h index d643aeccc4f..aeb42521d1f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetProjectedZF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetProjectedZF1D_Type; -#define BPy_GetProjectedZF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedZF1D_Type)) +#define BPy_GetProjectedZF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetProjectedZF1D_Type)) /*---------------------------Python BPy_GetProjectedZF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetProjectedZF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.cpp index ad56182d065..a112dee15c7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.cpp @@ -33,92 +33,94 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetSteerableViewMapDensityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetSteerableViewMapDensityF1D`\n" -"\n" -".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a GetSteerableViewMapDensityF1D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain: the\n" -" corresponding 0D function is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the density of the ViewMap for a given Interface1D. The\n" -" density of each :class:`freestyle.types.FEdge` is evaluated in the\n" -" proper steerable :class:`freestyle.types.ViewMap` depending on its\n" -" orientation.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The density of the ViewMap for a given Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetSteerableViewMapDensityF1D`\n" + "\n" + ".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" + "\n" + " Builds a GetSteerableViewMapDensityF1D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain: the\n" + " corresponding 0D function is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the density of the ViewMap for a given Interface1D. The\n" + " density of each :class:`freestyle.types.FEdge` is evaluated in the\n" + " proper steerable :class:`freestyle.types.ViewMap` depending on its\n" + " orientation.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The density of the ViewMap for a given Interface1D.\n" + " :rtype: float\n"; static int GetSteerableViewMapDensityF1D___init__(BPy_GetSteerableViewMapDensityF1D *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - int i; - float f = 2.0; + static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + int i; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetSteerableViewMapDensityF1D(i, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetSteerableViewMapDensityF1D(i, t, f); + return 0; } /*-----------------------BPy_GetSteerableViewMapDensityF1D type definition ------------------------------*/ PyTypeObject GetSteerableViewMapDensityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetSteerableViewMapDensityF1D", /* tp_name */ - sizeof(BPy_GetSteerableViewMapDensityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetSteerableViewMapDensityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetSteerableViewMapDensityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetSteerableViewMapDensityF1D", /* tp_name */ + sizeof(BPy_GetSteerableViewMapDensityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetSteerableViewMapDensityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetSteerableViewMapDensityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.h index ce80107a6d9..c4881a79649 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetSteerableViewMapDensityF1D.h @@ -32,13 +32,12 @@ extern "C" { extern PyTypeObject GetSteerableViewMapDensityF1D_Type; #define BPy_GetSteerableViewMapDensityF1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetSteerableViewMapDensityF1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetSteerableViewMapDensityF1D_Type)) /*---------------------------Python BPy_GetSteerableViewMapDensityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetSteerableViewMapDensityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.cpp index 23eae370434..b2bb2947be7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.cpp @@ -33,91 +33,94 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetViewMapGradientNormF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetViewMapGradientNormF1D`\n" -"\n" -".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" -"\n" -" Builds a GetViewMapGradientNormF1D object.\n" -"\n" -" :arg level: The level of the pyramid from which the pixel must be\n" -" read.\n" -" :type level: int\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -" :arg sampling: The resolution used to sample the chain: the\n" -" corresponding 0D function is evaluated at each sample point and\n" -" the result is obtained by combining the resulting values into a\n" -" single one, following the method specified by integration_type.\n" -" :type sampling: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the density of the ViewMap for a given Interface1D. The\n" -" density of each :class:`freestyle.types.FEdge` is evaluated in the\n" -" proper steerable :class:`freestyle.types.ViewMap` depending on its\n" -" orientation.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The density of the ViewMap for a given Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetViewMapGradientNormF1D`\n" + "\n" + ".. method:: __init__(level, integration_type=IntegrationType.MEAN, sampling=2.0)\n" + "\n" + " Builds a GetViewMapGradientNormF1D object.\n" + "\n" + " :arg level: The level of the pyramid from which the pixel must be\n" + " read.\n" + " :type level: int\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + " :arg sampling: The resolution used to sample the chain: the\n" + " corresponding 0D function is evaluated at each sample point and\n" + " the result is obtained by combining the resulting values into a\n" + " single one, following the method specified by integration_type.\n" + " :type sampling: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the density of the ViewMap for a given Interface1D. The\n" + " density of each :class:`freestyle.types.FEdge` is evaluated in the\n" + " proper steerable :class:`freestyle.types.ViewMap` depending on its\n" + " orientation.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The density of the ViewMap for a given Interface1D.\n" + " :rtype: float\n"; -static int GetViewMapGradientNormF1D___init__(BPy_GetViewMapGradientNormF1D *self, PyObject *args, PyObject *kwds) +static int GetViewMapGradientNormF1D___init__(BPy_GetViewMapGradientNormF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; - PyObject *obj = 0; - int i; - float f = 2.0; + static const char *kwlist[] = {"level", "integration_type", "sampling", NULL}; + PyObject *obj = 0; + int i; + float f = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetViewMapGradientNormF1D(i, t, f); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "i|O!f", (char **)kwlist, &i, &IntegrationType_Type, &obj, &f)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetViewMapGradientNormF1D(i, t, f); + return 0; } /*-----------------------BPy_GetViewMapGradientNormF1D type definition ------------------------------*/ PyTypeObject GetViewMapGradientNormF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetViewMapGradientNormF1D", /* tp_name */ - sizeof(BPy_GetViewMapGradientNormF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetViewMapGradientNormF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetViewMapGradientNormF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetViewMapGradientNormF1D", /* tp_name */ + sizeof(BPy_GetViewMapGradientNormF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetViewMapGradientNormF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetViewMapGradientNormF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.h index 4d4f562c9d1..4f19b4ac67f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetViewMapGradientNormF1D.h @@ -32,15 +32,14 @@ extern "C" { extern PyTypeObject GetViewMapGradientNormF1D_Type; #define BPy_GetViewMapGradientNormF1D_Check(v) \ - (((PyObject *)v)->ob_type == PyObject_IsInstance((PyObject *)v, \ - (PyObject *)&GetViewMapGradientNormF1D_Type)) + (((PyObject *)v)->ob_type == \ + PyObject_IsInstance((PyObject *)v, (PyObject *)&GetViewMapGradientNormF1D_Type)) /*---------------------------Python BPy_GetViewMapGradientNormF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetViewMapGradientNormF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.cpp index f02b5cd4ad5..6a5e999ecf3 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetXF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetXF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetXF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the X 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The X 3D coordinate of the Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetXF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetXF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the X 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The X 3D coordinate of the Interface1D.\n" + " :rtype: float\n"; static int GetXF1D___init__(BPy_GetXF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetXF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetXF1D(t); + return 0; } /*-----------------------BPy_GetXF1D type definition ------------------------------*/ PyTypeObject GetXF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetXF1D", /* tp_name */ - sizeof(BPy_GetXF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetXF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetXF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetXF1D", /* tp_name */ + sizeof(BPy_GetXF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetXF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetXF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.h index 2e548a76cba..7db31882381 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetXF1D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetXF1D_Type; /*---------------------------Python BPy_GetXF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetXF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.cpp index 2bb6011dc84..b7a1e2a3072 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.cpp @@ -33,77 +33,78 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetYF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetYF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetYF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the Y 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The Y 3D coordinate of the Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetYF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetYF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the Y 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The Y 3D coordinate of the Interface1D.\n" + " :rtype: float\n"; static int GetYF1D___init__(BPy_GetYF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetYF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetYF1D(t); + return 0; } /*-----------------------BPy_GetYF1D type definition ------------------------------*/ PyTypeObject GetYF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetYF1D", /* tp_name */ - sizeof(BPy_GetYF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetYF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetYF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetYF1D", /* tp_name */ + sizeof(BPy_GetYF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetYF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetYF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.h index eedec9929d3..3f70d64e200 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetYF1D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetYF1D_Type; /*---------------------------Python BPy_GetYF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetYF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.cpp index 1c334c5089d..db42bdcc3eb 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.cpp @@ -33,78 +33,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetZF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetZF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a GetZF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the Z 3D coordinate of an Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The Z 3D coordinate of the Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`GetZF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a GetZF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the Z 3D coordinate of an Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The Z 3D coordinate of the Interface1D.\n" + " :rtype: float\n"; static int GetZF1D___init__(BPy_GetZF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::GetZF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::GetZF1D(t); + return 0; } /*-----------------------BPy_GetZF1D type definition ------------------------------*/ PyTypeObject GetZF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetZF1D", /* tp_name */ - sizeof(BPy_GetZF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetZF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetZF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetZF1D", /* tp_name */ + sizeof(BPy_GetZF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetZF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetZF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.h index b8c5107add7..b841bde2a5c 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_GetZF1D.h @@ -35,10 +35,9 @@ extern PyTypeObject GetZF1D_Type; /*---------------------------Python BPy_GetZF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_GetZF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.cpp index 992c620f5e9..8e139f5a627 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.cpp @@ -33,86 +33,89 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char LocalAverageDepthF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`LocalAverageDepthF1D`\n" -"\n" -".. method:: __init__(sigma, integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a LocalAverageDepthF1D object.\n" -"\n" -" :arg sigma: The sigma used in DensityF0D and determining the window\n" -" size used in each density query.\n" -" :type sigma: float\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the average depth evaluated for an Interface1D. The average\n" -" depth is evaluated for a set of points along the Interface1D (using\n" -" the :class:`freestyle.functions.LocalAverageDepthF0D` functor) with a\n" -" user-defined sampling and then integrated into a single value using a\n" -" user-defined integration method.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The average depth evaluated for the Interface1D.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`LocalAverageDepthF1D`\n" + "\n" + ".. method:: __init__(sigma, integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a LocalAverageDepthF1D object.\n" + "\n" + " :arg sigma: The sigma used in DensityF0D and determining the window\n" + " size used in each density query.\n" + " :type sigma: float\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the average depth evaluated for an Interface1D. The average\n" + " depth is evaluated for a set of points along the Interface1D (using\n" + " the :class:`freestyle.functions.LocalAverageDepthF0D` functor) with a\n" + " user-defined sampling and then integrated into a single value using a\n" + " user-defined integration method.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The average depth evaluated for the Interface1D.\n" + " :rtype: float\n"; -static int LocalAverageDepthF1D___init__(BPy_LocalAverageDepthF1D *self, PyObject *args, PyObject *kwds) +static int LocalAverageDepthF1D___init__(BPy_LocalAverageDepthF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"sigma", "integration_type", NULL}; - PyObject *obj = 0; - double d; + static const char *kwlist[] = {"sigma", "integration_type", NULL}; + PyObject *obj = 0; + double d; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|O!", (char **)kwlist, &d, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::LocalAverageDepthF1D(d, t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "d|O!", (char **)kwlist, &d, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::LocalAverageDepthF1D(d, t); + return 0; } /*-----------------------BPy_LocalAverageDepthF1D type definition ------------------------------*/ PyTypeObject LocalAverageDepthF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "LocalAverageDepthF1D", /* tp_name */ - sizeof(BPy_LocalAverageDepthF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - LocalAverageDepthF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)LocalAverageDepthF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "LocalAverageDepthF1D", /* tp_name */ + sizeof(BPy_LocalAverageDepthF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + LocalAverageDepthF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)LocalAverageDepthF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.h index 5bcb3130d70..258d028bfbd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_LocalAverageDepthF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject LocalAverageDepthF1D_Type; -#define BPy_LocalAverageDepthF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&LocalAverageDepthF1D_Type)) +#define BPy_LocalAverageDepthF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&LocalAverageDepthF1D_Type)) /*---------------------------Python BPy_LocalAverageDepthF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_LocalAverageDepthF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.cpp index e0511734e75..1f5b262f71a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.cpp @@ -33,82 +33,83 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ZDiscontinuityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DDouble` > :class:`ZDiscontinuityF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a ZDiscontinuityF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns a real value giving the distance between an Interface1D\n" -" and the shape that lies behind (occludee). This distance is\n" -" evaluated in the camera space and normalized between 0 and 1.\n" -" Therefore, if no object is occluded by the shape to which the\n" -" Interface1D belongs to, 1 is returned.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The normalized distance between the Interface1D and the occludee.\n" -" :rtype: float\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DDouble` > :class:`ZDiscontinuityF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a ZDiscontinuityF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns a real value giving the distance between an Interface1D\n" + " and the shape that lies behind (occludee). This distance is\n" + " evaluated in the camera space and normalized between 0 and 1.\n" + " Therefore, if no object is occluded by the shape to which the\n" + " Interface1D belongs to, 1 is returned.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The normalized distance between the Interface1D and the occludee.\n" + " :rtype: float\n"; static int ZDiscontinuityF1D___init__(BPy_ZDiscontinuityF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_double.uf1D_double = new Functions1D::ZDiscontinuityF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_double.uf1D_double = new Functions1D::ZDiscontinuityF1D(t); + return 0; } /*-----------------------BPy_ZDiscontinuityF1D type definition ------------------------------*/ PyTypeObject ZDiscontinuityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ZDiscontinuityF1D", /* tp_name */ - sizeof(BPy_ZDiscontinuityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ZDiscontinuityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DDouble_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ZDiscontinuityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ZDiscontinuityF1D", /* tp_name */ + sizeof(BPy_ZDiscontinuityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ZDiscontinuityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DDouble_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ZDiscontinuityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.h index 22d6fdac96d..c336591842b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_double/BPy_ZDiscontinuityF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject ZDiscontinuityF1D_Type; -#define BPy_ZDiscontinuityF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ZDiscontinuityF1D_Type)) +#define BPy_ZDiscontinuityF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ZDiscontinuityF1D_Type)) /*---------------------------Python BPy_ZDiscontinuityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DDouble py_uf1D_double; + BPy_UnaryFunction1DDouble py_uf1D_double; } BPy_ZDiscontinuityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.cpp index eccf788c631..f955c90842a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.cpp @@ -33,82 +33,85 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char QuantitativeInvisibilityF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DUnsigned` > :class:`QuantitativeInvisibilityF1D`\n" -"\n" -".. method:: __init__(integration_type=IntegrationType.MEAN)\n" -"\n" -" Builds a QuantitativeInvisibilityF1D object.\n" -"\n" -" :arg integration_type: The integration method used to compute a single value\n" -" from a set of values.\n" -" :type integration_type: :class:`freestyle.types.IntegrationType`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the Quantitative Invisibility of an Interface1D element. If\n" -" the Interface1D is a :class:`freestyle.types.ViewEdge`, then there is\n" -" no ambiguity concerning the result. But, if the Interface1D results\n" -" of a chaining (chain, stroke), then it might be made of several 1D\n" -" elements of different Quantitative Invisibilities.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: The Quantitative Invisibility of the Interface1D.\n" -" :rtype: int\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DUnsigned` > :class:`QuantitativeInvisibilityF1D`\n" + "\n" + ".. method:: __init__(integration_type=IntegrationType.MEAN)\n" + "\n" + " Builds a QuantitativeInvisibilityF1D object.\n" + "\n" + " :arg integration_type: The integration method used to compute a single value\n" + " from a set of values.\n" + " :type integration_type: :class:`freestyle.types.IntegrationType`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the Quantitative Invisibility of an Interface1D element. If\n" + " the Interface1D is a :class:`freestyle.types.ViewEdge`, then there is\n" + " no ambiguity concerning the result. But, if the Interface1D results\n" + " of a chaining (chain, stroke), then it might be made of several 1D\n" + " elements of different Quantitative Invisibilities.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: The Quantitative Invisibility of the Interface1D.\n" + " :rtype: int\n"; -static int QuantitativeInvisibilityF1D___init__(BPy_QuantitativeInvisibilityF1D *self, PyObject *args, PyObject *kwds) +static int QuantitativeInvisibilityF1D___init__(BPy_QuantitativeInvisibilityF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"integration_type", NULL}; - PyObject *obj = 0; + static const char *kwlist[] = {"integration_type", NULL}; + PyObject *obj = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) - return -1; - IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; - self->py_uf1D_unsigned.uf1D_unsigned = new Functions1D::QuantitativeInvisibilityF1D(t); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) + return -1; + IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; + self->py_uf1D_unsigned.uf1D_unsigned = new Functions1D::QuantitativeInvisibilityF1D(t); + return 0; } /*-----------------------BPy_QuantitativeInvisibilityF1D type definition ------------------------------*/ PyTypeObject QuantitativeInvisibilityF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "QuantitativeInvisibilityF1D", /* tp_name */ - sizeof(BPy_QuantitativeInvisibilityF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - QuantitativeInvisibilityF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DUnsigned_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)QuantitativeInvisibilityF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "QuantitativeInvisibilityF1D", /* tp_name */ + sizeof(BPy_QuantitativeInvisibilityF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + QuantitativeInvisibilityF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DUnsigned_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)QuantitativeInvisibilityF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.h index edaeea2a2d9..35cd9e779bd 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject QuantitativeInvisibilityF1D_Type; #define BPy_QuantitativeInvisibilityF1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityF1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityF1D_Type)) /*---------------------------Python BPy_QuantitativeInvisibilityF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DUnsigned py_uf1D_unsigned; + BPy_UnaryFunction1DUnsigned py_uf1D_unsigned; } BPy_QuantitativeInvisibilityF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.cpp index 4b5fee581f7..0d7944de788 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.cpp @@ -33,72 +33,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetOccludeeF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetOccludeeF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetOccludeeF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns a list of occluded shapes covered by this Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: A list of occluded shapes covered by the Interface1D.\n" -" :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetOccludeeF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetOccludeeF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns a list of occluded shapes covered by this Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: A list of occluded shapes covered by the Interface1D.\n" + " :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; static int GetOccludeeF1D___init__(BPy_GetOccludeeF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetOccludeeF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetOccludeeF1D(); + return 0; } /*-----------------------BPy_GetOccludeeF1D type definition ------------------------------*/ PyTypeObject GetOccludeeF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetOccludeeF1D", /* tp_name */ - sizeof(BPy_GetOccludeeF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetOccludeeF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVectorViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetOccludeeF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetOccludeeF1D", /* tp_name */ + sizeof(BPy_GetOccludeeF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetOccludeeF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVectorViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetOccludeeF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.h index 6e619ffd42e..5a14b5dc35d 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetOccludeeF1D_Type; -#define BPy_GetOccludeeF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludeeF1D_Type)) +#define BPy_GetOccludeeF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludeeF1D_Type)) /*---------------------------Python BPy_GetOccludeeF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; + BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; } BPy_GetOccludeeF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.cpp index a42064be52c..38651154ce7 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.cpp @@ -33,72 +33,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetOccludersF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetOccludersF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetOccludersF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns a list of occluding shapes that cover this Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: A list of occluding shapes that cover the Interface1D.\n" -" :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetOccludersF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetOccludersF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns a list of occluding shapes that cover this Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: A list of occluding shapes that cover the Interface1D.\n" + " :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; static int GetOccludersF1D___init__(BPy_GetOccludersF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetOccludersF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetOccludersF1D(); + return 0; } /*-----------------------BPy_GetOccludersF1D type definition ------------------------------*/ PyTypeObject GetOccludersF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetOccludersF1D", /* tp_name */ - sizeof(BPy_GetOccludersF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetOccludersF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVectorViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetOccludersF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetOccludersF1D", /* tp_name */ + sizeof(BPy_GetOccludersF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetOccludersF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVectorViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetOccludersF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.h index 93f1fef2167..29899d443a6 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetOccludersF1D_Type; -#define BPy_GetOccludersF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludersF1D_Type)) +#define BPy_GetOccludersF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetOccludersF1D_Type)) /*---------------------------Python BPy_GetOccludersF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; + BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; } BPy_GetOccludersF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.cpp index 1ef8502dfbe..537e57c7106 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.cpp @@ -33,72 +33,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char GetShapeF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetShapeF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a GetShapeF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns a list of shapes covered by this Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: A list of shapes covered by the Interface1D.\n" -" :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVectorViewShape` > :class:`GetShapeF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a GetShapeF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns a list of shapes covered by this Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: A list of shapes covered by the Interface1D.\n" + " :rtype: list of :class:`freestyle.types.ViewShape` objects\n"; static int GetShapeF1D___init__(BPy_GetShapeF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetShapeF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_vectorviewshape.uf1D_vectorviewshape = new Functions1D::GetShapeF1D(); + return 0; } /*-----------------------BPy_GetShapeF1D type definition ------------------------------*/ PyTypeObject GetShapeF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "GetShapeF1D", /* tp_name */ - sizeof(BPy_GetShapeF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - GetShapeF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVectorViewShape_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)GetShapeF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "GetShapeF1D", /* tp_name */ + sizeof(BPy_GetShapeF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + GetShapeF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVectorViewShape_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)GetShapeF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.h index 6f2ec2bec1d..b90f3df5831 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject GetShapeF1D_Type; -#define BPy_GetShapeF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetShapeF1D_Type)) +#define BPy_GetShapeF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&GetShapeF1D_Type)) /*---------------------------Python BPy_GetShapeF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; + BPy_UnaryFunction1DVectorViewShape py_uf1D_vectorviewshape; } BPy_GetShapeF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.cpp index 4f3a8c00cbd..da9d3301e5f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.cpp @@ -33,70 +33,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ChainingTimeStampF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVoid` > :class:`ChainingTimeStampF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a ChainingTimeStampF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Sets the chaining time stamp of the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVoid` > :class:`ChainingTimeStampF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a ChainingTimeStampF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Sets the chaining time stamp of the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n"; -static int ChainingTimeStampF1D___init__(BPy_ChainingTimeStampF1D *self, PyObject *args, PyObject *kwds) +static int ChainingTimeStampF1D___init__(BPy_ChainingTimeStampF1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_void.uf1D_void = new Functions1D::ChainingTimeStampF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_void.uf1D_void = new Functions1D::ChainingTimeStampF1D(); + return 0; } /*-----------------------BPy_ChainingTimeStampF1D type definition ------------------------------*/ PyTypeObject ChainingTimeStampF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainingTimeStampF1D", /* tp_name */ - sizeof(BPy_ChainingTimeStampF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainingTimeStampF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVoid_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainingTimeStampF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainingTimeStampF1D", /* tp_name */ + sizeof(BPy_ChainingTimeStampF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainingTimeStampF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVoid_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainingTimeStampF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.h index 860cbd47e81..c6423ef434f 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_ChainingTimeStampF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject ChainingTimeStampF1D_Type; -#define BPy_ChainingTimeStampF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingTimeStampF1D_Type)) +#define BPy_ChainingTimeStampF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingTimeStampF1D_Type)) /*---------------------------Python BPy_ChainingTimeStampF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVoid py_uf1D_void; + BPy_UnaryFunction1DVoid py_uf1D_void; } BPy_ChainingTimeStampF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.cpp index 55536d9aff8..3aa694a5739 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.cpp @@ -33,71 +33,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char IncrementChainingTimeStampF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVoid` > :class:`IncrementChainingTimeStampF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds an IncrementChainingTimeStampF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Increments the chaining time stamp of the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVoid` > :class:`IncrementChainingTimeStampF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds an IncrementChainingTimeStampF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Increments the chaining time stamp of the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n"; static int IncrementChainingTimeStampF1D___init__(BPy_IncrementChainingTimeStampF1D *self, - PyObject *args, PyObject *kwds) + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_void.uf1D_void = new Functions1D::IncrementChainingTimeStampF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_void.uf1D_void = new Functions1D::IncrementChainingTimeStampF1D(); + return 0; } /*-----------------------BPy_IncrementChainingTimeStampF1D type definition ------------------------------*/ PyTypeObject IncrementChainingTimeStampF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "IncrementChainingTimeStampF1D", /* tp_name */ - sizeof(BPy_IncrementChainingTimeStampF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - IncrementChainingTimeStampF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVoid_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)IncrementChainingTimeStampF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "IncrementChainingTimeStampF1D", /* tp_name */ + sizeof(BPy_IncrementChainingTimeStampF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + IncrementChainingTimeStampF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVoid_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)IncrementChainingTimeStampF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.h index 4e27c628cef..3030528a49b 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_IncrementChainingTimeStampF1D.h @@ -32,14 +32,13 @@ extern "C" { extern PyTypeObject IncrementChainingTimeStampF1D_Type; #define BPy_IncrementChainingTimeStampF1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncrementChainingTimeStampF1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&IncrementChainingTimeStampF1D_Type)) /*---------------------------Python BPy_IncrementChainingTimeStampF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVoid py_uf1D_void; + BPy_UnaryFunction1DVoid py_uf1D_void; } BPy_IncrementChainingTimeStampF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.cpp index d21aa97b591..eb53bca5874 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.cpp @@ -33,70 +33,70 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char TimeStampF1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > :class:`freestyle.types.UnaryFunction1DVoid` > :class:`TimeStampF1D`\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a TimeStampF1D object.\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns the time stamp of the Interface1D.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n"; + "Class hierarchy: :class:`freestyle.types.UnaryFunction1D` > " + ":class:`freestyle.types.UnaryFunction1DVoid` > :class:`TimeStampF1D`\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Builds a TimeStampF1D object.\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns the time stamp of the Interface1D.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n"; static int TimeStampF1D___init__(BPy_TimeStampF1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_uf1D_void.uf1D_void = new Functions1D::TimeStampF1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_uf1D_void.uf1D_void = new Functions1D::TimeStampF1D(); + return 0; } /*-----------------------BPy_TimeStampF1D type definition ------------------------------*/ PyTypeObject TimeStampF1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TimeStampF1D", /* tp_name */ - sizeof(BPy_TimeStampF1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TimeStampF1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryFunction1DVoid_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TimeStampF1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TimeStampF1D", /* tp_name */ + sizeof(BPy_TimeStampF1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TimeStampF1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryFunction1DVoid_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TimeStampF1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.h b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.h index c5c58f40080..4787f35cfc5 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.h +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/UnaryFunction1D_void/BPy_TimeStampF1D.h @@ -31,14 +31,14 @@ extern "C" { extern PyTypeObject TimeStampF1D_Type; -#define BPy_TimeStampF1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&TimeStampF1D_Type)) +#define BPy_TimeStampF1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&TimeStampF1D_Type)) /*---------------------------Python BPy_TimeStampF1D structure definition----------*/ typedef struct { - BPy_UnaryFunction1DVoid py_uf1D_void; + BPy_UnaryFunction1DVoid py_uf1D_void; } BPy_TimeStampF1D; - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.cpp index f2ba1f7aafb..8289d4b6386 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.cpp @@ -29,68 +29,67 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char FalseUP0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate0D` > :class:`FalseUP0D`\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Always returns false.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: False.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate0D` > :class:`FalseUP0D`\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Always returns false.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: False.\n" + " :rtype: bool\n"; static int FalseUP0D___init__(BPy_FalseUP0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up0D.up0D = new Predicates0D::FalseUP0D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up0D.up0D = new Predicates0D::FalseUP0D(); + return 0; } /*-----------------------BPy_FalseUP0D type definition ------------------------------*/ PyTypeObject FalseUP0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FalseUP0D", /* tp_name */ - sizeof(BPy_FalseUP0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FalseUP0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FalseUP0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FalseUP0D", /* tp_name */ + sizeof(BPy_FalseUP0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FalseUP0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FalseUP0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.h b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.h index dbc395fc2f4..b947ccf5b95 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_FalseUP0D.h @@ -35,7 +35,7 @@ extern PyTypeObject FalseUP0D_Type; /*---------------------------Python BPy_FalseUP0D structure definition----------*/ typedef struct { - BPy_UnaryPredicate0D py_up0D; + BPy_UnaryPredicate0D py_up0D; } BPy_FalseUP0D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.cpp index fd79c44da43..697e9bc2c92 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.cpp @@ -29,68 +29,67 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char TrueUP0D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate0D` > :class:`TrueUP0D`\n" -"\n" -".. method:: __call__(it)\n" -"\n" -" Always returns true.\n" -"\n" -" :arg it: An Interface0DIterator object.\n" -" :type it: :class:`freestyle.types.Interface0DIterator`\n" -" :return: True.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate0D` > :class:`TrueUP0D`\n" + "\n" + ".. method:: __call__(it)\n" + "\n" + " Always returns true.\n" + "\n" + " :arg it: An Interface0DIterator object.\n" + " :type it: :class:`freestyle.types.Interface0DIterator`\n" + " :return: True.\n" + " :rtype: bool\n"; static int TrueUP0D___init__(BPy_TrueUP0D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up0D.up0D = new Predicates0D::TrueUP0D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up0D.up0D = new Predicates0D::TrueUP0D(); + return 0; } /*-----------------------BPy_TrueUP0D type definition ------------------------------*/ PyTypeObject TrueUP0D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TrueUP0D", /* tp_name */ - sizeof(BPy_TrueUP0D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TrueUP0D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate0D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TrueUP0D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TrueUP0D", /* tp_name */ + sizeof(BPy_TrueUP0D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TrueUP0D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TrueUP0D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.h b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.h index 9dd4a5ecd34..72acf363992 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate0D/BPy_TrueUP0D.h @@ -35,7 +35,7 @@ extern PyTypeObject TrueUP0D_Type; /*---------------------------Python BPy_TrueUP0D structure definition----------*/ typedef struct { - BPy_UnaryPredicate0D py_up0D; + BPy_UnaryPredicate0D py_up0D; } BPy_TrueUP0D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.cpp index 5a20dd323f6..faf0c98641a 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.cpp @@ -29,69 +29,68 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ContourUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ContourUP1D`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Interface1D is a contour. An Interface1D is a\n" -" contour if it is borded by a different shape on each of its sides.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if the Interface1D is a contour, false otherwise.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ContourUP1D`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Interface1D is a contour. An Interface1D is a\n" + " contour if it is borded by a different shape on each of its sides.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if the Interface1D is a contour, false otherwise.\n" + " :rtype: bool\n"; static int ContourUP1D___init__(BPy_ContourUP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up1D.up1D = new Predicates1D::ContourUP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up1D.up1D = new Predicates1D::ContourUP1D(); + return 0; } /*-----------------------BPy_ContourUP1D type definition ------------------------------*/ PyTypeObject ContourUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ContourUP1D", /* tp_name */ - sizeof(BPy_ContourUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ContourUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ContourUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ContourUP1D", /* tp_name */ + sizeof(BPy_ContourUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ContourUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ContourUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.h index 32f9080173f..de6c40fa8ac 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ContourUP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject ContourUP1D_Type; -#define BPy_ContourUP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ContourUP1D_Type)) +#define BPy_ContourUP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ContourUP1D_Type)) /*---------------------------Python BPy_ContourUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_ContourUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.cpp index 75df852ddfa..065329847b3 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.cpp @@ -31,81 +31,82 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char DensityLowerThanUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`DensityLowerThanUP1D`\n" -"\n" -".. method:: __init__(threshold, sigma=2.0)\n" -"\n" -" Builds a DensityLowerThanUP1D object.\n" -"\n" -" :arg threshold: The value of the threshold density. Any Interface1D\n" -" having a density lower than this threshold will match.\n" -" :type threshold: float\n" -" :arg sigma: The sigma value defining the density evaluation window\n" -" size used in the :class:`freestyle.functions.DensityF0D` functor.\n" -" :type sigma: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the density evaluated for the Interface1D is less\n" -" than a user-defined density value.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if the density is lower than a threshold.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`DensityLowerThanUP1D`\n" + "\n" + ".. method:: __init__(threshold, sigma=2.0)\n" + "\n" + " Builds a DensityLowerThanUP1D object.\n" + "\n" + " :arg threshold: The value of the threshold density. Any Interface1D\n" + " having a density lower than this threshold will match.\n" + " :type threshold: float\n" + " :arg sigma: The sigma value defining the density evaluation window\n" + " size used in the :class:`freestyle.functions.DensityF0D` functor.\n" + " :type sigma: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the density evaluated for the Interface1D is less\n" + " than a user-defined density value.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if the density is lower than a threshold.\n" + " :rtype: bool\n"; -static int DensityLowerThanUP1D___init__(BPy_DensityLowerThanUP1D *self, PyObject *args, PyObject *kwds) +static int DensityLowerThanUP1D___init__(BPy_DensityLowerThanUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"threshold", "sigma", NULL}; - double d1, d2 = 2.0; + static const char *kwlist[] = {"threshold", "sigma", NULL}; + double d1, d2 = 2.0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|d", (char **)kwlist, &d1, &d2)) - return -1; - self->py_up1D.up1D = new Predicates1D::DensityLowerThanUP1D(d1, d2); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|d", (char **)kwlist, &d1, &d2)) + return -1; + self->py_up1D.up1D = new Predicates1D::DensityLowerThanUP1D(d1, d2); + return 0; } /*-----------------------BPy_DensityLowerThanUP1D type definition ------------------------------*/ PyTypeObject DensityLowerThanUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "DensityLowerThanUP1D", /* tp_name */ - sizeof(BPy_DensityLowerThanUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - DensityLowerThanUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)DensityLowerThanUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "DensityLowerThanUP1D", /* tp_name */ + sizeof(BPy_DensityLowerThanUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + DensityLowerThanUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)DensityLowerThanUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.h index e8ea1daca19..fb02b63fa3d 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_DensityLowerThanUP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject DensityLowerThanUP1D_Type; -#define BPy_DensityLowerThanUP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&DensityLowerThanUP1D_Type)) +#define BPy_DensityLowerThanUP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&DensityLowerThanUP1D_Type)) /*---------------------------Python BPy_DensityLowerThanUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_DensityLowerThanUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.cpp index ea885e74174..f3b6a71585f 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.cpp @@ -29,77 +29,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char EqualToChainingTimeStampUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`freestyle.types.EqualToChainingTimeStampUP1D`\n" -"\n" -".. method:: __init__(ts)\n" -"\n" -" Builds a EqualToChainingTimeStampUP1D object.\n" -"\n" -" :arg ts: A time stamp value.\n" -" :type ts: int\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Interface1D's time stamp is equal to a certain\n" -" user-defined value.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if the time stamp is equal to a user-defined value.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > " + ":class:`freestyle.types.EqualToChainingTimeStampUP1D`\n" + "\n" + ".. method:: __init__(ts)\n" + "\n" + " Builds a EqualToChainingTimeStampUP1D object.\n" + "\n" + " :arg ts: A time stamp value.\n" + " :type ts: int\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Interface1D's time stamp is equal to a certain\n" + " user-defined value.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if the time stamp is equal to a user-defined value.\n" + " :rtype: bool\n"; -static int EqualToChainingTimeStampUP1D___init__(BPy_EqualToChainingTimeStampUP1D *self, PyObject *args, PyObject *kwds) +static int EqualToChainingTimeStampUP1D___init__(BPy_EqualToChainingTimeStampUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"ts", NULL}; - unsigned u; + static const char *kwlist[] = {"ts", NULL}; + unsigned u; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &u)) - return -1; - self->py_up1D.up1D = new Predicates1D::EqualToChainingTimeStampUP1D(u); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &u)) + return -1; + self->py_up1D.up1D = new Predicates1D::EqualToChainingTimeStampUP1D(u); + return 0; } /*-----------------------BPy_EqualToChainingTimeStampUP1D type definition ------------------------------*/ PyTypeObject EqualToChainingTimeStampUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "EqualToChainingTimeStampUP1D", /* tp_name */ - sizeof(BPy_EqualToChainingTimeStampUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - EqualToChainingTimeStampUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)EqualToChainingTimeStampUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "EqualToChainingTimeStampUP1D", /* tp_name */ + sizeof(BPy_EqualToChainingTimeStampUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + EqualToChainingTimeStampUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)EqualToChainingTimeStampUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.h index a542c53a88b..eab08c6588d 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToChainingTimeStampUP1D.h @@ -32,11 +32,11 @@ extern "C" { extern PyTypeObject EqualToChainingTimeStampUP1D_Type; #define BPy_EqualToChainingTimeStampUP1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&EqualToChainingTimeStampUP1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&EqualToChainingTimeStampUP1D_Type)) /*---------------------------Python BPy_EqualToChainingTimeStampUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_EqualToChainingTimeStampUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.cpp index 280e7088628..30b8e3fce95 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.cpp @@ -29,77 +29,78 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char EqualToTimeStampUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`EqualToTimeStampUP1D`\n" -"\n" -".. method:: __init__(ts)\n" -"\n" -" Builds a EqualToTimeStampUP1D object.\n" -"\n" -" :arg ts: A time stamp value.\n" -" :type ts: int\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Interface1D's time stamp is equal to a certain\n" -" user-defined value.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if the time stamp is equal to a user-defined value.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`EqualToTimeStampUP1D`\n" + "\n" + ".. method:: __init__(ts)\n" + "\n" + " Builds a EqualToTimeStampUP1D object.\n" + "\n" + " :arg ts: A time stamp value.\n" + " :type ts: int\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Interface1D's time stamp is equal to a certain\n" + " user-defined value.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if the time stamp is equal to a user-defined value.\n" + " :rtype: bool\n"; -static int EqualToTimeStampUP1D___init__(BPy_EqualToTimeStampUP1D *self, PyObject *args, PyObject *kwds) +static int EqualToTimeStampUP1D___init__(BPy_EqualToTimeStampUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"ts", NULL}; - unsigned u; + static const char *kwlist[] = {"ts", NULL}; + unsigned u; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &u)) - return -1; - self->py_up1D.up1D = new Predicates1D::EqualToTimeStampUP1D(u); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &u)) + return -1; + self->py_up1D.up1D = new Predicates1D::EqualToTimeStampUP1D(u); + return 0; } /*-----------------------BPy_EqualToTimeStampUP1D type definition ------------------------------*/ PyTypeObject EqualToTimeStampUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "EqualToTimeStampUP1D", /* tp_name */ - sizeof(BPy_EqualToTimeStampUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - EqualToTimeStampUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)EqualToTimeStampUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "EqualToTimeStampUP1D", /* tp_name */ + sizeof(BPy_EqualToTimeStampUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + EqualToTimeStampUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)EqualToTimeStampUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.h index b27509e7205..13736242382 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_EqualToTimeStampUP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject EqualToTimeStampUP1D_Type; -#define BPy_EqualToTimeStampUP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&EqualToTimeStampUP1D_Type)) +#define BPy_EqualToTimeStampUP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&EqualToTimeStampUP1D_Type)) /*---------------------------Python BPy_EqualToTimeStampUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_EqualToTimeStampUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.cpp index 3b00ab2dba8..8bd31209291 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.cpp @@ -29,71 +29,72 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ExternalContourUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ExternalContourUP1D`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Interface1D is an external contour. An\n" -" Interface1D is an external contour if it is borded by no shape on\n" -" one of its sides.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if the Interface1D is an external contour, false\n" -" otherwise.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ExternalContourUP1D`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Interface1D is an external contour. An\n" + " Interface1D is an external contour if it is borded by no shape on\n" + " one of its sides.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if the Interface1D is an external contour, false\n" + " otherwise.\n" + " :rtype: bool\n"; -static int ExternalContourUP1D___init__(BPy_ExternalContourUP1D *self, PyObject *args, PyObject *kwds) +static int ExternalContourUP1D___init__(BPy_ExternalContourUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up1D.up1D = new Predicates1D::ExternalContourUP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up1D.up1D = new Predicates1D::ExternalContourUP1D(); + return 0; } /*-----------------------BPy_ExternalContourUP1D type definition ------------------------------*/ PyTypeObject ExternalContourUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ExternalContourUP1D", /* tp_name */ - sizeof(BPy_ExternalContourUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ExternalContourUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ExternalContourUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ExternalContourUP1D", /* tp_name */ + sizeof(BPy_ExternalContourUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ExternalContourUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ExternalContourUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.h index 91140eb9670..4d2a22731fa 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ExternalContourUP1D.h @@ -31,11 +31,12 @@ extern "C" { extern PyTypeObject ExternalContourUP1D_Type; -#define BPy_ExternalContourUP1D_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ExternalContourUP1D_Type)) +#define BPy_ExternalContourUP1D_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ExternalContourUP1D_Type)) /*---------------------------Python BPy_ExternalContourUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_ExternalContourUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.cpp index a3a0d8c544c..b4db7e65090 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.cpp @@ -29,68 +29,67 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char FalseUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`FalseUP1D`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Always returns false.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: False.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`FalseUP1D`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Always returns false.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: False.\n" + " :rtype: bool\n"; static int FalseUP1D___init__(BPy_FalseUP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up1D.up1D = new Predicates1D::FalseUP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up1D.up1D = new Predicates1D::FalseUP1D(); + return 0; } /*-----------------------BPy_FalseUP1D type definition ------------------------------*/ PyTypeObject FalseUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "FalseUP1D", /* tp_name */ - sizeof(BPy_FalseUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FalseUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)FalseUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "FalseUP1D", /* tp_name */ + sizeof(BPy_FalseUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + FalseUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FalseUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.h index d138f9d7f9f..57255c2333f 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_FalseUP1D.h @@ -35,7 +35,7 @@ extern PyTypeObject FalseUP1D_Type; /*---------------------------Python BPy_FalseUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_FalseUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.cpp index eb4968484fc..885ecb16695 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.cpp @@ -29,81 +29,83 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char QuantitativeInvisibilityUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`QuantitativeInvisibilityUP1D`\n" -"\n" -".. method:: __init__(qi=0)\n" -"\n" -" Builds a QuantitativeInvisibilityUP1D object.\n" -"\n" -" :arg qi: The Quantitative Invisibility you want the Interface1D to\n" -" have.\n" -" :type qi: int\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Quantitative Invisibility evaluated at an\n" -" Interface1D, using the\n" -" :class:`freestyle.functions.QuantitativeInvisibilityF1D` functor,\n" -" equals a certain user-defined value.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if Quantitative Invisibility equals a user-defined\n" -" value.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > " + ":class:`QuantitativeInvisibilityUP1D`\n" + "\n" + ".. method:: __init__(qi=0)\n" + "\n" + " Builds a QuantitativeInvisibilityUP1D object.\n" + "\n" + " :arg qi: The Quantitative Invisibility you want the Interface1D to\n" + " have.\n" + " :type qi: int\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Quantitative Invisibility evaluated at an\n" + " Interface1D, using the\n" + " :class:`freestyle.functions.QuantitativeInvisibilityF1D` functor,\n" + " equals a certain user-defined value.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if Quantitative Invisibility equals a user-defined\n" + " value.\n" + " :rtype: bool\n"; -static int QuantitativeInvisibilityUP1D___init__(BPy_QuantitativeInvisibilityUP1D *self, PyObject *args, PyObject *kwds) +static int QuantitativeInvisibilityUP1D___init__(BPy_QuantitativeInvisibilityUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"qi", NULL}; - int i = 0; + static const char *kwlist[] = {"qi", NULL}; + int i = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", (char **)kwlist, &i)) - return -1; - self->py_up1D.up1D = new Predicates1D::QuantitativeInvisibilityUP1D(i); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", (char **)kwlist, &i)) + return -1; + self->py_up1D.up1D = new Predicates1D::QuantitativeInvisibilityUP1D(i); + return 0; } /*-----------------------BPy_QuantitativeInvisibilityUP1D type definition ------------------------------*/ PyTypeObject QuantitativeInvisibilityUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "QuantitativeInvisibilityUP1D", /* tp_name */ - sizeof(BPy_QuantitativeInvisibilityUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - QuantitativeInvisibilityUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)QuantitativeInvisibilityUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "QuantitativeInvisibilityUP1D", /* tp_name */ + sizeof(BPy_QuantitativeInvisibilityUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + QuantitativeInvisibilityUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)QuantitativeInvisibilityUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.h index bfd7302b0e1..879c6c5b7be 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_QuantitativeInvisibilityUP1D.h @@ -32,11 +32,11 @@ extern "C" { extern PyTypeObject QuantitativeInvisibilityUP1D_Type; #define BPy_QuantitativeInvisibilityUP1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityUP1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&QuantitativeInvisibilityUP1D_Type)) /*---------------------------Python BPy_QuantitativeInvisibilityUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_QuantitativeInvisibilityUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.cpp index adf44287582..54a6a70c3bf 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.cpp @@ -29,80 +29,79 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char ShapeUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ShapeUP1D`\n" -"\n" -".. method:: __init__(first, second=0)\n" -"\n" -" Builds a ShapeUP1D object.\n" -"\n" -" :arg first: The first Id component.\n" -" :type first: int\n" -" :arg second: The second Id component.\n" -" :type second: int\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the shape to which the Interface1D belongs to has the\n" -" same :class:`freestyle.types.Id` as the one specified by the user.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True if Interface1D belongs to the shape of the\n" -" user-specified Id.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`ShapeUP1D`\n" + "\n" + ".. method:: __init__(first, second=0)\n" + "\n" + " Builds a ShapeUP1D object.\n" + "\n" + " :arg first: The first Id component.\n" + " :type first: int\n" + " :arg second: The second Id component.\n" + " :type second: int\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the shape to which the Interface1D belongs to has the\n" + " same :class:`freestyle.types.Id` as the one specified by the user.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True if Interface1D belongs to the shape of the\n" + " user-specified Id.\n" + " :rtype: bool\n"; static int ShapeUP1D___init__(BPy_ShapeUP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"first", "second", NULL}; - unsigned u1, u2 = 0; + static const char *kwlist[] = {"first", "second", NULL}; + unsigned u1, u2 = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "I|I", (char **)kwlist, &u1, &u2)) - return -1; - self->py_up1D.up1D = new Predicates1D::ShapeUP1D(u1, u2); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I|I", (char **)kwlist, &u1, &u2)) + return -1; + self->py_up1D.up1D = new Predicates1D::ShapeUP1D(u1, u2); + return 0; } /*-----------------------BPy_ShapeUP1D type definition ------------------------------*/ PyTypeObject ShapeUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ShapeUP1D", /* tp_name */ - sizeof(BPy_ShapeUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ShapeUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ShapeUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ShapeUP1D", /* tp_name */ + sizeof(BPy_ShapeUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ShapeUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ShapeUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.h index 9cfeded4452..a48ed0aa0da 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_ShapeUP1D.h @@ -35,7 +35,7 @@ extern PyTypeObject ShapeUP1D_Type; /*---------------------------Python BPy_ShapeUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_ShapeUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.cpp index d1562dfa692..55c8c1ee889 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.cpp @@ -29,68 +29,67 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char TrueUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`TrueUP1D`\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Always returns true.\n" -"\n" -" :arg inter: An Interface1D object.\n" -" :type inter: :class:`freestyle.types.Interface1D`\n" -" :return: True.\n" -" :rtype: bool\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`TrueUP1D`\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Always returns true.\n" + "\n" + " :arg inter: An Interface1D object.\n" + " :type inter: :class:`freestyle.types.Interface1D`\n" + " :return: True.\n" + " :rtype: bool\n"; static int TrueUP1D___init__(BPy_TrueUP1D *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {NULL}; + static const char *kwlist[] = {NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_up1D.up1D = new Predicates1D::TrueUP1D(); - return 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) + return -1; + self->py_up1D.up1D = new Predicates1D::TrueUP1D(); + return 0; } /*-----------------------BPy_TrueUP1D type definition ------------------------------*/ PyTypeObject TrueUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TrueUP1D", /* tp_name */ - sizeof(BPy_TrueUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TrueUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TrueUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "TrueUP1D", /* tp_name */ + sizeof(BPy_TrueUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TrueUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TrueUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.h index 5d4420a2ccd..49c3dcdacca 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_TrueUP1D.h @@ -35,7 +35,7 @@ extern PyTypeObject TrueUP1D_Type; /*---------------------------Python BPy_TrueUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_TrueUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.cpp b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.cpp index 26269c34dc7..4fc163dbd01 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.cpp +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.cpp @@ -29,77 +29,80 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- static char WithinImageBoundaryUP1D___doc__[] = -"Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > :class:`WithinImageBoundaryUP1D`\n" -"\n" -".. method:: __init__(xmin, ymin, xmax, ymax)\n" -"\n" -" Builds an WithinImageBoundaryUP1D object.\n" -"\n" -" :arg xmin: X lower bound of the image boundary.\n" -" :type xmin: float\n" -" :arg ymin: Y lower bound of the image boundary.\n" -" :type ymin: float\n" -" :arg xmax: X upper bound of the image boundary.\n" -" :type xmax: float\n" -" :arg ymax: Y upper bound of the image boundary.\n" -" :type ymax: float\n" -"\n" -".. method:: __call__(inter)\n" -"\n" -" Returns true if the Interface1D intersects with image boundary.\n"; + "Class hierarchy: :class:`freestyle.types.UnaryPredicate1D` > " + ":class:`WithinImageBoundaryUP1D`\n" + "\n" + ".. method:: __init__(xmin, ymin, xmax, ymax)\n" + "\n" + " Builds an WithinImageBoundaryUP1D object.\n" + "\n" + " :arg xmin: X lower bound of the image boundary.\n" + " :type xmin: float\n" + " :arg ymin: Y lower bound of the image boundary.\n" + " :type ymin: float\n" + " :arg xmax: X upper bound of the image boundary.\n" + " :type xmax: float\n" + " :arg ymax: Y upper bound of the image boundary.\n" + " :type ymax: float\n" + "\n" + ".. method:: __call__(inter)\n" + "\n" + " Returns true if the Interface1D intersects with image boundary.\n"; -static int WithinImageBoundaryUP1D___init__(BPy_WithinImageBoundaryUP1D *self, PyObject *args, PyObject *kwds) +static int WithinImageBoundaryUP1D___init__(BPy_WithinImageBoundaryUP1D *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL}; - double xmin, ymin, xmax, ymax; + static const char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL}; + double xmin, ymin, xmax, ymax; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "dddd", (char **)kwlist, &xmin, &ymin, &xmax, &ymax)) - return -1; - self->py_up1D.up1D = new Predicates1D::WithinImageBoundaryUP1D(xmin, ymin, xmax, ymax); - return 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "dddd", (char **)kwlist, &xmin, &ymin, &xmax, &ymax)) + return -1; + self->py_up1D.up1D = new Predicates1D::WithinImageBoundaryUP1D(xmin, ymin, xmax, ymax); + return 0; } /*-----------------------BPy_TrueUP1D type definition ------------------------------*/ PyTypeObject WithinImageBoundaryUP1D_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "WithinImageBoundaryUP1D", /* tp_name */ - sizeof(BPy_WithinImageBoundaryUP1D), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - WithinImageBoundaryUP1D___doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &UnaryPredicate1D_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)WithinImageBoundaryUP1D___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "WithinImageBoundaryUP1D", /* tp_name */ + sizeof(BPy_WithinImageBoundaryUP1D), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + WithinImageBoundaryUP1D___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &UnaryPredicate1D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)WithinImageBoundaryUP1D___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.h b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.h index 39eb3f34b7f..2481beee78e 100644 --- a/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.h +++ b/source/blender/freestyle/intern/python/UnaryPredicate1D/BPy_WithinImageBoundaryUP1D.h @@ -32,11 +32,11 @@ extern "C" { extern PyTypeObject WithinImageBoundaryUP1D_Type; #define BPy_WithinImageBoundaryUP1D_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&WithinImageBoundaryUP1D_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&WithinImageBoundaryUP1D_Type)) /*---------------------------Python BPy_WithinImageBoundaryUP1D structure definition----------*/ typedef struct { - BPy_UnaryPredicate1D py_up1D; + BPy_UnaryPredicate1D py_up1D; } BPy_WithinImageBoundaryUP1D; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/scene_graph/DrawingStyle.h b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h index 5ad16845327..631f4b99adc 100644 --- a/source/blender/freestyle/intern/scene_graph/DrawingStyle.h +++ b/source/blender/freestyle/intern/scene_graph/DrawingStyle.h @@ -23,105 +23,106 @@ */ #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class DrawingStyle -{ -public: - enum STYLE { - FILLED, - LINES, - POINTS, - INVISIBLE, - }; - - inline DrawingStyle() - { - Style = FILLED; - LineWidth = 2.0f; - PointSize = 2.0f; - LightingEnabled = true; - } - - inline explicit DrawingStyle(const DrawingStyle& iBrother); - - virtual ~DrawingStyle() {} - - /*! operators */ - inline DrawingStyle& operator=(const DrawingStyle& ds); - - inline void setStyle(const STYLE iStyle) - { - Style = iStyle; - } - - inline void setLineWidth(const float iLineWidth) - { - LineWidth = iLineWidth; - } - - inline void setPointSize(const float iPointSize) - { - PointSize = iPointSize; - } - - inline void setLightingEnabled(const bool on) - { - LightingEnabled = on; - } - - inline STYLE style() const - { - return Style; - } - - inline float lineWidth() const - { - return LineWidth; - } - - inline float pointSize() const - { - return PointSize; - } - - inline bool lightingEnabled() const - { - return LightingEnabled; - } - -private: - STYLE Style; - float LineWidth; - float PointSize; - bool LightingEnabled; +class DrawingStyle { + public: + enum STYLE { + FILLED, + LINES, + POINTS, + INVISIBLE, + }; + + inline DrawingStyle() + { + Style = FILLED; + LineWidth = 2.0f; + PointSize = 2.0f; + LightingEnabled = true; + } + + inline explicit DrawingStyle(const DrawingStyle &iBrother); + + virtual ~DrawingStyle() + { + } + + /*! operators */ + inline DrawingStyle &operator=(const DrawingStyle &ds); + + inline void setStyle(const STYLE iStyle) + { + Style = iStyle; + } + + inline void setLineWidth(const float iLineWidth) + { + LineWidth = iLineWidth; + } + + inline void setPointSize(const float iPointSize) + { + PointSize = iPointSize; + } + + inline void setLightingEnabled(const bool on) + { + LightingEnabled = on; + } + + inline STYLE style() const + { + return Style; + } + + inline float lineWidth() const + { + return LineWidth; + } + + inline float pointSize() const + { + return PointSize; + } + + inline bool lightingEnabled() const + { + return LightingEnabled; + } + + private: + STYLE Style; + float LineWidth; + float PointSize; + bool LightingEnabled; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:DrawingStyle") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:DrawingStyle") #endif }; -DrawingStyle::DrawingStyle(const DrawingStyle& iBrother) +DrawingStyle::DrawingStyle(const DrawingStyle &iBrother) { - Style = iBrother.Style; - LineWidth = iBrother.LineWidth; - PointSize = iBrother.PointSize; - LightingEnabled = iBrother.LightingEnabled; + Style = iBrother.Style; + LineWidth = iBrother.LineWidth; + PointSize = iBrother.PointSize; + LightingEnabled = iBrother.LightingEnabled; } -DrawingStyle& DrawingStyle::operator=(const DrawingStyle& ds) +DrawingStyle &DrawingStyle::operator=(const DrawingStyle &ds) { - Style = ds.Style; - LineWidth = ds.LineWidth; - PointSize = ds.PointSize; - LightingEnabled = ds.LightingEnabled; + Style = ds.Style; + LineWidth = ds.LineWidth; + PointSize = ds.PointSize; + LightingEnabled = ds.LightingEnabled; - return *this; + return *this; } } /* namespace Freestyle */ -#endif // __FREESTYLE_DRAWING_STYLE_H__ +#endif // __FREESTYLE_DRAWING_STYLE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h index 2a830a40da8..4176a558009 100644 --- a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h +++ b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h @@ -25,441 +25,452 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { /*! Class defining a material */ -class FrsMaterial -{ -public: - /*! Default constructor */ - inline FrsMaterial(); - - /*! Builds a Material from its line, diffuse, ambiant, specular, emissive - * colors, a shininess coefficient and line color priority. - * \param iLine: - * A 4 element float-array containing the line color. - * \param iDiffuse: - * A 4 element float-array containing the diffuse color. - * \param iAmbiant: - * A 4 element float-array containing the ambiant color. - * \param iSpecular: - * A 4 element float-array containing the specular color. - * \param iEmission: - * A 4 element float-array containing the emissive color. - * \param iShininess: - * The shininess coefficient. - * \param iPriority: - * The line color priority. - */ - inline FrsMaterial(const float *iLine, const float *iDiffuse, const float *iAmbiant, const float *iSpecular, - const float *iEmission, const float iShininess, const int iPriority); - - /*! Copy constructor */ - inline FrsMaterial(const FrsMaterial& m); - - /*! Destructor */ - virtual ~FrsMaterial() {} - - /*! Returns the line color as a 4 float array */ - inline const float *line() const - { - return Line; - } - - /*! Returns the red component of the line color */ - inline const float lineR() const - { - return Line[0]; - } - - /*! Returns the green component of the line color */ - inline const float lineG() const - { - return Line[1]; - } - - /*! Returns the blue component of the line color */ - inline const float lineB() const - { - return Line[2]; - } - - /*! Returns the alpha component of the line color */ - inline const float lineA() const - { - return Line[3]; - } - - /*! Returns the diffuse color as a 4 float array */ - inline const float *diffuse() const - { - return Diffuse; - } - - /*! Returns the red component of the diffuse color */ - inline const float diffuseR() const - { - return Diffuse[0]; - } - - /*! Returns the green component of the diffuse color */ - inline const float diffuseG() const - { - return Diffuse[1]; - } - - /*! Returns the blue component of the diffuse color */ - inline const float diffuseB() const - { - return Diffuse[2]; - } - - /*! Returns the alpha component of the diffuse color */ - inline const float diffuseA() const - { - return Diffuse[3]; - } - - /*! Returns the specular color as a 4 float array */ - inline const float *specular() const - { - return Specular; - } - - /*! Returns the red component of the specular color */ - inline const float specularR() const - { - return Specular[0]; - } - - /*! Returns the green component of the specular color */ - inline const float specularG() const - { - return Specular[1]; - } - - /*! Returns the blue component of the specular color */ - inline const float specularB() const - { - return Specular[2]; - } - - /*! Returns the alpha component of the specular color */ - inline const float specularA() const - { - return Specular[3]; - } - - /*! Returns the ambiant color as a 4 float array */ - inline const float *ambient() const - { - return Ambient; - } - - /*! Returns the red component of the ambiant color */ - inline const float ambientR() const - { - return Ambient[0]; - } - - /*! Returns the green component of the ambiant color */ - inline const float ambientG() const - { - return Ambient[1]; - } - - /*! Returns the blue component of the ambiant color */ - inline const float ambientB() const - { - return Ambient[2]; - } - - /*! Returns the alpha component of the ambiant color */ - inline const float ambientA() const - { - return Ambient[3]; - } - - /*! Returns the emissive color as a 4 float array */ - inline const float *emission() const - { - return Emission; - } - - /*! Returns the red component of the emissive color */ - inline const float emissionR() const - { - return Emission[0]; - } - - /*! Returns the green component of the emissive color */ - inline const float emissionG() const - { - return Emission[1]; - } - - /*! Returns the blue component of the emissive color */ - inline const float emissionB() const - { - return Emission[2]; - } - - /*! Returns the alpha component of the emissive color */ - inline const float emissionA() const - { - return Emission[3]; - } - - /*! Returns the shininess coefficient */ - inline const float shininess() const - { - return Shininess; - } - - /*! Returns the line color priority */ - inline const int priority() const - { - return Priority; - } - - /*! Sets the line color. - * \param r: - * Red component - * \param g: - * Green component - * \param b: - * Blue component - * \param a: - * Alpha component - */ - inline void setLine(const float r, const float g, const float b, const float a); - - /*! Sets the diffuse color. - * \param r: - * Red component - * \param g: - * Green component - * \param b: - * Blue component - * \param a: - * Alpha component - */ - inline void setDiffuse(const float r, const float g, const float b, const float a); - - /*! Sets the specular color. - * \param r: - * Red component - * \param g: - * Green component - * \param b: - * Blue component - * \param a: - * Alpha component - */ - inline void setSpecular(const float r, const float g, const float b, const float a); - - /*! Sets the ambiant color. - * \param r: - * Red component - * \param g: - * Green component - * \param b: - * Blue component - * \param a: - * Alpha component - */ - inline void setAmbient(const float r, const float g, const float b, const float a); - - /*! Sets the emissive color. - * \param r: - * Red component - * \param g: - * Green component - * \param b: - * Blue component - * \param a: - * Alpha component - */ - inline void setEmission(const float r, const float g, const float b, const float a); - - /*! Sets the shininess. - * \param s: - * Shininess - */ - inline void setShininess(const float s); - - /*! Sets the line color priority. - * \param priority: - * Priority - */ - inline void setPriority(const int priority); - - /* operators */ - inline FrsMaterial& operator=(const FrsMaterial& m); - inline bool operator!=(const FrsMaterial& m) const; - inline bool operator==(const FrsMaterial& m) const; - -private: - /*! Material properties */ - float Line[4]; - float Diffuse[4]; - float Specular[4]; - float Ambient[4]; - float Emission[4]; - float Shininess; - int Priority; +class FrsMaterial { + public: + /*! Default constructor */ + inline FrsMaterial(); + + /*! Builds a Material from its line, diffuse, ambiant, specular, emissive + * colors, a shininess coefficient and line color priority. + * \param iLine: + * A 4 element float-array containing the line color. + * \param iDiffuse: + * A 4 element float-array containing the diffuse color. + * \param iAmbiant: + * A 4 element float-array containing the ambiant color. + * \param iSpecular: + * A 4 element float-array containing the specular color. + * \param iEmission: + * A 4 element float-array containing the emissive color. + * \param iShininess: + * The shininess coefficient. + * \param iPriority: + * The line color priority. + */ + inline FrsMaterial(const float *iLine, + const float *iDiffuse, + const float *iAmbiant, + const float *iSpecular, + const float *iEmission, + const float iShininess, + const int iPriority); + + /*! Copy constructor */ + inline FrsMaterial(const FrsMaterial &m); + + /*! Destructor */ + virtual ~FrsMaterial() + { + } + + /*! Returns the line color as a 4 float array */ + inline const float *line() const + { + return Line; + } + + /*! Returns the red component of the line color */ + inline const float lineR() const + { + return Line[0]; + } + + /*! Returns the green component of the line color */ + inline const float lineG() const + { + return Line[1]; + } + + /*! Returns the blue component of the line color */ + inline const float lineB() const + { + return Line[2]; + } + + /*! Returns the alpha component of the line color */ + inline const float lineA() const + { + return Line[3]; + } + + /*! Returns the diffuse color as a 4 float array */ + inline const float *diffuse() const + { + return Diffuse; + } + + /*! Returns the red component of the diffuse color */ + inline const float diffuseR() const + { + return Diffuse[0]; + } + + /*! Returns the green component of the diffuse color */ + inline const float diffuseG() const + { + return Diffuse[1]; + } + + /*! Returns the blue component of the diffuse color */ + inline const float diffuseB() const + { + return Diffuse[2]; + } + + /*! Returns the alpha component of the diffuse color */ + inline const float diffuseA() const + { + return Diffuse[3]; + } + + /*! Returns the specular color as a 4 float array */ + inline const float *specular() const + { + return Specular; + } + + /*! Returns the red component of the specular color */ + inline const float specularR() const + { + return Specular[0]; + } + + /*! Returns the green component of the specular color */ + inline const float specularG() const + { + return Specular[1]; + } + + /*! Returns the blue component of the specular color */ + inline const float specularB() const + { + return Specular[2]; + } + + /*! Returns the alpha component of the specular color */ + inline const float specularA() const + { + return Specular[3]; + } + + /*! Returns the ambiant color as a 4 float array */ + inline const float *ambient() const + { + return Ambient; + } + + /*! Returns the red component of the ambiant color */ + inline const float ambientR() const + { + return Ambient[0]; + } + + /*! Returns the green component of the ambiant color */ + inline const float ambientG() const + { + return Ambient[1]; + } + + /*! Returns the blue component of the ambiant color */ + inline const float ambientB() const + { + return Ambient[2]; + } + + /*! Returns the alpha component of the ambiant color */ + inline const float ambientA() const + { + return Ambient[3]; + } + + /*! Returns the emissive color as a 4 float array */ + inline const float *emission() const + { + return Emission; + } + + /*! Returns the red component of the emissive color */ + inline const float emissionR() const + { + return Emission[0]; + } + + /*! Returns the green component of the emissive color */ + inline const float emissionG() const + { + return Emission[1]; + } + + /*! Returns the blue component of the emissive color */ + inline const float emissionB() const + { + return Emission[2]; + } + + /*! Returns the alpha component of the emissive color */ + inline const float emissionA() const + { + return Emission[3]; + } + + /*! Returns the shininess coefficient */ + inline const float shininess() const + { + return Shininess; + } + + /*! Returns the line color priority */ + inline const int priority() const + { + return Priority; + } + + /*! Sets the line color. + * \param r: + * Red component + * \param g: + * Green component + * \param b: + * Blue component + * \param a: + * Alpha component + */ + inline void setLine(const float r, const float g, const float b, const float a); + + /*! Sets the diffuse color. + * \param r: + * Red component + * \param g: + * Green component + * \param b: + * Blue component + * \param a: + * Alpha component + */ + inline void setDiffuse(const float r, const float g, const float b, const float a); + + /*! Sets the specular color. + * \param r: + * Red component + * \param g: + * Green component + * \param b: + * Blue component + * \param a: + * Alpha component + */ + inline void setSpecular(const float r, const float g, const float b, const float a); + + /*! Sets the ambiant color. + * \param r: + * Red component + * \param g: + * Green component + * \param b: + * Blue component + * \param a: + * Alpha component + */ + inline void setAmbient(const float r, const float g, const float b, const float a); + + /*! Sets the emissive color. + * \param r: + * Red component + * \param g: + * Green component + * \param b: + * Blue component + * \param a: + * Alpha component + */ + inline void setEmission(const float r, const float g, const float b, const float a); + + /*! Sets the shininess. + * \param s: + * Shininess + */ + inline void setShininess(const float s); + + /*! Sets the line color priority. + * \param priority: + * Priority + */ + inline void setPriority(const int priority); + + /* operators */ + inline FrsMaterial &operator=(const FrsMaterial &m); + inline bool operator!=(const FrsMaterial &m) const; + inline bool operator==(const FrsMaterial &m) const; + + private: + /*! Material properties */ + float Line[4]; + float Diffuse[4]; + float Specular[4]; + float Ambient[4]; + float Emission[4]; + float Shininess; + int Priority; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsMaterial") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsMaterial") #endif }; FrsMaterial::FrsMaterial() { - Line[0] = Line[1] = Line[2] = 0.0f; - Line[3] = 1.0f; + Line[0] = Line[1] = Line[2] = 0.0f; + Line[3] = 1.0f; - Ambient[0] = Ambient[1] = Ambient[2] = 0.2f; - Ambient[3] = 1.0f; + Ambient[0] = Ambient[1] = Ambient[2] = 0.2f; + Ambient[3] = 1.0f; - Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f; - Diffuse[3] = 1.0f; + Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f; + Diffuse[3] = 1.0f; - Emission[0] = Emission[1] = Emission[2] = 0.0f; - Emission[3] = 1.0f; + Emission[0] = Emission[1] = Emission[2] = 0.0f; + Emission[3] = 1.0f; - Specular[0] = Specular[1] = Specular[2] = 0.0f; - Specular[3] = 1.0f; + Specular[0] = Specular[1] = Specular[2] = 0.0f; + Specular[3] = 1.0f; - Shininess = 0.0f; - Priority = 0; + Shininess = 0.0f; + Priority = 0; } -FrsMaterial::FrsMaterial(const float *iLine, const float *iDiffuse, const float *iAmbiant, const float *iSpecular, - const float *iEmission, const float iShininess, const int iPriority) +FrsMaterial::FrsMaterial(const float *iLine, + const float *iDiffuse, + const float *iAmbiant, + const float *iSpecular, + const float *iEmission, + const float iShininess, + const int iPriority) { - for (int i = 0; i < 4; i++) { - Line[i] = iLine[i]; - Diffuse[i] = iDiffuse[i]; - Specular[i] = iSpecular[i]; - Ambient[i] = iAmbiant[i]; - Emission[i] = iEmission[i]; - } - - Shininess = iShininess; - Priority = iPriority; + for (int i = 0; i < 4; i++) { + Line[i] = iLine[i]; + Diffuse[i] = iDiffuse[i]; + Specular[i] = iSpecular[i]; + Ambient[i] = iAmbiant[i]; + Emission[i] = iEmission[i]; + } + + Shininess = iShininess; + Priority = iPriority; } -FrsMaterial::FrsMaterial(const FrsMaterial& m) +FrsMaterial::FrsMaterial(const FrsMaterial &m) { - for (int i = 0; i < 4; i++) { - Line[i] = m.line()[i]; - Diffuse[i] = m.diffuse()[i]; - Specular[i] = m.specular()[i]; - Ambient[i] = m.ambient()[i]; - Emission[i] = m.emission()[i]; - } - - Shininess = m.shininess(); - Priority = m.priority(); + for (int i = 0; i < 4; i++) { + Line[i] = m.line()[i]; + Diffuse[i] = m.diffuse()[i]; + Specular[i] = m.specular()[i]; + Ambient[i] = m.ambient()[i]; + Emission[i] = m.emission()[i]; + } + + Shininess = m.shininess(); + Priority = m.priority(); } void FrsMaterial::setLine(const float r, const float g, const float b, const float a) { - Line[0] = r; - Line[1] = g; - Line[2] = b; - Line[3] = a; + Line[0] = r; + Line[1] = g; + Line[2] = b; + Line[3] = a; } void FrsMaterial::setDiffuse(const float r, const float g, const float b, const float a) { - Diffuse[0] = r; - Diffuse[1] = g; - Diffuse[2] = b; - Diffuse[3] = a; + Diffuse[0] = r; + Diffuse[1] = g; + Diffuse[2] = b; + Diffuse[3] = a; } void FrsMaterial::setSpecular(const float r, const float g, const float b, const float a) { - Specular[0] = r; - Specular[1] = g; - Specular[2] = b; - Specular[3] = a; + Specular[0] = r; + Specular[1] = g; + Specular[2] = b; + Specular[3] = a; } void FrsMaterial::setAmbient(const float r, const float g, const float b, const float a) { - Ambient[0] = r; - Ambient[1] = g; - Ambient[2] = b; - Ambient[3] = a; + Ambient[0] = r; + Ambient[1] = g; + Ambient[2] = b; + Ambient[3] = a; } void FrsMaterial::setEmission(const float r, const float g, const float b, const float a) { - Emission[0] = r; - Emission[1] = g; - Emission[2] = b; - Emission[3] = a; + Emission[0] = r; + Emission[1] = g; + Emission[2] = b; + Emission[3] = a; } void FrsMaterial::setShininess(const float s) { - Shininess = s; + Shininess = s; } void FrsMaterial::setPriority(const int priority) { - Priority = priority; + Priority = priority; } -FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m) +FrsMaterial &FrsMaterial::operator=(const FrsMaterial &m) { - for (int i = 0; i < 4; i++) { - Line[i] = m.line()[i]; - Diffuse[i] = m.diffuse()[i]; - Specular[i] = m.specular()[i]; - Ambient[i] = m.ambient()[i]; - Emission[i] = m.emission()[i]; - } - - Shininess = m.shininess(); - Priority = m.priority(); - return *this; + for (int i = 0; i < 4; i++) { + Line[i] = m.line()[i]; + Diffuse[i] = m.diffuse()[i]; + Specular[i] = m.specular()[i]; + Ambient[i] = m.ambient()[i]; + Emission[i] = m.emission()[i]; + } + + Shininess = m.shininess(); + Priority = m.priority(); + return *this; } -bool FrsMaterial::operator!=(const FrsMaterial& m) const +bool FrsMaterial::operator!=(const FrsMaterial &m) const { - if (Shininess != m.shininess()) - return true; - if (Priority != m.priority()) - return true; - - for (int i = 0; i < 4; i++) { - if (Line[i] != m.line()[i]) - return true; - if (Diffuse[i] != m.diffuse()[i]) - return true; - if (Specular[i] != m.specular()[i]) - return true; - if (Ambient[i] != m.ambient()[i]) - return true; - if (Emission[i] != m.emission()[i]) - return true; - } - - return false; + if (Shininess != m.shininess()) + return true; + if (Priority != m.priority()) + return true; + + for (int i = 0; i < 4; i++) { + if (Line[i] != m.line()[i]) + return true; + if (Diffuse[i] != m.diffuse()[i]) + return true; + if (Specular[i] != m.specular()[i]) + return true; + if (Ambient[i] != m.ambient()[i]) + return true; + if (Emission[i] != m.emission()[i]) + return true; + } + + return false; } -bool FrsMaterial::operator==(const FrsMaterial& m) const +bool FrsMaterial::operator==(const FrsMaterial &m) const { - return (!((*this) != m)); + return (!((*this) != m)); } } /* namespace Freestyle */ -#endif // __FREESTYLE_MATERIAL_H__ +#endif // __FREESTYLE_MATERIAL_H__ diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp index d39f6fac75d..7a6b276bc44 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp @@ -25,288 +25,303 @@ namespace Freestyle { IndexedFaceSet::IndexedFaceSet() : Rep() { - _Vertices = NULL; - _Normals = NULL; - _FrsMaterials = 0; - _TexCoords = NULL; - _FaceEdgeMarks = 0; - _VSize = 0; - _NSize = 0; - _MSize = 0; - _TSize = 0; - _NumFaces = 0; - _NumVertexPerFace = NULL; - _FaceStyle = NULL; - _VIndices = NULL; - _VISize = 0; - _NIndices = NULL; - _NISize = 0; - _MIndices = NULL; - _MISize = 0; - _TIndices = NULL; - _TISize = 0; + _Vertices = NULL; + _Normals = NULL; + _FrsMaterials = 0; + _TexCoords = NULL; + _FaceEdgeMarks = 0; + _VSize = 0; + _NSize = 0; + _MSize = 0; + _TSize = 0; + _NumFaces = 0; + _NumVertexPerFace = NULL; + _FaceStyle = NULL; + _VIndices = NULL; + _VISize = 0; + _NIndices = NULL; + _NISize = 0; + _MIndices = NULL; + _MISize = 0; + _TIndices = NULL; + _TISize = 0; } -IndexedFaceSet::IndexedFaceSet(float *iVertices, unsigned iVSize, float *iNormals, unsigned iNSize, - FrsMaterial **iMaterials, unsigned iMSize, float *iTexCoords, unsigned iTSize, - unsigned iNumFaces, unsigned *iNumVertexPerFace, TRIANGLES_STYLE *iFaceStyle, - FaceEdgeMark *iFaceEdgeMarks, unsigned *iVIndices, unsigned iVISize, - unsigned *iNIndices, unsigned iNISize, unsigned *iMIndices, unsigned iMISize, - unsigned *iTIndices, unsigned iTISize, unsigned iCopy) -: Rep() +IndexedFaceSet::IndexedFaceSet(float *iVertices, + unsigned iVSize, + float *iNormals, + unsigned iNSize, + FrsMaterial **iMaterials, + unsigned iMSize, + float *iTexCoords, + unsigned iTSize, + unsigned iNumFaces, + unsigned *iNumVertexPerFace, + TRIANGLES_STYLE *iFaceStyle, + FaceEdgeMark *iFaceEdgeMarks, + unsigned *iVIndices, + unsigned iVISize, + unsigned *iNIndices, + unsigned iNISize, + unsigned *iMIndices, + unsigned iMISize, + unsigned *iTIndices, + unsigned iTISize, + unsigned iCopy) + : Rep() { - if (1 == iCopy) { - _VSize = iVSize; - _Vertices = new float[_VSize]; - memcpy(_Vertices, iVertices, iVSize * sizeof(float)); - - _NSize = iNSize; - _Normals = new float[_NSize]; - memcpy(_Normals, iNormals, iNSize * sizeof(float)); - - _MSize = iMSize; - _FrsMaterials = 0; - if (iMaterials) { - _FrsMaterials = new FrsMaterial * [_MSize]; - for (unsigned int i = 0; i < _MSize; ++i) - _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i])); - } - _TSize = iTSize; - _TexCoords = 0; - if (_TSize) { - _TexCoords = new float[_TSize]; - memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float)); - } - - _NumFaces = iNumFaces; - _NumVertexPerFace = new unsigned[_NumFaces]; - memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(unsigned)); - - _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; - memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE)); - - _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; - memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark)); - - _VISize = iVISize; - _VIndices = new unsigned[_VISize]; - memcpy(_VIndices, iVIndices, _VISize * sizeof(unsigned)); - - _NISize = iNISize; - _NIndices = new unsigned[_NISize]; - memcpy(_NIndices, iNIndices, _NISize * sizeof(unsigned)); - - _MISize = iMISize; - _MIndices = 0; - if (iMIndices) { - _MIndices = new unsigned[_MISize]; - memcpy(_MIndices, iMIndices, _MISize * sizeof(unsigned)); - } - _TISize = iTISize; - _TIndices = 0; - if (_TISize) { - _TIndices = new unsigned[_TISize]; - memcpy(_TIndices, iTIndices, _TISize * sizeof(unsigned)); - } - } - else { - _VSize = iVSize; - _Vertices = iVertices; - - _NSize = iNSize; - _Normals = iNormals; - - _MSize = iMSize; - _FrsMaterials = 0; - if (iMaterials) - _FrsMaterials = iMaterials; - - _TSize = iTSize; - _TexCoords = iTexCoords; - - _NumFaces = iNumFaces; - _NumVertexPerFace = iNumVertexPerFace; - _FaceStyle = iFaceStyle; - _FaceEdgeMarks = iFaceEdgeMarks; - - _VISize = iVISize; - _VIndices = iVIndices; - - _NISize = iNISize; - _NIndices = iNIndices; - - _MISize = iMISize; - _MIndices = 0; - if (iMISize) - _MIndices = iMIndices; - - _TISize = iTISize; - _TIndices = iTIndices; - } + if (1 == iCopy) { + _VSize = iVSize; + _Vertices = new float[_VSize]; + memcpy(_Vertices, iVertices, iVSize * sizeof(float)); + + _NSize = iNSize; + _Normals = new float[_NSize]; + memcpy(_Normals, iNormals, iNSize * sizeof(float)); + + _MSize = iMSize; + _FrsMaterials = 0; + if (iMaterials) { + _FrsMaterials = new FrsMaterial *[_MSize]; + for (unsigned int i = 0; i < _MSize; ++i) + _FrsMaterials[i] = new FrsMaterial(*(iMaterials[i])); + } + _TSize = iTSize; + _TexCoords = 0; + if (_TSize) { + _TexCoords = new float[_TSize]; + memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float)); + } + + _NumFaces = iNumFaces; + _NumVertexPerFace = new unsigned[_NumFaces]; + memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(unsigned)); + + _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; + memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE)); + + _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; + memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark)); + + _VISize = iVISize; + _VIndices = new unsigned[_VISize]; + memcpy(_VIndices, iVIndices, _VISize * sizeof(unsigned)); + + _NISize = iNISize; + _NIndices = new unsigned[_NISize]; + memcpy(_NIndices, iNIndices, _NISize * sizeof(unsigned)); + + _MISize = iMISize; + _MIndices = 0; + if (iMIndices) { + _MIndices = new unsigned[_MISize]; + memcpy(_MIndices, iMIndices, _MISize * sizeof(unsigned)); + } + _TISize = iTISize; + _TIndices = 0; + if (_TISize) { + _TIndices = new unsigned[_TISize]; + memcpy(_TIndices, iTIndices, _TISize * sizeof(unsigned)); + } + } + else { + _VSize = iVSize; + _Vertices = iVertices; + + _NSize = iNSize; + _Normals = iNormals; + + _MSize = iMSize; + _FrsMaterials = 0; + if (iMaterials) + _FrsMaterials = iMaterials; + + _TSize = iTSize; + _TexCoords = iTexCoords; + + _NumFaces = iNumFaces; + _NumVertexPerFace = iNumVertexPerFace; + _FaceStyle = iFaceStyle; + _FaceEdgeMarks = iFaceEdgeMarks; + + _VISize = iVISize; + _VIndices = iVIndices; + + _NISize = iNISize; + _NIndices = iNIndices; + + _MISize = iMISize; + _MIndices = 0; + if (iMISize) + _MIndices = iMIndices; + + _TISize = iTISize; + _TIndices = iTIndices; + } } -IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother) +IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet &iBrother) : Rep(iBrother) { - _VSize = iBrother.vsize(); - _Vertices = new float[_VSize]; - memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float)); - - _NSize = iBrother.nsize(); - _Normals = new float[_NSize]; - memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float)); - - _MSize = iBrother.msize(); - if (_MSize) { - _FrsMaterials = new FrsMaterial * [_MSize]; - for (unsigned int i = 0; i < _MSize; ++i) { - _FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i])); - } - } - else { - _FrsMaterials = 0; - } - - _TSize = iBrother.tsize(); - _TexCoords = 0; - if (_TSize) { - _TexCoords = new float[_TSize]; - memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float)); - } - - _NumFaces = iBrother.numFaces(); - _NumVertexPerFace = new unsigned[_NumFaces]; - memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(unsigned)); - - _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; - memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE)); - - _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; - memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark)); - - _VISize = iBrother.visize(); - _VIndices = new unsigned[_VISize]; - memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(unsigned)); - - _NISize = iBrother.nisize(); - _NIndices = new unsigned[_NISize]; - memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(unsigned)); - - _MISize = iBrother.misize(); - if (_MISize) { - _MIndices = new unsigned[_MISize]; - memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(unsigned)); - } - else { - _MIndices = 0; - } - - _TISize = iBrother.tisize(); - _TIndices = 0; - if (_TISize) { - _TIndices = new unsigned[_TISize]; - memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(unsigned)); - } + _VSize = iBrother.vsize(); + _Vertices = new float[_VSize]; + memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float)); + + _NSize = iBrother.nsize(); + _Normals = new float[_NSize]; + memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float)); + + _MSize = iBrother.msize(); + if (_MSize) { + _FrsMaterials = new FrsMaterial *[_MSize]; + for (unsigned int i = 0; i < _MSize; ++i) { + _FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i])); + } + } + else { + _FrsMaterials = 0; + } + + _TSize = iBrother.tsize(); + _TexCoords = 0; + if (_TSize) { + _TexCoords = new float[_TSize]; + memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float)); + } + + _NumFaces = iBrother.numFaces(); + _NumVertexPerFace = new unsigned[_NumFaces]; + memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(unsigned)); + + _FaceStyle = new TRIANGLES_STYLE[_NumFaces]; + memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE)); + + _FaceEdgeMarks = new FaceEdgeMark[_NumFaces]; + memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark)); + + _VISize = iBrother.visize(); + _VIndices = new unsigned[_VISize]; + memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(unsigned)); + + _NISize = iBrother.nisize(); + _NIndices = new unsigned[_NISize]; + memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(unsigned)); + + _MISize = iBrother.misize(); + if (_MISize) { + _MIndices = new unsigned[_MISize]; + memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(unsigned)); + } + else { + _MIndices = 0; + } + + _TISize = iBrother.tisize(); + _TIndices = 0; + if (_TISize) { + _TIndices = new unsigned[_TISize]; + memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(unsigned)); + } } IndexedFaceSet::~IndexedFaceSet() { - if (NULL != _Vertices) { - delete[] _Vertices; - _Vertices = NULL; - } - - if (NULL != _Normals) { - delete[] _Normals; - _Normals = NULL; - } - - if (NULL != _FrsMaterials) { - for (unsigned int i = 0; i < _MSize; ++i) - delete _FrsMaterials[i]; - delete[] _FrsMaterials; - _FrsMaterials = NULL; - } - - if (NULL != _TexCoords) { - delete[] _TexCoords; - _TexCoords = NULL; - } - - if (NULL != _NumVertexPerFace) { - delete[] _NumVertexPerFace; - _NumVertexPerFace = NULL; - } - - if (NULL != _FaceStyle) { - delete[] _FaceStyle; - _FaceStyle = NULL; - } - - if (NULL != _FaceEdgeMarks) { - delete[] _FaceEdgeMarks; - _FaceEdgeMarks = NULL; - } - - if (NULL != _VIndices) { - delete[] _VIndices; - _VIndices = NULL; - } - - if (NULL != _NIndices) { - delete[] _NIndices; - _NIndices = NULL; - } - - if (NULL != _MIndices) { - delete[] _MIndices; - _MIndices = NULL; - } - if (NULL != _TIndices) { - delete[] _TIndices; - _TIndices = NULL; - } + if (NULL != _Vertices) { + delete[] _Vertices; + _Vertices = NULL; + } + + if (NULL != _Normals) { + delete[] _Normals; + _Normals = NULL; + } + + if (NULL != _FrsMaterials) { + for (unsigned int i = 0; i < _MSize; ++i) + delete _FrsMaterials[i]; + delete[] _FrsMaterials; + _FrsMaterials = NULL; + } + + if (NULL != _TexCoords) { + delete[] _TexCoords; + _TexCoords = NULL; + } + + if (NULL != _NumVertexPerFace) { + delete[] _NumVertexPerFace; + _NumVertexPerFace = NULL; + } + + if (NULL != _FaceStyle) { + delete[] _FaceStyle; + _FaceStyle = NULL; + } + + if (NULL != _FaceEdgeMarks) { + delete[] _FaceEdgeMarks; + _FaceEdgeMarks = NULL; + } + + if (NULL != _VIndices) { + delete[] _VIndices; + _VIndices = NULL; + } + + if (NULL != _NIndices) { + delete[] _NIndices; + _NIndices = NULL; + } + + if (NULL != _MIndices) { + delete[] _MIndices; + _MIndices = NULL; + } + if (NULL != _TIndices) { + delete[] _TIndices; + _TIndices = NULL; + } } -void IndexedFaceSet::accept(SceneVisitor& v) +void IndexedFaceSet::accept(SceneVisitor &v) { - Rep::accept(v); - v.visitIndexedFaceSet(*this); + Rep::accept(v); + v.visitIndexedFaceSet(*this); } void IndexedFaceSet::ComputeBBox() { - float XMax = _Vertices[0]; - float YMax = _Vertices[1]; - float ZMax = _Vertices[2]; - - float XMin = _Vertices[0]; - float YMin = _Vertices[1]; - float ZMin = _Vertices[2]; - - // parse all the coordinates to find the Xmax, YMax, ZMax - float *v = _Vertices; - - for (unsigned int i = 0; i < (_VSize / 3); ++i) { - if (*v > XMax) - XMax = *v; - if (*v < XMin) - XMin = *v; - ++v; - - if (*v > YMax) - YMax = *v; - if (*v < YMin) - YMin = *v; - ++v; - - if (*v > ZMax) - ZMax = *v; - if (*v < ZMin) - ZMin = *v; - ++v; - } - - setBBox(BBox(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax))); + float XMax = _Vertices[0]; + float YMax = _Vertices[1]; + float ZMax = _Vertices[2]; + + float XMin = _Vertices[0]; + float YMin = _Vertices[1]; + float ZMin = _Vertices[2]; + + // parse all the coordinates to find the Xmax, YMax, ZMax + float *v = _Vertices; + + for (unsigned int i = 0; i < (_VSize / 3); ++i) { + if (*v > XMax) + XMax = *v; + if (*v < XMin) + XMin = *v; + ++v; + + if (*v > YMax) + YMax = *v; + if (*v < YMin) + YMin = *v; + ++v; + + if (*v > ZMax) + ZMax = *v; + if (*v < ZMin) + ZMin = *v; + ++v; + } + + setBBox(BBox(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax))); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h index b875be7200e..83672199e37 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h @@ -32,271 +32,286 @@ namespace Freestyle { -class IndexedFaceSet : public Rep -{ -public: - /*! Triangles description style:*/ - enum TRIANGLES_STYLE { - TRIANGLE_STRIP, - TRIANGLE_FAN, - TRIANGLES, - }; - - /*! User-specified face and edge marks for feature edge detection */ - /* XXX Why in hel not use an enum here too? */ - typedef unsigned char FaceEdgeMark; - static const FaceEdgeMark FACE_MARK = 1 << 0; - static const FaceEdgeMark EDGE_MARK_V1V2 = 1 << 1; - static const FaceEdgeMark EDGE_MARK_V2V3 = 1 << 2; - static const FaceEdgeMark EDGE_MARK_V3V1 = 1 << 3; - - /*! Builds an empty indexed face set */ - IndexedFaceSet(); - - /*! Builds an indexed face set - * iVertices - * The array of object vertices 3D coordinates (for all faces). - * If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not. - * iVSize - * The size of iVertices (must be a multiple of 3) - * iNormals - * The array of object normals 3D coordinates. - * If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not. - * iNSize - * The size of iNormals - * iMaterials - * The array of materials - * iMSize - * The size of iMaterials - * iTexCoords - * The array of texture coordinates. - * iTSize - * The size of iTexCoords (must be multiple of 2) - * iNumFaces - * The number of faces - * iNumVertexPerFace - * Array containing the number of vertices per face. - * iFaceStyle - * Array containing the description style of each faces. - * The style belongs to: - * - TRIANGLE_STRIP: the face indices describe a triangle strip - * - TRIANGLE_FAN : the face indices describe a triangle fan - * - TRIANGLES : the face indices describe single triangles - * If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not. - * iVIndices, - * Array of vertices indices. - * The integers contained in this array must be multiple of 3. - * If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not. - * iVISize - * The size of iVIndices. - * iNIndices - * Array of normals indices. - * The integers contained in this array must be multiple of 3. - * If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not. - * iNISize - * The size of iNIndices - * iMIndices - * The Material indices (per vertex) - * iMISize - * The size of iMIndices - * iTIndices - * The Texture coordinates indices (per vertex). The integers contained in this array must be multiple of 2. - * iTISize - * The size of iMIndices - * iCopy - * 0 : the arrays are not copied. The pointers passed as arguments are used. IndexedFaceSet takes these - * arrays desallocation in charge. - * 1 : the arrays are copied. The caller is in charge of the arrays, passed as arguments desallocation. - */ - IndexedFaceSet(float *iVertices, unsigned iVSize, float *iNormals, unsigned iNSize, FrsMaterial **iMaterials, - unsigned iMSize, float *iTexCoords, unsigned iTSize, unsigned iNumFaces, unsigned *iNumVertexPerFace, - TRIANGLES_STYLE *iFaceStyle, FaceEdgeMark *iFaceEdgeMarks, unsigned *iVIndices, unsigned iVISize, - unsigned *iNIndices, unsigned iNISize, unsigned *iMIndices, unsigned iMISize, unsigned *iTIndices, - unsigned iTISize, unsigned iCopy = 1); - - /*! Builds an indexed face set from an other indexed face set */ - IndexedFaceSet(const IndexedFaceSet& iBrother); - - void swap(IndexedFaceSet& ioOther) - { - std::swap(_Vertices, ioOther._Vertices); - std::swap(_Normals, ioOther._Normals); - std::swap(_FrsMaterials, ioOther._FrsMaterials); - std::swap(_TexCoords, ioOther._TexCoords); - std::swap(_FaceEdgeMarks, ioOther._FaceEdgeMarks); - - std::swap(_VSize, ioOther._VSize); - std::swap(_NSize, ioOther._NSize); - std::swap(_MSize, ioOther._MSize); - std::swap(_TSize, ioOther._TSize); - - std::swap(_NumFaces, ioOther._NumFaces); - std::swap(_NumVertexPerFace, ioOther._NumVertexPerFace); - std::swap(_FaceStyle, ioOther._FaceStyle); - - std::swap(_VIndices, ioOther._VIndices); - std::swap(_NIndices, ioOther._NIndices); - std::swap(_MIndices, ioOther._MIndices); // Material Indices - std::swap(_TIndices, ioOther._TIndices); - - std::swap(_VISize, ioOther._VISize); - std::swap(_NISize, ioOther._NISize); - std::swap(_MISize, ioOther._MISize); - std::swap(_TISize, ioOther._TISize); - - Rep::swap(ioOther); - } - - IndexedFaceSet& operator=(const IndexedFaceSet& iBrother) - { - IndexedFaceSet tmp(iBrother); - swap(tmp); - return *this; - } - - /*! Desctructor - * desallocates all the ressources - */ - virtual ~IndexedFaceSet(); - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Compute the Bounding Box */ - virtual void ComputeBBox(); - - /*! Accessors */ - virtual const float *vertices() const - { - return _Vertices; - } - - virtual const float *normals() const - { - return _Normals; - } - - virtual const FrsMaterial * const *frs_materials() const - { - return _FrsMaterials; - } - - virtual const float *texCoords() const - { - return _TexCoords; - } - - virtual const unsigned vsize() const - { - return _VSize; - } - - virtual const unsigned nsize() const - { - return _NSize; - } - - virtual const unsigned msize() const - { - return _MSize; - } - - virtual const unsigned tsize() const - { - return _TSize; - } - - virtual const unsigned numFaces() const - { - return _NumFaces; - } - - virtual const unsigned *numVertexPerFaces() const - { - return _NumVertexPerFace; - } - - virtual const TRIANGLES_STYLE *trianglesStyle() const - { - return _FaceStyle; - } - - virtual const unsigned char *faceEdgeMarks() const - { - return _FaceEdgeMarks; - } - - virtual const unsigned *vindices() const - { - return _VIndices; - } - - virtual const unsigned *nindices() const - { - return _NIndices; - } - - virtual const unsigned *mindices() const - { - return _MIndices; - } - - virtual const unsigned *tindices() const - { - return _TIndices; - } - - virtual const unsigned visize() const - { - return _VISize; - } - - virtual const unsigned nisize() const - { - return _NISize; - } - - virtual const unsigned misize() const - { - return _MISize; - } - - virtual const unsigned tisize() const - { - return _TISize; - } - -protected: - float *_Vertices; - float *_Normals; - FrsMaterial **_FrsMaterials; - float *_TexCoords; - - unsigned _VSize; - unsigned _NSize; - unsigned _MSize; - unsigned _TSize; - - unsigned _NumFaces; - unsigned *_NumVertexPerFace; - TRIANGLES_STYLE *_FaceStyle; - FaceEdgeMark *_FaceEdgeMarks; - - unsigned *_VIndices; - unsigned *_NIndices; - unsigned *_MIndices; // Material Indices - unsigned *_TIndices; // Texture coordinates Indices - - unsigned _VISize; - unsigned _NISize; - unsigned _MISize; - unsigned _TISize; +class IndexedFaceSet : public Rep { + public: + /*! Triangles description style:*/ + enum TRIANGLES_STYLE { + TRIANGLE_STRIP, + TRIANGLE_FAN, + TRIANGLES, + }; + + /*! User-specified face and edge marks for feature edge detection */ + /* XXX Why in hel not use an enum here too? */ + typedef unsigned char FaceEdgeMark; + static const FaceEdgeMark FACE_MARK = 1 << 0; + static const FaceEdgeMark EDGE_MARK_V1V2 = 1 << 1; + static const FaceEdgeMark EDGE_MARK_V2V3 = 1 << 2; + static const FaceEdgeMark EDGE_MARK_V3V1 = 1 << 3; + + /*! Builds an empty indexed face set */ + IndexedFaceSet(); + + /*! Builds an indexed face set + * iVertices + * The array of object vertices 3D coordinates (for all faces). + * If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not. + * iVSize + * The size of iVertices (must be a multiple of 3) + * iNormals + * The array of object normals 3D coordinates. + * If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not. + * iNSize + * The size of iNormals + * iMaterials + * The array of materials + * iMSize + * The size of iMaterials + * iTexCoords + * The array of texture coordinates. + * iTSize + * The size of iTexCoords (must be multiple of 2) + * iNumFaces + * The number of faces + * iNumVertexPerFace + * Array containing the number of vertices per face. + * iFaceStyle + * Array containing the description style of each faces. + * The style belongs to: + * - TRIANGLE_STRIP: the face indices describe a triangle strip + * - TRIANGLE_FAN : the face indices describe a triangle fan + * - TRIANGLES : the face indices describe single triangles + * If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not. + * iVIndices, + * Array of vertices indices. + * The integers contained in this array must be multiple of 3. + * If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not. + * iVISize + * The size of iVIndices. + * iNIndices + * Array of normals indices. + * The integers contained in this array must be multiple of 3. + * If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not. + * iNISize + * The size of iNIndices + * iMIndices + * The Material indices (per vertex) + * iMISize + * The size of iMIndices + * iTIndices + * The Texture coordinates indices (per vertex). The integers contained in this array must be multiple of 2. + * iTISize + * The size of iMIndices + * iCopy + * 0 : the arrays are not copied. The pointers passed as arguments are used. IndexedFaceSet takes these + * arrays desallocation in charge. + * 1 : the arrays are copied. The caller is in charge of the arrays, passed as arguments desallocation. + */ + IndexedFaceSet(float *iVertices, + unsigned iVSize, + float *iNormals, + unsigned iNSize, + FrsMaterial **iMaterials, + unsigned iMSize, + float *iTexCoords, + unsigned iTSize, + unsigned iNumFaces, + unsigned *iNumVertexPerFace, + TRIANGLES_STYLE *iFaceStyle, + FaceEdgeMark *iFaceEdgeMarks, + unsigned *iVIndices, + unsigned iVISize, + unsigned *iNIndices, + unsigned iNISize, + unsigned *iMIndices, + unsigned iMISize, + unsigned *iTIndices, + unsigned iTISize, + unsigned iCopy = 1); + + /*! Builds an indexed face set from an other indexed face set */ + IndexedFaceSet(const IndexedFaceSet &iBrother); + + void swap(IndexedFaceSet &ioOther) + { + std::swap(_Vertices, ioOther._Vertices); + std::swap(_Normals, ioOther._Normals); + std::swap(_FrsMaterials, ioOther._FrsMaterials); + std::swap(_TexCoords, ioOther._TexCoords); + std::swap(_FaceEdgeMarks, ioOther._FaceEdgeMarks); + + std::swap(_VSize, ioOther._VSize); + std::swap(_NSize, ioOther._NSize); + std::swap(_MSize, ioOther._MSize); + std::swap(_TSize, ioOther._TSize); + + std::swap(_NumFaces, ioOther._NumFaces); + std::swap(_NumVertexPerFace, ioOther._NumVertexPerFace); + std::swap(_FaceStyle, ioOther._FaceStyle); + + std::swap(_VIndices, ioOther._VIndices); + std::swap(_NIndices, ioOther._NIndices); + std::swap(_MIndices, ioOther._MIndices); // Material Indices + std::swap(_TIndices, ioOther._TIndices); + + std::swap(_VISize, ioOther._VISize); + std::swap(_NISize, ioOther._NISize); + std::swap(_MISize, ioOther._MISize); + std::swap(_TISize, ioOther._TISize); + + Rep::swap(ioOther); + } + + IndexedFaceSet &operator=(const IndexedFaceSet &iBrother) + { + IndexedFaceSet tmp(iBrother); + swap(tmp); + return *this; + } + + /*! Desctructor + * desallocates all the ressources + */ + virtual ~IndexedFaceSet(); + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); + + /*! Compute the Bounding Box */ + virtual void ComputeBBox(); + + /*! Accessors */ + virtual const float *vertices() const + { + return _Vertices; + } + + virtual const float *normals() const + { + return _Normals; + } + + virtual const FrsMaterial *const *frs_materials() const + { + return _FrsMaterials; + } + + virtual const float *texCoords() const + { + return _TexCoords; + } + + virtual const unsigned vsize() const + { + return _VSize; + } + + virtual const unsigned nsize() const + { + return _NSize; + } + + virtual const unsigned msize() const + { + return _MSize; + } + + virtual const unsigned tsize() const + { + return _TSize; + } + + virtual const unsigned numFaces() const + { + return _NumFaces; + } + + virtual const unsigned *numVertexPerFaces() const + { + return _NumVertexPerFace; + } + + virtual const TRIANGLES_STYLE *trianglesStyle() const + { + return _FaceStyle; + } + + virtual const unsigned char *faceEdgeMarks() const + { + return _FaceEdgeMarks; + } + + virtual const unsigned *vindices() const + { + return _VIndices; + } + + virtual const unsigned *nindices() const + { + return _NIndices; + } + + virtual const unsigned *mindices() const + { + return _MIndices; + } + + virtual const unsigned *tindices() const + { + return _TIndices; + } + + virtual const unsigned visize() const + { + return _VISize; + } + + virtual const unsigned nisize() const + { + return _NISize; + } + + virtual const unsigned misize() const + { + return _MISize; + } + + virtual const unsigned tisize() const + { + return _TISize; + } + + protected: + float *_Vertices; + float *_Normals; + FrsMaterial **_FrsMaterials; + float *_TexCoords; + + unsigned _VSize; + unsigned _NSize; + unsigned _MSize; + unsigned _TSize; + + unsigned _NumFaces; + unsigned *_NumVertexPerFace; + TRIANGLES_STYLE *_FaceStyle; + FaceEdgeMark *_FaceEdgeMarks; + + unsigned *_VIndices; + unsigned *_NIndices; + unsigned *_MIndices; // Material Indices + unsigned *_TIndices; // Texture coordinates Indices + + unsigned _VISize; + unsigned _NISize; + unsigned _MISize; + unsigned _TISize; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedFaceSet") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedFaceSet") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_INDEXED_FACE_SET_H__ +#endif // __FREESTYLE_INDEXED_FACE_SET_H__ diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.cpp b/source/blender/freestyle/intern/scene_graph/LineRep.cpp index 8484aea0376..39be998cb90 100644 --- a/source/blender/freestyle/intern/scene_graph/LineRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/LineRep.cpp @@ -25,38 +25,38 @@ namespace Freestyle { void LineRep::ComputeBBox() { - real XMax = _vertices.front()[0]; - real YMax = _vertices.front()[1]; - real ZMax = _vertices.front()[2]; - - real XMin = _vertices.front()[0]; - real YMin = _vertices.front()[1]; - real ZMin = _vertices.front()[2]; - - // parse all the coordinates to find - // the XMax, YMax, ZMax - vector::iterator v; - for (v = _vertices.begin(); v != _vertices.end(); ++v) { - // X - if ((*v)[0] > XMax) - XMax = (*v)[0]; - if ((*v)[0] < XMin) - XMin = (*v)[0]; - - // Y - if ((*v)[1] > YMax) - YMax = (*v)[1]; - if ((*v)[1] < YMin) - YMin = (*v)[1]; - - // Z - if ((*v)[2] > ZMax) - ZMax = (*v)[2]; - if ((*v)[2] < ZMin) - ZMin = (*v)[2]; - } - - setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + real XMax = _vertices.front()[0]; + real YMax = _vertices.front()[1]; + real ZMax = _vertices.front()[2]; + + real XMin = _vertices.front()[0]; + real YMin = _vertices.front()[1]; + real ZMin = _vertices.front()[2]; + + // parse all the coordinates to find + // the XMax, YMax, ZMax + vector::iterator v; + for (v = _vertices.begin(); v != _vertices.end(); ++v) { + // X + if ((*v)[0] > XMax) + XMax = (*v)[0]; + if ((*v)[0] < XMin) + XMin = (*v)[0]; + + // Y + if ((*v)[1] > YMax) + YMax = (*v)[1]; + if ((*v)[1] < YMin) + YMin = (*v)[1]; + + // Z + if ((*v)[2] > ZMax) + ZMax = (*v)[2]; + if ((*v)[2] < ZMin) + ZMin = (*v)[2]; + } + + setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/LineRep.h b/source/blender/freestyle/intern/scene_graph/LineRep.h index a7349240e3b..e45a33d9fc4 100644 --- a/source/blender/freestyle/intern/scene_graph/LineRep.h +++ b/source/blender/freestyle/intern/scene_graph/LineRep.h @@ -34,121 +34,120 @@ using namespace std; namespace Freestyle { /*! Base class for all lines objects */ -class LineRep : public Rep -{ -public: - /*! Line description style */ - enum LINES_STYLE { - LINES, - LINE_STRIP, - LINE_LOOP, - }; - - inline LineRep() : Rep() - { - _width = 0.0f; - } - - /*! Builds a single line from 2 vertices - * v1 - * first vertex - * v2 - * second vertex - */ - inline LineRep(const Vec3r& v1, const Vec3r& v2) : Rep() - { - setStyle(LINES); - AddVertex(v1); - AddVertex(v2); - _width = 0.0f; - } - - /*! Builds a line rep from a vertex chain */ - inline LineRep(const vector& vertices) : Rep() - { - _vertices = vertices; - setStyle(LINE_STRIP); - _width = 0.0f; - } - - /*! Builds a line rep from a vertex chain */ - inline LineRep(const list& vertices) : Rep() - { - for (list::const_iterator v = vertices.begin(), end = vertices.end(); v != end; ++v) { - _vertices.push_back(*v); - } - setStyle(LINE_STRIP); - _width = 0.0f; - } - - virtual ~LineRep() - { - _vertices.clear(); - } - - /*! accessors */ - inline const LINES_STYLE style() const - { - return _Style; - } - - inline const vector& vertices() const - { - return _vertices; - } - - inline float width() const - { - return _width; - } - - /*! modifiers */ - inline void setStyle(const LINES_STYLE iStyle) - { - _Style = iStyle; - } - - inline void AddVertex(const Vec3r& iVertex) - { - _vertices.push_back(iVertex); - } - - inline void setVertices(const vector& iVertices) - { - if (0 != _vertices.size()) { - _vertices.clear(); - } - for (vector::const_iterator v = iVertices.begin(), end = iVertices.end(); v != end; ++v) { - _vertices.push_back(*v); - } - } - - inline void setWidth(float iWidth) - { - _width = iWidth; - } - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v) - { - Rep::accept(v); - v.visitLineRep(*this); - } - - /*! Computes the line bounding box.*/ - virtual void ComputeBBox(); - -private: - LINES_STYLE _Style; - vector _vertices; - float _width; +class LineRep : public Rep { + public: + /*! Line description style */ + enum LINES_STYLE { + LINES, + LINE_STRIP, + LINE_LOOP, + }; + + inline LineRep() : Rep() + { + _width = 0.0f; + } + + /*! Builds a single line from 2 vertices + * v1 + * first vertex + * v2 + * second vertex + */ + inline LineRep(const Vec3r &v1, const Vec3r &v2) : Rep() + { + setStyle(LINES); + AddVertex(v1); + AddVertex(v2); + _width = 0.0f; + } + + /*! Builds a line rep from a vertex chain */ + inline LineRep(const vector &vertices) : Rep() + { + _vertices = vertices; + setStyle(LINE_STRIP); + _width = 0.0f; + } + + /*! Builds a line rep from a vertex chain */ + inline LineRep(const list &vertices) : Rep() + { + for (list::const_iterator v = vertices.begin(), end = vertices.end(); v != end; ++v) { + _vertices.push_back(*v); + } + setStyle(LINE_STRIP); + _width = 0.0f; + } + + virtual ~LineRep() + { + _vertices.clear(); + } + + /*! accessors */ + inline const LINES_STYLE style() const + { + return _Style; + } + + inline const vector &vertices() const + { + return _vertices; + } + + inline float width() const + { + return _width; + } + + /*! modifiers */ + inline void setStyle(const LINES_STYLE iStyle) + { + _Style = iStyle; + } + + inline void AddVertex(const Vec3r &iVertex) + { + _vertices.push_back(iVertex); + } + + inline void setVertices(const vector &iVertices) + { + if (0 != _vertices.size()) { + _vertices.clear(); + } + for (vector::const_iterator v = iVertices.begin(), end = iVertices.end(); v != end; + ++v) { + _vertices.push_back(*v); + } + } + + inline void setWidth(float iWidth) + { + _width = iWidth; + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v) + { + Rep::accept(v); + v.visitLineRep(*this); + } + + /*! Computes the line bounding box.*/ + virtual void ComputeBBox(); + + private: + LINES_STYLE _Style; + vector _vertices; + float _width; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:LineRep") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:LineRep") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_LINE_REP_H__ +#endif // __FREESTYLE_LINE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/Node.h b/source/blender/freestyle/intern/scene_graph/Node.h index 5fbbc797ebf..a9424fe14d2 100644 --- a/source/blender/freestyle/intern/scene_graph/Node.h +++ b/source/blender/freestyle/intern/scene_graph/Node.h @@ -37,76 +37,77 @@ namespace Freestyle { using namespace Geometry; -class Node : public BaseObject -{ -public: - inline Node() : BaseObject() {} - - inline Node(const Node& iBrother) : BaseObject() - { - _BBox = iBrother.bbox(); - } - - virtual ~Node() {} - - /*! Accept the corresponding visitor - * Each inherited node must overload this method - */ - virtual void accept(SceneVisitor& v) - { - v.visitNode(*this); - } - - /*! bounding box management */ - /*! Returns the node bounding box - * If no bounding box exists, an empty bbox is returned - */ - virtual const BBox& bbox() const - { - return _BBox; - } - - /*! Sets the Node bounding box */ - virtual void setBBox(const BBox& iBox) - { - _BBox = iBox; - } - - /*! Makes the union of _BBox and iBox */ - virtual void AddBBox(const BBox& iBox) - { - if (iBox.empty()) - return; - - if (_BBox.empty()) - _BBox = iBox; - else - _BBox += iBox; - } - - /*! Updates the BBox */ - virtual const BBox& UpdateBBox() - { - return _BBox; - } - - /*! Clears the bounding box */ - virtual void clearBBox() - { - _BBox.clear(); - } - -protected: - -private: - BBox _BBox; +class Node : public BaseObject { + public: + inline Node() : BaseObject() + { + } + + inline Node(const Node &iBrother) : BaseObject() + { + _BBox = iBrother.bbox(); + } + + virtual ~Node() + { + } + + /*! Accept the corresponding visitor + * Each inherited node must overload this method + */ + virtual void accept(SceneVisitor &v) + { + v.visitNode(*this); + } + + /*! bounding box management */ + /*! Returns the node bounding box + * If no bounding box exists, an empty bbox is returned + */ + virtual const BBox &bbox() const + { + return _BBox; + } + + /*! Sets the Node bounding box */ + virtual void setBBox(const BBox &iBox) + { + _BBox = iBox; + } + + /*! Makes the union of _BBox and iBox */ + virtual void AddBBox(const BBox &iBox) + { + if (iBox.empty()) + return; + + if (_BBox.empty()) + _BBox = iBox; + else + _BBox += iBox; + } + + /*! Updates the BBox */ + virtual const BBox &UpdateBBox() + { + return _BBox; + } + + /*! Clears the bounding box */ + virtual void clearBBox() + { + _BBox.clear(); + } + + protected: + private: + BBox _BBox; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Node") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Node") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_H__ +#endif // __FREESTYLE_NODE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp index 3413cd125c7..30d05ee571c 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.cpp @@ -20,81 +20,97 @@ */ #include -#include // for memcpy +#include // for memcpy #include "NodeCamera.h" namespace Freestyle { -static void loadIdentity(double * matrix) +static void loadIdentity(double *matrix) { - int i; - - // Build Identity matrix - for (i = 0; i < 16; ++i) { - double value ; - if ((i % 5) == 0) - value = 1.0; - else - value = 0; - matrix[i] = value; - } + int i; + + // Build Identity matrix + for (i = 0; i < 16; ++i) { + double value; + if ((i % 5) == 0) + value = 1.0; + else + value = 0; + matrix[i] = value; + } } NodeCamera::NodeCamera(CameraType camera_type) : camera_type_(camera_type) { - loadIdentity(modelview_matrix_); - loadIdentity(projection_matrix_); + loadIdentity(modelview_matrix_); + loadIdentity(projection_matrix_); } -#if 0 /* UNUSED, gives warning in gcc */ +#if 0 /* UNUSED, gives warning in gcc */ NodeCamera::NodeCamera(const NodeCamera& iBrother) : camera_type_(iBrother.camera_type_) { - memcpy(modelview_matrix_, iBrother.modelview_matrix_, 16 * sizeof(double)); - memcpy(projection_matrix_, iBrother.projection_matrix_, 16 * sizeof(double)); + memcpy(modelview_matrix_, iBrother.modelview_matrix_, 16 * sizeof(double)); + memcpy(projection_matrix_, iBrother.projection_matrix_, 16 * sizeof(double)); } #endif -void NodeCamera::accept(SceneVisitor& v) +void NodeCamera::accept(SceneVisitor &v) { - v.visitNodeCamera(*this); + v.visitNodeCamera(*this); } void NodeCamera::setModelViewMatrix(double modelview_matrix[16]) { - memcpy(modelview_matrix_, modelview_matrix, 16 * sizeof(double)); + memcpy(modelview_matrix_, modelview_matrix, 16 * sizeof(double)); } void NodeCamera::setProjectionMatrix(double projection_matrix[16]) { - memcpy(projection_matrix_, projection_matrix, 16 * sizeof(double)); + memcpy(projection_matrix_, projection_matrix, 16 * sizeof(double)); } NodeOrthographicCamera::NodeOrthographicCamera() -: NodeCamera(NodeCamera::ORTHOGRAPHIC), left_(0), right_(0), bottom_(0), top_(0), zNear_(0), zFar_(0) + : NodeCamera(NodeCamera::ORTHOGRAPHIC), + left_(0), + right_(0), + bottom_(0), + top_(0), + zNear_(0), + zFar_(0) { - loadIdentity(projection_matrix_); - loadIdentity(modelview_matrix_); + loadIdentity(projection_matrix_); + loadIdentity(modelview_matrix_); } -NodeOrthographicCamera::NodeOrthographicCamera(double left, double right, double bottom, double top, - double zNear, double zFar) -: NodeCamera(NodeCamera::ORTHOGRAPHIC), left_(left), right_(right), bottom_(bottom), top_(top), - zNear_(zNear), zFar_(zFar) +NodeOrthographicCamera::NodeOrthographicCamera( + double left, double right, double bottom, double top, double zNear, double zFar) + : NodeCamera(NodeCamera::ORTHOGRAPHIC), + left_(left), + right_(right), + bottom_(bottom), + top_(top), + zNear_(zNear), + zFar_(zFar) { - loadIdentity(projection_matrix_); - - projection_matrix_[0] = 2.0 / (right - left); - projection_matrix_[3] = -(right + left) / (right - left) ; - projection_matrix_[5] = 2.0 / (top - bottom); - projection_matrix_[7] = -(top + bottom) / (top - bottom) ; - projection_matrix_[10] = -2.0 / (zFar - zNear); - projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear); + loadIdentity(projection_matrix_); + + projection_matrix_[0] = 2.0 / (right - left); + projection_matrix_[3] = -(right + left) / (right - left); + projection_matrix_[5] = 2.0 / (top - bottom); + projection_matrix_[7] = -(top + bottom) / (top - bottom); + projection_matrix_[10] = -2.0 / (zFar - zNear); + projection_matrix_[11] = -(zFar + zNear) / (zFar - zNear); } -NodeOrthographicCamera::NodeOrthographicCamera(const NodeOrthographicCamera& iBrother) -: NodeCamera(iBrother), left_(iBrother.left_), right_(iBrother.right_), bottom_(iBrother.bottom_), top_(iBrother.top_), - zNear_(iBrother.zNear_), zFar_(iBrother.zFar_) +NodeOrthographicCamera::NodeOrthographicCamera(const NodeOrthographicCamera &iBrother) + : NodeCamera(iBrother), + left_(iBrother.left_), + right_(iBrother.right_), + bottom_(iBrother.bottom_), + top_(iBrother.top_), + zNear_(iBrother.zNear_), + zFar_(iBrother.zFar_) { } @@ -103,34 +119,34 @@ NodePerspectiveCamera::NodePerspectiveCamera() : NodeCamera(NodeCamera::PERSPECT } NodePerspectiveCamera::NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar) -: NodeCamera(NodeCamera::PERSPECTIVE) + : NodeCamera(NodeCamera::PERSPECTIVE) { - loadIdentity(projection_matrix_); + loadIdentity(projection_matrix_); - double f = cos(fovy / 2.0) / sin(fovy / 2.0); // cotangent + double f = cos(fovy / 2.0) / sin(fovy / 2.0); // cotangent - projection_matrix_[0] = f / aspect; - projection_matrix_[5] = f; - projection_matrix_[10] = (zNear + zFar) / (zNear - zFar); - projection_matrix_[11] = (2.0 * zNear * zFar) / (zNear - zFar); - projection_matrix_[14] = -1.0; - projection_matrix_[15] = 0; + projection_matrix_[0] = f / aspect; + projection_matrix_[5] = f; + projection_matrix_[10] = (zNear + zFar) / (zNear - zFar); + projection_matrix_[11] = (2.0 * zNear * zFar) / (zNear - zFar); + projection_matrix_[14] = -1.0; + projection_matrix_[15] = 0; } -NodePerspectiveCamera::NodePerspectiveCamera(double left, double right, double bottom, double top, - double zNear, double zFar) -: NodeCamera(NodeCamera::PERSPECTIVE) +NodePerspectiveCamera::NodePerspectiveCamera( + double left, double right, double bottom, double top, double zNear, double zFar) + : NodeCamera(NodeCamera::PERSPECTIVE) { - loadIdentity(projection_matrix_); - - projection_matrix_[0] = (2.0 * zNear) / (right - left); - projection_matrix_[2] = (right + left) / (right - left); - projection_matrix_[5] = (2.0 * zNear) / (top - bottom); - projection_matrix_[6] = (top + bottom) / (top - bottom); - projection_matrix_[10] = -(zFar + zNear) / (zFar - zNear); - projection_matrix_[11] = -(2.0 * zFar * zNear) / (zFar - zNear); - projection_matrix_[14] = -1.0; - projection_matrix_[15] = 0; + loadIdentity(projection_matrix_); + + projection_matrix_[0] = (2.0 * zNear) / (right - left); + projection_matrix_[2] = (right + left) / (right - left); + projection_matrix_[5] = (2.0 * zNear) / (top - bottom); + projection_matrix_[6] = (top + bottom) / (top - bottom); + projection_matrix_[10] = -(zFar + zNear) / (zFar - zNear); + projection_matrix_[11] = -(2.0 * zFar * zNear) / (zFar - zNear); + projection_matrix_[14] = -1.0; + projection_matrix_[15] = 0; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h b/source/blender/freestyle/intern/scene_graph/NodeCamera.h index cbff332849c..c3c93fa1f88 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.h +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h @@ -36,188 +36,186 @@ class NodeOrthographicCamera; class NodePerspectiveCamera; -class NodeCamera : public Node -{ -public: - typedef enum { - PERSPECTIVE, - ORTHOGRAPHIC, - GENERIC, - } CameraType; - - /*! Default matrices: Identity for both projection and modelview. */ - NodeCamera(CameraType camera_type = GENERIC); -#if 0 /* UNUSED, gives warning in gcc */ - NodeCamera(const NodeCamera& iBrother); +class NodeCamera : public Node { + public: + typedef enum { + PERSPECTIVE, + ORTHOGRAPHIC, + GENERIC, + } CameraType; + + /*! Default matrices: Identity for both projection and modelview. */ + NodeCamera(CameraType camera_type = GENERIC); +#if 0 /* UNUSED, gives warning in gcc */ + NodeCamera(const NodeCamera& iBrother); #endif - virtual ~NodeCamera() {} + virtual ~NodeCamera() + { + } - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); - /*! Matrix is copied */ - void setModelViewMatrix(double modelview_matrix[16]); + /*! Matrix is copied */ + void setModelViewMatrix(double modelview_matrix[16]); - /*! Matrix is copied */ - void setProjectionMatrix(double projection_matrix[16]); + /*! Matrix is copied */ + void setProjectionMatrix(double projection_matrix[16]); - double *modelViewMatrix() - { - return modelview_matrix_; - } + double *modelViewMatrix() + { + return modelview_matrix_; + } - double *projectionMatrix() - { - return projection_matrix_; - } + double *projectionMatrix() + { + return projection_matrix_; + } -protected: - // row major right handed matrix - double modelview_matrix_[16]; - // row major right handed matrix - double projection_matrix_[16]; + protected: + // row major right handed matrix + double modelview_matrix_[16]; + // row major right handed matrix + double projection_matrix_[16]; - CameraType camera_type_; + CameraType camera_type_; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeCamera") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeCamera") #endif - }; -class NodeOrthographicCamera : public NodeCamera -{ -public: - NodeOrthographicCamera(); - - /*! Builds a parallel projection matrix a la glOrtho. - * A 0 0 tx - * 0 B 0 ty - * 0 0 C tz - * 0 0 0 1 - * - * where - * A = 2 / (right - left) - * B = 2 / (top - bottom) - * C = -2 / (far - near) - * tx = -(right + left) / (right - left) - * ty = -(top + bottom) / (top - bottom) - * tz = -(zFar + zNear) / (zFar - zNear) - */ - NodeOrthographicCamera(double left, double right, double bottom, double top, double zNear, double zFar); - - double left() const - { - return left_; - } - - double right() const - { - return right_; - } - - double bottom() const - { - return bottom_; - } - - double top() const - { - return top_; - } - - double zNear() const - { - return zNear_; - } - - double zFar() const - { - return zFar_; - } - - NodeOrthographicCamera(const NodeOrthographicCamera& iBrother); - -private: - double left_; - double right_; - double bottom_; - double top_; - double zNear_; - double zFar_; +class NodeOrthographicCamera : public NodeCamera { + public: + NodeOrthographicCamera(); + + /*! Builds a parallel projection matrix a la glOrtho. + * A 0 0 tx + * 0 B 0 ty + * 0 0 C tz + * 0 0 0 1 + * + * where + * A = 2 / (right - left) + * B = 2 / (top - bottom) + * C = -2 / (far - near) + * tx = -(right + left) / (right - left) + * ty = -(top + bottom) / (top - bottom) + * tz = -(zFar + zNear) / (zFar - zNear) + */ + NodeOrthographicCamera( + double left, double right, double bottom, double top, double zNear, double zFar); + + double left() const + { + return left_; + } + + double right() const + { + return right_; + } + + double bottom() const + { + return bottom_; + } + + double top() const + { + return top_; + } + + double zNear() const + { + return zNear_; + } + + double zFar() const + { + return zFar_; + } + + NodeOrthographicCamera(const NodeOrthographicCamera &iBrother); + + private: + double left_; + double right_; + double bottom_; + double top_; + double zNear_; + double zFar_; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeOrthographicCamera") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeOrthographicCamera") #endif - }; -class NodePerspectiveCamera : public NodeCamera -{ -public: - NodePerspectiveCamera(); - - /*! Builds a perspective projection matrix a la gluPerspective. - * Given f defined as follows: - * fovy - * f = cotangent(____) - * 2 - * The generated matrix is - * ( f ) - * | ______ 0 0 0 | - * | aspect | - * | | - * | 0 f 0 0 | - * | | - * | zNear+zFar 2*zNear*zFar | - * | 0 0 __________ ____________ | - * | zNear-zFar zNear-zFar | - * | | - * ( 0 0 -1 0 ) - * \param fovy: - * Field of View specified in radians. - */ - NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar); - - /*! Builds a perspective projection matrix a la glFrustum. - * ( 2*zNear ) - * | __________ 0 A 0 | - * | right-left | - * | | - * | 2*zNear | - * | 0 __________ B 0 | - * | top-bottom | - * | | - * | 0 0 C D | - * | | - * | 0 0 -1 0 | - * ( ) - * - * right+left - * A = __________ - * right-left - * - * top+bottom - * B = __________ - * top-bottom - * - * zFar+zNear - * C = - __________ - * zFar-zNear - * - * 2*zFar*zNear - * D = - ____________ - * zFar-zNear - */ - NodePerspectiveCamera(double left, double right, double bottom, double top, double zNear, double zFar); +class NodePerspectiveCamera : public NodeCamera { + public: + NodePerspectiveCamera(); + + /*! Builds a perspective projection matrix a la gluPerspective. + * Given f defined as follows: + * fovy + * f = cotangent(____) + * 2 + * The generated matrix is + * ( f ) + * | ______ 0 0 0 | + * | aspect | + * | | + * | 0 f 0 0 | + * | | + * | zNear+zFar 2*zNear*zFar | + * | 0 0 __________ ____________ | + * | zNear-zFar zNear-zFar | + * | | + * ( 0 0 -1 0 ) + * \param fovy: + * Field of View specified in radians. + */ + NodePerspectiveCamera(double fovy, double aspect, double zNear, double zFar); + + /*! Builds a perspective projection matrix a la glFrustum. + * ( 2*zNear ) + * | __________ 0 A 0 | + * | right-left | + * | | + * | 2*zNear | + * | 0 __________ B 0 | + * | top-bottom | + * | | + * | 0 0 C D | + * | | + * | 0 0 -1 0 | + * ( ) + * + * right+left + * A = __________ + * right-left + * + * top+bottom + * B = __________ + * top-bottom + * + * zFar+zNear + * C = - __________ + * zFar-zNear + * + * 2*zFar*zNear + * D = - ____________ + * zFar-zNear + */ + NodePerspectiveCamera( + double left, double right, double bottom, double top, double zNear, double zFar); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodePerspectiveCamera") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodePerspectiveCamera") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_CAMERA_H__ +#endif // __FREESTYLE_NODE_CAMERA_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp index c94ee961881..2564a462407 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.cpp @@ -23,15 +23,16 @@ namespace Freestyle { -void NodeDrawingStyle::accept(SceneVisitor& v) +void NodeDrawingStyle::accept(SceneVisitor &v) { - v.visitNodeDrawingStyle(*this); + v.visitNodeDrawingStyle(*this); - v.visitNodeDrawingStyleBefore(*this); - v.visitDrawingStyle(_DrawingStyle); - for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) - (*node)->accept(v); - v.visitNodeDrawingStyleAfter(*this); + v.visitNodeDrawingStyleBefore(*this); + v.visitDrawingStyle(_DrawingStyle); + for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; + ++node) + (*node)->accept(v); + v.visitNodeDrawingStyleAfter(*this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h index f7bef20bc8f..ea617a912f6 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h +++ b/source/blender/freestyle/intern/scene_graph/NodeDrawingStyle.h @@ -29,79 +29,81 @@ namespace Freestyle { -class NodeDrawingStyle : public NodeGroup -{ -public: - inline NodeDrawingStyle() : NodeGroup() {} - virtual ~NodeDrawingStyle() {} - - inline const DrawingStyle& drawingStyle() const - { - return _DrawingStyle; - } - - inline void setDrawingStyle(const DrawingStyle& iDrawingStyle) - { - _DrawingStyle = iDrawingStyle; - } - - /*! Sets the style. Must be one of FILLED, LINES, POINTS, INVISIBLE. */ - inline void setStyle(const DrawingStyle::STYLE iStyle) - { - _DrawingStyle.setStyle(iStyle); - } - - /*! Sets the line width in the LINES style case */ - inline void setLineWidth(const float iLineWidth) - { - _DrawingStyle.setLineWidth(iLineWidth); - } - - /*! Sets the Point size in the POINTS style case */ - inline void setPointSize(const float iPointSize) - { - _DrawingStyle.setPointSize(iPointSize); - } - - /*! Enables or disables the lighting. true = enable */ - inline void setLightingEnabled(const bool iEnableLighting) - { - _DrawingStyle.setLightingEnabled(iEnableLighting); - } - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! accessors */ - inline DrawingStyle::STYLE style() const - { - return _DrawingStyle.style(); - } - - inline float lineWidth() const - { - return _DrawingStyle.lineWidth(); - } - - inline float pointSize() const - { - return _DrawingStyle.pointSize(); - } - - inline bool lightingEnabled() const - { - return _DrawingStyle.lightingEnabled(); - } - -private: - DrawingStyle _DrawingStyle; +class NodeDrawingStyle : public NodeGroup { + public: + inline NodeDrawingStyle() : NodeGroup() + { + } + virtual ~NodeDrawingStyle() + { + } + + inline const DrawingStyle &drawingStyle() const + { + return _DrawingStyle; + } + + inline void setDrawingStyle(const DrawingStyle &iDrawingStyle) + { + _DrawingStyle = iDrawingStyle; + } + + /*! Sets the style. Must be one of FILLED, LINES, POINTS, INVISIBLE. */ + inline void setStyle(const DrawingStyle::STYLE iStyle) + { + _DrawingStyle.setStyle(iStyle); + } + + /*! Sets the line width in the LINES style case */ + inline void setLineWidth(const float iLineWidth) + { + _DrawingStyle.setLineWidth(iLineWidth); + } + + /*! Sets the Point size in the POINTS style case */ + inline void setPointSize(const float iPointSize) + { + _DrawingStyle.setPointSize(iPointSize); + } + + /*! Enables or disables the lighting. true = enable */ + inline void setLightingEnabled(const bool iEnableLighting) + { + _DrawingStyle.setLightingEnabled(iEnableLighting); + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); + + /*! accessors */ + inline DrawingStyle::STYLE style() const + { + return _DrawingStyle.style(); + } + + inline float lineWidth() const + { + return _DrawingStyle.lineWidth(); + } + + inline float pointSize() const + { + return _DrawingStyle.pointSize(); + } + + inline bool lightingEnabled() const + { + return _DrawingStyle.lightingEnabled(); + } + + private: + DrawingStyle _DrawingStyle; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeDrawingStyle") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NodeDrawingStyle") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_DRAWING_STYLE_H__ +#endif // __FREESTYLE_NODE_DRAWING_STYLE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp index ee1f0b71b20..204e5e1c60e 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.cpp @@ -26,92 +26,93 @@ namespace Freestyle { void NodeGroup::AddChild(Node *iChild) { - if (NULL == iChild) - return; + if (NULL == iChild) + return; - _Children.push_back(iChild); - iChild->addRef(); + _Children.push_back(iChild); + iChild->addRef(); } int NodeGroup::destroy() { - /*! Node::destroy makes a release on the object and then returns the reference counter. - * If the reference counter is equal to 0, that means that nobody else is linking this node group and - * that we can destroy the whole underlying tree. - * Else, one or several Node link this node group, and we only returns the reference counter - * decremented by Node::destroy(); - */ - int refThis = Node::destroy(); - - // if refThis != 0, we can't destroy the tree - if (0 != refThis) - return refThis; - - // If we are here, that means that nobody else needs our NodeGroup and we can destroy it. - int refCount = 0; - vector::iterator node; - - for (node = _Children.begin(); node != _Children.end(); ++node) { - refCount = (*node)->destroy(); - if (0 == refCount) - delete (*node); - } - - _Children.clear(); - - return refThis; + /*! Node::destroy makes a release on the object and then returns the reference counter. + * If the reference counter is equal to 0, that means that nobody else is linking this node group and + * that we can destroy the whole underlying tree. + * Else, one or several Node link this node group, and we only returns the reference counter + * decremented by Node::destroy(); + */ + int refThis = Node::destroy(); + + // if refThis != 0, we can't destroy the tree + if (0 != refThis) + return refThis; + + // If we are here, that means that nobody else needs our NodeGroup and we can destroy it. + int refCount = 0; + vector::iterator node; + + for (node = _Children.begin(); node != _Children.end(); ++node) { + refCount = (*node)->destroy(); + if (0 == refCount) + delete (*node); + } + + _Children.clear(); + + return refThis; } -void NodeGroup::accept(SceneVisitor& v) +void NodeGroup::accept(SceneVisitor &v) { - v.visitNodeGroup(*this); + v.visitNodeGroup(*this); - v.visitNodeGroupBefore(*this); - for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) - (*node)->accept(v); - v.visitNodeGroupAfter(*this); + v.visitNodeGroupBefore(*this); + for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; + ++node) + (*node)->accept(v); + v.visitNodeGroupAfter(*this); } void NodeGroup::DetachChildren() { - vector::iterator node; + vector::iterator node; - for (node = _Children.begin(); node != _Children.end(); ++node) { - (*node)->release(); - } + for (node = _Children.begin(); node != _Children.end(); ++node) { + (*node)->release(); + } - _Children.clear(); + _Children.clear(); } void NodeGroup::DetachChild(Node *iChild) { - /* int found = 0; */ /* UNUSED */ - vector::iterator node; - - for (node = _Children.begin(); node != _Children.end(); ++node) { - if ((*node) == iChild) { - (*node)->release(); - _Children.erase(node); - /* found = 1; */ /* UNUSED */ - break; - } - } + /* int found = 0; */ /* UNUSED */ + vector::iterator node; + + for (node = _Children.begin(); node != _Children.end(); ++node) { + if ((*node) == iChild) { + (*node)->release(); + _Children.erase(node); + /* found = 1; */ /* UNUSED */ + break; + } + } } -void NodeGroup::RetrieveChildren(vector& oNodes) +void NodeGroup::RetrieveChildren(vector &oNodes) { - oNodes = _Children; + oNodes = _Children; } -const BBox& NodeGroup::UpdateBBox() +const BBox &NodeGroup::UpdateBBox() { - vector::iterator node; - clearBBox(); - for (node = _Children.begin(); node != _Children.end(); ++node) { - AddBBox((*node)->UpdateBBox()); - } + vector::iterator node; + clearBBox(); + for (node = _Children.begin(); node != _Children.end(); ++node) { + AddBBox((*node)->UpdateBBox()); + } - return Node::UpdateBBox(); + return Node::UpdateBBox(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.h b/source/blender/freestyle/intern/scene_graph/NodeGroup.h index 23a168eba01..89f81cc2b13 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeGroup.h +++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.h @@ -33,48 +33,51 @@ using namespace std; namespace Freestyle { -class NodeGroup : public Node -{ -public: - inline NodeGroup(): Node() {} - virtual ~NodeGroup() {} +class NodeGroup : public Node { + public: + inline NodeGroup() : Node() + { + } + virtual ~NodeGroup() + { + } - /*! Adds a child. Makes a addRef on the iChild reference counter */ - virtual void AddChild(Node *iChild); + /*! Adds a child. Makes a addRef on the iChild reference counter */ + virtual void AddChild(Node *iChild); - /*! destroys all the underlying nodes - * Returns the reference counter after having done a release() - */ - virtual int destroy(); + /*! destroys all the underlying nodes + * Returns the reference counter after having done a release() + */ + virtual int destroy(); - /*! Detaches all the children */ - virtual void DetachChildren(); + /*! Detaches all the children */ + virtual void DetachChildren(); - /*! Detached the sepcified child */ - virtual void DetachChild(Node *iChild); + /*! Detached the sepcified child */ + virtual void DetachChild(Node *iChild); - /*! Retrieve children */ - virtual void RetrieveChildren(vector& oNodes); + /*! Retrieve children */ + virtual void RetrieveChildren(vector &oNodes); - /*! Renders every children */ -// virtual void Render(Renderer *iRenderer); + /*! Renders every children */ + // virtual void Render(Renderer *iRenderer); - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); - /*! Updates the BBox */ - virtual const BBox& UpdateBBox(); + /*! Updates the BBox */ + virtual const BBox &UpdateBBox(); - /*! Returns the number of children */ - virtual int numberOfChildren() - { - return _Children.size(); - } + /*! Returns the number of children */ + virtual int numberOfChildren() + { + return _Children.size(); + } -protected: - vector _Children; + protected: + vector _Children; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_GROUP_H__ +#endif // __FREESTYLE_NODE_GROUP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.cpp b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp index 9e513f6a488..f6585d9f932 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeLight.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeLight.cpp @@ -27,51 +27,51 @@ int NodeLight::numberOfLights = 0; NodeLight::NodeLight() : Node() { - if (numberOfLights > 7) { - _number = 7; - } - else { - _number = numberOfLights; - numberOfLights++; - } + if (numberOfLights > 7) { + _number = 7; + } + else { + _number = numberOfLights; + numberOfLights++; + } - Ambient[0] = Ambient[1] = Ambient[2] = 0.0f; - Ambient[3] = 1.0f; + Ambient[0] = Ambient[1] = Ambient[2] = 0.0f; + Ambient[3] = 1.0f; - for (int i = 0; i < 4; i++) { - Diffuse[i] = 1.0f; - Specular[i] = 1.0f; - } + for (int i = 0; i < 4; i++) { + Diffuse[i] = 1.0f; + Specular[i] = 1.0f; + } - Position[0] = Position[1] = Position[3] = 0.0f; - Position[2] = 1.0f; + Position[0] = Position[1] = Position[3] = 0.0f; + Position[2] = 1.0f; - on = true; + on = true; } -NodeLight::NodeLight(NodeLight& iBrother) : Node(iBrother) +NodeLight::NodeLight(NodeLight &iBrother) : Node(iBrother) { - if (numberOfLights > 7) { - _number = 7; - } - else { - _number = numberOfLights; - numberOfLights++; - } + if (numberOfLights > 7) { + _number = 7; + } + else { + _number = numberOfLights; + numberOfLights++; + } - for (int i = 0; i < 4; i++) { - Ambient[i] = iBrother.ambient()[i]; - Diffuse[i] = iBrother.diffuse()[i]; - Specular[i] = iBrother.specular()[i]; - Position[i] = iBrother.position()[i]; - } + for (int i = 0; i < 4; i++) { + Ambient[i] = iBrother.ambient()[i]; + Diffuse[i] = iBrother.diffuse()[i]; + Specular[i] = iBrother.specular()[i]; + Position[i] = iBrother.position()[i]; + } - on = iBrother.isOn(); + on = iBrother.isOn(); } -void NodeLight::accept(SceneVisitor& v) +void NodeLight::accept(SceneVisitor &v) { - v.visitNodeLight(*this); + v.visitNodeLight(*this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeLight.h b/source/blender/freestyle/intern/scene_graph/NodeLight.h index 4381d047540..046b61beaf4 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeLight.h +++ b/source/blender/freestyle/intern/scene_graph/NodeLight.h @@ -32,73 +32,74 @@ namespace Freestyle { using namespace Geometry; -class NodeLight : public Node -{ -public: - NodeLight(); - NodeLight(NodeLight& iBrother); - - virtual ~NodeLight() {} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Accessors for the light properties */ - inline const float * ambient() const - { - return Ambient; - } - - inline const float * diffuse() const - { - return Diffuse; - } - - inline const float * specular() const - { - return Specular; - } - - inline const float * position() const - { - return Position; - } - - inline bool isOn() const - { - return on; - } - - inline int number() const - { - return _number; - } - -private: - // Data members - // ============ - - /*! on=true, the light is on */ - bool on; - - /*! The color definition */ - float Ambient[4]; - float Diffuse[4]; - float Specular[4]; - - /*! Light position. if w = 0, the light is placed at infinite. */ - float Position[4]; - - /*! used to manage the number of lights */ - /*! numberOfLights - * the number of lights in the scene. - * Initially, 0. - */ - static int numberOfLights; - /*! The current lignt number */ - int _number; +class NodeLight : public Node { + public: + NodeLight(); + NodeLight(NodeLight &iBrother); + + virtual ~NodeLight() + { + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); + + /*! Accessors for the light properties */ + inline const float *ambient() const + { + return Ambient; + } + + inline const float *diffuse() const + { + return Diffuse; + } + + inline const float *specular() const + { + return Specular; + } + + inline const float *position() const + { + return Position; + } + + inline bool isOn() const + { + return on; + } + + inline int number() const + { + return _number; + } + + private: + // Data members + // ============ + + /*! on=true, the light is on */ + bool on; + + /*! The color definition */ + float Ambient[4]; + float Diffuse[4]; + float Specular[4]; + + /*! Light position. if w = 0, the light is placed at infinite. */ + float Position[4]; + + /*! used to manage the number of lights */ + /*! numberOfLights + * the number of lights in the scene. + * Initially, 0. + */ + static int numberOfLights; + /*! The current lignt number */ + int _number; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_LIGHT_H__ +#endif // __FREESTYLE_NODE_LIGHT_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.cpp b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp index 56c8068ad62..b16ca3eda33 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeShape.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeShape.cpp @@ -25,30 +25,30 @@ namespace Freestyle { NodeShape::~NodeShape() { - vector::iterator rep; + vector::iterator rep; - if (0 != _Shapes.size()) { - for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) { - int refCount = (*rep)->destroy(); - if (0 == refCount) - delete (*rep); - } + if (0 != _Shapes.size()) { + for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) { + int refCount = (*rep)->destroy(); + if (0 == refCount) + delete (*rep); + } - _Shapes.clear(); - } + _Shapes.clear(); + } } -void NodeShape::accept(SceneVisitor& v) +void NodeShape::accept(SceneVisitor &v) { - v.visitNodeShape(*this); + v.visitNodeShape(*this); - v.visitFrsMaterial(_FrsMaterial); + v.visitFrsMaterial(_FrsMaterial); - v.visitNodeShapeBefore(*this); - vector::iterator rep; - for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) - (*rep)->accept(v); - v.visitNodeShapeAfter(*this); + v.visitNodeShapeBefore(*this); + vector::iterator rep; + for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) + (*rep)->accept(v); + v.visitNodeShapeAfter(*this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeShape.h b/source/blender/freestyle/intern/scene_graph/NodeShape.h index f0dd24a9d14..ec7e09d6c88 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeShape.h +++ b/source/blender/freestyle/intern/scene_graph/NodeShape.h @@ -39,57 +39,58 @@ namespace Freestyle { using namespace Geometry; -class NodeShape : public Node -{ -public: - inline NodeShape() : Node() {} - - virtual ~NodeShape(); - - /*! Adds a Rep to the _Shapes list - * The delete of the rep is done when it is not used any more by the Scene Manager. - * So, it must not be deleted by the caller - */ - virtual void AddRep(Rep *iRep) - { - if (NULL == iRep) - return; - _Shapes.push_back(iRep); - iRep->addRef(); - - // updates bbox: - AddBBox(iRep->bbox()); - } - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Sets the shape material */ - inline void setFrsMaterial(const FrsMaterial& iMaterial) - { - _FrsMaterial = iMaterial; - } - - /*! accessors */ - /*! returns the shape's material */ - inline FrsMaterial& frs_material() - { - return _FrsMaterial; - } - - inline const vector& shapes() - { - return _Shapes; - } - -private: - /*! list of shapes */ - vector _Shapes; - - /*! Shape Material */ - FrsMaterial _FrsMaterial; +class NodeShape : public Node { + public: + inline NodeShape() : Node() + { + } + + virtual ~NodeShape(); + + /*! Adds a Rep to the _Shapes list + * The delete of the rep is done when it is not used any more by the Scene Manager. + * So, it must not be deleted by the caller + */ + virtual void AddRep(Rep *iRep) + { + if (NULL == iRep) + return; + _Shapes.push_back(iRep); + iRep->addRef(); + + // updates bbox: + AddBBox(iRep->bbox()); + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); + + /*! Sets the shape material */ + inline void setFrsMaterial(const FrsMaterial &iMaterial) + { + _FrsMaterial = iMaterial; + } + + /*! accessors */ + /*! returns the shape's material */ + inline FrsMaterial &frs_material() + { + return _FrsMaterial; + } + + inline const vector &shapes() + { + return _Shapes; + } + + private: + /*! list of shapes */ + vector _Shapes; + + /*! Shape Material */ + FrsMaterial _FrsMaterial; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_SHAPE_H__ +#endif // __FREESTYLE_NODE_SHAPE_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp index b4af715b3e4..69179eb6c84 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.cpp @@ -28,142 +28,142 @@ namespace Freestyle { void NodeTransform::Translate(real x, real y, real z) { - _Matrix(0, 3) += x; - _Matrix(1, 3) += y; - _Matrix(2, 3) += z; + _Matrix(0, 3) += x; + _Matrix(1, 3) += y; + _Matrix(2, 3) += z; } void NodeTransform::Rotate(real iAngle, real x, real y, real z) { - //Normalize the x,y,z vector; - real norm = (real)sqrt(x * x + y * y + z * z); - if (0 == norm) - return; - - x /= norm; - y /= norm; - z /= norm; - - /* find the corresponding matrix with the Rodrigues formula: - * R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda - */ - Matrix33r Ntilda; - Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f; - Ntilda(0, 1) = -z; - Ntilda(0, 2) = y; - Ntilda(1, 0) = z; - Ntilda(1, 2) = -x; - Ntilda(2, 0) = -y; - Ntilda(2, 1) = x; - - const Matrix33r Ntilda2(Ntilda * Ntilda); - - - const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI); - const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI); - - Matrix33r NS(Ntilda * sinAngle); - Matrix33r NC(Ntilda2 * (1.0f - cosAngle)); - Matrix33r R; - R = Matrix33r::identity(); - R += NS + NC; - - // R4 is the corresponding 4x4 matrix - Matrix44r R4; - R4 = Matrix44r::identity(); - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) - R4(i, j) = R(i, j); - } - - // Finally, we multiply our current matrix by R4: - Matrix44r mat_tmp(_Matrix); - _Matrix = mat_tmp * R4; + //Normalize the x,y,z vector; + real norm = (real)sqrt(x * x + y * y + z * z); + if (0 == norm) + return; + + x /= norm; + y /= norm; + z /= norm; + + /* find the corresponding matrix with the Rodrigues formula: + * R = I + sin(iAngle)*Ntilda + (1-cos(iAngle))*Ntilda*Ntilda + */ + Matrix33r Ntilda; + Ntilda(0, 0) = Ntilda(1, 1) = Ntilda(2, 2) = 0.0f; + Ntilda(0, 1) = -z; + Ntilda(0, 2) = y; + Ntilda(1, 0) = z; + Ntilda(1, 2) = -x; + Ntilda(2, 0) = -y; + Ntilda(2, 1) = x; + + const Matrix33r Ntilda2(Ntilda * Ntilda); + + const real sinAngle = (real)sin((iAngle / 180.0f) * M_PI); + const real cosAngle = (real)cos((iAngle / 180.0f) * M_PI); + + Matrix33r NS(Ntilda * sinAngle); + Matrix33r NC(Ntilda2 * (1.0f - cosAngle)); + Matrix33r R; + R = Matrix33r::identity(); + R += NS + NC; + + // R4 is the corresponding 4x4 matrix + Matrix44r R4; + R4 = Matrix44r::identity(); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) + R4(i, j) = R(i, j); + } + + // Finally, we multiply our current matrix by R4: + Matrix44r mat_tmp(_Matrix); + _Matrix = mat_tmp * R4; } void NodeTransform::Scale(real x, real y, real z) { - _Matrix(0, 0) *= x; - _Matrix(1, 1) *= y; - _Matrix(2, 2) *= z; + _Matrix(0, 0) *= x; + _Matrix(1, 1) *= y; + _Matrix(2, 2) *= z; - _Scaled = true; + _Scaled = true; } void NodeTransform::MultiplyMatrix(const Matrix44r &iMatrix) { - Matrix44r mat_tmp(_Matrix); - _Matrix = mat_tmp * iMatrix; + Matrix44r mat_tmp(_Matrix); + _Matrix = mat_tmp * iMatrix; } void NodeTransform::setMatrix(const Matrix44r &iMatrix) { - _Matrix = iMatrix; - if (isScaled(iMatrix)) - _Scaled = true; + _Matrix = iMatrix; + if (isScaled(iMatrix)) + _Scaled = true; } -void NodeTransform::accept(SceneVisitor& v) +void NodeTransform::accept(SceneVisitor &v) { - v.visitNodeTransform(*this); + v.visitNodeTransform(*this); - v.visitNodeTransformBefore(*this); - for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; ++node) - (*node)->accept(v); - v.visitNodeTransformAfter(*this); + v.visitNodeTransformBefore(*this); + for (vector::iterator node = _Children.begin(), end = _Children.end(); node != end; + ++node) + (*node)->accept(v); + v.visitNodeTransformAfter(*this); } -void NodeTransform::AddBBox(const BBox& iBBox) +void NodeTransform::AddBBox(const BBox &iBBox) { - Vec3r oldMin(iBBox.getMin()); - Vec3r oldMax(iBBox.getMax()); - - // compute the 8 corners of the bbox - HVec3r box[8]; - box[0] = HVec3r(iBBox.getMin()); - box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]); - box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]); - box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]); - box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]); - box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]); - box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]); - box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]); - - // Computes the transform iBBox - HVec3r tbox[8]; - unsigned int i; - for (i = 0; i < 8; i++) - tbox[i] = _Matrix * box[i]; - - Vec3r newMin(tbox[0]); - Vec3r newMax(tbox[0]); - for (i = 0; i < 8; i++) { - for (unsigned int j = 0; j < 3; j++) { - if (newMin[j] > tbox[i][j]) - newMin[j] = tbox[i][j]; - if (newMax[j] < tbox[i][j]) - newMax[j] = tbox[i][j]; - } - } - - BBox transformBox(newMin, newMax); - - Node::AddBBox(transformBox); + Vec3r oldMin(iBBox.getMin()); + Vec3r oldMax(iBBox.getMax()); + + // compute the 8 corners of the bbox + HVec3r box[8]; + box[0] = HVec3r(iBBox.getMin()); + box[1] = HVec3r(oldMax[0], oldMin[1], oldMin[2]); + box[2] = HVec3r(oldMax[0], oldMax[1], oldMin[2]); + box[3] = HVec3r(oldMin[0], oldMax[1], oldMin[2]); + box[4] = HVec3r(oldMin[0], oldMin[1], oldMax[2]); + box[5] = HVec3r(oldMax[0], oldMin[1], oldMax[2]); + box[6] = HVec3r(oldMax[0], oldMax[1], oldMax[2]); + box[7] = HVec3r(oldMin[0], oldMax[1], oldMax[2]); + + // Computes the transform iBBox + HVec3r tbox[8]; + unsigned int i; + for (i = 0; i < 8; i++) + tbox[i] = _Matrix * box[i]; + + Vec3r newMin(tbox[0]); + Vec3r newMax(tbox[0]); + for (i = 0; i < 8; i++) { + for (unsigned int j = 0; j < 3; j++) { + if (newMin[j] > tbox[i][j]) + newMin[j] = tbox[i][j]; + if (newMax[j] < tbox[i][j]) + newMax[j] = tbox[i][j]; + } + } + + BBox transformBox(newMin, newMax); + + Node::AddBBox(transformBox); } bool NodeTransform::isScaled(const Matrix44r &M) { - for (unsigned int j = 0; j < 3; j++) { - real norm = 0; - for (unsigned int i = 0; i < 3; i++) { - norm += M(i, j) * M(i, j); - } - if ((norm > 1.01) || (norm < 0.99)) - return true; - } - - return false; + for (unsigned int j = 0; j < 3; j++) { + real norm = 0; + for (unsigned int i = 0; i < 3; i++) { + norm += M(i, j) * M(i, j); + } + if ((norm > 1.01) || (norm < 0.99)) + return true; + } + + return false; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeTransform.h b/source/blender/freestyle/intern/scene_graph/NodeTransform.h index 29760cd1951..c816d30c03b 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeTransform.h +++ b/source/blender/freestyle/intern/scene_graph/NodeTransform.h @@ -33,69 +33,70 @@ namespace Freestyle { using namespace Geometry; -class NodeTransform : public NodeGroup -{ -public: - inline NodeTransform() : NodeGroup() - { - _Matrix = Matrix44r::identity(); - _Scaled = false; - } - - virtual ~NodeTransform() {} - - /*! multiplys the current matrix by the x, y, z translation matrix. */ - void Translate(real x, real y, real z); - - /*! multiplys the current matrix by a rotation matrix - * iAngle - * The rotation angle - * x, y, z - * The rotation axis - */ - void Rotate(real iAngle, real x, real y, real z); - - /*! multiplys the current matrix by a scaling matrix. - * x, y, z - * The scaling coefficients with respect to the x,y,z axis - */ - void Scale(real x, real y, real z); - - /*! Multiplys the current matrix by iMatrix */ - void MultiplyMatrix(const Matrix44r &iMatrix); - - /*! Sets the current matrix to iMatrix */ - void setMatrix(const Matrix44r &iMatrix); - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); - - /*! Overloads the Node::AddBBox in order to take care about the transformation */ - virtual void AddBBox(const BBox& iBBox); - - /*! Checks whether a matrix contains a scale factor or not. - * Returns true if yes. - * M - * The matrix to check - */ - bool isScaled(const Matrix44r &M); - - /*! accessors */ - inline const Matrix44r& matrix() const - { - return _Matrix; - } - - inline bool scaled() const - { - return _Scaled; - } - -private: - Matrix44r _Matrix; - bool _Scaled; +class NodeTransform : public NodeGroup { + public: + inline NodeTransform() : NodeGroup() + { + _Matrix = Matrix44r::identity(); + _Scaled = false; + } + + virtual ~NodeTransform() + { + } + + /*! multiplys the current matrix by the x, y, z translation matrix. */ + void Translate(real x, real y, real z); + + /*! multiplys the current matrix by a rotation matrix + * iAngle + * The rotation angle + * x, y, z + * The rotation axis + */ + void Rotate(real iAngle, real x, real y, real z); + + /*! multiplys the current matrix by a scaling matrix. + * x, y, z + * The scaling coefficients with respect to the x,y,z axis + */ + void Scale(real x, real y, real z); + + /*! Multiplys the current matrix by iMatrix */ + void MultiplyMatrix(const Matrix44r &iMatrix); + + /*! Sets the current matrix to iMatrix */ + void setMatrix(const Matrix44r &iMatrix); + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); + + /*! Overloads the Node::AddBBox in order to take care about the transformation */ + virtual void AddBBox(const BBox &iBBox); + + /*! Checks whether a matrix contains a scale factor or not. + * Returns true if yes. + * M + * The matrix to check + */ + bool isScaled(const Matrix44r &M); + + /*! accessors */ + inline const Matrix44r &matrix() const + { + return _Matrix; + } + + inline bool scaled() const + { + return _Scaled; + } + + private: + Matrix44r _Matrix; + bool _Scaled; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_TRANSFORM_H__ +#endif // __FREESTYLE_NODE_TRANSFORM_H__ diff --git a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp index 24e1e88afa0..6c64f8a53d9 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp +++ b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp @@ -23,9 +23,9 @@ namespace Freestyle { -void NodeViewLayer::accept(SceneVisitor& v) +void NodeViewLayer::accept(SceneVisitor &v) { - v.visitNodeViewLayer(*this); + v.visitNodeViewLayer(*this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h index 9a646208dec..f220bbfd6f1 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h +++ b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h @@ -32,31 +32,34 @@ using namespace std; namespace Freestyle { -class NodeViewLayer : public Node -{ -public: - inline NodeViewLayer(Scene& scene, ViewLayer& view_layer) : Node(), _Scene(scene), _ViewLayer(view_layer) {} - virtual ~NodeViewLayer() {} +class NodeViewLayer : public Node { + public: + inline NodeViewLayer(Scene &scene, ViewLayer &view_layer) + : Node(), _Scene(scene), _ViewLayer(view_layer) + { + } + virtual ~NodeViewLayer() + { + } - inline struct Scene& scene() const - { - return _Scene; - } + inline struct Scene &scene() const + { + return _Scene; + } - inline struct ViewLayer& sceneLayer() const - { - return _ViewLayer; - } + inline struct ViewLayer &sceneLayer() const + { + return _ViewLayer; + } - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); -protected: - - Scene& _Scene; - ViewLayer& _ViewLayer; + protected: + Scene &_Scene; + ViewLayer &_ViewLayer; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_NODE_VIEW_LAYER_H__ +#endif // __FREESTYLE_NODE_VIEW_LAYER_H__ diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp index ba1dfe7478e..60730528f1a 100644 --- a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.cpp @@ -25,13 +25,13 @@ namespace Freestyle { -void OrientedLineRep::accept(SceneVisitor& v) +void OrientedLineRep::accept(SceneVisitor &v) { - Rep::accept(v); - if (!frs_material()) - v.visitOrientedLineRep(*this); - else - v.visitLineRep(*this); + Rep::accept(v); + if (!frs_material()) + v.visitOrientedLineRep(*this); + else + v.visitLineRep(*this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h index af06840419e..2e39259077e 100644 --- a/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h +++ b/source/blender/freestyle/intern/scene_graph/OrientedLineRep.h @@ -28,30 +28,39 @@ namespace Freestyle { -class OrientedLineRep : public LineRep -{ -public: - OrientedLineRep() : LineRep() {} - /*! Builds a single line from 2 vertices - * v1 - * first vertex - * v2 - * second vertex - */ - inline OrientedLineRep(const Vec3r& v1, const Vec3r& v2) : LineRep(v1, v2) {} - - /*! Builds a line rep from a vertex chain */ - inline OrientedLineRep(const vector& vertices) : LineRep(vertices) {} - - /*! Builds a line rep from a vertex chain */ - inline OrientedLineRep(const list& vertices) : LineRep(vertices) {} - - virtual ~OrientedLineRep() {} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v); +class OrientedLineRep : public LineRep { + public: + OrientedLineRep() : LineRep() + { + } + /*! Builds a single line from 2 vertices + * v1 + * first vertex + * v2 + * second vertex + */ + inline OrientedLineRep(const Vec3r &v1, const Vec3r &v2) : LineRep(v1, v2) + { + } + + /*! Builds a line rep from a vertex chain */ + inline OrientedLineRep(const vector &vertices) : LineRep(vertices) + { + } + + /*! Builds a line rep from a vertex chain */ + inline OrientedLineRep(const list &vertices) : LineRep(vertices) + { + } + + virtual ~OrientedLineRep() + { + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v); }; } /* namespace Freestyle */ -#endif // __FREESTYLE_ORIENTED_LINE_REP_H__ +#endif // __FREESTYLE_ORIENTED_LINE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/Rep.h b/source/blender/freestyle/intern/scene_graph/Rep.h index db4e9e6782b..7b5e752ea07 100644 --- a/source/blender/freestyle/intern/scene_graph/Rep.h +++ b/source/blender/freestyle/intern/scene_graph/Rep.h @@ -40,143 +40,142 @@ namespace Freestyle { using namespace Geometry; -class Rep : public BaseObject -{ -public: - inline Rep() : BaseObject() - { - _Id = 0; - _FrsMaterial = 0; - } - - inline Rep(const Rep& iBrother) : BaseObject() - { - _Id = iBrother._Id; - _Name = iBrother._Name; - _LibraryPath = iBrother._LibraryPath; - if (0 == iBrother._FrsMaterial) - _FrsMaterial = 0; - else - _FrsMaterial = new FrsMaterial(*(iBrother._FrsMaterial)); - - _BBox = iBrother.bbox(); - } - - inline void swap(Rep& ioOther) - { - std::swap(_BBox, ioOther._BBox); - std::swap(_Id, ioOther._Id); - std::swap(_Name, ioOther._Name); - std::swap(_LibraryPath, ioOther._LibraryPath); - std::swap(_FrsMaterial, ioOther._FrsMaterial); - } - - Rep& operator=(const Rep& iBrother) - { - if (&iBrother != this) { - _Id = iBrother._Id; - _Name = iBrother._Name; - _LibraryPath = iBrother._LibraryPath; - if (0 == iBrother._FrsMaterial) { - _FrsMaterial = 0; - } - else { - if (_FrsMaterial == 0) { - _FrsMaterial = new FrsMaterial(*iBrother._FrsMaterial); - } - else { - (*_FrsMaterial) = (*(iBrother._FrsMaterial)); - } - _BBox = iBrother.bbox(); - } - } - return *this; - } - - virtual ~Rep() - { - if (0 != _FrsMaterial) { - delete _FrsMaterial; - _FrsMaterial = 0; - } - } - - /*! Accept the corresponding visitor - * Must be overload by inherited classes - */ - virtual void accept(SceneVisitor& v) - { - if (_FrsMaterial) - v.visitFrsMaterial(*_FrsMaterial); - v.visitRep(*this); - } - - /*! Computes the rep bounding box. - * Each Inherited rep must compute its bbox depending on the way the data are stored. So, each inherited class - * must overload this method - */ - virtual void ComputeBBox() = 0; - - /*! Returns the rep bounding box */ - virtual const BBox& bbox() const - { - return _BBox; - } - - inline Id getId() const - { - return _Id; - } - - inline const string& getName() const - { - return _Name; - } - - inline const string& getLibraryPath() const - { - return _LibraryPath; - } - - inline const FrsMaterial *frs_material() const - { - return _FrsMaterial; - } - - /*! Sets the Rep bounding box */ - virtual void setBBox(const BBox& iBox) - { - _BBox = iBox; - } - - inline void setId(const Id& id) - { - _Id = id; - } - - inline void setName(const string& name) - { - _Name = name; - } - - inline void setLibraryPath(const string& path) - { - _LibraryPath = path; - } - - inline void setFrsMaterial(const FrsMaterial& iMaterial) - { - _FrsMaterial = new FrsMaterial(iMaterial); - } - -private: - BBox _BBox; - Id _Id; - string _Name; - string _LibraryPath; - FrsMaterial *_FrsMaterial; +class Rep : public BaseObject { + public: + inline Rep() : BaseObject() + { + _Id = 0; + _FrsMaterial = 0; + } + + inline Rep(const Rep &iBrother) : BaseObject() + { + _Id = iBrother._Id; + _Name = iBrother._Name; + _LibraryPath = iBrother._LibraryPath; + if (0 == iBrother._FrsMaterial) + _FrsMaterial = 0; + else + _FrsMaterial = new FrsMaterial(*(iBrother._FrsMaterial)); + + _BBox = iBrother.bbox(); + } + + inline void swap(Rep &ioOther) + { + std::swap(_BBox, ioOther._BBox); + std::swap(_Id, ioOther._Id); + std::swap(_Name, ioOther._Name); + std::swap(_LibraryPath, ioOther._LibraryPath); + std::swap(_FrsMaterial, ioOther._FrsMaterial); + } + + Rep &operator=(const Rep &iBrother) + { + if (&iBrother != this) { + _Id = iBrother._Id; + _Name = iBrother._Name; + _LibraryPath = iBrother._LibraryPath; + if (0 == iBrother._FrsMaterial) { + _FrsMaterial = 0; + } + else { + if (_FrsMaterial == 0) { + _FrsMaterial = new FrsMaterial(*iBrother._FrsMaterial); + } + else { + (*_FrsMaterial) = (*(iBrother._FrsMaterial)); + } + _BBox = iBrother.bbox(); + } + } + return *this; + } + + virtual ~Rep() + { + if (0 != _FrsMaterial) { + delete _FrsMaterial; + _FrsMaterial = 0; + } + } + + /*! Accept the corresponding visitor + * Must be overload by inherited classes + */ + virtual void accept(SceneVisitor &v) + { + if (_FrsMaterial) + v.visitFrsMaterial(*_FrsMaterial); + v.visitRep(*this); + } + + /*! Computes the rep bounding box. + * Each Inherited rep must compute its bbox depending on the way the data are stored. So, each inherited class + * must overload this method + */ + virtual void ComputeBBox() = 0; + + /*! Returns the rep bounding box */ + virtual const BBox &bbox() const + { + return _BBox; + } + + inline Id getId() const + { + return _Id; + } + + inline const string &getName() const + { + return _Name; + } + + inline const string &getLibraryPath() const + { + return _LibraryPath; + } + + inline const FrsMaterial *frs_material() const + { + return _FrsMaterial; + } + + /*! Sets the Rep bounding box */ + virtual void setBBox(const BBox &iBox) + { + _BBox = iBox; + } + + inline void setId(const Id &id) + { + _Id = id; + } + + inline void setName(const string &name) + { + _Name = name; + } + + inline void setLibraryPath(const string &path) + { + _LibraryPath = path; + } + + inline void setFrsMaterial(const FrsMaterial &iMaterial) + { + _FrsMaterial = new FrsMaterial(iMaterial); + } + + private: + BBox _BBox; + Id _Id; + string _Name; + string _LibraryPath; + FrsMaterial *_FrsMaterial; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_REP_H__ +#endif // __FREESTYLE_REP_H__ diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp index fcecb67cae9..b5d954664e4 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp @@ -26,55 +26,55 @@ namespace Freestyle { string SceneHash::toString() { - stringstream ss; - ss << hex << _sum; - return ss.str(); + stringstream ss; + ss << hex << _sum; + return ss.str(); } -void SceneHash::visitNodeViewLayer(NodeViewLayer& node) +void SceneHash::visitNodeViewLayer(NodeViewLayer &node) { - struct RenderData *r = &node.scene().r; - adler32((unsigned char *)&r->xsch, sizeof(r->xsch)); // resolution_x - adler32((unsigned char *)&r->ysch, sizeof(r->ysch)); // resolution_y - adler32((unsigned char *)&r->size, sizeof(r->size)); // resolution_percentage + struct RenderData *r = &node.scene().r; + adler32((unsigned char *)&r->xsch, sizeof(r->xsch)); // resolution_x + adler32((unsigned char *)&r->ysch, sizeof(r->ysch)); // resolution_y + adler32((unsigned char *)&r->size, sizeof(r->size)); // resolution_percentage - struct FreestyleConfig *config = &node.sceneLayer().freestyle_config; - adler32((unsigned char *)&config->flags, sizeof(config->flags)); - adler32((unsigned char *)&config->crease_angle, sizeof(config->crease_angle)); - adler32((unsigned char *)&config->sphere_radius, sizeof(config->sphere_radius)); - adler32((unsigned char *)&config->dkr_epsilon, sizeof(config->dkr_epsilon)); + struct FreestyleConfig *config = &node.sceneLayer().freestyle_config; + adler32((unsigned char *)&config->flags, sizeof(config->flags)); + adler32((unsigned char *)&config->crease_angle, sizeof(config->crease_angle)); + adler32((unsigned char *)&config->sphere_radius, sizeof(config->sphere_radius)); + adler32((unsigned char *)&config->dkr_epsilon, sizeof(config->dkr_epsilon)); } -void SceneHash::visitNodeCamera(NodeCamera& cam) +void SceneHash::visitNodeCamera(NodeCamera &cam) { - double *proj = cam.projectionMatrix(); - for (int i = 0; i < 16; i++) { - adler32((unsigned char *)&proj[i], sizeof(double)); - } + double *proj = cam.projectionMatrix(); + for (int i = 0; i < 16; i++) { + adler32((unsigned char *)&proj[i], sizeof(double)); + } } -void SceneHash::visitIndexedFaceSet(IndexedFaceSet& ifs) +void SceneHash::visitIndexedFaceSet(IndexedFaceSet &ifs) { - const float *v = ifs.vertices(); - const unsigned n = ifs.vsize(); + const float *v = ifs.vertices(); + const unsigned n = ifs.vsize(); - for (unsigned i = 0; i < n; i++) { - adler32((unsigned char *)&v[i], sizeof(v[i])); - } + for (unsigned i = 0; i < n; i++) { + adler32((unsigned char *)&v[i], sizeof(v[i])); + } } static const int MOD_ADLER = 65521; void SceneHash::adler32(unsigned char *data, int size) { - uint32_t sum1 = _sum & 0xffff; - uint32_t sum2 = (_sum >> 16) & 0xffff; + uint32_t sum1 = _sum & 0xffff; + uint32_t sum2 = (_sum >> 16) & 0xffff; - for (int i = 0; i < size; i++) { - sum1 = (sum1 + data[i]) % MOD_ADLER; - sum2 = (sum1 + sum2) % MOD_ADLER; - } - _sum = sum1 | (sum2 << 16); + for (int i = 0; i < size; i++) { + sum1 = (sum1 + data[i]) % MOD_ADLER; + sum2 = (sum1 + sum2) % MOD_ADLER; + } + _sum = sum1 | (sum2 << 16); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.h b/source/blender/freestyle/intern/scene_graph/SceneHash.h index 4c6bd6216d0..05a8aadc8c5 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneHash.h +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h @@ -29,50 +29,54 @@ #include "BLI_sys_types.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class SceneHash : public SceneVisitor -{ -public: - inline SceneHash() : SceneVisitor() - { - _sum = 1; - } +class SceneHash : public SceneVisitor { + public: + inline SceneHash() : SceneVisitor() + { + _sum = 1; + } - virtual ~SceneHash() {} + virtual ~SceneHash() + { + } - VISIT_DECL(NodeCamera) - VISIT_DECL(NodeViewLayer) - VISIT_DECL(IndexedFaceSet) + VISIT_DECL(NodeCamera) + VISIT_DECL(NodeViewLayer) + VISIT_DECL(IndexedFaceSet) - string toString(); + string toString(); - inline bool match() { - return _sum == _prevSum; - } + inline bool match() + { + return _sum == _prevSum; + } - inline void store() { - _prevSum = _sum; - } + inline void store() + { + _prevSum = _sum; + } - inline void reset() { - _sum = 1; - } + inline void reset() + { + _sum = 1; + } -private: - void adler32(unsigned char *data, int size); + private: + void adler32(unsigned char *data, int size); - uint32_t _sum; - uint32_t _prevSum; + uint32_t _sum; + uint32_t _prevSum; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_SCENE_HASH_H__ +#endif // __FREESTYLE_SCENE_HASH_H__ diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp index 29da69a37ee..0c533232179 100644 --- a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp +++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp @@ -26,11 +26,11 @@ namespace Freestyle { -#define VISIT(CLASS) \ - void ScenePrettyPrinter::visit##CLASS(CLASS&) \ - { \ - _ofs << _space << #CLASS << endl; \ - } +#define VISIT(CLASS) \ + void ScenePrettyPrinter::visit##CLASS(CLASS &) \ + { \ + _ofs << _space << #CLASS << endl; \ + } VISIT(Node) VISIT(NodeShape) @@ -39,44 +39,44 @@ VISIT(NodeLight) VISIT(NodeDrawingStyle) VISIT(NodeTransform) -void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape&) +void ScenePrettyPrinter::visitNodeShapeBefore(NodeShape &) { - increaseSpace(); + increaseSpace(); } -void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape&) +void ScenePrettyPrinter::visitNodeShapeAfter(NodeShape &) { - decreaseSpace(); + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup&) +void ScenePrettyPrinter::visitNodeGroupBefore(NodeGroup &) { - increaseSpace(); + increaseSpace(); } -void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup&) +void ScenePrettyPrinter::visitNodeGroupAfter(NodeGroup &) { - decreaseSpace(); + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle&) +void ScenePrettyPrinter::visitNodeDrawingStyleBefore(NodeDrawingStyle &) { - increaseSpace(); + increaseSpace(); } -void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle&) +void ScenePrettyPrinter::visitNodeDrawingStyleAfter(NodeDrawingStyle &) { - decreaseSpace(); + decreaseSpace(); } -void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform&) +void ScenePrettyPrinter::visitNodeTransformBefore(NodeTransform &) { - increaseSpace(); + increaseSpace(); } -void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform&) +void ScenePrettyPrinter::visitNodeTransformAfter(NodeTransform &) { - decreaseSpace(); + decreaseSpace(); } VISIT(LineRep) @@ -84,17 +84,18 @@ VISIT(OrientedLineRep) VISIT(TriangleRep) VISIT(VertexRep) -void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet& ifs) +void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet &ifs) { - const float *vertices = ifs.vertices(); - unsigned vsize = ifs.vsize(); - - _ofs << _space << "IndexedFaceSet" << endl; - const float *p = vertices; - for (unsigned int i = 0; i < vsize / 3; i++) { - _ofs << _space << " " << setw(3) << setfill('0') << i << ": " << p[0] << ", " << p[1] << ", " << p[2] << endl; - p += 3; - } + const float *vertices = ifs.vertices(); + unsigned vsize = ifs.vsize(); + + _ofs << _space << "IndexedFaceSet" << endl; + const float *p = vertices; + for (unsigned int i = 0; i < vsize / 3; i++) { + _ofs << _space << " " << setw(3) << setfill('0') << i << ": " << p[0] << ", " << p[1] << ", " + << p[2] << endl; + p += 3; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h index 715f78ab044..989e9e36faa 100644 --- a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h +++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.h @@ -32,68 +32,66 @@ using namespace std; namespace Freestyle { -class ScenePrettyPrinter : public SceneVisitor -{ -public: - ScenePrettyPrinter(const string filename = "SceneLog.txt") : SceneVisitor() - { - if (!filename.empty()) - _ofs.open(filename.c_str()); - if (!_ofs.is_open()) - cerr << "Warning, unable to open file \"" << filename << "\"" << endl; - _space = ""; - } - - virtual ~ScenePrettyPrinter() - { - if (_ofs.is_open()) - _ofs.close(); - } - - - // - // visitClass methods - // - ////////////////////////////////////////////// - - VISIT_DECL(Node); - VISIT_DECL(NodeShape); - VISIT_DECL(NodeGroup); - VISIT_DECL(NodeLight); - VISIT_DECL(NodeDrawingStyle); - VISIT_DECL(NodeTransform); - - VISIT_DECL(LineRep); - VISIT_DECL(OrientedLineRep); - VISIT_DECL(TriangleRep); - VISIT_DECL(VertexRep); - VISIT_DECL(IndexedFaceSet); - - virtual void visitNodeShapeBefore(NodeShape&); - virtual void visitNodeShapeAfter(NodeShape&); - virtual void visitNodeGroupBefore(NodeGroup&); - virtual void visitNodeGroupAfter(NodeGroup&); - virtual void visitNodeDrawingStyleBefore(NodeDrawingStyle&); - virtual void visitNodeDrawingStyleAfter(NodeDrawingStyle&); - virtual void visitNodeTransformBefore(NodeTransform&); - virtual void visitNodeTransformAfter(NodeTransform&); - -protected: - void increaseSpace() - { - _space += " "; - } - - void decreaseSpace() - { - _space.erase(0, 2); - } - -private: - ofstream _ofs; - string _space; +class ScenePrettyPrinter : public SceneVisitor { + public: + ScenePrettyPrinter(const string filename = "SceneLog.txt") : SceneVisitor() + { + if (!filename.empty()) + _ofs.open(filename.c_str()); + if (!_ofs.is_open()) + cerr << "Warning, unable to open file \"" << filename << "\"" << endl; + _space = ""; + } + + virtual ~ScenePrettyPrinter() + { + if (_ofs.is_open()) + _ofs.close(); + } + + // + // visitClass methods + // + ////////////////////////////////////////////// + + VISIT_DECL(Node); + VISIT_DECL(NodeShape); + VISIT_DECL(NodeGroup); + VISIT_DECL(NodeLight); + VISIT_DECL(NodeDrawingStyle); + VISIT_DECL(NodeTransform); + + VISIT_DECL(LineRep); + VISIT_DECL(OrientedLineRep); + VISIT_DECL(TriangleRep); + VISIT_DECL(VertexRep); + VISIT_DECL(IndexedFaceSet); + + virtual void visitNodeShapeBefore(NodeShape &); + virtual void visitNodeShapeAfter(NodeShape &); + virtual void visitNodeGroupBefore(NodeGroup &); + virtual void visitNodeGroupAfter(NodeGroup &); + virtual void visitNodeDrawingStyleBefore(NodeDrawingStyle &); + virtual void visitNodeDrawingStyleAfter(NodeDrawingStyle &); + virtual void visitNodeTransformBefore(NodeTransform &); + virtual void visitNodeTransformAfter(NodeTransform &); + + protected: + void increaseSpace() + { + _space += " "; + } + + void decreaseSpace() + { + _space.erase(0, 2); + } + + private: + ofstream _ofs; + string _space; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_SCENE_PRETTY_PRINTER_H__ +#endif // __FREESTYLE_SCENE_PRETTY_PRINTER_H__ diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h index 67b89f014cf..d1b64663ca9 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h +++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h @@ -25,23 +25,28 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -#define VISIT_COMPLETE_DEF(type) \ - virtual void visit##type(type&) {} \ - virtual void visit##type##Before(type&) {} \ - virtual void visit##type##After(type&) {} +#define VISIT_COMPLETE_DEF(type) \ + virtual void visit##type(type &) \ + { \ + } \ + virtual void visit##type##Before(type &) \ + { \ + } \ + virtual void visit##type##After(type &) \ + { \ + } -#define VISIT_DECL(type) \ - virtual void visit##type(type&); +#define VISIT_DECL(type) virtual void visit##type(type &); -#define VISIT_COMPLETE_DECL(type) \ - virtual void visit##type##Before(type&); \ - virtual void visit##type(type&); \ - virtual void visit##type##After(type&); +#define VISIT_COMPLETE_DECL(type) \ + virtual void visit##type##Before(type &); \ + virtual void visit##type(type &); \ + virtual void visit##type##After(type &); class Node; class NodeShape; @@ -61,43 +66,50 @@ class IndexedFaceSet; class DrawingStyle; class FrsMaterial; -class SceneVisitor -{ -public: - SceneVisitor() {} - virtual ~SceneVisitor() {} - - virtual void beginScene() {} - virtual void endScene() {} - - // - // visitClass methods - // - ////////////////////////////////////////////// - - VISIT_COMPLETE_DEF(Node) - VISIT_COMPLETE_DEF(NodeShape) - VISIT_COMPLETE_DEF(NodeGroup) - VISIT_COMPLETE_DEF(NodeLight) - VISIT_COMPLETE_DEF(NodeCamera) - VISIT_COMPLETE_DEF(NodeDrawingStyle) - VISIT_COMPLETE_DEF(NodeTransform) - VISIT_COMPLETE_DEF(NodeViewLayer) - - VISIT_COMPLETE_DEF(Rep) - VISIT_COMPLETE_DEF(LineRep) - VISIT_COMPLETE_DEF(OrientedLineRep) - VISIT_COMPLETE_DEF(TriangleRep) - VISIT_COMPLETE_DEF(VertexRep) - VISIT_COMPLETE_DEF(IndexedFaceSet) - VISIT_COMPLETE_DEF(DrawingStyle) - VISIT_COMPLETE_DEF(FrsMaterial) +class SceneVisitor { + public: + SceneVisitor() + { + } + virtual ~SceneVisitor() + { + } + + virtual void beginScene() + { + } + virtual void endScene() + { + } + + // + // visitClass methods + // + ////////////////////////////////////////////// + + VISIT_COMPLETE_DEF(Node) + VISIT_COMPLETE_DEF(NodeShape) + VISIT_COMPLETE_DEF(NodeGroup) + VISIT_COMPLETE_DEF(NodeLight) + VISIT_COMPLETE_DEF(NodeCamera) + VISIT_COMPLETE_DEF(NodeDrawingStyle) + VISIT_COMPLETE_DEF(NodeTransform) + VISIT_COMPLETE_DEF(NodeViewLayer) + + VISIT_COMPLETE_DEF(Rep) + VISIT_COMPLETE_DEF(LineRep) + VISIT_COMPLETE_DEF(OrientedLineRep) + VISIT_COMPLETE_DEF(TriangleRep) + VISIT_COMPLETE_DEF(VertexRep) + VISIT_COMPLETE_DEF(IndexedFaceSet) + VISIT_COMPLETE_DEF(DrawingStyle) + VISIT_COMPLETE_DEF(FrsMaterial) #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneVisitor") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneVisitor") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_SCENE_VISITOR_H__ +#endif // __FREESTYLE_SCENE_VISITOR_H__ diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp index dbd5efc65f5..ab8ee9e9bb6 100644 --- a/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.cpp @@ -25,36 +25,36 @@ namespace Freestyle { void TriangleRep::ComputeBBox() { - real XMax = _vertices[0][0]; - real YMax = _vertices[0][1]; - real ZMax = _vertices[0][2]; - - real XMin = _vertices[0][0]; - real YMin = _vertices[0][1]; - real ZMin = _vertices[0][2]; - - // parse all the coordinates to find the XMax, YMax, ZMax - for (int i = 0; i < 3; ++i) { - // X - if (_vertices[i][0] > XMax) - XMax = _vertices[i][0]; - if (_vertices[i][0] < XMin) - XMin = _vertices[i][0]; - - // Y - if (_vertices[i][1] > YMax) - YMax = _vertices[i][1]; - if (_vertices[i][1] < YMin) - YMin = _vertices[i][1]; - - // Z - if (_vertices[i][2] > ZMax) - ZMax = _vertices[i][2]; - if (_vertices[i][2] < ZMin) - ZMin = _vertices[i][2]; - } - - setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + real XMax = _vertices[0][0]; + real YMax = _vertices[0][1]; + real ZMax = _vertices[0][2]; + + real XMin = _vertices[0][0]; + real YMin = _vertices[0][1]; + real ZMin = _vertices[0][2]; + + // parse all the coordinates to find the XMax, YMax, ZMax + for (int i = 0; i < 3; ++i) { + // X + if (_vertices[i][0] > XMax) + XMax = _vertices[i][0]; + if (_vertices[i][0] < XMin) + XMin = _vertices[i][0]; + + // Y + if (_vertices[i][1] > YMax) + YMax = _vertices[i][1]; + if (_vertices[i][1] < YMin) + YMin = _vertices[i][1]; + + // Z + if (_vertices[i][2] > ZMax) + ZMax = _vertices[i][2]; + if (_vertices[i][2] < ZMin) + ZMin = _vertices[i][2]; + } + + setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/TriangleRep.h b/source/blender/freestyle/intern/scene_graph/TriangleRep.h index 364943a14ba..5385ae941cd 100644 --- a/source/blender/freestyle/intern/scene_graph/TriangleRep.h +++ b/source/blender/freestyle/intern/scene_graph/TriangleRep.h @@ -28,112 +28,117 @@ namespace Freestyle { /*! Base class for all lines objects */ -class TriangleRep : public Rep -{ -public: - /*! Line description style */ - enum TRIANGLE_STYLE { - FILL, - LINES, - }; - -private: - TRIANGLE_STYLE _Style; - Vec3r _vertices[3]; - Vec3r _colors[3]; - -public: - inline TriangleRep() : Rep() - { - _Style = FILL; - } - - /*! Builds a triangle from 3 vertices - * v0 - * first vertex - * v1 - * second vertex - * v2 - * third vertex - */ - inline TriangleRep(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) : Rep() - { - _vertices[0] = v0; - _vertices[1] = v1; - _vertices[2] = v2; - _Style = FILL; - } - - inline TriangleRep(const Vec3r& v0, const Vec3r& c0, const Vec3r& v1, const Vec3r& c1, - const Vec3r& v2, const Vec3r& c2) - : Rep() - { - _vertices[0] = v0; - _vertices[1] = v1; - _vertices[2] = v2; - _colors[0] = c0; - _colors[1] = c1; - _colors[2] = c2; - _Style = FILL; - } - - virtual ~TriangleRep() {} - - /*! accessors */ - inline const TRIANGLE_STYLE style() const - { - return _Style; - } - - inline const Vec3r& vertex(int index) const - { - return _vertices[index]; - } - - inline const Vec3r& color(int index) const - { - return _colors[index]; - } - - /*! modifiers */ - inline void setStyle(const TRIANGLE_STYLE iStyle) - { - _Style = iStyle; - } - - inline void setVertex(int index, const Vec3r& iVertex) - { - _vertices[index] = iVertex; - } - - inline void setColor(int index, const Vec3r& iColor) - { - _colors[index] = iColor; - } - - inline void setVertices(const Vec3r& v0, const Vec3r& v1, const Vec3r& v2) - { - _vertices[0] = v0; - _vertices[1] = v1; - _vertices[2] = v2; - } - - inline void setColors(const Vec3r& c0, const Vec3r& c1, const Vec3r& c2) - { - _colors[0] = c0; - _colors[1] = c1; - _colors[2] = c2; - } - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v) - { - Rep::accept(v); - v.visitTriangleRep(*this); - } - - /*! Computes the triangle bounding box.*/ - virtual void ComputeBBox(); +class TriangleRep : public Rep { + public: + /*! Line description style */ + enum TRIANGLE_STYLE { + FILL, + LINES, + }; + + private: + TRIANGLE_STYLE _Style; + Vec3r _vertices[3]; + Vec3r _colors[3]; + + public: + inline TriangleRep() : Rep() + { + _Style = FILL; + } + + /*! Builds a triangle from 3 vertices + * v0 + * first vertex + * v1 + * second vertex + * v2 + * third vertex + */ + inline TriangleRep(const Vec3r &v0, const Vec3r &v1, const Vec3r &v2) : Rep() + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + _Style = FILL; + } + + inline TriangleRep(const Vec3r &v0, + const Vec3r &c0, + const Vec3r &v1, + const Vec3r &c1, + const Vec3r &v2, + const Vec3r &c2) + : Rep() + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + _colors[0] = c0; + _colors[1] = c1; + _colors[2] = c2; + _Style = FILL; + } + + virtual ~TriangleRep() + { + } + + /*! accessors */ + inline const TRIANGLE_STYLE style() const + { + return _Style; + } + + inline const Vec3r &vertex(int index) const + { + return _vertices[index]; + } + + inline const Vec3r &color(int index) const + { + return _colors[index]; + } + + /*! modifiers */ + inline void setStyle(const TRIANGLE_STYLE iStyle) + { + _Style = iStyle; + } + + inline void setVertex(int index, const Vec3r &iVertex) + { + _vertices[index] = iVertex; + } + + inline void setColor(int index, const Vec3r &iColor) + { + _colors[index] = iColor; + } + + inline void setVertices(const Vec3r &v0, const Vec3r &v1, const Vec3r &v2) + { + _vertices[0] = v0; + _vertices[1] = v1; + _vertices[2] = v2; + } + + inline void setColors(const Vec3r &c0, const Vec3r &c1, const Vec3r &c2) + { + _colors[0] = c0; + _colors[1] = c1; + _colors[2] = c2; + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v) + { + Rep::accept(v); + v.visitTriangleRep(*this); + } + + /*! Computes the triangle bounding box.*/ + virtual void ComputeBBox(); }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.cpp b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp index 47462d0f497..164b9af9ac7 100644 --- a/source/blender/freestyle/intern/scene_graph/VertexRep.cpp +++ b/source/blender/freestyle/intern/scene_graph/VertexRep.cpp @@ -25,8 +25,8 @@ namespace Freestyle { void VertexRep::ComputeBBox() { - setBBox(BBox(Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]), - Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]))); + setBBox(BBox(Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]), + Vec3r(_coordinates[0], _coordinates[1], _coordinates[2]))); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/VertexRep.h b/source/blender/freestyle/intern/scene_graph/VertexRep.h index 8d3e66d7323..3831be3105a 100644 --- a/source/blender/freestyle/intern/scene_graph/VertexRep.h +++ b/source/blender/freestyle/intern/scene_graph/VertexRep.h @@ -26,107 +26,108 @@ namespace Freestyle { -class VertexRep : public Rep -{ -public: - inline VertexRep() : Rep() - { - _vid = 0; - _PointSize = 0.0f; - } - - inline VertexRep(real x, real y, real z, int id = 0) : Rep() - { - _coordinates[0] = x; - _coordinates[1] = y; - _coordinates[2] = z; - - _vid = id; - _PointSize = 0.0f; - } - - inline ~VertexRep() {} - - /*! Accept the corresponding visitor */ - virtual void accept(SceneVisitor& v) - { - Rep::accept(v); - v.visitVertexRep(*this); - } - - /*! Computes the rep bounding box. */ - virtual void ComputeBBox(); - - /*! accessors */ - inline const int vid() const - { - return _vid; - } - - inline const real * coordinates() const - { - return _coordinates; - } - - inline real x() const - { - return _coordinates[0]; - } - - inline real y() const - { - return _coordinates[1]; - } - - inline real z() const - { - return _coordinates[2]; - } - - inline float pointSize() const - { - return _PointSize; - } - - /*! modifiers */ - inline void setVid(int id) - { - _vid = id; - } - - inline void setX(real x) - { - _coordinates[0] = x; - } - - inline void setY(real y) - { - _coordinates[1] = y; - } - - inline void setZ(real z) - { - _coordinates[2] = z; - } - - inline void setCoordinates(real x, real y, real z) - { - _coordinates[0] = x; - _coordinates[1] = y; - _coordinates[2] = z; - } - - inline void setPointSize(float iPointSize) - { - _PointSize = iPointSize; - } - -private: - int _vid; // vertex id - real _coordinates[3]; - float _PointSize; +class VertexRep : public Rep { + public: + inline VertexRep() : Rep() + { + _vid = 0; + _PointSize = 0.0f; + } + + inline VertexRep(real x, real y, real z, int id = 0) : Rep() + { + _coordinates[0] = x; + _coordinates[1] = y; + _coordinates[2] = z; + + _vid = id; + _PointSize = 0.0f; + } + + inline ~VertexRep() + { + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor &v) + { + Rep::accept(v); + v.visitVertexRep(*this); + } + + /*! Computes the rep bounding box. */ + virtual void ComputeBBox(); + + /*! accessors */ + inline const int vid() const + { + return _vid; + } + + inline const real *coordinates() const + { + return _coordinates; + } + + inline real x() const + { + return _coordinates[0]; + } + + inline real y() const + { + return _coordinates[1]; + } + + inline real z() const + { + return _coordinates[2]; + } + + inline float pointSize() const + { + return _PointSize; + } + + /*! modifiers */ + inline void setVid(int id) + { + _vid = id; + } + + inline void setX(real x) + { + _coordinates[0] = x; + } + + inline void setY(real y) + { + _coordinates[1] = y; + } + + inline void setZ(real z) + { + _coordinates[2] = z; + } + + inline void setCoordinates(real x, real y, real z) + { + _coordinates[0] = x; + _coordinates[1] = y; + _coordinates[2] = z; + } + + inline void setPointSize(float iPointSize) + { + _PointSize = iPointSize; + } + + private: + int _vid; // vertex id + real _coordinates[3]; + float _PointSize; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_VERTEX_REP_H__ +#endif // __FREESTYLE_VERTEX_REP_H__ diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp b/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp index 0047940a5b7..95d4735ddc4 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.cpp @@ -29,81 +29,91 @@ namespace Freestyle { namespace Functions0D { -int DensityF0D::operator()(Interface0DIterator& iter) +int DensityF0D::operator()(Interface0DIterator &iter) { - Canvas *canvas = Canvas::getInstance(); - int bound = _filter.getBound(); - - if ((iter->getProjectedX() - bound < 0) || (iter->getProjectedX() + bound>canvas->width()) || - (iter->getProjectedY() - bound < 0) || (iter->getProjectedY() + bound>canvas->height())) - { - result = 0.0; - return 0; - } - - RGBImage image; - canvas->readColorPixels((int)iter->getProjectedX() - bound, (int)iter->getProjectedY() - bound, - _filter.maskSize(), _filter.maskSize(), image); - result = _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY()); - - return 0; + Canvas *canvas = Canvas::getInstance(); + int bound = _filter.getBound(); + + if ((iter->getProjectedX() - bound < 0) || (iter->getProjectedX() + bound > canvas->width()) || + (iter->getProjectedY() - bound < 0) || (iter->getProjectedY() + bound > canvas->height())) { + result = 0.0; + return 0; + } + + RGBImage image; + canvas->readColorPixels((int)iter->getProjectedX() - bound, + (int)iter->getProjectedY() - bound, + _filter.maskSize(), + _filter.maskSize(), + image); + result = _filter.getSmoothedPixel( + &image, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + + return 0; } - -int LocalAverageDepthF0D::operator()(Interface0DIterator& iter) +int LocalAverageDepthF0D::operator()(Interface0DIterator &iter) { - Canvas *iViewer = Canvas::getInstance(); - int bound = _filter.getBound(); - - if ((iter->getProjectedX() - bound < 0) || (iter->getProjectedX() + bound>iViewer->width()) || - (iter->getProjectedY() - bound < 0) || (iter->getProjectedY() + bound>iViewer->height())) - { - result = 0.0; - return 0; - } - - GrayImage image; - iViewer->readDepthPixels((int)iter->getProjectedX() - bound, (int)iter->getProjectedY() - bound, - _filter.maskSize(), _filter.maskSize(), image); - result = _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY()); - - return 0; + Canvas *iViewer = Canvas::getInstance(); + int bound = _filter.getBound(); + + if ((iter->getProjectedX() - bound < 0) || (iter->getProjectedX() + bound > iViewer->width()) || + (iter->getProjectedY() - bound < 0) || (iter->getProjectedY() + bound > iViewer->height())) { + result = 0.0; + return 0; + } + + GrayImage image; + iViewer->readDepthPixels((int)iter->getProjectedX() - bound, + (int)iter->getProjectedY() - bound, + _filter.maskSize(), + _filter.maskSize(), + image); + result = _filter.getSmoothedPixel( + &image, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + + return 0; } -int ReadMapPixelF0D::operator()(Interface0DIterator& iter) +int ReadMapPixelF0D::operator()(Interface0DIterator &iter) { - Canvas *canvas = Canvas::getInstance(); - result = canvas->readMapPixel(_mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); - return 0; + Canvas *canvas = Canvas::getInstance(); + result = canvas->readMapPixel( + _mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + return 0; } -int ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator& iter) +int ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator &iter) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - result = svm->readSteerableViewMapPixel(_orientation, _level, (int)iter->getProjectedX(), - (int)iter->getProjectedY()); - return 0; + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + result = svm->readSteerableViewMapPixel( + _orientation, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + return 0; } -int ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator& iter) +int ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator &iter) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - result = svm->readCompleteViewMapPixel(_level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); - return 0; + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + result = svm->readCompleteViewMapPixel( + _level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + return 0; } -int GetViewMapGradientNormF0D::operator()(Interface0DIterator& iter) +int GetViewMapGradientNormF0D::operator()(Interface0DIterator &iter) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - float pxy = svm->readCompleteViewMapPixel(_level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); - float gx = svm->readCompleteViewMapPixel(_level, (int)iter->getProjectedX() + _step, - (int)iter->getProjectedY()) - pxy; - float gy = svm->readCompleteViewMapPixel(_level, (int)iter->getProjectedX(), - (int)iter->getProjectedY() + _step) - pxy; - result = Vec2f(gx, gy).norm(); - return 0; + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + float pxy = svm->readCompleteViewMapPixel( + _level, (int)iter->getProjectedX(), (int)iter->getProjectedY()); + float gx = svm->readCompleteViewMapPixel( + _level, (int)iter->getProjectedX() + _step, (int)iter->getProjectedY()) - + pxy; + float gy = svm->readCompleteViewMapPixel( + _level, (int)iter->getProjectedX(), (int)iter->getProjectedY() + _step) - + pxy; + result = Vec2f(gx, gy).norm(); + return 0; } -} // end of namespace Functions0D +} // end of namespace Functions0D } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h b/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h index 5889f3c4ed3..24c710bd163 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions0D.h @@ -41,179 +41,173 @@ namespace Functions0D { * This density is evaluated using a pixels square window around the evaluation point and integrating * these values using a gaussian. */ -class DensityF0D : public UnaryFunction0D -{ -public: - /*! Builds the functor from the gaussian sigma value. - * \param sigma: - * sigma indicates the x value for which the gaussian function is 0.5. It leads to the window size value. - * (the larger, the smoother) - */ - DensityF0D(double sigma = 2) : UnaryFunction0D() - { - _filter.setSigma((float)sigma); - } - - /*! Returns the string "DensityF0D" */ - string getName() const - { - return "DensityF0D"; - } - - /*! The () operator. */ - int operator()(Interface0DIterator& iter); - -private: - GaussianFilter _filter; +class DensityF0D : public UnaryFunction0D { + public: + /*! Builds the functor from the gaussian sigma value. + * \param sigma: + * sigma indicates the x value for which the gaussian function is 0.5. It leads to the window size value. + * (the larger, the smoother) + */ + DensityF0D(double sigma = 2) : UnaryFunction0D() + { + _filter.setSigma((float)sigma); + } + + /*! Returns the string "DensityF0D" */ + string getName() const + { + return "DensityF0D"; + } + + /*! The () operator. */ + int operator()(Interface0DIterator &iter); + + private: + GaussianFilter _filter; }; // LocalAverageDepthF0D /*! Returns the average depth around a point. * The result is obtained by querying the depth buffer on a window around that point. */ -class LocalAverageDepthF0D : public UnaryFunction0D -{ -private: - GaussianFilter _filter; - -public: - /*! Builds the functor from the size of the mask that will be used. */ - LocalAverageDepthF0D(real maskSize = 5.0f) : UnaryFunction0D() - { - _filter.setSigma((float)maskSize / 2.0f); - } - - /*! Returns the string "LocalAverageDepthF0D" */ - string getName() const - { - return "LocalAverageDepthF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class LocalAverageDepthF0D : public UnaryFunction0D { + private: + GaussianFilter _filter; + + public: + /*! Builds the functor from the size of the mask that will be used. */ + LocalAverageDepthF0D(real maskSize = 5.0f) : UnaryFunction0D() + { + _filter.setSigma((float)maskSize / 2.0f); + } + + /*! Returns the string "LocalAverageDepthF0D" */ + string getName() const + { + return "LocalAverageDepthF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // ReadMapPixel /*! Reads a pixel in a map. */ -class ReadMapPixelF0D : public UnaryFunction0D -{ -private: - const char * _mapName; - int _level; - -public: - /*! Builds the functor from name of the - * Map that must be read. - * \param iMapName: - * The name of the map. - * \param level: - * The level of the pyramid from which the pixel must be read. - */ - ReadMapPixelF0D(const char *iMapName, int level) : UnaryFunction0D() - { - _mapName = iMapName; - _level = level; - } - - /*! Returns the string "ReadMapPixelF0D" */ - string getName() const - { - return "ReadMapPixelF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class ReadMapPixelF0D : public UnaryFunction0D { + private: + const char *_mapName; + int _level; + + public: + /*! Builds the functor from name of the + * Map that must be read. + * \param iMapName: + * The name of the map. + * \param level: + * The level of the pyramid from which the pixel must be read. + */ + ReadMapPixelF0D(const char *iMapName, int level) : UnaryFunction0D() + { + _mapName = iMapName; + _level = level; + } + + /*! Returns the string "ReadMapPixelF0D" */ + string getName() const + { + return "ReadMapPixelF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // ReadSteerableViewMapPixel /*! Reads a pixel in one of the level of one of the steerable viewmaps. */ -class ReadSteerableViewMapPixelF0D : public UnaryFunction0D -{ -private: - unsigned _orientation; - int _level; - -public: - /*! Builds the functor - * \param nOrientation: - * The integer belonging to [0,4] indicating the orientation (E,NE,N,NW) we are interested in. - * \param level: - * The level of the pyramid from which the pixel must be read. - */ - ReadSteerableViewMapPixelF0D(unsigned nOrientation, int level) : UnaryFunction0D() - { - _orientation = nOrientation; - _level = level; - } - - /*! Returns the string "ReadSteerableViewMapPixelF0D" */ - string getName() const - { - return "ReadSteerableViewMapPixelF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class ReadSteerableViewMapPixelF0D : public UnaryFunction0D { + private: + unsigned _orientation; + int _level; + + public: + /*! Builds the functor + * \param nOrientation: + * The integer belonging to [0,4] indicating the orientation (E,NE,N,NW) we are interested in. + * \param level: + * The level of the pyramid from which the pixel must be read. + */ + ReadSteerableViewMapPixelF0D(unsigned nOrientation, int level) : UnaryFunction0D() + { + _orientation = nOrientation; + _level = level; + } + + /*! Returns the string "ReadSteerableViewMapPixelF0D" */ + string getName() const + { + return "ReadSteerableViewMapPixelF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // ReadCompleteViewMapPixel /*! Reads a pixel in one of the level of the complete viewmap. */ -class ReadCompleteViewMapPixelF0D : public UnaryFunction0D -{ -private: - int _level; - -public: - /*! Builds the functor - * \param level: - * The level of the pyramid from which the pixel must be read. - */ - ReadCompleteViewMapPixelF0D(int level) : UnaryFunction0D() - { - _level = level; - } - - /*! Returns the string "ReadCompleteViewMapPixelF0D" */ - string getName() const - { - return "ReadCompleteViewMapPixelF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class ReadCompleteViewMapPixelF0D : public UnaryFunction0D { + private: + int _level; + + public: + /*! Builds the functor + * \param level: + * The level of the pyramid from which the pixel must be read. + */ + ReadCompleteViewMapPixelF0D(int level) : UnaryFunction0D() + { + _level = level; + } + + /*! Returns the string "ReadCompleteViewMapPixelF0D" */ + string getName() const + { + return "ReadCompleteViewMapPixelF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // GetViewMapGradientNormF0D /*! Returns the norm of the gradient of the global viewmap density image. */ -class GetViewMapGradientNormF0D: public UnaryFunction0D< float> -{ -private: - int _level; - float _step; - -public: - /*! Builds the functor - * \param level: - * The level of the pyramid from which the pixel must be read. - */ - GetViewMapGradientNormF0D(int level) : UnaryFunction0D() - { - _level = level; - _step = (float)pow(2.0, _level); - } - - /*! Returns the string "GetOccludeeF0D" */ - string getName() const - { - return "GetViewMapGradientNormF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class GetViewMapGradientNormF0D : public UnaryFunction0D { + private: + int _level; + float _step; + + public: + /*! Builds the functor + * \param level: + * The level of the pyramid from which the pixel must be read. + */ + GetViewMapGradientNormF0D(int level) : UnaryFunction0D() + { + _level = level; + _step = (float)pow(2.0, _level); + } + + /*! Returns the string "GetOccludeeF0D" */ + string getName() const + { + return "GetViewMapGradientNormF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; -} // end of namespace Functions0D +} // end of namespace Functions0D } /* namespace Freestyle */ -#endif // __FREESTYLE_ADVANCED_FUNCTIONS_0D_H__ +#endif // __FREESTYLE_ADVANCED_FUNCTIONS_0D_H__ diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp index 6d006dd395d..eadc8993dc6 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.cpp @@ -29,100 +29,101 @@ namespace Freestyle { // FIXME namespace Functions1D { -int GetSteerableViewMapDensityF1D::operator()(Interface1D& inter) +int GetSteerableViewMapDensityF1D::operator()(Interface1D &inter) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - Interface0DIterator it = inter.pointsBegin(_sampling); - Interface0DIterator itnext = it; - ++itnext; - FEdge *fe; - unsigned nSVM; - vector values; + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + Interface0DIterator it = inter.pointsBegin(_sampling); + Interface0DIterator itnext = it; + ++itnext; + FEdge *fe; + unsigned nSVM; + vector values; - while (!itnext.isEnd()) { - Interface0D& i0D = (*it); - Interface0D& i0Dnext = (*itnext); - fe = i0D.getFEdge(i0Dnext); - if (fe == 0) { - cerr << "GetSteerableViewMapDensityF1D warning: no FEdge between " << i0D.getId() << " and " << - i0Dnext.getId() << endl; - // compute the direction between these two ??? - Vec2f dir = i0Dnext.getPoint2D() - i0D.getPoint2D(); - nSVM = svm->getSVMNumber(dir); - } - else { - nSVM = svm->getSVMNumber(fe->getId().getFirst()); - } - Vec2r m((i0D.getProjectedX() + i0Dnext.getProjectedX()) / 2.0, - (i0D.getProjectedY() + i0Dnext.getProjectedY()) / 2.0); - values.push_back(svm->readSteerableViewMapPixel(nSVM, _level, (int)m[0], (int)m[1])); - ++it; - ++itnext; - } + while (!itnext.isEnd()) { + Interface0D &i0D = (*it); + Interface0D &i0Dnext = (*itnext); + fe = i0D.getFEdge(i0Dnext); + if (fe == 0) { + cerr << "GetSteerableViewMapDensityF1D warning: no FEdge between " << i0D.getId() << " and " + << i0Dnext.getId() << endl; + // compute the direction between these two ??? + Vec2f dir = i0Dnext.getPoint2D() - i0D.getPoint2D(); + nSVM = svm->getSVMNumber(dir); + } + else { + nSVM = svm->getSVMNumber(fe->getId().getFirst()); + } + Vec2r m((i0D.getProjectedX() + i0Dnext.getProjectedX()) / 2.0, + (i0D.getProjectedY() + i0Dnext.getProjectedY()) / 2.0); + values.push_back(svm->readSteerableViewMapPixel(nSVM, _level, (int)m[0], (int)m[1])); + ++it; + ++itnext; + } - float res, res_tmp; - vector::iterator v = values.begin(), vend = values.end(); - unsigned size = 1; - switch (_integration) { - case MIN: - res = *v; - ++v; - for (; v != vend; ++v) { - res_tmp = *v; - if (res_tmp < res) - res = res_tmp; - } - break; - case MAX: - res = *v; - ++v; - for (; v != vend; ++v) { - res_tmp = *v; - if (res_tmp > res) - res = res_tmp; - } - break; - case FIRST: - res = *v; - break; - case LAST: - --vend; - res = *vend; - break; - case MEAN: - default: - res = *v; - ++v; - for (; v != vend; ++v, ++size) - res += *v; - res /= (size ? size : 1); - break; - } - result = res; - return 0; + float res, res_tmp; + vector::iterator v = values.begin(), vend = values.end(); + unsigned size = 1; + switch (_integration) { + case MIN: + res = *v; + ++v; + for (; v != vend; ++v) { + res_tmp = *v; + if (res_tmp < res) + res = res_tmp; + } + break; + case MAX: + res = *v; + ++v; + for (; v != vend; ++v) { + res_tmp = *v; + if (res_tmp > res) + res = res_tmp; + } + break; + case FIRST: + res = *v; + break; + case LAST: + --vend; + res = *vend; + break; + case MEAN: + default: + res = *v; + ++v; + for (; v != vend; ++v, ++size) + res += *v; + res /= (size ? size : 1); + break; + } + result = res; + return 0; } -int GetDirectionalViewMapDensityF1D::operator()(Interface1D& inter) +int GetDirectionalViewMapDensityF1D::operator()(Interface1D &inter) { - //soc unsigned size; - result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); - return 0; + //soc unsigned size; + result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); + return 0; } -int GetCompleteViewMapDensityF1D::operator()(Interface1D& inter) +int GetCompleteViewMapDensityF1D::operator()(Interface1D &inter) { - //soc unsigned size; - /* Id id = inter.getId(); */ /* UNUSED */ - result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); - return 0; + //soc unsigned size; + /* Id id = inter.getId(); */ /* UNUSED */ + result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); + return 0; } -int GetViewMapGradientNormF1D::operator()(Interface1D& inter) +int GetViewMapGradientNormF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); - return 0; + result = integrate( + _func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); + return 0; } -} // Functions1D namespace +} // namespace Functions1D } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h index 6f5b2f34640..76a70d4f50d 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h @@ -40,46 +40,48 @@ namespace Functions1D { * The density is evaluated for a set of points along the Interface1D (using the DensityF0D functor) with a * user-defined sampling and then integrated into a single value using a user-defined integration method. */ -class DensityF1D : public UnaryFunction1D -{ -private: - float _sampling; - -public: - /*! Builds the functor. - * \param sigma: - * Thesigma used in DensityF0D and determining the window size used in each density query. - * \param iType: - * The integration method used to compute a single value from a set of values. - * \param sampling: - * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and - * the result is obtained by combining the resulting values into a single one, following the method specified - * by iType. - */ - DensityF1D(double sigma = 2, IntegrationType iType = MEAN, float sampling = 2.0f) - : UnaryFunction1D(iType), _fun(sigma) - { - _sampling = sampling; - } - - /*! Destructor */ - virtual ~DensityF1D() {} - - /*! Returns the string "DensityF1D"*/ - string getName() const - { - return "DensityF1D"; - } - - /*! the () operator.*/ - int operator()(Interface1D& inter) - { - result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); - return 0; - } - -private: - Functions0D::DensityF0D _fun; +class DensityF1D : public UnaryFunction1D { + private: + float _sampling; + + public: + /*! Builds the functor. + * \param sigma: + * Thesigma used in DensityF0D and determining the window size used in each density query. + * \param iType: + * The integration method used to compute a single value from a set of values. + * \param sampling: + * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and + * the result is obtained by combining the resulting values into a single one, following the method specified + * by iType. + */ + DensityF1D(double sigma = 2, IntegrationType iType = MEAN, float sampling = 2.0f) + : UnaryFunction1D(iType), _fun(sigma) + { + _sampling = sampling; + } + + /*! Destructor */ + virtual ~DensityF1D() + { + } + + /*! Returns the string "DensityF1D"*/ + string getName() const + { + return "DensityF1D"; + } + + /*! the () operator.*/ + int operator()(Interface1D &inter) + { + result = integrate( + _fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration); + return 0; + } + + private: + Functions0D::DensityF0D _fun; }; // LocalAverageDepthF1D @@ -87,35 +89,34 @@ private: * The average depth is evaluated for a set of points along the Interface1D (using the LocalAverageDepthF0D functor) * with a user-defined sampling and then integrated into a single value using a user-defined integration method. */ -class LocalAverageDepthF1D : public UnaryFunction1D -{ -public: - /*! Builds the functor. - * \param sigma: - * The sigma used in DensityF0D and determining the window size used in each density query. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - LocalAverageDepthF1D(real sigma, IntegrationType iType = MEAN) - : UnaryFunction1D(iType), _fun(sigma) - { - } - - /*! Returns the string "LocalAverageDepthF1D" */ - string getName() const - { - return "LocalAverageDepthF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter) - { - result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; - } - -private: - Functions0D::LocalAverageDepthF0D _fun; +class LocalAverageDepthF1D : public UnaryFunction1D { + public: + /*! Builds the functor. + * \param sigma: + * The sigma used in DensityF0D and determining the window size used in each density query. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + LocalAverageDepthF1D(real sigma, IntegrationType iType = MEAN) + : UnaryFunction1D(iType), _fun(sigma) + { + } + + /*! Returns the string "LocalAverageDepthF1D" */ + string getName() const + { + return "LocalAverageDepthF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter) + { + result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; + } + + private: + Functions0D::LocalAverageDepthF0D _fun; }; // GetCompleteViewMapDensity @@ -123,40 +124,39 @@ private: * The density is evaluated for a set of points along the Interface1D (using the ReadCompleteViewMapPixelF0D functor) * and then integrated into a single value using a user-defined integration method. */ -class GetCompleteViewMapDensityF1D : public UnaryFunction1D -{ -public: - /*! Builds the functor. - * \param level: - * The level of the pyramid from which - * the pixel must be read. - * \param iType: - * The integration method used to compute - * a single value from a set of values. - * \param sampling: - * The resolution used to sample the chain: the corresponding 0D function - * is evaluated at each sample point and the result is obtained by - * combining the resulting values into a single one, following the - * method specified by iType. - */ - GetCompleteViewMapDensityF1D(unsigned level, IntegrationType iType = MEAN, float sampling = 2.0f) - : UnaryFunction1D(iType), _fun(level) - { - _sampling = sampling; - } - - /*! Returns the string "GetCompleteViewMapDensityF1D" */ - string getName() const - { - return "GetCompleteViewMapDensityF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); - -private: - Functions0D::ReadCompleteViewMapPixelF0D _fun; - float _sampling; +class GetCompleteViewMapDensityF1D : public UnaryFunction1D { + public: + /*! Builds the functor. + * \param level: + * The level of the pyramid from which + * the pixel must be read. + * \param iType: + * The integration method used to compute + * a single value from a set of values. + * \param sampling: + * The resolution used to sample the chain: the corresponding 0D function + * is evaluated at each sample point and the result is obtained by + * combining the resulting values into a single one, following the + * method specified by iType. + */ + GetCompleteViewMapDensityF1D(unsigned level, IntegrationType iType = MEAN, float sampling = 2.0f) + : UnaryFunction1D(iType), _fun(level) + { + _sampling = sampling; + } + + /*! Returns the string "GetCompleteViewMapDensityF1D" */ + string getName() const + { + return "GetCompleteViewMapDensityF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); + + private: + Functions0D::ReadCompleteViewMapPixelF0D _fun; + float _sampling; }; // GetDirectionalViewMapDensity @@ -165,124 +165,125 @@ private: * The density is evaluated for a set of points along the Interface1D (using the ReadSteerableViewMapPixelF0D functor) * and then integrated into a single value using a user-defined integration method. */ -class GetDirectionalViewMapDensityF1D : public UnaryFunction1D -{ -public: - /*! Builds the functor. - * \param iOrientation: - * The number of the directional map we must work with. - * \param level: - * The level of the pyramid from which the pixel must be read. - * \param iType: - * The integration method used to compute a single value from a set of values. - * \param sampling: - * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and - * the result is obtained by combining the resulting values into a single one, following the method specified - * by iType. - */ - GetDirectionalViewMapDensityF1D(unsigned iOrientation, unsigned level, IntegrationType iType = MEAN, - float sampling = 2.0f) - : UnaryFunction1D(iType), _fun(iOrientation, level) - { - _sampling = sampling; - } - - /*! Returns the string "GetDirectionalViewMapDensityF1D" */ - string getName() const - { - return "GetDirectionalViewMapDensityF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); - -private: - Functions0D::ReadSteerableViewMapPixelF0D _fun; - float _sampling; +class GetDirectionalViewMapDensityF1D : public UnaryFunction1D { + public: + /*! Builds the functor. + * \param iOrientation: + * The number of the directional map we must work with. + * \param level: + * The level of the pyramid from which the pixel must be read. + * \param iType: + * The integration method used to compute a single value from a set of values. + * \param sampling: + * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and + * the result is obtained by combining the resulting values into a single one, following the method specified + * by iType. + */ + GetDirectionalViewMapDensityF1D(unsigned iOrientation, + unsigned level, + IntegrationType iType = MEAN, + float sampling = 2.0f) + : UnaryFunction1D(iType), _fun(iOrientation, level) + { + _sampling = sampling; + } + + /*! Returns the string "GetDirectionalViewMapDensityF1D" */ + string getName() const + { + return "GetDirectionalViewMapDensityF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); + + private: + Functions0D::ReadSteerableViewMapPixelF0D _fun; + float _sampling; }; // GetSteerableViewMapDensityF1D /*! Returns the density of the viewmap for a given Interface1D. The density of each FEdge is evaluated * in the proper steerable ViewMap depending on its oorientation. */ -class GetSteerableViewMapDensityF1D : public UnaryFunction1D -{ -private: - int _level; - float _sampling; - -public: - /*! Builds the functor from the level of the pyramid from which the pixel must be read. - * \param level: - * The level of the pyramid from which the pixel must be read. - * \param iType: - * The integration method used to compute a single value from a set of values. - * \param sampling: - * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and - * the result is obtained by combining the resulting values into a single one, following the method specified - * by iType. - */ - GetSteerableViewMapDensityF1D(int level, IntegrationType iType = MEAN, float sampling = 2.0f) - : UnaryFunction1D(iType) - { - _level = level; - _sampling = sampling; - } - - /*! Destructor */ - virtual ~GetSteerableViewMapDensityF1D() {} - - /*! Returns the string "GetSteerableViewMapDensityF1D" */ - string getName() const - { - return "GetSteerableViewMapDensityF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetSteerableViewMapDensityF1D : public UnaryFunction1D { + private: + int _level; + float _sampling; + + public: + /*! Builds the functor from the level of the pyramid from which the pixel must be read. + * \param level: + * The level of the pyramid from which the pixel must be read. + * \param iType: + * The integration method used to compute a single value from a set of values. + * \param sampling: + * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and + * the result is obtained by combining the resulting values into a single one, following the method specified + * by iType. + */ + GetSteerableViewMapDensityF1D(int level, IntegrationType iType = MEAN, float sampling = 2.0f) + : UnaryFunction1D(iType) + { + _level = level; + _sampling = sampling; + } + + /*! Destructor */ + virtual ~GetSteerableViewMapDensityF1D() + { + } + + /*! Returns the string "GetSteerableViewMapDensityF1D" */ + string getName() const + { + return "GetSteerableViewMapDensityF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetViewMapGradientNormF1D /*! Returns the density of the viewmap for a given Interface1D. The density of each FEdge is evaluated in * the proper steerable ViewMap depending on its oorientation. */ -class GetViewMapGradientNormF1D : public UnaryFunction1D -{ -private: - int _level; - float _sampling; - Functions0D::GetViewMapGradientNormF0D _func; - -public: - /*! Builds the functor from the level of the pyramid from which the pixel must be read. - * \param level: - * The level of the pyramid from which the pixel must be read. - * \param iType: - * The integration method used to compute a single value from a set of values. - * \param sampling: - * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and - * the result is obtained by combining the resulting values into a single one, following the method specified - * by iType. - */ - GetViewMapGradientNormF1D(int level, IntegrationType iType = MEAN, float sampling = 2.0f) - : UnaryFunction1D(iType), _func(level) - { - _level = level; - _sampling = sampling; - } - - /*! Returns the string "GetSteerableViewMapDensityF1D" */ - string getName() const - { - return "GetViewMapGradientNormF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetViewMapGradientNormF1D : public UnaryFunction1D { + private: + int _level; + float _sampling; + Functions0D::GetViewMapGradientNormF0D _func; + + public: + /*! Builds the functor from the level of the pyramid from which the pixel must be read. + * \param level: + * The level of the pyramid from which the pixel must be read. + * \param iType: + * The integration method used to compute a single value from a set of values. + * \param sampling: + * The resolution used to sample the chain: the corresponding 0D function is evaluated at each sample point and + * the result is obtained by combining the resulting values into a single one, following the method specified + * by iType. + */ + GetViewMapGradientNormF1D(int level, IntegrationType iType = MEAN, float sampling = 2.0f) + : UnaryFunction1D(iType), _func(level) + { + _level = level; + _sampling = sampling; + } + + /*! Returns the string "GetSteerableViewMapDensityF1D" */ + string getName() const + { + return "GetViewMapGradientNormF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; -} // end of namespace Functions1D +} // end of namespace Functions1D } /* namespace Freestyle */ -#endif // __FREESTYLE_ADVANCED_FUNCTIONS_1D_H__ +#endif // __FREESTYLE_ADVANCED_FUNCTIONS_1D_H__ diff --git a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h index e3bfae8289a..df66f82b868 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedPredicates1D.h @@ -42,45 +42,44 @@ namespace Predicates1D { /*! Returns true if the density evaluated for the * Interface1D is less than a user-defined density value. */ -class DensityLowerThanUP1D : public UnaryPredicate1D -{ -public: - /*! Builds the functor. - * \param threshold: - * The value of the threshold density. - * Any Interface1D having a density lower than this threshold will match. - * \param sigma: - * The sigma value defining the density evaluation window size used in the DensityF0D functor. - */ - DensityLowerThanUP1D(double threshold, double sigma = 2) - { - _threshold = threshold; - _sigma = sigma; - } +class DensityLowerThanUP1D : public UnaryPredicate1D { + public: + /*! Builds the functor. + * \param threshold: + * The value of the threshold density. + * Any Interface1D having a density lower than this threshold will match. + * \param sigma: + * The sigma value defining the density evaluation window size used in the DensityF0D functor. + */ + DensityLowerThanUP1D(double threshold, double sigma = 2) + { + _threshold = threshold; + _sigma = sigma; + } - /*! Returns the string "DensityLowerThanUP1D" */ - string getName() const - { - return "DensityLowerThanUP1D"; - } + /*! Returns the string "DensityLowerThanUP1D" */ + string getName() const + { + return "DensityLowerThanUP1D"; + } - /*! The () operator. */ - int operator()(Interface1D& inter) - { - Functions1D::DensityF1D fun(_sigma); - if (fun(inter) < 0) - return -1; - result = (fun.result < _threshold); - return 0; - } + /*! The () operator. */ + int operator()(Interface1D &inter) + { + Functions1D::DensityF1D fun(_sigma); + if (fun(inter) < 0) + return -1; + result = (fun.result < _threshold); + return 0; + } -private: - double _sigma; - double _threshold; + private: + double _sigma; + double _threshold; }; -} // end of namespace Predicates1D +} // end of namespace Predicates1D } /* namespace Freestyle */ -#endif // __FREESTYLE_ADVANCED_PREDICATES_1D_H__ +#endif // __FREESTYLE_ADVANCED_PREDICATES_1D_H__ diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp index 247fde9a9c0..a7883187066 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp @@ -33,46 +33,49 @@ namespace Freestyle { // ///////////////////////////////////////// -CalligraphicShader::CalligraphicShader(real iMinThickness, real iMaxThickness, const Vec2f &iOrientation, bool clamp) -: StrokeShader() +CalligraphicShader::CalligraphicShader(real iMinThickness, + real iMaxThickness, + const Vec2f &iOrientation, + bool clamp) + : StrokeShader() { - _minThickness = iMinThickness; - _maxThickness = iMaxThickness; - _orientation = iOrientation; - _orientation.normalize(); - _clamp = clamp; + _minThickness = iMinThickness; + _maxThickness = iMaxThickness; + _orientation = iOrientation; + _orientation.normalize(); + _clamp = clamp; } int CalligraphicShader::shade(Stroke &ioStroke) const { - Interface0DIterator v; - Functions0D::VertexOrientation2DF0D fun; - StrokeVertex *sv; - for (v = ioStroke.verticesBegin(); !v.isEnd(); ++v) { - real thickness; - if (fun(v) < 0) - return -1; - - Vec2f vertexOri(fun.result); - Vec2r ori2d(-vertexOri[1], vertexOri[0]); - ori2d.normalizeSafe(); - real scal = ori2d * _orientation; - sv = dynamic_cast(&(*v)); - if (_clamp && (scal<0)) { - scal = 0.0; - sv->attribute().setColor(1, 1, 1); - } - else { - scal = fabs(scal); - sv->attribute().setColor(0, 0, 0); - } - thickness = _minThickness + scal * (_maxThickness - _minThickness); - if (thickness < 0.0) - thickness = 0.0; - sv->attribute().setThickness(thickness / 2.0, thickness / 2.0); - } - - return 0; + Interface0DIterator v; + Functions0D::VertexOrientation2DF0D fun; + StrokeVertex *sv; + for (v = ioStroke.verticesBegin(); !v.isEnd(); ++v) { + real thickness; + if (fun(v) < 0) + return -1; + + Vec2f vertexOri(fun.result); + Vec2r ori2d(-vertexOri[1], vertexOri[0]); + ori2d.normalizeSafe(); + real scal = ori2d * _orientation; + sv = dynamic_cast(&(*v)); + if (_clamp && (scal < 0)) { + scal = 0.0; + sv->attribute().setColor(1, 1, 1); + } + else { + scal = fabs(scal); + sv->attribute().setColor(0, 0, 0); + } + thickness = _minThickness + scal * (_maxThickness - _minThickness); + if (thickness < 0.0) + thickness = 0.0; + sv->attribute().setThickness(thickness / 2.0, thickness / 2.0); + } + + return 0; } ///////////////////////////////////////// @@ -83,64 +86,65 @@ int CalligraphicShader::shade(Stroke &ioStroke) const static const unsigned NB_VALUE_NOISE = 512; -SpatialNoiseShader::SpatialNoiseShader(float ioamount, float ixScale, int nbOctave, bool smooth, bool pureRandom) -: StrokeShader() +SpatialNoiseShader::SpatialNoiseShader( + float ioamount, float ixScale, int nbOctave, bool smooth, bool pureRandom) + : StrokeShader() { - _amount = ioamount; - if (ixScale == 0) - _xScale = 0; - else - _xScale = 1.0 / ixScale / real(NB_VALUE_NOISE); - _nbOctave = nbOctave; - _smooth = smooth; - _pureRandom = pureRandom; + _amount = ioamount; + if (ixScale == 0) + _xScale = 0; + else + _xScale = 1.0 / ixScale / real(NB_VALUE_NOISE); + _nbOctave = nbOctave; + _smooth = smooth; + _pureRandom = pureRandom; } int SpatialNoiseShader::shade(Stroke &ioStroke) const { - Interface0DIterator v, v2; - v = ioStroke.verticesBegin(); - Vec2r p(v->getProjectedX(), v->getProjectedY()); - v2 = v; - ++v2; - Vec2r p0(v2->getProjectedX(), v2->getProjectedY()); - p0 = p + 2 * (p - p0); - StrokeVertex *sv; - sv = dynamic_cast(&(*v)); - real initU = sv->strokeLength() * real(NB_VALUE_NOISE); - if (_pureRandom) - initU += RandGen::drand48() * real(NB_VALUE_NOISE); - - Functions0D::VertexOrientation2DF0D fun; - while (!v.isEnd()) { - sv = dynamic_cast(&(*v)); - Vec2r p(sv->getPoint()); - if (fun(v) < 0) - return -1; - Vec2r vertexOri(fun.result); - Vec2r ori2d(vertexOri[0], vertexOri[1]); - ori2d = Vec2r(p - p0); - ori2d.normalizeSafe(); - - PseudoNoise mynoise; - real bruit; - - if (_smooth) - bruit = mynoise.turbulenceSmooth(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); - else - bruit = mynoise.turbulenceLinear(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); - - Vec2r noise(-ori2d[1] * _amount * bruit, ori2d[0] * _amount * bruit); - - sv->setPoint(p[0] + noise[0], p[1] + noise[1]); - p0 = p; - - ++v; - } - - ioStroke.UpdateLength(); - - return 0; + Interface0DIterator v, v2; + v = ioStroke.verticesBegin(); + Vec2r p(v->getProjectedX(), v->getProjectedY()); + v2 = v; + ++v2; + Vec2r p0(v2->getProjectedX(), v2->getProjectedY()); + p0 = p + 2 * (p - p0); + StrokeVertex *sv; + sv = dynamic_cast(&(*v)); + real initU = sv->strokeLength() * real(NB_VALUE_NOISE); + if (_pureRandom) + initU += RandGen::drand48() * real(NB_VALUE_NOISE); + + Functions0D::VertexOrientation2DF0D fun; + while (!v.isEnd()) { + sv = dynamic_cast(&(*v)); + Vec2r p(sv->getPoint()); + if (fun(v) < 0) + return -1; + Vec2r vertexOri(fun.result); + Vec2r ori2d(vertexOri[0], vertexOri[1]); + ori2d = Vec2r(p - p0); + ori2d.normalizeSafe(); + + PseudoNoise mynoise; + real bruit; + + if (_smooth) + bruit = mynoise.turbulenceSmooth(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); + else + bruit = mynoise.turbulenceLinear(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave); + + Vec2r noise(-ori2d[1] * _amount * bruit, ori2d[0] * _amount * bruit); + + sv->setPoint(p[0] + noise[0], p[1] + noise[1]); + p0 = p; + + ++v; + } + + ioStroke.UpdateLength(); + + return 0; } ///////////////////////////////////////// @@ -149,29 +153,40 @@ int SpatialNoiseShader::shade(Stroke &ioStroke) const // ///////////////////////////////////////// -SmoothingShader::SmoothingShader(int ionbIteration, real iFactorPoint, real ifactorCurvature, - real iFactorCurvatureDifference, real iAnisoPoint, real iAnisoNormal, - real iAnisoCurvature, real iCarricatureFactor) -: StrokeShader() +SmoothingShader::SmoothingShader(int ionbIteration, + real iFactorPoint, + real ifactorCurvature, + real iFactorCurvatureDifference, + real iAnisoPoint, + real iAnisoNormal, + real iAnisoCurvature, + real iCarricatureFactor) + : StrokeShader() { - _nbIterations = ionbIteration; - _factorCurvature = ifactorCurvature; - _factorCurvatureDifference = iFactorCurvatureDifference; - _anisoNormal = iAnisoNormal; - _anisoCurvature = iAnisoCurvature; - _carricatureFactor = iCarricatureFactor; - _factorPoint = iFactorPoint; - _anisoPoint = iAnisoPoint; + _nbIterations = ionbIteration; + _factorCurvature = ifactorCurvature; + _factorCurvatureDifference = iFactorCurvatureDifference; + _anisoNormal = iAnisoNormal; + _anisoCurvature = iAnisoCurvature; + _carricatureFactor = iCarricatureFactor; + _factorPoint = iFactorPoint; + _anisoPoint = iAnisoPoint; } int SmoothingShader::shade(Stroke &ioStroke) const { - // cerr << " Smoothing a stroke " << endl; - - Smoother smoother(ioStroke); - smoother.smooth(_nbIterations, _factorPoint, _factorCurvature, _factorCurvatureDifference, _anisoPoint, - _anisoNormal, _anisoCurvature, _carricatureFactor); - return 0; + // cerr << " Smoothing a stroke " << endl; + + Smoother smoother(ioStroke); + smoother.smooth(_nbIterations, + _factorPoint, + _factorCurvature, + _factorCurvatureDifference, + _anisoPoint, + _anisoNormal, + _anisoCurvature, + _carricatureFactor); + return 0; } // SMOOTHER @@ -179,152 +194,162 @@ int SmoothingShader::shade(Stroke &ioStroke) const Smoother::Smoother(Stroke &ioStroke) { - _stroke = &ioStroke; - - _nbVertices = ioStroke.vertices_size(); - _vertex = new Vec2r[_nbVertices]; - _curvature = new real[_nbVertices]; - _normal = new Vec2r[_nbVertices]; - StrokeInternal::StrokeVertexIterator v, vend; - int i = 0; - for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v, ++i) { - _vertex[i] = (v)->getPoint(); - } - Vec2r vec_tmp(_vertex[0] - _vertex[_nbVertices - 1]); - _isClosedCurve = (vec_tmp.norm() < M_EPSILON); - - _safeTest = (_nbVertices > 4); + _stroke = &ioStroke; + + _nbVertices = ioStroke.vertices_size(); + _vertex = new Vec2r[_nbVertices]; + _curvature = new real[_nbVertices]; + _normal = new Vec2r[_nbVertices]; + StrokeInternal::StrokeVertexIterator v, vend; + int i = 0; + for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; + ++v, ++i) { + _vertex[i] = (v)->getPoint(); + } + Vec2r vec_tmp(_vertex[0] - _vertex[_nbVertices - 1]); + _isClosedCurve = (vec_tmp.norm() < M_EPSILON); + + _safeTest = (_nbVertices > 4); } Smoother::~Smoother() { - delete[] _vertex; - delete[] _curvature; - delete[] _normal; + delete[] _vertex; + delete[] _curvature; + delete[] _normal; } -void Smoother::smooth(int nbIteration, real iFactorPoint, real ifactorCurvature, real iFactorCurvatureDifference, - real iAnisoPoint, real iAnisoNormal, real iAnisoCurvature, real iCarricatureFactor) +void Smoother::smooth(int nbIteration, + real iFactorPoint, + real ifactorCurvature, + real iFactorCurvatureDifference, + real iAnisoPoint, + real iAnisoNormal, + real iAnisoCurvature, + real iCarricatureFactor) { - _factorCurvature = ifactorCurvature; - _factorCurvatureDifference = iFactorCurvatureDifference; - _anisoNormal = iAnisoNormal; - _anisoCurvature = iAnisoCurvature; - _carricatureFactor = iCarricatureFactor; - _factorPoint = iFactorPoint; - _anisoPoint = iAnisoPoint; - - for (int i = 0; i < nbIteration; ++i) - iteration (); - copyVertices(); + _factorCurvature = ifactorCurvature; + _factorCurvatureDifference = iFactorCurvatureDifference; + _anisoNormal = iAnisoNormal; + _anisoCurvature = iAnisoCurvature; + _carricatureFactor = iCarricatureFactor; + _factorPoint = iFactorPoint; + _anisoPoint = iAnisoPoint; + + for (int i = 0; i < nbIteration; ++i) + iteration(); + copyVertices(); } static real edgeStopping(real x, real sigma) { - if (sigma == 0.0) - return 1.0; - return exp(-x * x / (sigma * sigma)); + if (sigma == 0.0) + return 1.0; + return exp(-x * x / (sigma * sigma)); } void Smoother::iteration() { - computeCurvature(); - for (int i = 1; i < (_nbVertices - 1); ++i) { - real motionNormal = _factorCurvature * _curvature[i] * edgeStopping(_curvature[i], _anisoNormal); - - real diffC1 = _curvature[i] - _curvature[i - 1]; - real diffC2 = _curvature[i] - _curvature[i + 1]; - real motionCurvature = edgeStopping(diffC1, _anisoCurvature) * diffC1 + - edgeStopping(diffC2, _anisoCurvature) * diffC2; //_factorCurvatureDifference; - motionCurvature *= _factorCurvatureDifference; - //motionCurvature = _factorCurvatureDifference * (diffC1 + diffC2); - if (_safeTest) - _vertex[i] = Vec2r(_vertex[i] + (motionNormal + motionCurvature) * _normal[i]); - Vec2r v1(_vertex[i - 1] - _vertex[i]); - Vec2r v2(_vertex[i + 1] - _vertex[i]); - real d1 = v1.norm(); - real d2 = v2.norm(); - _vertex[i] = Vec2r(_vertex[i] + - _factorPoint * edgeStopping(d2, _anisoPoint) * (_vertex[i - 1] - _vertex[i]) + - _factorPoint * edgeStopping(d1, _anisoPoint) * (_vertex[i + 1] - _vertex[i])); - } - - if (_isClosedCurve) { - real motionNormal = _factorCurvature * _curvature[0] * edgeStopping(_curvature[0], _anisoNormal); - - real diffC1 = _curvature[0] - _curvature[_nbVertices - 2]; - real diffC2 = _curvature[0] - _curvature[1]; - real motionCurvature = edgeStopping(diffC1, _anisoCurvature) * diffC1 + - edgeStopping(diffC2, _anisoCurvature) * diffC2; //_factorCurvatureDifference; - motionCurvature *= _factorCurvatureDifference; - //motionCurvature = _factorCurvatureDifference * (diffC1 + diffC2); - _vertex[0] = Vec2r(_vertex[0] + (motionNormal + motionCurvature) * _normal[0]); - _vertex[_nbVertices - 1] = _vertex[0]; - } + computeCurvature(); + for (int i = 1; i < (_nbVertices - 1); ++i) { + real motionNormal = _factorCurvature * _curvature[i] * + edgeStopping(_curvature[i], _anisoNormal); + + real diffC1 = _curvature[i] - _curvature[i - 1]; + real diffC2 = _curvature[i] - _curvature[i + 1]; + real motionCurvature = edgeStopping(diffC1, _anisoCurvature) * diffC1 + + edgeStopping(diffC2, _anisoCurvature) * + diffC2; //_factorCurvatureDifference; + motionCurvature *= _factorCurvatureDifference; + //motionCurvature = _factorCurvatureDifference * (diffC1 + diffC2); + if (_safeTest) + _vertex[i] = Vec2r(_vertex[i] + (motionNormal + motionCurvature) * _normal[i]); + Vec2r v1(_vertex[i - 1] - _vertex[i]); + Vec2r v2(_vertex[i + 1] - _vertex[i]); + real d1 = v1.norm(); + real d2 = v2.norm(); + _vertex[i] = Vec2r( + _vertex[i] + _factorPoint * edgeStopping(d2, _anisoPoint) * (_vertex[i - 1] - _vertex[i]) + + _factorPoint * edgeStopping(d1, _anisoPoint) * (_vertex[i + 1] - _vertex[i])); + } + + if (_isClosedCurve) { + real motionNormal = _factorCurvature * _curvature[0] * + edgeStopping(_curvature[0], _anisoNormal); + + real diffC1 = _curvature[0] - _curvature[_nbVertices - 2]; + real diffC2 = _curvature[0] - _curvature[1]; + real motionCurvature = edgeStopping(diffC1, _anisoCurvature) * diffC1 + + edgeStopping(diffC2, _anisoCurvature) * + diffC2; //_factorCurvatureDifference; + motionCurvature *= _factorCurvatureDifference; + //motionCurvature = _factorCurvatureDifference * (diffC1 + diffC2); + _vertex[0] = Vec2r(_vertex[0] + (motionNormal + motionCurvature) * _normal[0]); + _vertex[_nbVertices - 1] = _vertex[0]; + } } - void Smoother::computeCurvature() { - int i; - Vec2r BA, BC, normalCurvature; - for (i = 1; i < (_nbVertices - 1); ++i) { - BA = _vertex[i - 1] - _vertex[i]; - BC = _vertex[i + 1] - _vertex[i]; - real lba = BA.norm(), lbc = BC.norm(); - BA.normalizeSafe(); - BC.normalizeSafe(); - normalCurvature = BA + BC; - - _normal[i] = Vec2r(-(BC - BA)[1], (BC - BA)[0]); - _normal[i].normalizeSafe(); - - _curvature[i] = normalCurvature * _normal[i]; - if (lba + lbc > M_EPSILON) - _curvature[i] /= (0.5 * lba + lbc); - } - _curvature[0] = _curvature[1]; - _curvature[_nbVertices - 1] = _curvature[_nbVertices - 2]; - Vec2r di(_vertex[1] - _vertex[0]); - _normal[0] = Vec2r(-di[1], di[0]); - _normal[0].normalizeSafe(); - di = _vertex[_nbVertices - 1] - _vertex[_nbVertices - 2]; - _normal[_nbVertices - 1] = Vec2r(-di[1], di[0]); - _normal[_nbVertices - 1].normalizeSafe(); - - if (_isClosedCurve) { - BA = _vertex[_nbVertices - 2] - _vertex[0]; - BC = _vertex[1] - _vertex[0]; - real lba = BA.norm(), lbc = BC.norm(); - BA.normalizeSafe(); - BC.normalizeSafe(); - normalCurvature = BA + BC; - - _normal[i] = Vec2r(-(BC - BA)[1], (BC - BA)[0]); - _normal[i].normalizeSafe(); - - _curvature[i] = normalCurvature * _normal[i]; - if (lba + lbc > M_EPSILON) - _curvature[i] /= (0.5 * lba + lbc); - - _normal[_nbVertices - 1] = _normal[0]; - _curvature[_nbVertices - 1] = _curvature[0]; - } + int i; + Vec2r BA, BC, normalCurvature; + for (i = 1; i < (_nbVertices - 1); ++i) { + BA = _vertex[i - 1] - _vertex[i]; + BC = _vertex[i + 1] - _vertex[i]; + real lba = BA.norm(), lbc = BC.norm(); + BA.normalizeSafe(); + BC.normalizeSafe(); + normalCurvature = BA + BC; + + _normal[i] = Vec2r(-(BC - BA)[1], (BC - BA)[0]); + _normal[i].normalizeSafe(); + + _curvature[i] = normalCurvature * _normal[i]; + if (lba + lbc > M_EPSILON) + _curvature[i] /= (0.5 * lba + lbc); + } + _curvature[0] = _curvature[1]; + _curvature[_nbVertices - 1] = _curvature[_nbVertices - 2]; + Vec2r di(_vertex[1] - _vertex[0]); + _normal[0] = Vec2r(-di[1], di[0]); + _normal[0].normalizeSafe(); + di = _vertex[_nbVertices - 1] - _vertex[_nbVertices - 2]; + _normal[_nbVertices - 1] = Vec2r(-di[1], di[0]); + _normal[_nbVertices - 1].normalizeSafe(); + + if (_isClosedCurve) { + BA = _vertex[_nbVertices - 2] - _vertex[0]; + BC = _vertex[1] - _vertex[0]; + real lba = BA.norm(), lbc = BC.norm(); + BA.normalizeSafe(); + BC.normalizeSafe(); + normalCurvature = BA + BC; + + _normal[i] = Vec2r(-(BC - BA)[1], (BC - BA)[0]); + _normal[i].normalizeSafe(); + + _curvature[i] = normalCurvature * _normal[i]; + if (lba + lbc > M_EPSILON) + _curvature[i] /= (0.5 * lba + lbc); + + _normal[_nbVertices - 1] = _normal[0]; + _curvature[_nbVertices - 1] = _curvature[0]; + } } void Smoother::copyVertices() { - int i = 0; - StrokeInternal::StrokeVertexIterator v, vend; - for (v = _stroke->strokeVerticesBegin(), vend = _stroke->strokeVerticesEnd(); v != vend; ++v) { - const Vec2r p0((v)->getPoint()); - const Vec2r p1(_vertex[i]); - Vec2r p(p0 + _carricatureFactor * (p1 - p0)); - - (v)->setPoint(p[0], p[1]); - ++i; - } - _stroke->UpdateLength(); + int i = 0; + StrokeInternal::StrokeVertexIterator v, vend; + for (v = _stroke->strokeVerticesBegin(), vend = _stroke->strokeVerticesEnd(); v != vend; ++v) { + const Vec2r p0((v)->getPoint()); + const Vec2r p1(_vertex[i]); + Vec2r p(p0 + _carricatureFactor * (p1 - p0)); + + (v)->setPoint(p[0], p[1]); + ++i; + } + _stroke->UpdateLength(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h index 0e14e4f3631..17b180531a2 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h @@ -31,32 +31,36 @@ namespace Freestyle { * i.e. The stroke will be the thickest in a main direction, the thinest in the direction perpendicular to this one, * and an interpolation inbetween. */ -class CalligraphicShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param iMinThickness: - * The minimum thickness in the direction perpandicular to the main direction. - * \param iMaxThickness: - * The maximum thickness in the main direction. - * \param iOrientation: - * The 2D vector giving the main direction. - * \param clamp: - * Tells ??? - */ - CalligraphicShader(real iMinThickness, real iMaxThickness, const Vec2f &iOrientation, bool clamp); - - /*! Destructor. */ - virtual ~CalligraphicShader() {} - - /*! The shading method */ - virtual int shade(Stroke &ioStroke) const; - -protected: - real _maxThickness; - real _minThickness; - Vec2f _orientation; - bool _clamp; +class CalligraphicShader : public StrokeShader { + public: + /*! Builds the shader. + * \param iMinThickness: + * The minimum thickness in the direction perpandicular to the main direction. + * \param iMaxThickness: + * The maximum thickness in the main direction. + * \param iOrientation: + * The 2D vector giving the main direction. + * \param clamp: + * Tells ??? + */ + CalligraphicShader(real iMinThickness, + real iMaxThickness, + const Vec2f &iOrientation, + bool clamp); + + /*! Destructor. */ + virtual ~CalligraphicShader() + { + } + + /*! The shading method */ + virtual int shade(Stroke &ioStroke) const; + + protected: + real _maxThickness; + real _minThickness; + Vec2f _orientation; + bool _clamp; }; /*! [ Geometry Shader ]. @@ -64,35 +68,36 @@ protected: * Moves the vertices to make the stroke more noisy. * \see \htmlonly noise/noise.html \endhtmlonly */ -class SpatialNoiseShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param iAmount: - * The amplitude of the noise. - * \param ixScale: - * The noise frequency - * \param nbOctave: - * The number of octaves - * \param smooth: - * If you want the noise to be smooth - * \param pureRandom: - * If you don't want any coherence - */ - SpatialNoiseShader(float iAmount, float ixScale, int nbOctave, bool smooth, bool pureRandom); - - /*! Destructor. */ - virtual ~SpatialNoiseShader() {} - - /*! The shading method. */ - virtual int shade(Stroke &ioStroke) const; - -protected: - float _amount; - float _xScale; - int _nbOctave; - bool _smooth; - bool _pureRandom; +class SpatialNoiseShader : public StrokeShader { + public: + /*! Builds the shader. + * \param iAmount: + * The amplitude of the noise. + * \param ixScale: + * The noise frequency + * \param nbOctave: + * The number of octaves + * \param smooth: + * If you want the noise to be smooth + * \param pureRandom: + * If you don't want any coherence + */ + SpatialNoiseShader(float iAmount, float ixScale, int nbOctave, bool smooth, bool pureRandom); + + /*! Destructor. */ + virtual ~SpatialNoiseShader() + { + } + + /*! The shading method. */ + virtual int shade(Stroke &ioStroke) const; + + protected: + float _amount; + float _xScale; + int _nbOctave; + bool _smooth; + bool _pureRandom; }; /*! [ Geometry Shader ]. @@ -102,116 +107,130 @@ protected: * to prevent the diffusion accross corners. * \see \htmlonly smoothing/smoothing.html \endhtmlonly */ -class SmoothingShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param iNbIteration: - * The number of iterations. (400) - * \param iFactorPoint: - * 0 - * \param ifactorCurvature: - * 0 - * \param iFactorCurvatureDifference: - * 0.2 - * \param iAnisoPoint: - * 0 - * \param iAnisNormal: - * 0 - * \param iAnisoCurvature: - * 0 - * \param icarricatureFactor: - * 1 - */ - SmoothingShader(int iNbIteration, real iFactorPoint, real ifactorCurvature, real iFactorCurvatureDifference, - real iAnisoPoint, real iAnisoNormal, real iAnisoCurvature, real icarricatureFactor); - - /*! Destructor. */ - virtual ~SmoothingShader() {} - - /*! The shading method. */ - virtual int shade(Stroke &ioStroke) const; - -protected: - int _nbIterations; - real _factorPoint; - real _factorCurvature; - real _factorCurvatureDifference; - real _anisoPoint; - real _anisoNormal; - real _anisoCurvature; - real _carricatureFactor; +class SmoothingShader : public StrokeShader { + public: + /*! Builds the shader. + * \param iNbIteration: + * The number of iterations. (400) + * \param iFactorPoint: + * 0 + * \param ifactorCurvature: + * 0 + * \param iFactorCurvatureDifference: + * 0.2 + * \param iAnisoPoint: + * 0 + * \param iAnisNormal: + * 0 + * \param iAnisoCurvature: + * 0 + * \param icarricatureFactor: + * 1 + */ + SmoothingShader(int iNbIteration, + real iFactorPoint, + real ifactorCurvature, + real iFactorCurvatureDifference, + real iAnisoPoint, + real iAnisoNormal, + real iAnisoCurvature, + real icarricatureFactor); + + /*! Destructor. */ + virtual ~SmoothingShader() + { + } + + /*! The shading method. */ + virtual int shade(Stroke &ioStroke) const; + + protected: + int _nbIterations; + real _factorPoint; + real _factorCurvature; + real _factorCurvatureDifference; + real _anisoPoint; + real _anisoNormal; + real _anisoCurvature; + real _carricatureFactor; }; -class Smoother -{ -public: - Smoother(Stroke &ioStroke); - - virtual ~Smoother(); - - void smooth(int nbIterations, real iFactorPoint, real ifactorCurvature, real iFactorCurvatureDifference, - real iAnisoPoint, real iAnisoNormal, real iAnisoCurvature, real icarricatureFactor); - - void computeCurvature(); - -protected: - real _factorPoint; - real _factorCurvature; - real _factorCurvatureDifference; - real _anisoPoint; - real _anisoNormal; - real _anisoCurvature; - real _carricatureFactor; - - void iteration(); - void copyVertices (); - - Stroke *_stroke; - int _nbVertices; - Vec2r *_vertex; - Vec2r *_normal; - real *_curvature; - bool *_isFixedVertex; - - bool _isClosedCurve; - bool _safeTest; +class Smoother { + public: + Smoother(Stroke &ioStroke); + + virtual ~Smoother(); + + void smooth(int nbIterations, + real iFactorPoint, + real ifactorCurvature, + real iFactorCurvatureDifference, + real iAnisoPoint, + real iAnisoNormal, + real iAnisoCurvature, + real icarricatureFactor); + + void computeCurvature(); + + protected: + real _factorPoint; + real _factorCurvature; + real _factorCurvatureDifference; + real _anisoPoint; + real _anisoNormal; + real _anisoCurvature; + real _carricatureFactor; + + void iteration(); + void copyVertices(); + + Stroke *_stroke; + int _nbVertices; + Vec2r *_vertex; + Vec2r *_normal; + real *_curvature; + bool *_isFixedVertex; + + bool _isClosedCurve; + bool _safeTest; }; -class Omitter : public Smoother -{ -public: - Omitter(Stroke &ioStroke); +class Omitter : public Smoother { + public: + Omitter(Stroke &ioStroke); - virtual ~Omitter() {} + virtual ~Omitter() + { + } - void omit(real sizeWindow, real thrVari, real thrFlat, real lFlat); + void omit(real sizeWindow, real thrVari, real thrFlat, real lFlat); -protected: - real *_u; + protected: + real *_u; - real _sizeWindow; - real _thresholdVariation; - real _thresholdFlat; - real _lengthFlat; + real _sizeWindow; + real _thresholdVariation; + real _thresholdFlat; + real _lengthFlat; }; /*! Omission shader */ -class OmissionShader : public StrokeShader -{ -public: - OmissionShader(real sizeWindow, real thrVari, real thrFlat, real lFlat); - virtual ~OmissionShader() {} - - virtual int shade(Stroke &ioStroke) const; - -protected: - real _sizeWindow; - real _thresholdVariation; - real _thresholdFlat; - real _lengthFlat; +class OmissionShader : public StrokeShader { + public: + OmissionShader(real sizeWindow, real thrVari, real thrFlat, real lFlat); + virtual ~OmissionShader() + { + } + + virtual int shade(Stroke &ioStroke) const; + + protected: + real _sizeWindow; + real _thresholdVariation; + real _thresholdFlat; + real _lengthFlat; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_ADVANCED_STROKE_SHADERS_H__ +#endif // __FREESTYLE_ADVANCED_STROKE_SHADERS_H__ diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index 0a925949617..15541c1f438 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -38,8 +38,8 @@ #include "BKE_global.h" extern "C" { -# include "IMB_imbuf.h" -# include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" } namespace Freestyle { @@ -51,143 +51,142 @@ namespace StrokeShaders { // ////////////////////////////////////////////////////////// -int ConstantThicknessShader::shade(Stroke& stroke) const +int ConstantThicknessShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v, vend; - int i = 0; - int size = stroke.strokeVerticesSize(); - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? - if ((1 == i) || (size - 2 == i)) - v->attribute().setThickness(_thickness / 4.0, _thickness / 4.0); - if ((0 == i) || (size - 1 == i)) - v->attribute().setThickness(0, 0); - - v->attribute().setThickness(_thickness / 2.0, _thickness / 2.0); - } - return 0; + StrokeInternal::StrokeVertexIterator v, vend; + int i = 0; + int size = stroke.strokeVerticesSize(); + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? + if ((1 == i) || (size - 2 == i)) + v->attribute().setThickness(_thickness / 4.0, _thickness / 4.0); + if ((0 == i) || (size - 1 == i)) + v->attribute().setThickness(0, 0); + + v->attribute().setThickness(_thickness / 2.0, _thickness / 2.0); + } + return 0; } -int ConstantExternThicknessShader::shade(Stroke& stroke) const +int ConstantExternThicknessShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v, vend; - int i = 0; - int size = stroke.strokeVerticesSize(); - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? - if ((1 == i) || (size - 2 == i)) - v->attribute().setThickness(_thickness / 2.0, 0); - if ((0 == i) || (size - 1 == i)) - v->attribute().setThickness(0, 0); - - v->attribute().setThickness(_thickness, 0); - } - return 0; + StrokeInternal::StrokeVertexIterator v, vend; + int i = 0; + int size = stroke.strokeVerticesSize(); + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? + if ((1 == i) || (size - 2 == i)) + v->attribute().setThickness(_thickness / 2.0, 0); + if ((0 == i) || (size - 1 == i)) + v->attribute().setThickness(0, 0); + + v->attribute().setThickness(_thickness, 0); + } + return 0; } -int IncreasingThicknessShader::shade(Stroke& stroke) const +int IncreasingThicknessShader::shade(Stroke &stroke) const { - int n = stroke.strokeVerticesSize() - 1, i; - StrokeInternal::StrokeVertexIterator v, vend; - for (i = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); - v != vend; - ++v, ++i) - { - float t; - if (i < (float)n / 2.0f) - t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * _ThicknessMax; - else - t = (1.0 - (float)i / (float)n) * _ThicknessMax + (float)i / (float)n * _ThicknessMin; - v->attribute().setThickness(t / 2.0, t / 2.0); - } - return 0; + int n = stroke.strokeVerticesSize() - 1, i; + StrokeInternal::StrokeVertexIterator v, vend; + for (i = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; + ++v, ++i) { + float t; + if (i < (float)n / 2.0f) + t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * _ThicknessMax; + else + t = (1.0 - (float)i / (float)n) * _ThicknessMax + (float)i / (float)n * _ThicknessMin; + v->attribute().setThickness(t / 2.0, t / 2.0); + } + return 0; } -int ConstrainedIncreasingThicknessShader::shade(Stroke& stroke) const +int ConstrainedIncreasingThicknessShader::shade(Stroke &stroke) const { - float slength = stroke.getLength2D(); - float maxT = min(_ratio * slength, _ThicknessMax); - int n = stroke.strokeVerticesSize() - 1, i; - StrokeInternal::StrokeVertexIterator v, vend; - for (i = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); - v != vend; - ++v, ++i) - { - // XXX Why not using an if/else here? Else, if last condition is true, everything else is computed for nothing! - float t; - if (i < (float)n / 2.0f) - t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * maxT; - else - t = (1.0 - (float)i / (float)n) * maxT + (float)i / (float)n * _ThicknessMin; - v->attribute().setThickness(t / 2.0, t / 2.0); - if (i == n - 1) - v->attribute().setThickness(_ThicknessMin / 2.0, _ThicknessMin / 2.0); - } - return 0; + float slength = stroke.getLength2D(); + float maxT = min(_ratio * slength, _ThicknessMax); + int n = stroke.strokeVerticesSize() - 1, i; + StrokeInternal::StrokeVertexIterator v, vend; + for (i = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; + ++v, ++i) { + // XXX Why not using an if/else here? Else, if last condition is true, everything else is computed for nothing! + float t; + if (i < (float)n / 2.0f) + t = (1.0 - (float)i / (float)n) * _ThicknessMin + (float)i / (float)n * maxT; + else + t = (1.0 - (float)i / (float)n) * maxT + (float)i / (float)n * _ThicknessMin; + v->attribute().setThickness(t / 2.0, t / 2.0); + if (i == n - 1) + v->attribute().setThickness(_ThicknessMin / 2.0, _ThicknessMin / 2.0); + } + return 0; } - -int LengthDependingThicknessShader::shade(Stroke& stroke) const +int LengthDependingThicknessShader::shade(Stroke &stroke) const { - float step = (_maxThickness - _minThickness) / 3.0f; - float l = stroke.getLength2D(); - float thickness = 0.0f; - if (l > 300.0f) - thickness = _minThickness + 3.0f * step; - else if ((l < 300.0f) && (l > 100.0f)) - thickness = _minThickness + 2.0f * step; - else if ((l < 100.0f) && (l > 50.0f)) - thickness = _minThickness + 1.0f * step; - else // else if (l < 50.0f), tsst... - thickness = _minThickness; - - StrokeInternal::StrokeVertexIterator v, vend; - int i = 0; - int size = stroke.strokeVerticesSize(); - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? - if ((1 == i) || (size - 2 == i)) - v->attribute().setThickness(thickness / 4.0, thickness / 4.0); - if ((0 == i) || (size - 1 == i)) - v->attribute().setThickness(0, 0); - - v->attribute().setThickness(thickness / 2.0, thickness / 2.0); - } - return 0; + float step = (_maxThickness - _minThickness) / 3.0f; + float l = stroke.getLength2D(); + float thickness = 0.0f; + if (l > 300.0f) + thickness = _minThickness + 3.0f * step; + else if ((l < 300.0f) && (l > 100.0f)) + thickness = _minThickness + 2.0f * step; + else if ((l < 100.0f) && (l > 50.0f)) + thickness = _minThickness + 1.0f * step; + else // else if (l < 50.0f), tsst... + thickness = _minThickness; + + StrokeInternal::StrokeVertexIterator v, vend; + int i = 0; + int size = stroke.strokeVerticesSize(); + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + // XXX What's the use of i here? And is not the thickness always overriden by the last line of the loop? + if ((1 == i) || (size - 2 == i)) + v->attribute().setThickness(thickness / 4.0, thickness / 4.0); + if ((0 == i) || (size - 1 == i)) + v->attribute().setThickness(0, 0); + + v->attribute().setThickness(thickness / 2.0, thickness / 2.0); + } + return 0; } static const unsigned NB_VALUE_NOISE = 512; ThicknessNoiseShader::ThicknessNoiseShader() : StrokeShader() { - _amplitude = 1.0f; - _scale = 1.0f / 2.0f / (float)NB_VALUE_NOISE; + _amplitude = 1.0f; + _scale = 1.0f / 2.0f / (float)NB_VALUE_NOISE; } ThicknessNoiseShader::ThicknessNoiseShader(float iAmplitude, float iPeriod) : StrokeShader() { - _amplitude = iAmplitude; - _scale = 1.0f / iPeriod / (float)NB_VALUE_NOISE; + _amplitude = iAmplitude; + _scale = 1.0f / iPeriod / (float)NB_VALUE_NOISE; } -int ThicknessNoiseShader::shade(Stroke& stroke) const +int ThicknessNoiseShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; - real initU1 = v->strokeLength() * real(NB_VALUE_NOISE) + RandGen::drand48() * real(NB_VALUE_NOISE); - real initU2 = v->strokeLength() * real(NB_VALUE_NOISE) + RandGen::drand48() * real(NB_VALUE_NOISE); - - real bruit, bruit2; - PseudoNoise mynoise, mynoise2; - for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU1, 2); // 2 : nbOctaves - bruit2 = mynoise2.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU2, 2); // 2 : nbOctaves - const float *originalThickness = v->attribute().getThickness(); - float r = bruit * _amplitude + originalThickness[0]; - float l = bruit2 * _amplitude + originalThickness[1]; - v->attribute().setThickness(r, l); - } - - return 0; + StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; + real initU1 = v->strokeLength() * real(NB_VALUE_NOISE) + + RandGen::drand48() * real(NB_VALUE_NOISE); + real initU2 = v->strokeLength() * real(NB_VALUE_NOISE) + + RandGen::drand48() * real(NB_VALUE_NOISE); + + real bruit, bruit2; + PseudoNoise mynoise, mynoise2; + for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU1, + 2); // 2 : nbOctaves + bruit2 = mynoise2.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU2, + 2); // 2 : nbOctaves + const float *originalThickness = v->attribute().getThickness(); + float r = bruit * _amplitude + originalThickness[0]; + float l = bruit2 * _amplitude + originalThickness[1]; + v->attribute().setThickness(r, l); + } + + return 0; } // @@ -195,78 +194,80 @@ int ThicknessNoiseShader::shade(Stroke& stroke) const // /////////////////////////////////////////////////////////////////////////////// -int ConstantColorShader::shade(Stroke& stroke) const +int ConstantColorShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v, vend; - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - v->attribute().setColor(_color[0], _color[1], _color[2]); - v->attribute().setAlpha(_color[3]); - } - return 0; + StrokeInternal::StrokeVertexIterator v, vend; + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + v->attribute().setColor(_color[0], _color[1], _color[2]); + v->attribute().setAlpha(_color[3]); + } + return 0; } -int IncreasingColorShader::shade(Stroke& stroke) const +int IncreasingColorShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v, vend; - int n = stroke.strokeVerticesSize() - 1, yo; - float newcolor[4]; - for (yo = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); - v != vend; - ++v, ++yo) - { - for (int i = 0; i < 4; ++i) { - newcolor[i] = (1.0 - (float) yo / (float)n) * _colorMin[i] + (float)yo / (float)n * _colorMax[i]; - } - v->attribute().setColor(newcolor[0], newcolor[1], newcolor[2]); - v->attribute().setAlpha(newcolor[3]); - } - return 0; + StrokeInternal::StrokeVertexIterator v, vend; + int n = stroke.strokeVerticesSize() - 1, yo; + float newcolor[4]; + for (yo = 0, v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; + ++v, ++yo) { + for (int i = 0; i < 4; ++i) { + newcolor[i] = (1.0 - (float)yo / (float)n) * _colorMin[i] + + (float)yo / (float)n * _colorMax[i]; + } + v->attribute().setColor(newcolor[0], newcolor[1], newcolor[2]); + v->attribute().setAlpha(newcolor[3]); + } + return 0; } -int MaterialColorShader::shade(Stroke& stroke) const +int MaterialColorShader::shade(Stroke &stroke) const { - Interface0DIterator v, vend; - Functions0D::MaterialF0D fun; - StrokeVertex *sv; - for (v = stroke.verticesBegin(), vend = stroke.verticesEnd(); v != vend; ++v) { - if (fun(v) < 0) - return -1; - const float *diffuse = fun.result.diffuse(); - sv = dynamic_cast(&(*v)); - sv->attribute().setColor(diffuse[0] * _coefficient, diffuse[1] * _coefficient, diffuse[2] * _coefficient); - sv->attribute().setAlpha(diffuse[3]); - } - return 0; + Interface0DIterator v, vend; + Functions0D::MaterialF0D fun; + StrokeVertex *sv; + for (v = stroke.verticesBegin(), vend = stroke.verticesEnd(); v != vend; ++v) { + if (fun(v) < 0) + return -1; + const float *diffuse = fun.result.diffuse(); + sv = dynamic_cast(&(*v)); + sv->attribute().setColor( + diffuse[0] * _coefficient, diffuse[1] * _coefficient, diffuse[2] * _coefficient); + sv->attribute().setAlpha(diffuse[3]); + } + return 0; } ColorNoiseShader::ColorNoiseShader() : StrokeShader() { - _amplitude = 1.0f; - _scale = 1.0f / 2.0f / (float)NB_VALUE_NOISE; + _amplitude = 1.0f; + _scale = 1.0f / 2.0f / (float)NB_VALUE_NOISE; } ColorNoiseShader::ColorNoiseShader(float iAmplitude, float iPeriod) : StrokeShader() { - _amplitude = iAmplitude; - _scale = 1.0f / iPeriod / (float)NB_VALUE_NOISE; + _amplitude = iAmplitude; + _scale = 1.0f / iPeriod / (float)NB_VALUE_NOISE; } -int ColorNoiseShader::shade(Stroke& stroke) const +int ColorNoiseShader::shade(Stroke &stroke) const { - StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; - real initU = v->strokeLength() * real(NB_VALUE_NOISE) + RandGen::drand48() * real(NB_VALUE_NOISE); - - real bruit; - PseudoNoise mynoise; - for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU, 2); // 2 : nbOctaves - const float *originalColor = v->attribute().getColor(); - float r = bruit * _amplitude + originalColor[0]; - float g = bruit * _amplitude + originalColor[1]; - float b = bruit * _amplitude + originalColor[2]; - v->attribute().setColor(r, g, b); - } - return 0; + StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; + real initU = v->strokeLength() * real(NB_VALUE_NOISE) + + RandGen::drand48() * real(NB_VALUE_NOISE); + + real bruit; + PseudoNoise mynoise; + for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU, + 2); // 2 : nbOctaves + const float *originalColor = v->attribute().getColor(); + float r = bruit * _amplitude + originalColor[0]; + float g = bruit * _amplitude + originalColor[1]; + float b = bruit * _amplitude + originalColor[2]; + v->attribute().setColor(r, g, b); + } + return 0; } // @@ -274,21 +275,21 @@ int ColorNoiseShader::shade(Stroke& stroke) const // /////////////////////////////////////////////////////////////////////////////// -int BlenderTextureShader::shade(Stroke& stroke) const +int BlenderTextureShader::shade(Stroke &stroke) const { - if (_mtex) - return stroke.setMTex(_mtex); - if (_nodeTree) { - stroke.setNodeTree(_nodeTree); - return 0; - } - return -1; + if (_mtex) + return stroke.setMTex(_mtex); + if (_nodeTree) { + stroke.setNodeTree(_nodeTree); + return 0; + } + return -1; } -int StrokeTextureStepShader::shade(Stroke& stroke) const +int StrokeTextureStepShader::shade(Stroke &stroke) const { - stroke.setTextureStep(_step); - return 0; + stroke.setTextureStep(_step); + return 0; } // @@ -296,319 +297,320 @@ int StrokeTextureStepShader::shade(Stroke& stroke) const // /////////////////////////////////////////////////////////////////////////////// -int BackboneStretcherShader::shade(Stroke& stroke) const +int BackboneStretcherShader::shade(Stroke &stroke) const { - float l = stroke.getLength2D(); - if (l <= 1.0e-6) - return 0; - - StrokeInternal::StrokeVertexIterator v0 = stroke.strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator v1 = v0; - ++v1; - StrokeInternal::StrokeVertexIterator vn = stroke.strokeVerticesEnd(); - --vn; - StrokeInternal::StrokeVertexIterator vn_1 = vn; - --vn_1; - - - Vec2d first((v0)->x(), (v0)->y()); - Vec2d last((vn)->x(), (vn)->y()); - - Vec2d d1(first - Vec2d((v1)->x(), (v1)->y())); - d1.normalize(); - Vec2d dn(last - Vec2d((vn_1)->x(), (vn_1)->y())); - dn.normalize(); - - Vec2d newFirst(first + _amount * d1); - (v0)->setPoint(newFirst[0], newFirst[1]); - Vec2d newLast(last + _amount * dn); - (vn)->setPoint(newLast[0], newLast[1]); - - stroke.UpdateLength(); - return 0; + float l = stroke.getLength2D(); + if (l <= 1.0e-6) + return 0; + + StrokeInternal::StrokeVertexIterator v0 = stroke.strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator v1 = v0; + ++v1; + StrokeInternal::StrokeVertexIterator vn = stroke.strokeVerticesEnd(); + --vn; + StrokeInternal::StrokeVertexIterator vn_1 = vn; + --vn_1; + + Vec2d first((v0)->x(), (v0)->y()); + Vec2d last((vn)->x(), (vn)->y()); + + Vec2d d1(first - Vec2d((v1)->x(), (v1)->y())); + d1.normalize(); + Vec2d dn(last - Vec2d((vn_1)->x(), (vn_1)->y())); + dn.normalize(); + + Vec2d newFirst(first + _amount * d1); + (v0)->setPoint(newFirst[0], newFirst[1]); + Vec2d newLast(last + _amount * dn); + (vn)->setPoint(newLast[0], newLast[1]); + + stroke.UpdateLength(); + return 0; } -int SamplingShader::shade(Stroke& stroke) const +int SamplingShader::shade(Stroke &stroke) const { - stroke.Resample(_sampling); - stroke.UpdateLength(); - return 0; + stroke.Resample(_sampling); + stroke.UpdateLength(); + return 0; } -int ExternalContourStretcherShader::shade(Stroke& stroke) const +int ExternalContourStretcherShader::shade(Stroke &stroke) const { - //float l = stroke.getLength2D(); - Interface0DIterator it; - Functions0D::Normal2DF0D fun; - StrokeVertex *sv; - for (it = stroke.verticesBegin(); !it.isEnd(); ++it) { - if (fun(it) < 0) - return -1; - Vec2f n(fun.result); - sv = dynamic_cast(&(*it)); - Vec2d newPoint(sv->x() + _amount * n.x(), sv->y() + _amount * n.y()); - sv->setPoint(newPoint[0], newPoint[1]); - } - stroke.UpdateLength(); - return 0; + //float l = stroke.getLength2D(); + Interface0DIterator it; + Functions0D::Normal2DF0D fun; + StrokeVertex *sv; + for (it = stroke.verticesBegin(); !it.isEnd(); ++it) { + if (fun(it) < 0) + return -1; + Vec2f n(fun.result); + sv = dynamic_cast(&(*it)); + Vec2d newPoint(sv->x() + _amount * n.x(), sv->y() + _amount * n.y()); + sv->setPoint(newPoint[0], newPoint[1]); + } + stroke.UpdateLength(); + return 0; } - //!! Bezier curve stroke shader -int BezierCurveShader::shade(Stroke& stroke) const +int BezierCurveShader::shade(Stroke &stroke) const { - if (stroke.strokeVerticesSize() < 4) - return 0; - - // Build the Bezier curve from this set of data points: - vector data; - StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; - data.push_back(Vec2d(v->x(), v->y())); //first one - StrokeInternal::StrokeVertexIterator previous = v; - ++v; - for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - if (!((fabs(v->x() - (previous)->x()) < M_EPSILON) && ((fabs(v->y() - (previous)->y()) < M_EPSILON)))) - data.push_back(Vec2d(v->x(), v->y())); - previous = v; - } - - // here we build the bezier curve - BezierCurve bcurve(data, _error); - - // bad performances are here !!! // FIXME - vector CurveVertices; - vector& bsegments = bcurve.segments(); - vector::iterator s = bsegments.begin(), send; - vector& segmentsVertices = (*s)->vertices(); - vector::iterator p, pend; - // first point - CurveVertices.push_back(segmentsVertices[0]); - for (send = bsegments.end(); s != send; ++s) { - segmentsVertices = (*s)->vertices(); - p = segmentsVertices.begin(); - ++p; - for (pend = segmentsVertices.end(); p != pend; ++p) { - CurveVertices.push_back((*p)); - } - } - - // Resample the Stroke depending on the number of vertices of the bezier curve: - int originalSize = CurveVertices.size(); + if (stroke.strokeVerticesSize() < 4) + return 0; + + // Build the Bezier curve from this set of data points: + vector data; + StrokeInternal::StrokeVertexIterator v = stroke.strokeVerticesBegin(), vend; + data.push_back(Vec2d(v->x(), v->y())); //first one + StrokeInternal::StrokeVertexIterator previous = v; + ++v; + for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + if (!((fabs(v->x() - (previous)->x()) < M_EPSILON) && + ((fabs(v->y() - (previous)->y()) < M_EPSILON)))) + data.push_back(Vec2d(v->x(), v->y())); + previous = v; + } + + // here we build the bezier curve + BezierCurve bcurve(data, _error); + + // bad performances are here !!! // FIXME + vector CurveVertices; + vector &bsegments = bcurve.segments(); + vector::iterator s = bsegments.begin(), send; + vector &segmentsVertices = (*s)->vertices(); + vector::iterator p, pend; + // first point + CurveVertices.push_back(segmentsVertices[0]); + for (send = bsegments.end(); s != send; ++s) { + segmentsVertices = (*s)->vertices(); + p = segmentsVertices.begin(); + ++p; + for (pend = segmentsVertices.end(); p != pend; ++p) { + CurveVertices.push_back((*p)); + } + } + + // Resample the Stroke depending on the number of vertices of the bezier curve: + int originalSize = CurveVertices.size(); #if 0 - float sampling = stroke.ComputeSampling(originalSize); - stroke.Resample(sampling); + float sampling = stroke.ComputeSampling(originalSize); + stroke.Resample(sampling); #endif - stroke.Resample(originalSize); - int newsize = stroke.strokeVerticesSize(); - int nExtraVertex = 0; - if (newsize < originalSize) { - cerr << "Warning: unsufficient resampling" << endl; - } - else { - nExtraVertex = newsize - originalSize; - if (nExtraVertex != 0) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Bezier Shader : Stroke " << stroke.getId() << " have not been resampled" << endl; - } - } - } - - // assigns the new coordinates: - p = CurveVertices.begin(); - vector::iterator last = p; - int n; - StrokeInternal::StrokeVertexIterator it, itend; - for (n = 0, it = stroke.strokeVerticesBegin(), itend = stroke.strokeVerticesEnd(), pend = CurveVertices.end(); - (it != itend) && (p != pend); - ++it, ++p, ++n) - { - it->setX(p->x()); - it->setY(p->y()); - last = p; - } - stroke.UpdateLength(); - - // Deal with extra vertices: - if (nExtraVertex == 0) - return 0; - - // nExtraVertex should stay unassigned - vector attributes; - vector verticesToRemove; - for (int i = 0; i < nExtraVertex; ++i, ++it, ++n) { - verticesToRemove.push_back(&(*it)); - if (it.isEnd()) { - // XXX Shocking! :P Shouldn't we break in this case??? - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "messed up!" << endl; - } - } - } - for (it = stroke.strokeVerticesBegin(); it != itend; ++it) { - attributes.push_back(it->attribute()); - } - - for (vector::iterator vr = verticesToRemove.begin(), vrend = verticesToRemove.end(); - vr != vrend; - ++vr) - { - stroke.RemoveVertex(*vr); - } - - vector::iterator a = attributes.begin(), aend = attributes.end(); - int index = 0; - int index1 = (int)floor((float)originalSize / 2.0); - int index2 = index1 + nExtraVertex; - for (it = stroke.strokeVerticesBegin(), itend = stroke.strokeVerticesEnd(); - (it != itend) && (a != aend); - ++it) - { - (it)->setAttribute(*a); - if ((index <= index1) || (index > index2)) { - ++a; - } - ++index; - } - return 0; + stroke.Resample(originalSize); + int newsize = stroke.strokeVerticesSize(); + int nExtraVertex = 0; + if (newsize < originalSize) { + cerr << "Warning: unsufficient resampling" << endl; + } + else { + nExtraVertex = newsize - originalSize; + if (nExtraVertex != 0) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Bezier Shader : Stroke " << stroke.getId() << " have not been resampled" << endl; + } + } + } + + // assigns the new coordinates: + p = CurveVertices.begin(); + vector::iterator last = p; + int n; + StrokeInternal::StrokeVertexIterator it, itend; + for (n = 0, + it = stroke.strokeVerticesBegin(), + itend = stroke.strokeVerticesEnd(), + pend = CurveVertices.end(); + (it != itend) && (p != pend); + ++it, ++p, ++n) { + it->setX(p->x()); + it->setY(p->y()); + last = p; + } + stroke.UpdateLength(); + + // Deal with extra vertices: + if (nExtraVertex == 0) + return 0; + + // nExtraVertex should stay unassigned + vector attributes; + vector verticesToRemove; + for (int i = 0; i < nExtraVertex; ++i, ++it, ++n) { + verticesToRemove.push_back(&(*it)); + if (it.isEnd()) { + // XXX Shocking! :P Shouldn't we break in this case??? + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "messed up!" << endl; + } + } + } + for (it = stroke.strokeVerticesBegin(); it != itend; ++it) { + attributes.push_back(it->attribute()); + } + + for (vector::iterator vr = verticesToRemove.begin(), + vrend = verticesToRemove.end(); + vr != vrend; + ++vr) { + stroke.RemoveVertex(*vr); + } + + vector::iterator a = attributes.begin(), aend = attributes.end(); + int index = 0; + int index1 = (int)floor((float)originalSize / 2.0); + int index2 = index1 + nExtraVertex; + for (it = stroke.strokeVerticesBegin(), itend = stroke.strokeVerticesEnd(); + (it != itend) && (a != aend); + ++it) { + (it)->setAttribute(*a); + if ((index <= index1) || (index > index2)) { + ++a; + } + ++index; + } + return 0; } - -class CurvePiece -{ -public: - StrokeInternal::StrokeVertexIterator _begin; - StrokeInternal::StrokeVertexIterator _last; - Vec2d A; - Vec2d B; - int size; - float _error; - - CurvePiece(StrokeInternal::StrokeVertexIterator b, StrokeInternal::StrokeVertexIterator l, int iSize) - { - _error = 0.0f; - _begin = b; - _last = l; - A = Vec2d((_begin)->x(), (_begin)->y()); - B = Vec2d((_last)->x(), (_last)->y()); - size = iSize; - } - - float error() - { - float maxE = 0.0f; - for (StrokeInternal::StrokeVertexIterator it = _begin; it != _last; ++it) { - Vec2d P(it->x(), it->y()); - float d = GeomUtils::distPointSegment(P, A, B); - if (d > maxE) - maxE = d; - } - _error = maxE; - return maxE; - } - - //! Subdivides the curve into two pieces. - // The first piece is this same object (modified) - // The second piece is returned by the method - CurvePiece *subdivide() - { - StrokeInternal::StrokeVertexIterator it = _begin; - int ns = size - 1; // number of segments (ns > 1) - int ns1 = ns / 2; - int ns2 = ns - ns1; - for (int i = 0; i < ns1; ++it, ++i); - - CurvePiece *second = new CurvePiece(it, _last, ns2 + 1); - size = ns1 + 1; - _last = it; - B = Vec2d((_last)->x(), (_last)->y()); - return second; - } +class CurvePiece { + public: + StrokeInternal::StrokeVertexIterator _begin; + StrokeInternal::StrokeVertexIterator _last; + Vec2d A; + Vec2d B; + int size; + float _error; + + CurvePiece(StrokeInternal::StrokeVertexIterator b, + StrokeInternal::StrokeVertexIterator l, + int iSize) + { + _error = 0.0f; + _begin = b; + _last = l; + A = Vec2d((_begin)->x(), (_begin)->y()); + B = Vec2d((_last)->x(), (_last)->y()); + size = iSize; + } + + float error() + { + float maxE = 0.0f; + for (StrokeInternal::StrokeVertexIterator it = _begin; it != _last; ++it) { + Vec2d P(it->x(), it->y()); + float d = GeomUtils::distPointSegment(P, A, B); + if (d > maxE) + maxE = d; + } + _error = maxE; + return maxE; + } + + //! Subdivides the curve into two pieces. + // The first piece is this same object (modified) + // The second piece is returned by the method + CurvePiece *subdivide() + { + StrokeInternal::StrokeVertexIterator it = _begin; + int ns = size - 1; // number of segments (ns > 1) + int ns1 = ns / 2; + int ns2 = ns - ns1; + for (int i = 0; i < ns1; ++it, ++i) + ; + + CurvePiece *second = new CurvePiece(it, _last, ns2 + 1); + size = ns1 + 1; + _last = it; + B = Vec2d((_last)->x(), (_last)->y()); + return second; + } }; -int PolygonalizationShader::shade(Stroke& stroke) const +int PolygonalizationShader::shade(Stroke &stroke) const { - vector _pieces; - vector _results; - vector::iterator cp, cpend; - - // Compute first approx: - StrokeInternal::StrokeVertexIterator a = stroke.strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator b = stroke.strokeVerticesEnd(); - --b; - int size = stroke.strokeVerticesSize(); - - CurvePiece *piece = new CurvePiece(a, b, size); - _pieces.push_back(piece); - - while (!_pieces.empty()) { - piece = _pieces.back(); - _pieces.pop_back(); - if (piece->size > 2 && piece->error() > _error) { - CurvePiece *second = piece->subdivide(); - _pieces.push_back(second); - _pieces.push_back(piece); - } - else { - _results.push_back(piece); - } - } - - // actually modify the geometry for each piece: - for (cp = _results.begin(), cpend = _results.end(); cp != cpend; ++cp) { - a = (*cp)->_begin; - b = (*cp)->_last; - Vec2d u = (*cp)->B - (*cp)->A; - Vec2d n(u[1], -u[0]); - n.normalize(); - //Vec2d n(0, 0); - float offset = ((*cp)->_error); - StrokeInternal::StrokeVertexIterator v; - for (v = a; v != b; ++v) { - v->setPoint((*cp)->A.x() + v->u() * u.x() + n.x() * offset, - (*cp)->A.y() + v->u() * u.y() + n.y() * offset); - } + vector _pieces; + vector _results; + vector::iterator cp, cpend; + + // Compute first approx: + StrokeInternal::StrokeVertexIterator a = stroke.strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator b = stroke.strokeVerticesEnd(); + --b; + int size = stroke.strokeVerticesSize(); + + CurvePiece *piece = new CurvePiece(a, b, size); + _pieces.push_back(piece); + + while (!_pieces.empty()) { + piece = _pieces.back(); + _pieces.pop_back(); + if (piece->size > 2 && piece->error() > _error) { + CurvePiece *second = piece->subdivide(); + _pieces.push_back(second); + _pieces.push_back(piece); + } + else { + _results.push_back(piece); + } + } + + // actually modify the geometry for each piece: + for (cp = _results.begin(), cpend = _results.end(); cp != cpend; ++cp) { + a = (*cp)->_begin; + b = (*cp)->_last; + Vec2d u = (*cp)->B - (*cp)->A; + Vec2d n(u[1], -u[0]); + n.normalize(); + //Vec2d n(0, 0); + float offset = ((*cp)->_error); + StrokeInternal::StrokeVertexIterator v; + for (v = a; v != b; ++v) { + v->setPoint((*cp)->A.x() + v->u() * u.x() + n.x() * offset, + (*cp)->A.y() + v->u() * u.y() + n.y() * offset); + } #if 0 - u.normalize(); - (*a)->setPoint((*a)->x() - u.x() * 10, (*a)->y() - u.y() * 10); + u.normalize(); + (*a)->setPoint((*a)->x() - u.x() * 10, (*a)->y() - u.y() * 10); #endif - } - stroke.UpdateLength(); - - // delete stuff - for (cp = _results.begin(), cpend = _results.end(); cp != cpend; ++cp) { - delete (*cp); - } - _results.clear(); - return 0; + } + stroke.UpdateLength(); + + // delete stuff + for (cp = _results.begin(), cpend = _results.end(); cp != cpend; ++cp) { + delete (*cp); + } + _results.clear(); + return 0; } -int GuidingLinesShader::shade(Stroke& stroke) const +int GuidingLinesShader::shade(Stroke &stroke) const { - Functions1D::Normal2DF1D norm_fun; - StrokeInternal::StrokeVertexIterator a = stroke.strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator b = stroke.strokeVerticesEnd(); - --b; - int size = stroke.strokeVerticesSize(); - CurvePiece piece(a, b, size); - - Vec2d u = piece.B - piece.A; - Vec2f n(u[1], -u[0]); - n.normalize(); - if (norm_fun(stroke) < 0) - return -1; - Vec2f strokeN(norm_fun.result); - if (n * strokeN < 0) { - n[0] = -n[0]; - n[1] = -n[1]; - } - float offset = (piece.error()) / 2.0f * _offset; - StrokeInternal::StrokeVertexIterator v, vend; - for (v = a, vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - v->setPoint(piece.A.x() + v->u() * u.x() + n.x() * offset, - piece.A.y() + v->u() * u.y() + n.y() * offset); - } - stroke.UpdateLength(); - return 0; + Functions1D::Normal2DF1D norm_fun; + StrokeInternal::StrokeVertexIterator a = stroke.strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator b = stroke.strokeVerticesEnd(); + --b; + int size = stroke.strokeVerticesSize(); + CurvePiece piece(a, b, size); + + Vec2d u = piece.B - piece.A; + Vec2f n(u[1], -u[0]); + n.normalize(); + if (norm_fun(stroke) < 0) + return -1; + Vec2f strokeN(norm_fun.result); + if (n * strokeN < 0) { + n[0] = -n[0]; + n[1] = -n[1]; + } + float offset = (piece.error()) / 2.0f * _offset; + StrokeInternal::StrokeVertexIterator v, vend; + for (v = a, vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + v->setPoint(piece.A.x() + v->u() * u.x() + n.x() * offset, + piece.A.y() + v->u() * u.y() + n.y() * offset); + } + stroke.UpdateLength(); + return 0; } ///////////////////////////////////////// @@ -617,55 +619,54 @@ int GuidingLinesShader::shade(Stroke& stroke) const // ///////////////////////////////////////// - TipRemoverShader::TipRemoverShader(real tipLength) : StrokeShader() { - _tipLength = tipLength; + _tipLength = tipLength; } -int TipRemoverShader::shade(Stroke& stroke) const +int TipRemoverShader::shade(Stroke &stroke) const { - int originalSize = stroke.strokeVerticesSize(); - - if (originalSize < 4) - return 0; - - StrokeInternal::StrokeVertexIterator v, vend; - vector verticesToRemove; - vector oldAttributes; - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - if ((v->curvilinearAbscissa() < _tipLength) || (v->strokeLength() - v->curvilinearAbscissa() < _tipLength)) { - verticesToRemove.push_back(&(*v)); - } - oldAttributes.push_back(v->attribute()); - } - - if (originalSize - verticesToRemove.size() < 2) - return 0; - - vector::iterator sv, svend; - for (sv = verticesToRemove.begin(), svend = verticesToRemove.end(); sv != svend; ++sv) { - stroke.RemoveVertex((*sv)); - } - - // Resample so that our new stroke have the same number of vertices than before - stroke.Resample(originalSize); - - if ((int)stroke.strokeVerticesSize() != originalSize) //soc - cerr << "Warning: resampling problem" << endl; - - // assign old attributes to new stroke vertices: - vector::iterator a = oldAttributes.begin(), aend = oldAttributes.end(); - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); - (v != vend) && (a != aend); - ++v, ++a) - { - v->setAttribute(*a); - } - // we're done! - return 0; + int originalSize = stroke.strokeVerticesSize(); + + if (originalSize < 4) + return 0; + + StrokeInternal::StrokeVertexIterator v, vend; + vector verticesToRemove; + vector oldAttributes; + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { + if ((v->curvilinearAbscissa() < _tipLength) || + (v->strokeLength() - v->curvilinearAbscissa() < _tipLength)) { + verticesToRemove.push_back(&(*v)); + } + oldAttributes.push_back(v->attribute()); + } + + if (originalSize - verticesToRemove.size() < 2) + return 0; + + vector::iterator sv, svend; + for (sv = verticesToRemove.begin(), svend = verticesToRemove.end(); sv != svend; ++sv) { + stroke.RemoveVertex((*sv)); + } + + // Resample so that our new stroke have the same number of vertices than before + stroke.Resample(originalSize); + + if ((int)stroke.strokeVerticesSize() != originalSize) //soc + cerr << "Warning: resampling problem" << endl; + + // assign old attributes to new stroke vertices: + vector::iterator a = oldAttributes.begin(), aend = oldAttributes.end(); + for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); + (v != vend) && (a != aend); + ++v, ++a) { + v->setAttribute(*a); + } + // we're done! + return 0; } -} // end of namespace StrokeShaders +} // end of namespace StrokeShaders } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h index 55f393c03df..e128817ffa5 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h @@ -51,32 +51,33 @@ namespace StrokeShaders { /*! [ Thickness Shader ]. * Assigns an absolute constant thickness to every vertices of the Stroke. */ -class ConstantThicknessShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param thickness: - * The thickness that must be assigned to the stroke. - */ - ConstantThicknessShader(float thickness) : StrokeShader() - { - _thickness = thickness; - } - - /*! Destructor. */ - virtual ~ConstantThicknessShader() {} - - /*! Returns the string "ConstantThicknessShader".*/ - virtual string getName() const - { - return "ConstantThicknessShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; - -private: - float _thickness; +class ConstantThicknessShader : public StrokeShader { + public: + /*! Builds the shader. + * \param thickness: + * The thickness that must be assigned to the stroke. + */ + ConstantThicknessShader(float thickness) : StrokeShader() + { + _thickness = thickness; + } + + /*! Destructor. */ + virtual ~ConstantThicknessShader() + { + } + + /*! Returns the string "ConstantThicknessShader".*/ + virtual string getName() const + { + return "ConstantThicknessShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; + + private: + float _thickness; }; /* [ Thickness Shader ]. @@ -84,25 +85,26 @@ private: * is its thickness from the point to the strip border in the direction pointing outside the object the * Stroke delimitates. */ -class ConstantExternThicknessShader : public StrokeShader -{ -public: - ConstantExternThicknessShader(float thickness) : StrokeShader() - { - _thickness = thickness; - } - - virtual ~ConstantExternThicknessShader() {} - - virtual string getName() const - { - return "ConstantExternThicknessShader"; - } - - virtual int shade(Stroke& stroke) const; - -private: - float _thickness; +class ConstantExternThicknessShader : public StrokeShader { + public: + ConstantExternThicknessShader(float thickness) : StrokeShader() + { + _thickness = thickness; + } + + virtual ~ConstantExternThicknessShader() + { + } + + virtual string getName() const + { + return "ConstantExternThicknessShader"; + } + + virtual int shade(Stroke &stroke) const; + + private: + float _thickness; }; /*! [ Thickness Shader ]. @@ -111,139 +113,140 @@ private: * and the last vertex. * The thickness is linearly interpolated from A to B. */ -class IncreasingThicknessShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param iThicknessMin: - * The first thickness value. - * \param iThicknessMax: - * The second thickness value. - */ - IncreasingThicknessShader(float iThicknessMin, float iThicknessMax) : StrokeShader() - { - _ThicknessMin = iThicknessMin; - _ThicknessMax = iThicknessMax; - } - - /*! Destructor.*/ - virtual ~IncreasingThicknessShader() {} - - virtual string getName() const - { - return "IncreasingThicknessShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; - -private: - float _ThicknessMin; - float _ThicknessMax; +class IncreasingThicknessShader : public StrokeShader { + public: + /*! Builds the shader. + * \param iThicknessMin: + * The first thickness value. + * \param iThicknessMax: + * The second thickness value. + */ + IncreasingThicknessShader(float iThicknessMin, float iThicknessMax) : StrokeShader() + { + _ThicknessMin = iThicknessMin; + _ThicknessMax = iThicknessMax; + } + + /*! Destructor.*/ + virtual ~IncreasingThicknessShader() + { + } + + virtual string getName() const + { + return "IncreasingThicknessShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; + + private: + float _ThicknessMin; + float _ThicknessMax; }; /*! [ Thickness shader ]. * Same as previous but here we allow the user to control the ratio thickness/length so that we don't get * fat short lines */ -class ConstrainedIncreasingThicknessShader : public StrokeShader -{ -private: - float _ThicknessMin; - float _ThicknessMax; - float _ratio; - -public: - /*! Builds the shader. - * \param iThicknessMin: - * The first thickness value. - * \param iThicknessMax: - * The second thickness value. - * \param iRatio: - * The ration thickness/length we don't want to exceed. - */ - ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio) : StrokeShader() - { - _ThicknessMin = iThicknessMin; - _ThicknessMax = iThicknessMax; - _ratio = iRatio; - } - - /*! Destructor.*/ - virtual ~ConstrainedIncreasingThicknessShader() {} - - virtual string getName() const - { - return "ConstrainedIncreasingThicknessShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; +class ConstrainedIncreasingThicknessShader : public StrokeShader { + private: + float _ThicknessMin; + float _ThicknessMax; + float _ratio; + + public: + /*! Builds the shader. + * \param iThicknessMin: + * The first thickness value. + * \param iThicknessMax: + * The second thickness value. + * \param iRatio: + * The ration thickness/length we don't want to exceed. + */ + ConstrainedIncreasingThicknessShader(float iThicknessMin, float iThicknessMax, float iRatio) + : StrokeShader() + { + _ThicknessMin = iThicknessMin; + _ThicknessMax = iThicknessMax; + _ratio = iRatio; + } + + /*! Destructor.*/ + virtual ~ConstrainedIncreasingThicknessShader() + { + } + + virtual string getName() const + { + return "ConstrainedIncreasingThicknessShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; }; /* [ Thickness Shader ]. * Modifys the thickness in a relative way depending on its length. */ -class LengthDependingThicknessShader : public StrokeShader -{ -private: - float _minThickness; - float _maxThickness; - // We divide the strokes in 4 categories: - // l > 300 - // 100 < l < 300 - // 50 < l < 100 - // l < 50 - -public: - LengthDependingThicknessShader(float iMinThickness, float iMaxThickness) : StrokeShader() - { - _minThickness = iMinThickness; - _maxThickness = iMaxThickness; - } - - virtual ~LengthDependingThicknessShader() {} - - virtual string getName() const - { - return "LengthDependingThicknessShader"; - } - - virtual int shade(Stroke& stroke) const; +class LengthDependingThicknessShader : public StrokeShader { + private: + float _minThickness; + float _maxThickness; + // We divide the strokes in 4 categories: + // l > 300 + // 100 < l < 300 + // 50 < l < 100 + // l < 50 + + public: + LengthDependingThicknessShader(float iMinThickness, float iMaxThickness) : StrokeShader() + { + _minThickness = iMinThickness; + _maxThickness = iMaxThickness; + } + + virtual ~LengthDependingThicknessShader() + { + } + + virtual string getName() const + { + return "LengthDependingThicknessShader"; + } + + virtual int shade(Stroke &stroke) const; }; - /*! [ Thickness Shader ]. * Adds some noise to the stroke thickness. * \see \htmlonly noise/noise.html\endhtmlonly */ -class ThicknessNoiseShader : public StrokeShader -{ -private: - float _amplitude; - float _scale; - -public: - ThicknessNoiseShader(); - - /*! Builds a Thickness Noise Shader - * \param iAmplitude: - * The amplitude of the noise signal - * \param iPeriod: - * The period of the noise signal - */ - ThicknessNoiseShader(float iAmplitude, float iPeriod); - - virtual string getName() const - { - return "ThicknessNoiseShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; +class ThicknessNoiseShader : public StrokeShader { + private: + float _amplitude; + float _scale; + + public: + ThicknessNoiseShader(); + + /*! Builds a Thickness Noise Shader + * \param iAmplitude: + * The amplitude of the noise signal + * \param iPeriod: + * The period of the noise signal + */ + ThicknessNoiseShader(float iAmplitude, float iPeriod); + + virtual string getName() const + { + return "ThicknessNoiseShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; }; - // // Color shaders // @@ -251,37 +254,36 @@ public: /*! [ Color Shader ]. * Assigns a constant color to every vertices of the Stroke. */ -class ConstantColorShader : public StrokeShader -{ -public: - /*! Builds the shader from a user-specified color. - * \param iR: - * The red component - * \param iG: - * The green component - * \param iB: - * The blue component - * \param iAlpha: - * The alpha value - */ - ConstantColorShader(float iR, float iG, float iB, float iAlpha = 1.0f) : StrokeShader() - { - _color[0] = iR; - _color[1] = iG; - _color[2] = iB; - _color[3] = iAlpha; - } - - virtual string getName() const - { - return "ConstantColorShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; - -private: - float _color[4]; +class ConstantColorShader : public StrokeShader { + public: + /*! Builds the shader from a user-specified color. + * \param iR: + * The red component + * \param iG: + * The green component + * \param iB: + * The blue component + * \param iAlpha: + * The alpha value + */ + ConstantColorShader(float iR, float iG, float iB, float iAlpha = 1.0f) : StrokeShader() + { + _color[0] = iR; + _color[1] = iG; + _color[2] = iB; + _color[3] = iAlpha; + } + + virtual string getName() const + { + return "ConstantColorShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; + + private: + float _color[4]; }; /*! [ Color Shader ]. @@ -289,104 +291,107 @@ private: * The user specifies 2 colors A and B. The stroke color will change linearly from A to B between the * first and the last vertex. */ -class IncreasingColorShader : public StrokeShader -{ -private: - float _colorMin[4]; - float _colorMax[4]; - -public: - /*! Builds the shader from 2 user-specified colors. - * \param iRm: - * The first color red component - * \param iGm: - * The first color green component - * \param iBm: - * The first color blue component - * \param iAlpham: - * The first color alpha value - * \param iRM: - * The second color red component - * \param iGM: - * The second color green component - * \param iBM: - * The second color blue component - * \param iAlphaM: - * The second color alpha value - */ - IncreasingColorShader(float iRm, float iGm, float iBm, float iAlpham, - float iRM, float iGM, float iBM, float iAlphaM) - : StrokeShader() - { - _colorMin[0] = iRm; - _colorMin[1] = iGm; - _colorMin[2] = iBm; - _colorMin[3] = iAlpham; - - _colorMax[0] = iRM; - _colorMax[1] = iGM; - _colorMax[2] = iBM; - _colorMax[3] = iAlphaM; - } - - virtual string getName() const - { - return "IncreasingColorShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; +class IncreasingColorShader : public StrokeShader { + private: + float _colorMin[4]; + float _colorMax[4]; + + public: + /*! Builds the shader from 2 user-specified colors. + * \param iRm: + * The first color red component + * \param iGm: + * The first color green component + * \param iBm: + * The first color blue component + * \param iAlpham: + * The first color alpha value + * \param iRM: + * The second color red component + * \param iGM: + * The second color green component + * \param iBM: + * The second color blue component + * \param iAlphaM: + * The second color alpha value + */ + IncreasingColorShader(float iRm, + float iGm, + float iBm, + float iAlpham, + float iRM, + float iGM, + float iBM, + float iAlphaM) + : StrokeShader() + { + _colorMin[0] = iRm; + _colorMin[1] = iGm; + _colorMin[2] = iBm; + _colorMin[3] = iAlpham; + + _colorMax[0] = iRM; + _colorMax[1] = iGM; + _colorMax[2] = iBM; + _colorMax[3] = iAlphaM; + } + + virtual string getName() const + { + return "IncreasingColorShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; }; /* [ Color Shader ]. * Assigns a color to the stroke depending on the material of the shape to which ot belongs to. (Disney shader) */ -class MaterialColorShader : public StrokeShader -{ -private: - float _coefficient; - -public: - MaterialColorShader(float coeff = 1.0f) : StrokeShader() - { - _coefficient = coeff; - } - - virtual string getName() const - { - return "MaterialColorShader"; - } - - virtual int shade(Stroke& stroke) const; +class MaterialColorShader : public StrokeShader { + private: + float _coefficient; + + public: + MaterialColorShader(float coeff = 1.0f) : StrokeShader() + { + _coefficient = coeff; + } + + virtual string getName() const + { + return "MaterialColorShader"; + } + + virtual int shade(Stroke &stroke) const; }; /*! [ Color Shader ]. * Shader to add noise to the stroke colors. */ -class ColorNoiseShader : public StrokeShader -{ -private: - float _amplitude; - float _scale; - -public: - ColorNoiseShader(); - - /*! Builds a Color Noise Shader - * \param iAmplitude: - * The amplitude of the noise signal - * \param iPeriod: - * The period of the noise signal - */ - ColorNoiseShader(float iAmplitude, float iPeriod); - - virtual string getName() const - { - return "ColorNoiseShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; +class ColorNoiseShader : public StrokeShader { + private: + float _amplitude; + float _scale; + + public: + ColorNoiseShader(); + + /*! Builds a Color Noise Shader + * \param iAmplitude: + * The amplitude of the noise signal + * \param iPeriod: + * The period of the noise signal + */ + ColorNoiseShader(float iAmplitude, float iPeriod); + + virtual string getName() const + { + return "ColorNoiseShader"; + } + + /*! The shading method. */ + virtual int shade(Stroke &stroke) const; }; // @@ -396,271 +401,260 @@ public: /*! [ Geometry Shader ]. * Stretches the stroke at its two extremities and following the respective directions: v(1)v(0) and v(n-1)v(n). */ -class BackboneStretcherShader : public StrokeShader -{ -private: - float _amount; - -public: - /*! Builds the shader. - * \param iAmount: - * The stretching amount value. - */ - BackboneStretcherShader(float iAmount = 2.0f) : StrokeShader() - { - _amount = iAmount; - } - - virtual string getName() const - { - return "BackboneStretcherShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class BackboneStretcherShader : public StrokeShader { + private: + float _amount; + + public: + /*! Builds the shader. + * \param iAmount: + * The stretching amount value. + */ + BackboneStretcherShader(float iAmount = 2.0f) : StrokeShader() + { + _amount = iAmount; + } + + virtual string getName() const + { + return "BackboneStretcherShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; /*! [ Geometry Shader. ] * Resamples the stroke. * \see Stroke::Resample(float). */ -class SamplingShader: public StrokeShader -{ -private: - float _sampling; - -public: - /*! Builds the shader. - * \param sampling: - * The sampling to use for the stroke resampling - */ - SamplingShader(float sampling) : StrokeShader() - { - _sampling = sampling; - } - - virtual string getName() const - { - return "SamplingShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class SamplingShader : public StrokeShader { + private: + float _sampling; + + public: + /*! Builds the shader. + * \param sampling: + * The sampling to use for the stroke resampling + */ + SamplingShader(float sampling) : StrokeShader() + { + _sampling = sampling; + } + + virtual string getName() const + { + return "SamplingShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; +class ExternalContourStretcherShader : public StrokeShader { + private: + float _amount; -class ExternalContourStretcherShader : public StrokeShader -{ -private: - float _amount; - -public: - ExternalContourStretcherShader(float iAmount = 2.0f) : StrokeShader() - { - _amount = iAmount; - } + public: + ExternalContourStretcherShader(float iAmount = 2.0f) : StrokeShader() + { + _amount = iAmount; + } - virtual string getName() const - { - return "ExternalContourStretcherShader"; - } + virtual string getName() const + { + return "ExternalContourStretcherShader"; + } - virtual int shade(Stroke& stroke) const; + virtual int shade(Stroke &stroke) const; }; - // Bezier curve stroke shader /*! [ Geometry Shader ]. * Transforms the stroke backbone geometry so that it corresponds to a Bezier Curve approximation of the * original backbone geometry. * \see \htmlonly bezier/bezier.html \endhtmlonly */ -class BezierCurveShader : public StrokeShader -{ -private: - float _error; - -public: - /*! Builds the shader. - * \param error: - * The error we're allowing for the approximation. - * This error is the max distance allowed between the new curve and the original geometry. - */ - BezierCurveShader(float error = 4.0) : StrokeShader() - { - _error = error; - } - - virtual string getName() const - { - return "BezierCurveShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class BezierCurveShader : public StrokeShader { + private: + float _error; + + public: + /*! Builds the shader. + * \param error: + * The error we're allowing for the approximation. + * This error is the max distance allowed between the new curve and the original geometry. + */ + BezierCurveShader(float error = 4.0) : StrokeShader() + { + _error = error; + } + + virtual string getName() const + { + return "BezierCurveShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; - /*! [ Geometry Shader ]. * Shader to modify the Stroke geometry so that it looks more "polygonal". * The basic idea is to start from the minimal stroke approximation consisting in a line joining the first vertex * to the last one and to subdivide using the original stroke vertices until a certain error is reached. */ -class PolygonalizationShader : public StrokeShader -{ -private: - float _error; - -public: - /*! Builds the shader. - * \param iError: - * The error we want our polygonal approximation to have with respect to the original geometry. - * The smaller, the closer the new stroke to the orinal one. - * This error corresponds to the maximum distance between the new stroke and the old one. - */ - PolygonalizationShader(float iError) : StrokeShader() - { - _error = iError; - } - - virtual string getName() const - { - return "PolygonalizationShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class PolygonalizationShader : public StrokeShader { + private: + float _error; + + public: + /*! Builds the shader. + * \param iError: + * The error we want our polygonal approximation to have with respect to the original geometry. + * The smaller, the closer the new stroke to the orinal one. + * This error corresponds to the maximum distance between the new stroke and the old one. + */ + PolygonalizationShader(float iError) : StrokeShader() + { + _error = iError; + } + + virtual string getName() const + { + return "PolygonalizationShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; - /*! [ Geometry Shader ]. * Shader to modify the Stroke geometry so that it corresponds to its main direction line. * This shader must be used together with the splitting operator using the curvature criterion. * Indeed, the precision of the approximation will depend on the size of the stroke's pieces. * The bigger the pieces, the rougher the approximation. */ -class GuidingLinesShader : public StrokeShader -{ -private: - float _offset; - -public: - /*! Builds a Guiding Lines shader - * \param iOffset: - * The line that replaces the stroke is initially in the middle of the initial stroke "bbox". - * iOffset is the value of the displacement which is applied to this line along its normal. - */ - GuidingLinesShader(float iOffset) : StrokeShader() - { - _offset = iOffset; - } - - virtual string getName() const - { - return "GuidingLinesShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class GuidingLinesShader : public StrokeShader { + private: + float _offset; + + public: + /*! Builds a Guiding Lines shader + * \param iOffset: + * The line that replaces the stroke is initially in the middle of the initial stroke "bbox". + * iOffset is the value of the displacement which is applied to this line along its normal. + */ + GuidingLinesShader(float iOffset) : StrokeShader() + { + _offset = iOffset; + } + + virtual string getName() const + { + return "GuidingLinesShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; /*! [ Geometry Shader ]. * Removes the stroke's extremities. */ -class TipRemoverShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param tipLength: - * The length of the piece of stroke we want to remove at each extremity. - */ - TipRemoverShader (real tipLength); - - /*! Destructor. */ - virtual ~TipRemoverShader () {} - - /*! The shading method */ - virtual string getName() const - { - return "TipRemoverShader"; - } - - virtual int shade(Stroke &stroke) const; - -protected: - real _tipLength; +class TipRemoverShader : public StrokeShader { + public: + /*! Builds the shader. + * \param tipLength: + * The length of the piece of stroke we want to remove at each extremity. + */ + TipRemoverShader(real tipLength); + + /*! Destructor. */ + virtual ~TipRemoverShader() + { + } + + /*! The shading method */ + virtual string getName() const + { + return "TipRemoverShader"; + } + + virtual int shade(Stroke &stroke) const; + + protected: + real _tipLength; }; /*! [ Texture Shader ]. * Shader to assign texture to the Stroke material. */ -class BlenderTextureShader : public StrokeShader -{ -private: - MTex *_mtex; - bNodeTree *_nodeTree; - -public: - /*! Builds the shader. - * \param mtex: - * The blender texture to use. - */ - BlenderTextureShader(MTex *mtex) : StrokeShader() - { - _mtex = mtex; - _nodeTree = NULL; - } - - /*! Builds the shader. - * \param nodetree: - * A node tree (of new shading nodes) to define textures. - */ - BlenderTextureShader(bNodeTree *nodetree) : StrokeShader() - { - _nodeTree = nodetree; - _mtex = NULL; - } - - virtual string getName() const - { - return "BlenderTextureShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class BlenderTextureShader : public StrokeShader { + private: + MTex *_mtex; + bNodeTree *_nodeTree; + + public: + /*! Builds the shader. + * \param mtex: + * The blender texture to use. + */ + BlenderTextureShader(MTex *mtex) : StrokeShader() + { + _mtex = mtex; + _nodeTree = NULL; + } + + /*! Builds the shader. + * \param nodetree: + * A node tree (of new shading nodes) to define textures. + */ + BlenderTextureShader(bNodeTree *nodetree) : StrokeShader() + { + _nodeTree = nodetree; + _mtex = NULL; + } + + virtual string getName() const + { + return "BlenderTextureShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; /*! [ Texture Shader ]. * Shader to assign texture to the Stroke material. */ -class StrokeTextureStepShader : public StrokeShader -{ -private: - float _step; - -public: - /*! Builds the shader. - * \param id: - * The number of the preset to use. - */ - StrokeTextureStepShader(float step) : StrokeShader() - { - _step = step; - } - - virtual string getName() const - { - return "StrokeTextureStepShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; +class StrokeTextureStepShader : public StrokeShader { + private: + float _step; + + public: + /*! Builds the shader. + * \param id: + * The number of the preset to use. + */ + StrokeTextureStepShader(float step) : StrokeShader() + { + _step = step; + } + + virtual string getName() const + { + return "StrokeTextureStepShader"; + } + + /*! The shading method */ + virtual int shade(Stroke &stroke) const; }; -} // end of namespace StrokeShaders +} // end of namespace StrokeShaders } /* namespace Freestyle */ -#endif // __FREESTYLE_BASIC_STROKE_SHADERS_H__ +#endif // __FREESTYLE_BASIC_STROKE_SHADERS_H__ diff --git a/source/blender/freestyle/intern/stroke/Canvas.cpp b/source/blender/freestyle/intern/stroke/Canvas.cpp index ea5b8334d20..b497b470492 100644 --- a/source/blender/freestyle/intern/stroke/Canvas.cpp +++ b/source/blender/freestyle/intern/stroke/Canvas.cpp @@ -42,8 +42,8 @@ //soc #include extern "C" { -# include "IMB_imbuf.h" -# include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" } using namespace std; @@ -56,409 +56,416 @@ const char *Canvas::_MapsPath = 0; Canvas::Canvas() { - _SelectedFEdge = 0; - _pInstance = this; - PseudoNoise::init(42); - _Renderer = 0; - _current_sm = NULL; - _steerableViewMap = new SteerableViewMap(NB_STEERABLE_VIEWMAP - 1); - _basic = false; + _SelectedFEdge = 0; + _pInstance = this; + PseudoNoise::init(42); + _Renderer = 0; + _current_sm = NULL; + _steerableViewMap = new SteerableViewMap(NB_STEERABLE_VIEWMAP - 1); + _basic = false; } -Canvas::Canvas(const Canvas& iBrother) +Canvas::Canvas(const Canvas &iBrother) { - _SelectedFEdge = iBrother._SelectedFEdge; - _pInstance = this; - PseudoNoise::init(42); - _Renderer = iBrother._Renderer; - _current_sm = iBrother._current_sm; - _steerableViewMap = new SteerableViewMap(*(iBrother._steerableViewMap)); - _basic = iBrother._basic; + _SelectedFEdge = iBrother._SelectedFEdge; + _pInstance = this; + PseudoNoise::init(42); + _Renderer = iBrother._Renderer; + _current_sm = iBrother._current_sm; + _steerableViewMap = new SteerableViewMap(*(iBrother._steerableViewMap)); + _basic = iBrother._basic; } Canvas::~Canvas() { - _pInstance = 0; - - Clear(); - if (_Renderer) { - delete _Renderer; - _Renderer = 0; - } - // FIXME: think about an easy control for the maps memory management... - if (!_maps.empty()) { - for (mapsMap::iterator m = _maps.begin(), mend = _maps.end(); m != mend; ++m) { - delete ((*m).second); - } - _maps.clear(); - } - if (_steerableViewMap) - delete _steerableViewMap; + _pInstance = 0; + + Clear(); + if (_Renderer) { + delete _Renderer; + _Renderer = 0; + } + // FIXME: think about an easy control for the maps memory management... + if (!_maps.empty()) { + for (mapsMap::iterator m = _maps.begin(), mend = _maps.end(); m != mend; ++m) { + delete ((*m).second); + } + _maps.clear(); + } + if (_steerableViewMap) + delete _steerableViewMap; } -void Canvas::preDraw() {} +void Canvas::preDraw() +{ +} void Canvas::Draw() { - if (_StyleModules.empty()) - return; - preDraw(); - TimeStamp *timestamp = TimeStamp::instance(); + if (_StyleModules.empty()) + return; + preDraw(); + TimeStamp *timestamp = TimeStamp::instance(); - for (unsigned int i = 0; i < _StyleModules.size(); ++i) { - _current_sm = _StyleModules[i]; + for (unsigned int i = 0; i < _StyleModules.size(); ++i) { + _current_sm = _StyleModules[i]; - if (i < _Layers.size() && _Layers[i]) - delete _Layers[i]; + if (i < _Layers.size() && _Layers[i]) + delete _Layers[i]; - _Layers[i] = _StyleModules[i]->execute(); - if (!_Layers[i]) - continue; + _Layers[i] = _StyleModules[i]->execute(); + if (!_Layers[i]) + continue; - stroke_count += _Layers[i]->strokes_size(); + stroke_count += _Layers[i]->strokes_size(); - timestamp->increment(); - } - postDraw(); + timestamp->increment(); + } + postDraw(); } void Canvas::postDraw() { - update(); + update(); } void Canvas::Clear() { - if (!_Layers.empty()) { - for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; ++sl) { - if (*sl) - delete (*sl); - } - _Layers.clear(); - } - - if (!_StyleModules.empty()) { - for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); s != send; ++s) { - if (*s) - delete (*s); - } - _StyleModules.clear(); - } - if (_steerableViewMap) - _steerableViewMap->Reset(); - - stroke_count = 0; + if (!_Layers.empty()) { + for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; + ++sl) { + if (*sl) + delete (*sl); + } + _Layers.clear(); + } + + if (!_StyleModules.empty()) { + for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); + s != send; + ++s) { + if (*s) + delete (*s); + } + _StyleModules.clear(); + } + if (_steerableViewMap) + _steerableViewMap->Reset(); + + stroke_count = 0; } void Canvas::Erase() { - if (!_Layers.empty()) { - for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; ++sl) { - if (*sl) - (*sl)->clear(); - } - } - if (_steerableViewMap) - _steerableViewMap->Reset(); - update(); - - stroke_count = 0; + if (!_Layers.empty()) { + for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; + ++sl) { + if (*sl) + (*sl)->clear(); + } + } + if (_steerableViewMap) + _steerableViewMap->Reset(); + update(); + + stroke_count = 0; } void Canvas::PushBackStyleModule(StyleModule *iStyleModule) { - StrokeLayer *layer = new StrokeLayer(); - _StyleModules.push_back(iStyleModule); - _Layers.push_back(layer); + StrokeLayer *layer = new StrokeLayer(); + _StyleModules.push_back(iStyleModule); + _Layers.push_back(layer); } void Canvas::InsertStyleModule(unsigned index, StyleModule *iStyleModule) { - unsigned size = _StyleModules.size(); - StrokeLayer *layer = new StrokeLayer(); - if ((_StyleModules.empty()) || (index == size)) { - _StyleModules.push_back(iStyleModule); - _Layers.push_back(layer); - return; - } - _StyleModules.insert(_StyleModules.begin() + index, iStyleModule); - _Layers.insert(_Layers.begin() + index, layer); + unsigned size = _StyleModules.size(); + StrokeLayer *layer = new StrokeLayer(); + if ((_StyleModules.empty()) || (index == size)) { + _StyleModules.push_back(iStyleModule); + _Layers.push_back(layer); + return; + } + _StyleModules.insert(_StyleModules.begin() + index, iStyleModule); + _Layers.insert(_Layers.begin() + index, layer); } void Canvas::RemoveStyleModule(unsigned index) { - unsigned int i = 0; - if (!_StyleModules.empty()) { - for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); - s != send; - ++s, ++i) - { - if (i == index) { - // remove shader - if (*s) - delete *s; - _StyleModules.erase(s); - break; - } - } - } - - if (!_Layers.empty()) { - i = 0; - for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); - sl != slend; - ++sl, ++i) - { - if (i == index) { - // remove layer - if (*sl) - delete *sl; - _Layers.erase(sl); - break; - } - } - } + unsigned int i = 0; + if (!_StyleModules.empty()) { + for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); + s != send; + ++s, ++i) { + if (i == index) { + // remove shader + if (*s) + delete *s; + _StyleModules.erase(s); + break; + } + } + } + + if (!_Layers.empty()) { + i = 0; + for (deque::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend; + ++sl, ++i) { + if (i == index) { + // remove layer + if (*sl) + delete *sl; + _Layers.erase(sl); + break; + } + } + } } void Canvas::SwapStyleModules(unsigned i1, unsigned i2) { - StyleModule *tmp; - tmp = _StyleModules[i1]; - _StyleModules[i1] = _StyleModules[i2]; - _StyleModules[i2] = tmp; - - StrokeLayer *tmp2; - tmp2 = _Layers[i1]; - _Layers[i1] = _Layers[i2]; - _Layers[i2] = tmp2; + StyleModule *tmp; + tmp = _StyleModules[i1]; + _StyleModules[i1] = _StyleModules[i2]; + _StyleModules[i2] = tmp; + + StrokeLayer *tmp2; + tmp2 = _Layers[i1]; + _Layers[i1] = _Layers[i2]; + _Layers[i2] = tmp2; } void Canvas::ReplaceStyleModule(unsigned index, StyleModule *iStyleModule) { - unsigned i = 0; - for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); s != send; ++s, ++i) { - if (i == index) { - if (*s) - delete *s; - *s = iStyleModule; - break; - } - } + unsigned i = 0; + for (deque::iterator s = _StyleModules.begin(), send = _StyleModules.end(); + s != send; + ++s, ++i) { + if (i == index) { + if (*s) + delete *s; + *s = iStyleModule; + break; + } + } } void Canvas::setVisible(unsigned index, bool iVisible) { - _StyleModules[index]->setDisplayed(iVisible); + _StyleModules[index]->setDisplayed(iVisible); } void Canvas::setModified(unsigned index, bool iMod) { - _StyleModules[index]->setModified(iMod); + _StyleModules[index]->setModified(iMod); } -void Canvas::resetModified(bool iMod/* = false */) +void Canvas::resetModified(bool iMod /* = false */) { - unsigned int size = _StyleModules.size(); - for (unsigned int i = 0; i < size; ++i) - setModified(i, iMod); + unsigned int size = _StyleModules.size(); + for (unsigned int i = 0; i < size; ++i) + setModified(i, iMod); } -void Canvas::causalStyleModules(vector& vec, unsigned index) +void Canvas::causalStyleModules(vector &vec, unsigned index) { - unsigned int size = _StyleModules.size(); + unsigned int size = _StyleModules.size(); - for (unsigned int i = index; i < size; ++i) { - if (_StyleModules[i]->getCausal()) - vec.push_back(i); - } + for (unsigned int i = index; i < size; ++i) { + if (_StyleModules[i]->getCausal()) + vec.push_back(i); + } } void Canvas::Render(const StrokeRenderer *iRenderer) { - for (unsigned int i = 0; i < _StyleModules.size(); ++i) { - if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) - continue; - _Layers[i]->Render(iRenderer); - } + for (unsigned int i = 0; i < _StyleModules.size(); ++i) { + if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) + continue; + _Layers[i]->Render(iRenderer); + } } void Canvas::RenderBasic(const StrokeRenderer *iRenderer) { - for (unsigned int i = 0; i < _StyleModules.size(); ++i) { - if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) - continue; - _Layers[i]->RenderBasic(iRenderer); - } + for (unsigned int i = 0; i < _StyleModules.size(); ++i) { + if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) + continue; + _Layers[i]->RenderBasic(iRenderer); + } } -void Canvas::loadMap(const char *iFileName, const char *iMapName, unsigned int iNbLevels, float iSigma) +void Canvas::loadMap(const char *iFileName, + const char *iMapName, + unsigned int iNbLevels, + float iSigma) { - // check whether this map was already loaded: - if (!_maps.empty()) { - mapsMap::iterator m = _maps.find(iMapName); - if (m != _maps.end()) { - // lazy check for size changes - ImagePyramid *pyramid = (*m).second; - if ((pyramid->width() != width()) || (pyramid->height() != height())) { - delete pyramid; - } - else { - return; - } - } - } - - string filePath; - if (_MapsPath) { - filePath = _MapsPath; - filePath += iFileName; - } - else { - filePath = iFileName; - } - -#if 0 //soc - QImage *qimg; - QImage newMap(filePath.c_str()); - if (newMap.isNull()) { - cerr << "Could not load image file " << filePath << endl; - return; - } - qimg = &newMap; + // check whether this map was already loaded: + if (!_maps.empty()) { + mapsMap::iterator m = _maps.find(iMapName); + if (m != _maps.end()) { + // lazy check for size changes + ImagePyramid *pyramid = (*m).second; + if ((pyramid->width() != width()) || (pyramid->height() != height())) { + delete pyramid; + } + else { + return; + } + } + } + + string filePath; + if (_MapsPath) { + filePath = _MapsPath; + filePath += iFileName; + } + else { + filePath = iFileName; + } + +#if 0 //soc + QImage *qimg; + QImage newMap(filePath.c_str()); + if (newMap.isNull()) { + cerr << "Could not load image file " << filePath << endl; + return; + } + qimg = &newMap; #endif - /* OCIO_TODO: support different input color space */ - ImBuf *qimg = IMB_loadiffname(filePath.c_str(), 0, NULL); - if (qimg == 0) { - cerr << "Could not load image file " << filePath << endl; - return; - } - -#if 0 // soc - // resize - QImage scaledImg; - if ((newMap.width() != width()) || (newMap.height() != height())) { - scaledImg = newMap.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - qimg = &scaledImg; - } + /* OCIO_TODO: support different input color space */ + ImBuf *qimg = IMB_loadiffname(filePath.c_str(), 0, NULL); + if (qimg == 0) { + cerr << "Could not load image file " << filePath << endl; + return; + } + +#if 0 // soc + // resize + QImage scaledImg; + if ((newMap.width() != width()) || (newMap.height() != height())) { + scaledImg = newMap.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + qimg = &scaledImg; + } #endif - ImBuf *scaledImg; - if ((qimg->x != width()) || (qimg->y != height())) { - scaledImg = IMB_dupImBuf(qimg); - IMB_scaleImBuf(scaledImg, width(), height()); - } - + ImBuf *scaledImg; + if ((qimg->x != width()) || (qimg->y != height())) { + scaledImg = IMB_dupImBuf(qimg); + IMB_scaleImBuf(scaledImg, width(), height()); + } - // deal with color image + // deal with color image #if 0 - if (newMap->depth() != 8) { - int w = newMap->width(); - int h = newMap->height(); - QImage *tmp = new QImage(w, h, 8); - for (unsigned int y = 0; y < h; ++y) { - for (unsigned int x = 0; x < w; ++x) { - int c = qGray(newMap->pixel(x, y)); - tmp->setPixel(x, y, c); - } - } - delete newMap; - newMap = tmp; - } + if (newMap->depth() != 8) { + int w = newMap->width(); + int h = newMap->height(); + QImage *tmp = new QImage(w, h, 8); + for (unsigned int y = 0; y < h; ++y) { + for (unsigned int x = 0; x < w; ++x) { + int c = qGray(newMap->pixel(x, y)); + tmp->setPixel(x, y, c); + } + } + delete newMap; + newMap = tmp; + } #endif - int x, y; - int w = qimg->x; - int h = qimg->y; - int rowbytes = w * 4; - GrayImage tmp(w, h); - char *pix; - - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - pix = (char *)qimg->rect + y * rowbytes + x * 4; - float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32; - tmp.setPixel(x, y, c); - } - } + int x, y; + int w = qimg->x; + int h = qimg->y; + int rowbytes = w * 4; + GrayImage tmp(w, h); + char *pix; + + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + pix = (char *)qimg->rect + y * rowbytes + x * 4; + float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32; + tmp.setPixel(x, y, c); + } + } #if 0 - GrayImage blur(w, h); - GaussianFilter gf(4.0f); - //int bound = gf.getBound(); - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - int c = gf.getSmoothedPixel(&tmp, x, y); - blur.setPixel(x, y, c); - } - } + GrayImage blur(w, h); + GaussianFilter gf(4.0f); + //int bound = gf.getBound(); + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + int c = gf.getSmoothedPixel(&tmp, x, y); + blur.setPixel(x, y, c); + } + } #endif - GaussianPyramid *pyramid = new GaussianPyramid(tmp, iNbLevels, iSigma); - int ow = pyramid->width(0); - int oh = pyramid->height(0); - string base(iMapName); //soc - for (int i = 0; i < pyramid->getNumberOfLevels(); ++i) { - // save each image: + GaussianPyramid *pyramid = new GaussianPyramid(tmp, iNbLevels, iSigma); + int ow = pyramid->width(0); + int oh = pyramid->height(0); + string base(iMapName); //soc + for (int i = 0; i < pyramid->getNumberOfLevels(); ++i) { + // save each image: #if 0 - w = pyramid.width(i); - h = pyramid.height(i); + w = pyramid.width(i); + h = pyramid.height(i); #endif - //soc QImage qtmp(ow, oh, QImage::Format_RGB32); - ImBuf *qtmp = IMB_allocImBuf(ow, oh, 32, IB_rect); - - //int k = (1 << i); - for (y = 0; y < oh; ++y) { - for (x = 0; x < ow; ++x) { - int c = pyramid->pixel(x, y, i); // 255 * pyramid->pixel(x, y, i); - //soc qtmp.setPixel(x, y, qRgb(c, c, c)); - pix = (char *)qtmp->rect + y * rowbytes + x * 4; - pix[0] = pix[1] = pix[2] = c; - } - } - //soc qtmp.save(base + QString::number(i) + ".bmp", "BMP"); - stringstream filename; - filename << base; - filename << i << ".bmp"; - qtmp->ftype = IMB_FTYPE_BMP; - IMB_saveiff(qtmp, const_cast(filename.str().c_str()), 0); - } + //soc QImage qtmp(ow, oh, QImage::Format_RGB32); + ImBuf *qtmp = IMB_allocImBuf(ow, oh, 32, IB_rect); + + //int k = (1 << i); + for (y = 0; y < oh; ++y) { + for (x = 0; x < ow; ++x) { + int c = pyramid->pixel(x, y, i); // 255 * pyramid->pixel(x, y, i); + //soc qtmp.setPixel(x, y, qRgb(c, c, c)); + pix = (char *)qtmp->rect + y * rowbytes + x * 4; + pix[0] = pix[1] = pix[2] = c; + } + } + //soc qtmp.save(base + QString::number(i) + ".bmp", "BMP"); + stringstream filename; + filename << base; + filename << i << ".bmp"; + qtmp->ftype = IMB_FTYPE_BMP; + IMB_saveiff(qtmp, const_cast(filename.str().c_str()), 0); + } #if 0 - QImage *qtmp = new QImage(w, h, 32); - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - int c = (int)blur.pixel(x, y); - qtmp->setPixel(x, y, qRgb(c, c, c)); - } - } - delete newMap; - newMap = qtmp; + QImage *qtmp = new QImage(w, h, 32); + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + int c = (int)blur.pixel(x, y); + qtmp->setPixel(x, y, qRgb(c, c, c)); + } + } + delete newMap; + newMap = qtmp; #endif - _maps[iMapName] = pyramid; - //newMap->save("toto.bmp", "BMP"); + _maps[iMapName] = pyramid; + //newMap->save("toto.bmp", "BMP"); } float Canvas::readMapPixel(const char *iMapName, int level, int x, int y) { - if (_maps.empty()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "readMapPixel warning: no map was loaded "<< endl; - } - return -1; - } - mapsMap::iterator m = _maps.find(iMapName); - if (m == _maps.end()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "readMapPixel warning: no map was loaded with the name " << iMapName << endl; - } - return -1; - } - ImagePyramid *pyramid = (*m).second; - if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) - return 0; - - return pyramid->pixel(x, height() - 1 - y, level); + if (_maps.empty()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "readMapPixel warning: no map was loaded " << endl; + } + return -1; + } + mapsMap::iterator m = _maps.find(iMapName); + if (m == _maps.end()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "readMapPixel warning: no map was loaded with the name " << iMapName << endl; + } + return -1; + } + ImagePyramid *pyramid = (*m).second; + if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) + return 0; + + return pyramid->pixel(x, height() - 1 - y, level); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Canvas.h b/source/blender/freestyle/intern/stroke/Canvas.h index 9431b37395c..e059bb07eda 100644 --- a/source/blender/freestyle/intern/stroke/Canvas.h +++ b/source/blender/freestyle/intern/stroke/Canvas.h @@ -35,19 +35,18 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { using namespace Geometry; -struct ltstr -{ - bool operator()(const char *s1, const char *s2) const - { - return strcmp(s1, s2) < 0; - } +struct ltstr { + bool operator()(const char *s1, const char *s2) const + { + return strcmp(s1, s2) < 0; + } }; class InformationMap; @@ -65,189 +64,191 @@ class StyleModule; /*! Class to define the canvas on which strokes are drawn. * It's used to store state information about the drawing. */ -class Canvas -{ -public: - /*! Returns a pointer on the Canvas instance */ - static Canvas *getInstance() - { - return _pInstance; - } - - typedef std::map mapsMap; - static const int NB_STEERABLE_VIEWMAP = 5; - -protected: - static Canvas *_pInstance; - std::deque _Layers; - std::deque _StyleModules; - FEdge *_SelectedFEdge; - - StrokeRenderer *_Renderer; - StyleModule *_current_sm; - mapsMap _maps; - static const char *_MapsPath; - SteerableViewMap *_steerableViewMap; - bool _basic; - int stroke_count; - -public: - /* Builds the Canvas */ - Canvas(); - /* Copy constructor */ - Canvas(const Canvas& iBrother); - /* Destructor */ - virtual ~Canvas(); - - /* operations that need to be done before a draw */ - virtual void preDraw(); - - /* Draw the canvas using the current shader */ - virtual void Draw(); - - /* operations that need to be done after a draw */ - virtual void postDraw(); - - /* Renders the created strokes */ - virtual void Render(const StrokeRenderer *iRenderer); - /* Basic Renders the created strokes */ - virtual void RenderBasic(const StrokeRenderer *iRenderer); - /* Renders a stroke */ - virtual void RenderStroke(Stroke *iStroke) = 0; - - /* init the canvas */ - virtual void init() = 0; - - /* Clears the Canvas (shaders stack, layers stack...) */ - void Clear(); - - /* Erases the layers */ - virtual void Erase(); - - /* Reads a pixel area from the canvas */ - virtual void readColorPixels(int x, int y, int w, int h, RGBImage& oImage) const = 0; - /* Reads a depth pixel area from the canvas */ - virtual void readDepthPixels(int x, int y, int w, int h, GrayImage& oImage) const = 0; - - /* update the canvas (display) */ - virtual void update() = 0; - - /* checks whether the canvas is empty or not */ - bool isEmpty() const - { - return (_Layers.empty()); - } - - /* Maps management */ - /*! Loads an image map. The map will be scaled (without preserving the ratio in order to fit the actual - * canvas size.). - * The image must be a gray values image... - * \param iFileName: - * The name of the image file - * \param iMapName: - * The name that will be used to access this image - * \param iNbLevels: - * The number of levels in the map pyramid. (default = 4). - * If iNbLevels == 0, the complete pyramid is built. - */ - void loadMap(const char *iFileName, const char *iMapName, unsigned iNbLevels = 4, float iSigma = 1.0f); - - /*! Reads a pixel value in a map. - * Returns a value between 0 and 1. - * \param iMapName: - * The name of the map - * \param level: - * The level of the pyramid from which the pixel must be read. - * \param x: - * The abscissa of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. - * \param y: - * The ordinate of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. - */ - float readMapPixel(const char *iMapName, int level, int x, int y); - - /*! Sets the steerable viewmap */ - void loadSteerableViewMap(SteerableViewMap *iSVM) - { - _steerableViewMap = iSVM; - } - - /*! Returns the steerable VM */ - SteerableViewMap *getSteerableViewMap() - { - return _steerableViewMap; - } - - /*! accessors */ - inline const FEdge *selectedFEdge() const - { - return _SelectedFEdge; - } - - inline FEdge *selectedFEdge() - { - return _SelectedFEdge; - } - - virtual int width() const = 0; - virtual int height() const = 0; - virtual BBox border() const = 0; - virtual BBox scene3DBBox() const = 0; - - inline const StrokeRenderer *renderer() const - { - return _Renderer; - } - - inline StyleModule *getCurrentStyleModule() - { - return _current_sm; - } - - virtual bool getRecordFlag() const - { - return false; - } - - inline int getStrokeCount() const - { - return stroke_count; - } - - /*! modifiers */ - inline void setSelectedFEdge(FEdge *iFEdge) - { - _SelectedFEdge = iFEdge; - } - - /*! inserts a shader at pos index+1 */ - void PushBackStyleModule(StyleModule *iStyleModule); - void InsertStyleModule(unsigned index, StyleModule *iStyleModule); - void RemoveStyleModule(unsigned index); - void SwapStyleModules(unsigned i1, unsigned i2); - void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule); - void setVisible(unsigned index, bool iVisible) ; +class Canvas { + public: + /*! Returns a pointer on the Canvas instance */ + static Canvas *getInstance() + { + return _pInstance; + } + + typedef std::map mapsMap; + static const int NB_STEERABLE_VIEWMAP = 5; + + protected: + static Canvas *_pInstance; + std::deque _Layers; + std::deque _StyleModules; + FEdge *_SelectedFEdge; + + StrokeRenderer *_Renderer; + StyleModule *_current_sm; + mapsMap _maps; + static const char *_MapsPath; + SteerableViewMap *_steerableViewMap; + bool _basic; + int stroke_count; + + public: + /* Builds the Canvas */ + Canvas(); + /* Copy constructor */ + Canvas(const Canvas &iBrother); + /* Destructor */ + virtual ~Canvas(); + + /* operations that need to be done before a draw */ + virtual void preDraw(); + + /* Draw the canvas using the current shader */ + virtual void Draw(); + + /* operations that need to be done after a draw */ + virtual void postDraw(); + + /* Renders the created strokes */ + virtual void Render(const StrokeRenderer *iRenderer); + /* Basic Renders the created strokes */ + virtual void RenderBasic(const StrokeRenderer *iRenderer); + /* Renders a stroke */ + virtual void RenderStroke(Stroke *iStroke) = 0; + + /* init the canvas */ + virtual void init() = 0; + + /* Clears the Canvas (shaders stack, layers stack...) */ + void Clear(); + + /* Erases the layers */ + virtual void Erase(); + + /* Reads a pixel area from the canvas */ + virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const = 0; + /* Reads a depth pixel area from the canvas */ + virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const = 0; + + /* update the canvas (display) */ + virtual void update() = 0; + + /* checks whether the canvas is empty or not */ + bool isEmpty() const + { + return (_Layers.empty()); + } + + /* Maps management */ + /*! Loads an image map. The map will be scaled (without preserving the ratio in order to fit the actual + * canvas size.). + * The image must be a gray values image... + * \param iFileName: + * The name of the image file + * \param iMapName: + * The name that will be used to access this image + * \param iNbLevels: + * The number of levels in the map pyramid. (default = 4). + * If iNbLevels == 0, the complete pyramid is built. + */ + void loadMap(const char *iFileName, + const char *iMapName, + unsigned iNbLevels = 4, + float iSigma = 1.0f); + + /*! Reads a pixel value in a map. + * Returns a value between 0 and 1. + * \param iMapName: + * The name of the map + * \param level: + * The level of the pyramid from which the pixel must be read. + * \param x: + * The abscissa of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. + * \param y: + * The ordinate of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. + */ + float readMapPixel(const char *iMapName, int level, int x, int y); + + /*! Sets the steerable viewmap */ + void loadSteerableViewMap(SteerableViewMap *iSVM) + { + _steerableViewMap = iSVM; + } + + /*! Returns the steerable VM */ + SteerableViewMap *getSteerableViewMap() + { + return _steerableViewMap; + } + + /*! accessors */ + inline const FEdge *selectedFEdge() const + { + return _SelectedFEdge; + } + + inline FEdge *selectedFEdge() + { + return _SelectedFEdge; + } + + virtual int width() const = 0; + virtual int height() const = 0; + virtual BBox border() const = 0; + virtual BBox scene3DBBox() const = 0; + + inline const StrokeRenderer *renderer() const + { + return _Renderer; + } + + inline StyleModule *getCurrentStyleModule() + { + return _current_sm; + } + + virtual bool getRecordFlag() const + { + return false; + } + + inline int getStrokeCount() const + { + return stroke_count; + } + + /*! modifiers */ + inline void setSelectedFEdge(FEdge *iFEdge) + { + _SelectedFEdge = iFEdge; + } + + /*! inserts a shader at pos index+1 */ + void PushBackStyleModule(StyleModule *iStyleModule); + void InsertStyleModule(unsigned index, StyleModule *iStyleModule); + void RemoveStyleModule(unsigned index); + void SwapStyleModules(unsigned i1, unsigned i2); + void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule); + void setVisible(unsigned index, bool iVisible); #if 0 - inline void setDensityMap(InformationMap *iMap) - { - _DensityMap = iMap; - } + inline void setDensityMap(InformationMap *iMap) + { + _DensityMap = iMap; + } #endif - inline void AddLayer(StrokeLayer *iLayer) - { - _Layers.push_back(iLayer); - } + inline void AddLayer(StrokeLayer *iLayer) + { + _Layers.push_back(iLayer); + } - void resetModified(bool iMod = false); - void causalStyleModules(std::vector& vec, unsigned index = 0); - void setModified(unsigned index, bool b); + void resetModified(bool iMod = false); + void causalStyleModules(std::vector &vec, unsigned index = 0); + void setModified(unsigned index, bool b); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Canvas") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Canvas") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_CANVAS_H__ +#endif // __FREESTYLE_CANVAS_H__ diff --git a/source/blender/freestyle/intern/stroke/Chain.cpp b/source/blender/freestyle/intern/stroke/Chain.cpp index 53e5c24352c..32b3ec2de31 100644 --- a/source/blender/freestyle/intern/stroke/Chain.cpp +++ b/source/blender/freestyle/intern/stroke/Chain.cpp @@ -28,122 +28,124 @@ namespace Freestyle { void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation) { - ViewEdge::vertex_iterator v; - ViewEdge::vertex_iterator vend; - ViewEdge::vertex_iterator vfirst; - Vec3r previous, current; - if (true == orientation) { - v = iViewEdge->vertices_begin(); - vfirst = v; - vend = iViewEdge->vertices_end(); - } - else { - v = iViewEdge->vertices_last(); - vfirst = v; - vend = iViewEdge->vertices_end(); - } + ViewEdge::vertex_iterator v; + ViewEdge::vertex_iterator vend; + ViewEdge::vertex_iterator vfirst; + Vec3r previous, current; + if (true == orientation) { + v = iViewEdge->vertices_begin(); + vfirst = v; + vend = iViewEdge->vertices_end(); + } + else { + v = iViewEdge->vertices_last(); + vfirst = v; + vend = iViewEdge->vertices_end(); + } - if (!_Vertices.empty()) { - previous = _Vertices.back()->point2d(); - if (orientation) - ++v; - else - --v; - // Ensure the continuity of underlying FEdges - CurvePoint *cp = _Vertices.back(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); - SVertex *sv_first = (*vfirst); - FEdge *fe = _fedgeB->duplicate(); - fe->setTemporary(true); - fe->setVertexB(sv_first); - fe->vertexA()->shape()->AddEdge(fe); - fe->vertexA()->AddFEdge(fe); - fe->vertexB()->AddFEdge(fe); - cp->setA(sv_first); - } - else { - previous = (*v)->point2d(); - } - do { - current = (*v)->point2d(); - Curve::push_vertex_back(*v); - //_Length += (current - previous).norm(); - previous = current; - if (orientation) - ++v; - else - --v; - } while ((v != vend) && (v != vfirst)); + if (!_Vertices.empty()) { + previous = _Vertices.back()->point2d(); + if (orientation) + ++v; + else + --v; + // Ensure the continuity of underlying FEdges + CurvePoint *cp = + _Vertices.back(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); + SVertex *sv_first = (*vfirst); + FEdge *fe = _fedgeB->duplicate(); + fe->setTemporary(true); + fe->setVertexB(sv_first); + fe->vertexA()->shape()->AddEdge(fe); + fe->vertexA()->AddFEdge(fe); + fe->vertexB()->AddFEdge(fe); + cp->setA(sv_first); + } + else { + previous = (*v)->point2d(); + } + do { + current = (*v)->point2d(); + Curve::push_vertex_back(*v); + //_Length += (current - previous).norm(); + previous = current; + if (orientation) + ++v; + else + --v; + } while ((v != vend) && (v != vfirst)); - if (v == vfirst) { - //Add last one: - current = (*v)->point2d(); - Curve::push_vertex_back(*v); - //_Length += (current - previous).norm(); - } + if (v == vfirst) { + //Add last one: + current = (*v)->point2d(); + Curve::push_vertex_back(*v); + //_Length += (current - previous).norm(); + } - _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA(); + _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA(); } void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation) { - orientation = !orientation; - ViewEdge::vertex_iterator v; - ViewEdge::vertex_iterator vend; - ViewEdge::vertex_iterator vfirst; - Vec3r previous, current; - if (true == orientation) { - v = iViewEdge->vertices_begin(); - vfirst = v; - vend = iViewEdge->vertices_end(); - } - else { - v = iViewEdge->vertices_last(); - vfirst = v; - vend = iViewEdge->vertices_end(); - } + orientation = !orientation; + ViewEdge::vertex_iterator v; + ViewEdge::vertex_iterator vend; + ViewEdge::vertex_iterator vfirst; + Vec3r previous, current; + if (true == orientation) { + v = iViewEdge->vertices_begin(); + vfirst = v; + vend = iViewEdge->vertices_end(); + } + else { + v = iViewEdge->vertices_last(); + vfirst = v; + vend = iViewEdge->vertices_end(); + } - if (!_Vertices.empty()) { - previous = _Vertices.front()->point2d(); - if (orientation) - ++v; - else - --v; - // Ensure the continuity of underlying FEdges - CurvePoint *cp = _Vertices.front(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); - SVertex *sv_last = cp->A(); - SVertex *sv_curr = (*v); - FEdge *fe = (orientation) ? iViewEdge->fedgeA() : iViewEdge->fedgeB(); - FEdge *fe2 = fe->duplicate(); - fe2->setTemporary(true); - fe2->setVertexA(sv_curr); - fe2->setVertexB(sv_last); - sv_last->AddFEdge(fe2); - sv_curr->AddFEdge(fe2); - sv_curr->shape()->AddEdge(fe2); - } - else { - previous = (*v)->point2d(); - } - do { - current = (*v)->point2d(); - Curve::push_vertex_front((*v)); - //_Length += (current - previous).norm(); - previous = current; - if (orientation) - ++v; - else - --v; - } while ((v != vend) && (v != vfirst)); + if (!_Vertices.empty()) { + previous = _Vertices.front()->point2d(); + if (orientation) + ++v; + else + --v; + // Ensure the continuity of underlying FEdges + CurvePoint *cp = + _Vertices.front(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.f); + SVertex *sv_last = cp->A(); + SVertex *sv_curr = (*v); + FEdge *fe = (orientation) ? iViewEdge->fedgeA() : iViewEdge->fedgeB(); + FEdge *fe2 = fe->duplicate(); + fe2->setTemporary(true); + fe2->setVertexA(sv_curr); + fe2->setVertexB(sv_last); + sv_last->AddFEdge(fe2); + sv_curr->AddFEdge(fe2); + sv_curr->shape()->AddEdge(fe2); + } + else { + previous = (*v)->point2d(); + } + do { + current = (*v)->point2d(); + Curve::push_vertex_front((*v)); + //_Length += (current - previous).norm(); + previous = current; + if (orientation) + ++v; + else + --v; + } while ((v != vend) && (v != vfirst)); - if (v == vfirst) { - //Add last one: - current = (*v)->point2d(); - Curve::push_vertex_front(*v); - //_Length += (current - previous).norm(); - } + if (v == vfirst) { + //Add last one: + current = (*v)->point2d(); + Curve::push_vertex_front(*v); + //_Length += (current - previous).norm(); + } - if (!_fedgeB) - _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA(); + if (!_fedgeB) + _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Chain.h b/source/blender/freestyle/intern/stroke/Chain.h index 21421c7298f..547fed70953 100644 --- a/source/blender/freestyle/intern/stroke/Chain.h +++ b/source/blender/freestyle/intern/stroke/Chain.h @@ -31,81 +31,82 @@ namespace Freestyle { /*! Class to represent a 1D elements issued from the chaining process. * A Chain is the last step before the Stroke and is used in the Splitting and Creation processes. */ -class Chain : public Curve -{ -protected: - // tmp - Id *_splittingId; - FEdge *_fedgeB; // the last FEdge of the ViewEdge passed to the last call for push_viewedge_back(). - -public: - /*! Defult constructor. */ - Chain() : Curve() - { - _splittingId = 0; - _fedgeB = 0; - } - - /*! Builds a chain from its Id. */ - Chain(const Id& id) : Curve(id) - { - _splittingId = 0; - _fedgeB = 0; - } - - /*! Copy Constructor */ - Chain(const Chain& iBrother) : Curve(iBrother) - { - _splittingId = iBrother._splittingId; - _fedgeB = iBrother._fedgeB; - } - - /*! Destructor. */ - virtual ~Chain() { - // only the last splitted deletes this id - if (_splittingId) { - if (*_splittingId == _Id) - delete _splittingId; - } - } - - /*! Returns the string "Chain" */ - virtual string getExactTypeName() const - { - return "Chain"; - } - - /*! Adds a ViewEdge at the end of the chain - * \param iViewEdge: - * The ViewEdge that must be added. - * \param orientation: - * The orientation with which this ViewEdge must be processed. - */ - void push_viewedge_back(ViewEdge *iViewEdge, bool orientation); - - /*! Adds a ViewEdge at the beginning of the chain - * \param iViewEdge: - * The ViewEdge that must be added. - * \param orientation: - * The orientation with which this ViewEdge must be processed. - */ - void push_viewedge_front(ViewEdge *iViewEdge, bool orientation); - - inline void setSplittingId(Id *sid) - { - _splittingId = sid; - } - - inline Id *getSplittingId() - { - return _splittingId; - } +class Chain : public Curve { + protected: + // tmp + Id *_splittingId; + FEdge * + _fedgeB; // the last FEdge of the ViewEdge passed to the last call for push_viewedge_back(). + + public: + /*! Defult constructor. */ + Chain() : Curve() + { + _splittingId = 0; + _fedgeB = 0; + } + + /*! Builds a chain from its Id. */ + Chain(const Id &id) : Curve(id) + { + _splittingId = 0; + _fedgeB = 0; + } + + /*! Copy Constructor */ + Chain(const Chain &iBrother) : Curve(iBrother) + { + _splittingId = iBrother._splittingId; + _fedgeB = iBrother._fedgeB; + } + + /*! Destructor. */ + virtual ~Chain() + { + // only the last splitted deletes this id + if (_splittingId) { + if (*_splittingId == _Id) + delete _splittingId; + } + } + + /*! Returns the string "Chain" */ + virtual string getExactTypeName() const + { + return "Chain"; + } + + /*! Adds a ViewEdge at the end of the chain + * \param iViewEdge: + * The ViewEdge that must be added. + * \param orientation: + * The orientation with which this ViewEdge must be processed. + */ + void push_viewedge_back(ViewEdge *iViewEdge, bool orientation); + + /*! Adds a ViewEdge at the beginning of the chain + * \param iViewEdge: + * The ViewEdge that must be added. + * \param orientation: + * The orientation with which this ViewEdge must be processed. + */ + void push_viewedge_front(ViewEdge *iViewEdge, bool orientation); + + inline void setSplittingId(Id *sid) + { + _splittingId = sid; + } + + inline Id *getSplittingId() + { + return _splittingId; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chain") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chain") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_CHAIN_H__ +#endif // __FREESTYLE_CHAIN_H__ diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.cpp b/source/blender/freestyle/intern/stroke/ChainingIterators.cpp index 08bdeb61713..de6c50fe571 100644 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.cpp +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.cpp @@ -29,93 +29,93 @@ namespace Freestyle { ViewEdge *AdjacencyIterator::operator*() { - return (*_internalIterator).first; + return (*_internalIterator).first; } bool AdjacencyIterator::isIncoming() const { - return (*_internalIterator).second; + return (*_internalIterator).second; } int AdjacencyIterator::increment() { - ++_internalIterator; - while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) - ++_internalIterator; - return 0; + ++_internalIterator; + while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) + ++_internalIterator; + return 0; } bool AdjacencyIterator::isValid(ViewEdge *edge) { - if (_restrictToSelection) { - if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) - return false; - } - if (_restrictToUnvisited) { - if (edge->getChainingTimeStamp() > TimeStamp::instance()->getTimeStamp()) - return false; - } - return true; + if (_restrictToSelection) { + if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) + return false; + } + if (_restrictToUnvisited) { + if (edge->getChainingTimeStamp() > TimeStamp::instance()->getTimeStamp()) + return false; + } + return true; } int ChainingIterator::init() { - return Director_BPy_ChainingIterator_init(this); + return Director_BPy_ChainingIterator_init(this); } int ChainingIterator::traverse(const AdjacencyIterator &it) { - return Director_BPy_ChainingIterator_traverse(this, const_cast(it)); + return Director_BPy_ChainingIterator_traverse(this, const_cast(it)); } int ChainingIterator::increment() { - _increment = true; - ViewVertex *vertex = getVertex(); - if (!vertex) { - _edge = 0; - return 0; - } - AdjacencyIterator it = AdjacencyIterator(vertex, _restrictToSelection, _restrictToUnvisited); - if (it.isEnd()) { - _edge = 0; - return 0; - } - if (traverse(it) < 0) - return -1; - _edge = result; - if (_edge == 0) - return 0; - if (_edge->A() == vertex) - _orientation = true; - else - _orientation = false; - return 0; + _increment = true; + ViewVertex *vertex = getVertex(); + if (!vertex) { + _edge = 0; + return 0; + } + AdjacencyIterator it = AdjacencyIterator(vertex, _restrictToSelection, _restrictToUnvisited); + if (it.isEnd()) { + _edge = 0; + return 0; + } + if (traverse(it) < 0) + return -1; + _edge = result; + if (_edge == 0) + return 0; + if (_edge->A() == vertex) + _orientation = true; + else + _orientation = false; + return 0; } int ChainingIterator::decrement() { - _increment = false; - ViewVertex *vertex = getVertex(); - if (!vertex) { - _edge = 0; - return 0; - } - AdjacencyIterator it = AdjacencyIterator(vertex, _restrictToSelection, _restrictToUnvisited); - if (it.isEnd()) { - _edge = 0; - return 0; - } - if (traverse(it) < 0) - return -1; - _edge = result; - if (_edge == 0) - return 0; - if (_edge->B() == vertex) - _orientation = true; - else - _orientation = false; - return 0; + _increment = false; + ViewVertex *vertex = getVertex(); + if (!vertex) { + _edge = 0; + return 0; + } + AdjacencyIterator it = AdjacencyIterator(vertex, _restrictToSelection, _restrictToUnvisited); + if (it.isEnd()) { + _edge = 0; + return 0; + } + if (traverse(it) < 0) + return -1; + _edge = result; + if (_edge == 0) + return 0; + if (_edge->B() == vertex) + _orientation = true; + else + _orientation = false; + return 0; } // @@ -123,88 +123,88 @@ int ChainingIterator::decrement() // /////////////////////////////////////////////////////////// -int ChainSilhouetteIterator::traverse(const AdjacencyIterator& ait) +int ChainSilhouetteIterator::traverse(const AdjacencyIterator &ait) { - AdjacencyIterator it(ait); - ViewVertex *nextVertex = getVertex(); - // we can't get a NULL nextVertex here, it was intercepted before - if (nextVertex->getNature() & Nature::T_VERTEX) { - TVertex *tvertex = (TVertex *)nextVertex; - ViewEdge *mate = (tvertex)->mate(getCurrentEdge()); - while (!it.isEnd()) { - ViewEdge *ve = *it; - if (ve == mate) { - result = ve; - return 0; - } - ++it; - } - result = 0; - return 0; - } - if (nextVertex->getNature() & Nature::NON_T_VERTEX) { - //soc NonTVertex *nontvertex = (NonTVertex*)nextVertex; - ViewEdge *newEdge(0); - // we'll try to chain the edges by keeping the same nature... - // the preseance order is : SILHOUETTE, BORDER, CREASE, MATERIAL_BOUNDARY, EDGE_MARK, SUGGESTIVE, VALLEY, RIDGE - Nature::EdgeNature natures[8] = { - Nature::SILHOUETTE, - Nature::BORDER, - Nature::CREASE, - Nature::MATERIAL_BOUNDARY, - Nature::EDGE_MARK, - Nature::SUGGESTIVE_CONTOUR, - Nature::VALLEY, - Nature::RIDGE, - }; - int numNatures = sizeof(natures) / sizeof(Nature::EdgeNature); - for (int i = 0; i < numNatures; ++i) { - if (getCurrentEdge()->getNature() & natures[i]) { - int n = 0; - while (!it.isEnd()) { - ViewEdge *ve = *it; - if (ve->getNature() & natures[i]) { - ++n; - newEdge = ve; - } - ++it; - } - if (n == 1) { - result = newEdge; - } - else { - result = 0; - } - return 0; - } - } - } - result = 0; - return 0; + AdjacencyIterator it(ait); + ViewVertex *nextVertex = getVertex(); + // we can't get a NULL nextVertex here, it was intercepted before + if (nextVertex->getNature() & Nature::T_VERTEX) { + TVertex *tvertex = (TVertex *)nextVertex; + ViewEdge *mate = (tvertex)->mate(getCurrentEdge()); + while (!it.isEnd()) { + ViewEdge *ve = *it; + if (ve == mate) { + result = ve; + return 0; + } + ++it; + } + result = 0; + return 0; + } + if (nextVertex->getNature() & Nature::NON_T_VERTEX) { + //soc NonTVertex *nontvertex = (NonTVertex*)nextVertex; + ViewEdge *newEdge(0); + // we'll try to chain the edges by keeping the same nature... + // the preseance order is : SILHOUETTE, BORDER, CREASE, MATERIAL_BOUNDARY, EDGE_MARK, SUGGESTIVE, VALLEY, RIDGE + Nature::EdgeNature natures[8] = { + Nature::SILHOUETTE, + Nature::BORDER, + Nature::CREASE, + Nature::MATERIAL_BOUNDARY, + Nature::EDGE_MARK, + Nature::SUGGESTIVE_CONTOUR, + Nature::VALLEY, + Nature::RIDGE, + }; + int numNatures = sizeof(natures) / sizeof(Nature::EdgeNature); + for (int i = 0; i < numNatures; ++i) { + if (getCurrentEdge()->getNature() & natures[i]) { + int n = 0; + while (!it.isEnd()) { + ViewEdge *ve = *it; + if (ve->getNature() & natures[i]) { + ++n; + newEdge = ve; + } + ++it; + } + if (n == 1) { + result = newEdge; + } + else { + result = 0; + } + return 0; + } + } + } + result = 0; + return 0; } -int ChainPredicateIterator::traverse(const AdjacencyIterator& ait) +int ChainPredicateIterator::traverse(const AdjacencyIterator &ait) { - if (!_unary_predicate || !_binary_predicate) - return -1; - AdjacencyIterator it(ait); - // Iterates over next edges to see if one of them respects the predicate: - while (!it.isEnd()) { - ViewEdge *ve = *it; - if (_unary_predicate->operator()(*ve) < 0) - return -1; - if (_unary_predicate->result) { - if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) - return -1; - if (_binary_predicate->result) { - result = ve; - return 0; - } - } - ++it; - } - result = 0; - return 0; + if (!_unary_predicate || !_binary_predicate) + return -1; + AdjacencyIterator it(ait); + // Iterates over next edges to see if one of them respects the predicate: + while (!it.isEnd()) { + ViewEdge *ve = *it; + if (_unary_predicate->operator()(*ve) < 0) + return -1; + if (_unary_predicate->result) { + if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) + return -1; + if (_binary_predicate->result) { + result = ve; + return 0; + } + } + ++it; + } + result = 0; + return 0; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.h b/source/blender/freestyle/intern/stroke/ChainingIterators.h index ee9730edf2b..57a73c64b3d 100644 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.h +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.h @@ -40,95 +40,98 @@ namespace Freestyle { // Adjacency iterator used in the chaining process // /////////////////////////////////////////////////////////// -class AdjacencyIterator : public Iterator -{ -protected: - ViewVertexInternal::orientedViewEdgeIterator _internalIterator; - bool _restrictToSelection; - bool _restrictToUnvisited; - -public: - AdjacencyIterator() - { - _restrictToSelection = true; - _restrictToUnvisited = true; - } - - AdjacencyIterator(ViewVertex *iVertex, bool iRestrictToSelection = true, bool iRestrictToUnvisited = true) - { - _restrictToSelection = iRestrictToSelection; - _restrictToUnvisited = iRestrictToUnvisited; - _internalIterator = iVertex->edgesBegin(); - while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) - ++_internalIterator; - } - - AdjacencyIterator(const AdjacencyIterator& iBrother) - { - _internalIterator = iBrother._internalIterator; - _restrictToSelection = iBrother._restrictToSelection; - _restrictToUnvisited = iBrother._restrictToUnvisited; - } - - AdjacencyIterator& operator=(const AdjacencyIterator& iBrother) - { - _internalIterator = iBrother._internalIterator; - _restrictToSelection = iBrother._restrictToSelection; - _restrictToUnvisited = iBrother._restrictToUnvisited; - return *this; - } - - virtual ~AdjacencyIterator() {} - - virtual string getExactTypeName() const - { - return "AdjacencyIterator"; - } - - virtual inline bool isEnd() const - { - return _internalIterator.isEnd(); - } - - virtual inline bool isBegin() const - { - return _internalIterator.isBegin(); - } - - /*! Returns true if the current ViewEdge is coming towards the iteration vertex. False otherwise. */ - bool isIncoming() const; - - /*! Returns a *pointer* to the pointed ViewEdge. */ - virtual ViewEdge *operator*(); - - virtual ViewEdge *operator->() - { - return operator*(); - } - - virtual AdjacencyIterator& operator++() - { - increment(); - return *this; - } - - virtual AdjacencyIterator operator++(int) - { - AdjacencyIterator tmp(*this); - increment(); - return tmp; - } - - virtual int increment(); - - virtual int decrement() - { - cerr << "Warning: method decrement() not implemented" << endl; - return 0; - } - -protected: - bool isValid(ViewEdge *edge); +class AdjacencyIterator : public Iterator { + protected: + ViewVertexInternal::orientedViewEdgeIterator _internalIterator; + bool _restrictToSelection; + bool _restrictToUnvisited; + + public: + AdjacencyIterator() + { + _restrictToSelection = true; + _restrictToUnvisited = true; + } + + AdjacencyIterator(ViewVertex *iVertex, + bool iRestrictToSelection = true, + bool iRestrictToUnvisited = true) + { + _restrictToSelection = iRestrictToSelection; + _restrictToUnvisited = iRestrictToUnvisited; + _internalIterator = iVertex->edgesBegin(); + while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) + ++_internalIterator; + } + + AdjacencyIterator(const AdjacencyIterator &iBrother) + { + _internalIterator = iBrother._internalIterator; + _restrictToSelection = iBrother._restrictToSelection; + _restrictToUnvisited = iBrother._restrictToUnvisited; + } + + AdjacencyIterator &operator=(const AdjacencyIterator &iBrother) + { + _internalIterator = iBrother._internalIterator; + _restrictToSelection = iBrother._restrictToSelection; + _restrictToUnvisited = iBrother._restrictToUnvisited; + return *this; + } + + virtual ~AdjacencyIterator() + { + } + + virtual string getExactTypeName() const + { + return "AdjacencyIterator"; + } + + virtual inline bool isEnd() const + { + return _internalIterator.isEnd(); + } + + virtual inline bool isBegin() const + { + return _internalIterator.isBegin(); + } + + /*! Returns true if the current ViewEdge is coming towards the iteration vertex. False otherwise. */ + bool isIncoming() const; + + /*! Returns a *pointer* to the pointed ViewEdge. */ + virtual ViewEdge *operator*(); + + virtual ViewEdge *operator->() + { + return operator*(); + } + + virtual AdjacencyIterator &operator++() + { + increment(); + return *this; + } + + virtual AdjacencyIterator operator++(int) + { + AdjacencyIterator tmp(*this); + increment(); + return tmp; + } + + virtual int increment(); + + virtual int decrement() + { + cerr << "Warning: method decrement() not implemented" << endl; + return 0; + } + + protected: + bool isValid(ViewEdge *edge); }; // @@ -144,101 +147,101 @@ protected: * If you specify restriction rules (such as "Chain only ViewEdges of the selection"), they will be included * in the adjacency iterator. (i.e, the adjacent iterator will only stop on "valid" edges). */ -class ChainingIterator : public ViewEdgeInternal::ViewEdgeIterator -{ -protected: - bool _restrictToSelection; - bool _restrictToUnvisited; - bool _increment; //true if we're currently incrementing, false when decrementing - -public: - ViewEdge *result; - void *py_c_it; - - /*! Builds a Chaining Iterator from the first ViewEdge used for iteration and its orientation. - * \param iRestrictToSelection: - * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. - * \param iRestrictToUnvisited: - * Indicates whether a ViewEdge that has already been chained must be ignored ot not. - * \param begin: - * The ViewEdge from which to start the chain. - * \param orientation: - * The direction to follow to explore the graph. If true, the direction indicated by the first ViewEdge is used. - */ - ChainingIterator(bool iRestrictToSelection = true, bool iRestrictToUnvisited = true, ViewEdge *begin = NULL, - bool orientation = true) - : ViewEdgeIterator(begin, orientation) - { - _restrictToSelection = iRestrictToSelection; - _restrictToUnvisited = iRestrictToUnvisited; - _increment = true; - py_c_it = NULL; - } - - /*! Copy constructor */ - ChainingIterator(const ChainingIterator& brother) - : ViewEdgeIterator(brother) - { - _restrictToSelection = brother._restrictToSelection; - _restrictToUnvisited = brother._restrictToUnvisited; - _increment = brother._increment; - py_c_it = brother.py_c_it; - } - - /*! Returns the string "ChainingIterator" */ - virtual string getExactTypeName() const - { - return "ChainingIterator"; - } - - /*! Inits the iterator context. - * This method is called each time a new chain is started. - * It can be used to reset some history information that you might want to keep. - */ - virtual int init(); - - /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. - * returns the next ViewEdge to follow or 0 when the end of the chain is reached. - * \param it: - * The iterator over the ViewEdges adjacent to the end vertex of the current ViewEdge. - * The Adjacency iterator reflects the restriction rules by only iterating over the valid ViewEdges. - */ - virtual int traverse(const AdjacencyIterator &it); - - /* accessors */ - /*! Returns true if the orientation of the current ViewEdge corresponds to its natural orientation */ - //inline bool getOrientation() const {} - - /*! Returns the vertex which is the next crossing */ - inline ViewVertex *getVertex() - { - if (_increment) { - if (_orientation) { - return _edge->B(); - } - else { - return _edge->A(); - } - } - else { - if (_orientation) { - return _edge->A(); - } - else { - return _edge->B(); - } - } - } - - /*! Returns true if the current iteration is an incrementation */ - inline bool isIncrementing() const - { - return _increment; - } - - /* increments.*/ - virtual int increment(); - virtual int decrement(); +class ChainingIterator : public ViewEdgeInternal::ViewEdgeIterator { + protected: + bool _restrictToSelection; + bool _restrictToUnvisited; + bool _increment; //true if we're currently incrementing, false when decrementing + + public: + ViewEdge *result; + void *py_c_it; + + /*! Builds a Chaining Iterator from the first ViewEdge used for iteration and its orientation. + * \param iRestrictToSelection: + * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. + * \param iRestrictToUnvisited: + * Indicates whether a ViewEdge that has already been chained must be ignored ot not. + * \param begin: + * The ViewEdge from which to start the chain. + * \param orientation: + * The direction to follow to explore the graph. If true, the direction indicated by the first ViewEdge is used. + */ + ChainingIterator(bool iRestrictToSelection = true, + bool iRestrictToUnvisited = true, + ViewEdge *begin = NULL, + bool orientation = true) + : ViewEdgeIterator(begin, orientation) + { + _restrictToSelection = iRestrictToSelection; + _restrictToUnvisited = iRestrictToUnvisited; + _increment = true; + py_c_it = NULL; + } + + /*! Copy constructor */ + ChainingIterator(const ChainingIterator &brother) : ViewEdgeIterator(brother) + { + _restrictToSelection = brother._restrictToSelection; + _restrictToUnvisited = brother._restrictToUnvisited; + _increment = brother._increment; + py_c_it = brother.py_c_it; + } + + /*! Returns the string "ChainingIterator" */ + virtual string getExactTypeName() const + { + return "ChainingIterator"; + } + + /*! Inits the iterator context. + * This method is called each time a new chain is started. + * It can be used to reset some history information that you might want to keep. + */ + virtual int init(); + + /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. + * returns the next ViewEdge to follow or 0 when the end of the chain is reached. + * \param it: + * The iterator over the ViewEdges adjacent to the end vertex of the current ViewEdge. + * The Adjacency iterator reflects the restriction rules by only iterating over the valid ViewEdges. + */ + virtual int traverse(const AdjacencyIterator &it); + + /* accessors */ + /*! Returns true if the orientation of the current ViewEdge corresponds to its natural orientation */ + //inline bool getOrientation() const {} + + /*! Returns the vertex which is the next crossing */ + inline ViewVertex *getVertex() + { + if (_increment) { + if (_orientation) { + return _edge->B(); + } + else { + return _edge->A(); + } + } + else { + if (_orientation) { + return _edge->A(); + } + else { + return _edge->B(); + } + } + } + + /*! Returns true if the current iteration is an incrementation */ + inline bool isIncrementing() const + { + return _increment; + } + + /* increments.*/ + virtual int increment(); + virtual int decrement(); }; // @@ -252,42 +255,45 @@ public: * In the case of an iteration over a set of ViewEdge that are both Silhouette and Crease, there will be a precedence * of the silhouette over the crease criterion. */ -class ChainSilhouetteIterator : public ChainingIterator -{ -public: - /*! Builds a ChainSilhouetteIterator from the first ViewEdge used for iteration and its orientation. - * \param iRestrictToSelection: - * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. - * \param begin: - * The ViewEdge from where to start the iteration. - * \param orientation: - * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. - * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. - */ - ChainSilhouetteIterator(bool iRestrictToSelection = true, ViewEdge *begin = NULL, bool orientation = true) - : ChainingIterator(iRestrictToSelection, true, begin, orientation) - { - } - - /*! Copy constructor */ - ChainSilhouetteIterator(const ChainSilhouetteIterator& brother) : ChainingIterator(brother) {} - - /*! Returns the string "ChainSilhouetteIterator" */ - virtual string getExactTypeName() const - { - return "ChainSilhouetteIterator"; - } - - /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. - * When reaching the end of a chain, 0 is returned. - */ - virtual int traverse(const AdjacencyIterator& it); - - /*! Inits the iterator context */ - virtual int init() - { - return 0; - } +class ChainSilhouetteIterator : public ChainingIterator { + public: + /*! Builds a ChainSilhouetteIterator from the first ViewEdge used for iteration and its orientation. + * \param iRestrictToSelection: + * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. + * \param begin: + * The ViewEdge from where to start the iteration. + * \param orientation: + * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. + * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. + */ + ChainSilhouetteIterator(bool iRestrictToSelection = true, + ViewEdge *begin = NULL, + bool orientation = true) + : ChainingIterator(iRestrictToSelection, true, begin, orientation) + { + } + + /*! Copy constructor */ + ChainSilhouetteIterator(const ChainSilhouetteIterator &brother) : ChainingIterator(brother) + { + } + + /*! Returns the string "ChainSilhouetteIterator" */ + virtual string getExactTypeName() const + { + return "ChainSilhouetteIterator"; + } + + /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. + * When reaching the end of a chain, 0 is returned. + */ + virtual int traverse(const AdjacencyIterator &it); + + /*! Inits the iterator context */ + virtual int init() + { + return 0; + } }; // @@ -303,88 +309,94 @@ public: * selection. The first ViewEdge respecting both the unary predicate and the binary predicate is kept as the next one. * If none of the potential next ViewEdge respects these 2 predicates, 0 is returned. */ -class ChainPredicateIterator : public ChainingIterator -{ -protected: - BinaryPredicate1D *_binary_predicate; // the caller is responsible for the deletion of this object - UnaryPredicate1D *_unary_predicate; // the caller is responsible for the deletion of this object - -public: - /*! Builds a ChainPredicateIterator from a starting ViewEdge and its orientation. - * \param iRestrictToSelection: - * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. - * \param iRestrictToUnvisited: - * Indicates whether a ViewEdge that has already been chained must be ignored ot not. - * \param begin: - * The ViewEdge from where to start the iteration. - * \param orientation: - * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. - * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. - */ - ChainPredicateIterator(bool iRestrictToSelection = true, bool iRestrictToUnvisited = true, ViewEdge *begin = NULL, - bool orientation = true) - : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) - { - _binary_predicate = 0; - _unary_predicate = 0; - } - - /*! Builds a ChainPredicateIterator from a unary predicate, a binary predicate, a starting ViewEdge and - * its orientation. - * \param iRestrictToSelection: - * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. - * \param iRestrictToUnvisited: - * Indicates whether a ViewEdge that has already been chained must be ignored ot not. - * \param upred: - * The unary predicate that the next ViewEdge must satisfy. - * \param bpred: - * The binary predicate that the next ViewEdge must satisfy together with the actual pointed ViewEdge. - * \param begin: - * The ViewEdge from where to start the iteration. - * \param orientation: - * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. - * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. - */ - ChainPredicateIterator(UnaryPredicate1D& upred, BinaryPredicate1D& bpred, bool iRestrictToSelection = true, - bool iRestrictToUnvisited = true, ViewEdge *begin = NULL, bool orientation = true) - : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) - { - _unary_predicate = &upred; - _binary_predicate = &bpred; - } - - /*! Copy constructor */ - ChainPredicateIterator(const ChainPredicateIterator& brother) : ChainingIterator(brother) - { - _unary_predicate = brother._unary_predicate; - _binary_predicate = brother._binary_predicate; - } - - /*! Destructor. */ - virtual ~ChainPredicateIterator() - { - _unary_predicate = 0; - _binary_predicate = 0; - } - - /*! Returns the string "ChainPredicateIterator" */ - virtual string getExactTypeName() const - { - return "ChainPredicateIterator"; - } - - /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. - * When reaching the end of a chain, 0 is returned. - */ - virtual int traverse(const AdjacencyIterator &it); - - /*! Inits the iterator context */ - virtual int init() - { - return 0; - } +class ChainPredicateIterator : public ChainingIterator { + protected: + BinaryPredicate1D + *_binary_predicate; // the caller is responsible for the deletion of this object + UnaryPredicate1D *_unary_predicate; // the caller is responsible for the deletion of this object + + public: + /*! Builds a ChainPredicateIterator from a starting ViewEdge and its orientation. + * \param iRestrictToSelection: + * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. + * \param iRestrictToUnvisited: + * Indicates whether a ViewEdge that has already been chained must be ignored ot not. + * \param begin: + * The ViewEdge from where to start the iteration. + * \param orientation: + * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. + * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. + */ + ChainPredicateIterator(bool iRestrictToSelection = true, + bool iRestrictToUnvisited = true, + ViewEdge *begin = NULL, + bool orientation = true) + : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) + { + _binary_predicate = 0; + _unary_predicate = 0; + } + + /*! Builds a ChainPredicateIterator from a unary predicate, a binary predicate, a starting ViewEdge and + * its orientation. + * \param iRestrictToSelection: + * Indicates whether to force the chaining to stay within the set of selected ViewEdges or not. + * \param iRestrictToUnvisited: + * Indicates whether a ViewEdge that has already been chained must be ignored ot not. + * \param upred: + * The unary predicate that the next ViewEdge must satisfy. + * \param bpred: + * The binary predicate that the next ViewEdge must satisfy together with the actual pointed ViewEdge. + * \param begin: + * The ViewEdge from where to start the iteration. + * \param orientation: + * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. + * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. + */ + ChainPredicateIterator(UnaryPredicate1D &upred, + BinaryPredicate1D &bpred, + bool iRestrictToSelection = true, + bool iRestrictToUnvisited = true, + ViewEdge *begin = NULL, + bool orientation = true) + : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation) + { + _unary_predicate = &upred; + _binary_predicate = &bpred; + } + + /*! Copy constructor */ + ChainPredicateIterator(const ChainPredicateIterator &brother) : ChainingIterator(brother) + { + _unary_predicate = brother._unary_predicate; + _binary_predicate = brother._binary_predicate; + } + + /*! Destructor. */ + virtual ~ChainPredicateIterator() + { + _unary_predicate = 0; + _binary_predicate = 0; + } + + /*! Returns the string "ChainPredicateIterator" */ + virtual string getExactTypeName() const + { + return "ChainPredicateIterator"; + } + + /*! This method iterates over the potential next ViewEdges and returns the one that will be followed next. + * When reaching the end of a chain, 0 is returned. + */ + virtual int traverse(const AdjacencyIterator &it); + + /*! Inits the iterator context */ + virtual int init() + { + return 0; + } }; } /* namespace Freestyle */ -#endif // __FREESTYLE_CHAINING_ITERATORS_H__ +#endif // __FREESTYLE_CHAINING_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/ContextFunctions.cpp b/source/blender/freestyle/intern/stroke/ContextFunctions.cpp index f390b4edfb6..5609013a417 100644 --- a/source/blender/freestyle/intern/stroke/ContextFunctions.cpp +++ b/source/blender/freestyle/intern/stroke/ContextFunctions.cpp @@ -32,52 +32,52 @@ namespace ContextFunctions { unsigned GetTimeStampCF() { - return TimeStamp::instance()->getTimeStamp(); + return TimeStamp::instance()->getTimeStamp(); } unsigned GetCanvasWidthCF() { - return Canvas::getInstance()->width(); + return Canvas::getInstance()->width(); } unsigned GetCanvasHeightCF() { - return Canvas::getInstance()->height(); + return Canvas::getInstance()->height(); } BBox GetBorderCF() { - return Canvas::getInstance()->border(); + return Canvas::getInstance()->border(); } void LoadMapCF(const char *iFileName, const char *iMapName, unsigned iNbLevels, float iSigma) { - return Canvas::getInstance()->loadMap(iFileName, iMapName, iNbLevels, iSigma); + return Canvas::getInstance()->loadMap(iFileName, iMapName, iNbLevels, iSigma); } float ReadMapPixelCF(const char *iMapName, int level, unsigned x, unsigned y) { - Canvas *canvas = Canvas::getInstance(); - return canvas->readMapPixel(iMapName, level, x, y); + Canvas *canvas = Canvas::getInstance(); + return canvas->readMapPixel(iMapName, level, x, y); } float ReadCompleteViewMapPixelCF(int level, unsigned x, unsigned y) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - return svm->readCompleteViewMapPixel(level, x, y); + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + return svm->readCompleteViewMapPixel(level, x, y); } float ReadDirectionalViewMapPixelCF(int iOrientation, int level, unsigned x, unsigned y) { - SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); - return svm->readSteerableViewMapPixel(iOrientation, level, x, y); + SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap(); + return svm->readSteerableViewMapPixel(iOrientation, level, x, y); } FEdge *GetSelectedFEdgeCF() { - return Canvas::getInstance()->selectedFEdge(); + return Canvas::getInstance()->selectedFEdge(); } -} // ContextFunctions namespace +} // namespace ContextFunctions } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/ContextFunctions.h b/source/blender/freestyle/intern/stroke/ContextFunctions.h index 190217c52f7..6897e2b193d 100644 --- a/source/blender/freestyle/intern/stroke/ContextFunctions.h +++ b/source/blender/freestyle/intern/stroke/ContextFunctions.h @@ -55,7 +55,10 @@ BBox GetBorderCF(); // Load map /*! Loads an image map for further reading */ -void LoadMapCF(const char *iFileName, const char *iMapName, unsigned iNbLevels = 4, float iSigma = 1.0f); +void LoadMapCF(const char *iFileName, + const char *iMapName, + unsigned iNbLevels = 4, + float iSigma = 1.0f); // ReadMapPixel /*! Reads a pixel in a user-defined map @@ -100,8 +103,8 @@ float ReadDirectionalViewMapPixelCF(int iOrientation, int level, unsigned x, uns // DEBUG FEdge *GetSelectedFEdgeCF(); -} // end of namespace ContextFunctions +} // end of namespace ContextFunctions } /* namespace Freestyle */ -#endif // __FREESTYLE_CONTEXT_FUNCTIONS_H__ +#endif // __FREESTYLE_CONTEXT_FUNCTIONS_H__ diff --git a/source/blender/freestyle/intern/stroke/Curve.cpp b/source/blender/freestyle/intern/stroke/Curve.cpp index f4439e1398c..f7309252aaf 100644 --- a/source/blender/freestyle/intern/stroke/Curve.cpp +++ b/source/blender/freestyle/intern/stroke/Curve.cpp @@ -19,7 +19,7 @@ * \brief Class to define a container for curves */ -#include /* printf */ +#include /* printf */ #include "Curve.h" #include "CurveIterators.h" @@ -40,455 +40,457 @@ namespace Freestyle { CurvePoint::CurvePoint() { - __A = 0; - __B = 0; - _t2d = 0; + __A = 0; + __B = 0; + _t2d = 0; } CurvePoint::CurvePoint(SVertex *iA, SVertex *iB, float t) { - __A = iA; - __B = iB; - _t2d = t; - if ((iA == 0) && (t == 1.0f)) { - _Point2d = __B->point2d(); - _Point3d = __B->point3d(); - } - else if ((iB == 0) && (t == 0.0f)) { - _Point2d = __A->point2d(); - _Point3d = __A->point3d(); - } - else { - _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d()); - _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); - } + __A = iA; + __B = iB; + _t2d = t; + if ((iA == 0) && (t == 1.0f)) { + _Point2d = __B->point2d(); + _Point3d = __B->point3d(); + } + else if ((iB == 0) && (t == 0.0f)) { + _Point2d = __A->point2d(); + _Point3d = __A->point3d(); + } + else { + _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d()); + _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); + } } CurvePoint::CurvePoint(CurvePoint *iA, CurvePoint *iB, float t3) { - __A = 0; - __B = 0; - float t1 = iA->t2d(); - float t2 = iB->t2d(); - if ((iA->A() == iB->A()) && (iA->B() == iB->B()) && - (iA->A() != 0) && (iA->B() != 0) && (iB->A() != 0) && (iB->B() != 0)) - { - __A = iA->A(); - __B = iB->B(); - _t2d = t1 + t2 * t3 - t1 * t3; - } - else if ((iA->B() == 0) && (iB->B() == 0)) { - __A = iA->A(); - __B = iB->A(); - _t2d = t3; - } - else if ((iA->t2d() == 0) && (iB->t2d() == 0)) { - __A = iA->A(); - __B = iB->A(); - _t2d = t3; - } - else if (iA->A() == iB->A()) { -iA_A_eq_iB_A: - if (iA->t2d() == 0) { - __A = iB->A(); - __B = iB->B(); - _t2d = t3; - } - else if (iB->t2d() == 0) { - __A = iA->A(); - __B = iA->B(); - _t2d = t3; - } - } - else if (iA->B() == iB->B()) { -iA_B_eq_iB_B: - if (iA->t2d() == 1) { - __A = iB->A(); - __B = iB->B(); - _t2d = t3; - } - else if (iB->t2d() == 1) { - __A = iA->A(); - __B = iA->B(); - _t2d = t3; - } - } - else if (iA->B() == iB->A()) { -iA_B_eq_iB_A: - if ((iA->t2d() != 1.0f) && (iB->t2d() == 0.0f)) { - __A = iA->A(); - __B = iA->B(); - _t2d = t1 + t3 - t1 * t3; - //_t2d = t3; - } - else if ((iA->t2d() == 1.0f) && (iB->t2d() != 0.0f)) { - __A = iB->A(); - __B = iB->B(); - //_t2d = t3; - _t2d = t2 * t3; - } - else if ((iA->getPoint2D() - iB->getPoint2D()).norm() < 1.0e-6) { - __A = iB->A(); - __B = iB->B(); - //_t2d = t3; - _t2d = t2 * t3; - } - } - else if (iA->A() != 0 && iB->A() != 0 && (iA->A()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) { - goto iA_A_eq_iB_A; - } - else if (iA->B() != 0 && iB->B() != 0 && (iA->B()->point3d() - iB->B()->point3d()).norm() < 1.0e-6) { - goto iA_B_eq_iB_B; - } - else if (iA->B() != 0 && iB->A() != 0 && (iA->B()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) { - goto iA_B_eq_iB_A; - } - - if (!__A || !__B) { - if (G.debug & G_DEBUG_FREESTYLE) { - printf("iA A 0x%p p (%f, %f)\n", iA->A(), iA->A()->getPoint2D().x(), iA->A()->getPoint2D().y()); - printf("iA B 0x%p p (%f, %f)\n", iA->B(), iA->B()->getPoint2D().x(), iA->B()->getPoint2D().y()); - printf("iB A 0x%p p (%f, %f)\n", iB->A(), iB->A()->getPoint2D().x(), iB->A()->getPoint2D().y()); - printf("iB B 0x%p p (%f, %f)\n", iB->B(), iB->B()->getPoint2D().x(), iB->B()->getPoint2D().y()); - printf("iA t2d %f p (%f, %f)\n", iA->t2d(), iA->getPoint2D().x(), iA->getPoint2D().y()); - printf("iB t2d %f p (%f, %f)\n", iB->t2d(), iB->getPoint2D().x(), iB->getPoint2D().y()); - } - cerr << "Fatal error in CurvePoint::CurvePoint(CurvePoint *iA, CurvePoint *iB, float t3)" << endl; - } - BLI_assert(__A != 0 && __B != 0); + __A = 0; + __B = 0; + float t1 = iA->t2d(); + float t2 = iB->t2d(); + if ((iA->A() == iB->A()) && (iA->B() == iB->B()) && (iA->A() != 0) && (iA->B() != 0) && + (iB->A() != 0) && (iB->B() != 0)) { + __A = iA->A(); + __B = iB->B(); + _t2d = t1 + t2 * t3 - t1 * t3; + } + else if ((iA->B() == 0) && (iB->B() == 0)) { + __A = iA->A(); + __B = iB->A(); + _t2d = t3; + } + else if ((iA->t2d() == 0) && (iB->t2d() == 0)) { + __A = iA->A(); + __B = iB->A(); + _t2d = t3; + } + else if (iA->A() == iB->A()) { + iA_A_eq_iB_A: + if (iA->t2d() == 0) { + __A = iB->A(); + __B = iB->B(); + _t2d = t3; + } + else if (iB->t2d() == 0) { + __A = iA->A(); + __B = iA->B(); + _t2d = t3; + } + } + else if (iA->B() == iB->B()) { + iA_B_eq_iB_B: + if (iA->t2d() == 1) { + __A = iB->A(); + __B = iB->B(); + _t2d = t3; + } + else if (iB->t2d() == 1) { + __A = iA->A(); + __B = iA->B(); + _t2d = t3; + } + } + else if (iA->B() == iB->A()) { + iA_B_eq_iB_A: + if ((iA->t2d() != 1.0f) && (iB->t2d() == 0.0f)) { + __A = iA->A(); + __B = iA->B(); + _t2d = t1 + t3 - t1 * t3; + //_t2d = t3; + } + else if ((iA->t2d() == 1.0f) && (iB->t2d() != 0.0f)) { + __A = iB->A(); + __B = iB->B(); + //_t2d = t3; + _t2d = t2 * t3; + } + else if ((iA->getPoint2D() - iB->getPoint2D()).norm() < 1.0e-6) { + __A = iB->A(); + __B = iB->B(); + //_t2d = t3; + _t2d = t2 * t3; + } + } + else if (iA->A() != 0 && iB->A() != 0 && + (iA->A()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) { + goto iA_A_eq_iB_A; + } + else if (iA->B() != 0 && iB->B() != 0 && + (iA->B()->point3d() - iB->B()->point3d()).norm() < 1.0e-6) { + goto iA_B_eq_iB_B; + } + else if (iA->B() != 0 && iB->A() != 0 && + (iA->B()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) { + goto iA_B_eq_iB_A; + } + + if (!__A || !__B) { + if (G.debug & G_DEBUG_FREESTYLE) { + printf( + "iA A 0x%p p (%f, %f)\n", iA->A(), iA->A()->getPoint2D().x(), iA->A()->getPoint2D().y()); + printf( + "iA B 0x%p p (%f, %f)\n", iA->B(), iA->B()->getPoint2D().x(), iA->B()->getPoint2D().y()); + printf( + "iB A 0x%p p (%f, %f)\n", iB->A(), iB->A()->getPoint2D().x(), iB->A()->getPoint2D().y()); + printf( + "iB B 0x%p p (%f, %f)\n", iB->B(), iB->B()->getPoint2D().x(), iB->B()->getPoint2D().y()); + printf("iA t2d %f p (%f, %f)\n", iA->t2d(), iA->getPoint2D().x(), iA->getPoint2D().y()); + printf("iB t2d %f p (%f, %f)\n", iB->t2d(), iB->getPoint2D().x(), iB->getPoint2D().y()); + } + cerr << "Fatal error in CurvePoint::CurvePoint(CurvePoint *iA, CurvePoint *iB, float t3)" + << endl; + } + BLI_assert(__A != 0 && __B != 0); #if 0 - _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d()); - _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); + _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d()); + _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); #endif - _Point2d = iA->point2d() + t3 * (iB->point2d() - iA->point2d()); - _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); + _Point2d = iA->point2d() + t3 * (iB->point2d() - iA->point2d()); + _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d()); } -CurvePoint::CurvePoint(const CurvePoint& iBrother) +CurvePoint::CurvePoint(const CurvePoint &iBrother) { - __A = iBrother.__A; - __B = iBrother.__B; - _t2d = iBrother._t2d; - _Point2d = iBrother._Point2d; - _Point3d = iBrother._Point3d; + __A = iBrother.__A; + __B = iBrother.__B; + _t2d = iBrother._t2d; + _Point2d = iBrother._Point2d; + _Point3d = iBrother._Point3d; } -CurvePoint& CurvePoint::operator=(const CurvePoint& iBrother) +CurvePoint &CurvePoint::operator=(const CurvePoint &iBrother) { - __A = iBrother.__A; - __B = iBrother.__B; - _t2d = iBrother._t2d; - _Point2d = iBrother._Point2d; - _Point3d = iBrother._Point3d; - return *this; + __A = iBrother.__A; + __B = iBrother.__B; + _t2d = iBrother._t2d; + _Point2d = iBrother._Point2d; + _Point3d = iBrother._Point3d; + return *this; } - FEdge *CurvePoint::fedge() { - if (getNature() & Nature::T_VERTEX) - return 0; - return __A->fedge(); -} - - -FEdge *CurvePoint::getFEdge(Interface0D& inter) -{ - CurvePoint *iVertexB = dynamic_cast(&inter); - if (!iVertexB) { - cerr << "Warning: CurvePoint::getFEdge() failed to cast the given 0D element to CurvePoint." << endl; - return 0; - } - if (((__A == iVertexB->__A) && (__B == iVertexB->__B)) || - ((__A == iVertexB->__B) && (__B == iVertexB->__A))) - { - return __A->getFEdge(*__B); - } - if (__B == 0) { - if (iVertexB->__B == 0) - return __A->getFEdge(*(iVertexB->__A)); - else if (iVertexB->__A == __A) - return __A->getFEdge(*(iVertexB->__B)); - else if (iVertexB->__B == __A) - return __A->getFEdge(*(iVertexB->__A)); - } - if (iVertexB->__B == 0) { - if (iVertexB->__A == __A) - return __B->getFEdge(*(iVertexB->__A)); - else if (iVertexB->__A == __B) - return __A->getFEdge(*(iVertexB->__A)); - } - if (__B == iVertexB->__A) { - if ((_t2d != 1) && (iVertexB->_t2d == 0)) - return __A->getFEdge(*__B); - if ((_t2d == 1) && (iVertexB->_t2d != 0)) - return iVertexB->__A->getFEdge(*(iVertexB->__B)); - } - if (__B == iVertexB->__B) { - if ((_t2d != 1) && (iVertexB->_t2d == 1)) - return __A->getFEdge(*__B); - if ((_t2d == 1) && (iVertexB->_t2d != 1)) - return iVertexB->__A->getFEdge(*(iVertexB->__B)); - } - if (__A == iVertexB->__A) { - if ((_t2d == 0) && (iVertexB->_t2d != 0)) - return iVertexB->__A->getFEdge(*(iVertexB->__B)); - if ((_t2d != 0) && (iVertexB->_t2d == 0)) - return __A->getFEdge(*__B); - } - if (__A == iVertexB->__B) { - if ((_t2d == 0) && (iVertexB->_t2d != 1)) - return iVertexB->__A->getFEdge(*(iVertexB->__B)); - if ((_t2d != 0) && (iVertexB->_t2d == 1)) - return __A->getFEdge(*__B); - } + if (getNature() & Nature::T_VERTEX) + return 0; + return __A->fedge(); +} + +FEdge *CurvePoint::getFEdge(Interface0D &inter) +{ + CurvePoint *iVertexB = dynamic_cast(&inter); + if (!iVertexB) { + cerr << "Warning: CurvePoint::getFEdge() failed to cast the given 0D element to CurvePoint." + << endl; + return 0; + } + if (((__A == iVertexB->__A) && (__B == iVertexB->__B)) || + ((__A == iVertexB->__B) && (__B == iVertexB->__A))) { + return __A->getFEdge(*__B); + } + if (__B == 0) { + if (iVertexB->__B == 0) + return __A->getFEdge(*(iVertexB->__A)); + else if (iVertexB->__A == __A) + return __A->getFEdge(*(iVertexB->__B)); + else if (iVertexB->__B == __A) + return __A->getFEdge(*(iVertexB->__A)); + } + if (iVertexB->__B == 0) { + if (iVertexB->__A == __A) + return __B->getFEdge(*(iVertexB->__A)); + else if (iVertexB->__A == __B) + return __A->getFEdge(*(iVertexB->__A)); + } + if (__B == iVertexB->__A) { + if ((_t2d != 1) && (iVertexB->_t2d == 0)) + return __A->getFEdge(*__B); + if ((_t2d == 1) && (iVertexB->_t2d != 0)) + return iVertexB->__A->getFEdge(*(iVertexB->__B)); + } + if (__B == iVertexB->__B) { + if ((_t2d != 1) && (iVertexB->_t2d == 1)) + return __A->getFEdge(*__B); + if ((_t2d == 1) && (iVertexB->_t2d != 1)) + return iVertexB->__A->getFEdge(*(iVertexB->__B)); + } + if (__A == iVertexB->__A) { + if ((_t2d == 0) && (iVertexB->_t2d != 0)) + return iVertexB->__A->getFEdge(*(iVertexB->__B)); + if ((_t2d != 0) && (iVertexB->_t2d == 0)) + return __A->getFEdge(*__B); + } + if (__A == iVertexB->__B) { + if ((_t2d == 0) && (iVertexB->_t2d != 1)) + return iVertexB->__A->getFEdge(*(iVertexB->__B)); + if ((_t2d != 0) && (iVertexB->_t2d == 1)) + return __A->getFEdge(*__B); + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - printf("__A 0x%p p (%f, %f)\n", __A, __A->getPoint2D().x(), __A->getPoint2D().y()); - printf("__B 0x%p p (%f, %f)\n", __B, __B->getPoint2D().x(), __B->getPoint2D().y()); - printf("iVertexB->A() 0x%p p (%f, %f)\n", iVertexB->A(), iVertexB->A()->getPoint2D().x(), - iVertexB->A()->getPoint2D().y()); - printf("iVertexB->B() 0x%p p (%f, %f)\n", iVertexB->B(), iVertexB->B()->getPoint2D().x(), - iVertexB->B()->getPoint2D().y()); - printf("_t2d %f p (%f, %f)\n", _t2d, getPoint2D().x(), getPoint2D().y()); - printf("iVertexB->t2d() %f p (%f, %f)\n", iVertexB->t2d(), iVertexB->getPoint2D().x(), - iVertexB->getPoint2D().y()); - } + if (G.debug & G_DEBUG_FREESTYLE) { + printf("__A 0x%p p (%f, %f)\n", __A, __A->getPoint2D().x(), __A->getPoint2D().y()); + printf("__B 0x%p p (%f, %f)\n", __B, __B->getPoint2D().x(), __B->getPoint2D().y()); + printf("iVertexB->A() 0x%p p (%f, %f)\n", iVertexB->A(), iVertexB->A()->getPoint2D().x(), + iVertexB->A()->getPoint2D().y()); + printf("iVertexB->B() 0x%p p (%f, %f)\n", iVertexB->B(), iVertexB->B()->getPoint2D().x(), + iVertexB->B()->getPoint2D().y()); + printf("_t2d %f p (%f, %f)\n", _t2d, getPoint2D().x(), getPoint2D().y()); + printf("iVertexB->t2d() %f p (%f, %f)\n", iVertexB->t2d(), iVertexB->getPoint2D().x(), + iVertexB->getPoint2D().y()); + } #endif - cerr << "Warning: CurvePoint::getFEdge() failed." << endl; + cerr << "Warning: CurvePoint::getFEdge() failed." << endl; - return NULL; + return NULL; } - Vec3r CurvePoint::normal() const { - if (__B == 0) - return __A->normal(); - if (__A == 0) - return __B->normal(); - Vec3r Na = __A->normal(); - if (Exception::getException()) - Na = Vec3r(0, 0, 0); - Vec3r Nb = __B->normal(); - if (Exception::getException()) - Nb = Vec3r(0, 0, 0); - // compute t3d: - real t3d = SilhouetteGeomEngine::ImageToWorldParameter(__A->getFEdge(*__B), _t2d); - return ((1 - t3d) * Na + t3d * Nb); + if (__B == 0) + return __A->normal(); + if (__A == 0) + return __B->normal(); + Vec3r Na = __A->normal(); + if (Exception::getException()) + Na = Vec3r(0, 0, 0); + Vec3r Nb = __B->normal(); + if (Exception::getException()) + Nb = Vec3r(0, 0, 0); + // compute t3d: + real t3d = SilhouetteGeomEngine::ImageToWorldParameter(__A->getFEdge(*__B), _t2d); + return ((1 - t3d) * Na + t3d * Nb); } - #if 0 Material CurvePoint::material() const { - if (__A == 0) - return __B->material(); - return __A->material(); + if (__A == 0) + return __B->material(); + return __A->material(); } Id CurvePoint::shape_id() const { - if (__A == 0) - return __B->shape_id(); - return __A->shape_id(); + if (__A == 0) + return __B->shape_id(); + return __A->shape_id(); } #endif - const SShape *CurvePoint::shape() const { - if (__A == 0) - return __B->shape(); - return __A->shape(); + if (__A == 0) + return __B->shape(); + return __A->shape(); } #if 0 float CurvePoint::shape_importance() const { - if (__A == 0) - return __B->shape_importance(); - return __A->shape_importance(); + if (__A == 0) + return __B->shape_importance(); + return __A->shape_importance(); } const unsigned CurvePoint::qi() const { - if (__A == 0) - return __B->qi(); - if (__B == 0) - return __A->qi(); - return __A->getFEdge(*__B)->qi(); + if (__A == 0) + return __B->qi(); + if (__B == 0) + return __A->qi(); + return __A->getFEdge(*__B)->qi(); } #endif occluder_container::const_iterator CurvePoint::occluders_begin() const { - if (__A == 0) - return __B->occluders_begin(); - if (__B == 0) - return __A->occluders_begin(); - return __A->getFEdge(*__B)->occluders_begin(); + if (__A == 0) + return __B->occluders_begin(); + if (__B == 0) + return __A->occluders_begin(); + return __A->getFEdge(*__B)->occluders_begin(); } occluder_container::const_iterator CurvePoint::occluders_end() const { - if (__A == 0) - return __B->occluders_end(); - if (__B == 0) - return __A->occluders_end(); - return __A->getFEdge(*__B)->occluders_end(); + if (__A == 0) + return __B->occluders_end(); + if (__B == 0) + return __A->occluders_end(); + return __A->getFEdge(*__B)->occluders_end(); } bool CurvePoint::occluders_empty() const { - if (__A == 0) - return __B->occluders_empty(); - if (__B == 0) - return __A->occluders_empty(); - return __A->getFEdge(*__B)->occluders_empty(); + if (__A == 0) + return __B->occluders_empty(); + if (__B == 0) + return __A->occluders_empty(); + return __A->getFEdge(*__B)->occluders_empty(); } int CurvePoint::occluders_size() const { - if (__A == 0) - return __B->occluders_size(); - if (__B == 0) - return __A->occluders_size(); - return __A->getFEdge(*__B)->occluders_size(); + if (__A == 0) + return __B->occluders_size(); + if (__B == 0) + return __A->occluders_size(); + return __A->getFEdge(*__B)->occluders_size(); } const SShape *CurvePoint::occluded_shape() const { - if (__A == 0) - return __B->occluded_shape(); - if (__B == 0) - return __A->occluded_shape(); - return __A->getFEdge(*__B)->occluded_shape(); + if (__A == 0) + return __B->occluded_shape(); + if (__B == 0) + return __A->occluded_shape(); + return __A->getFEdge(*__B)->occluded_shape(); } -const Polygon3r& CurvePoint::occludee() const +const Polygon3r &CurvePoint::occludee() const { - if (__A == 0) - return __B->occludee(); - if (__B == 0) - return __A->occludee(); - return __A->getFEdge(*__B)->occludee(); + if (__A == 0) + return __B->occludee(); + if (__B == 0) + return __A->occludee(); + return __A->getFEdge(*__B)->occludee(); } -const bool CurvePoint::occludee_empty() const +const bool CurvePoint::occludee_empty() const { - if (__A == 0) - return __B->occludee_empty(); - if (__B == 0) - return __A->occludee_empty(); - return __A->getFEdge(*__B)->occludee_empty(); + if (__A == 0) + return __B->occludee_empty(); + if (__B == 0) + return __A->occludee_empty(); + return __A->getFEdge(*__B)->occludee_empty(); } real CurvePoint::z_discontinuity() const { - if (__A == 0) - return __B->z_discontinuity(); - if (__B == 0) - return __A->z_discontinuity(); - if (__A->getFEdge(*__B) == 0) - return 0.0; + if (__A == 0) + return __B->z_discontinuity(); + if (__B == 0) + return __A->z_discontinuity(); + if (__A->getFEdge(*__B) == 0) + return 0.0; - return __A->getFEdge(*__B)->z_discontinuity(); + return __A->getFEdge(*__B)->z_discontinuity(); } #if 0 float CurvePoint::local_average_depth() const { - return local_average_depth_function(this); + return local_average_depth_function(this); } float CurvePoint::local_depth_variance() const { - return local_depth_variance_function(this); + return local_depth_variance_function(this); } real CurvePoint::local_average_density(float sigma) const { - //return local_average_density(this); - return density_function(this); + //return local_average_density(this); + return density_function(this); } Vec3r shaded_color() const; Vec3r CurvePoint::orientation2d() const { - if (__A == 0) - return __B->orientation2d(); - if (__B == 0) - return __A->orientation2d(); - return __B->point2d() - __A->point2d(); + if (__A == 0) + return __B->orientation2d(); + if (__B == 0) + return __A->orientation2d(); + return __B->point2d() - __A->point2d(); } Vec3r CurvePoint::orientation3d() const { - if (__A == 0) - return __B->orientation3d(); - if (__B == 0) - return __A->orientation3d(); - return __B->point3d() - __A->point3d(); + if (__A == 0) + return __B->orientation3d(); + if (__B == 0) + return __A->orientation3d(); + return __B->point3d() - __A->point3d(); } real curvature2d() const { - return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); + return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); } Vec3r CurvePoint::curvature2d_as_vector() const { -#if 0 - Vec3r edgeA = (_FEdges[0])->orientation2d().normalize(); - Vec3r edgeB = (_FEdges[1])->orientation2d().normalize(); - return edgeA + edgeB; -#endif - if (__A == 0) - return __B->curvature2d_as_vector(); - if (__B == 0) - return __A->curvature2d_as_vector(); - return ((1 - _t2d) * __A->curvature2d_as_vector() + _t2d * __B->curvature2d_as_vector()); +# if 0 + Vec3r edgeA = (_FEdges[0])->orientation2d().normalize(); + Vec3r edgeB = (_FEdges[1])->orientation2d().normalize(); + return edgeA + edgeB; +# endif + if (__A == 0) + return __B->curvature2d_as_vector(); + if (__B == 0) + return __A->curvature2d_as_vector(); + return ((1 - _t2d) * __A->curvature2d_as_vector() + _t2d * __B->curvature2d_as_vector()); } real CurvePoint::curvature2d_as_angle() const { -#if 0 - Vec3r edgeA = (_FEdges[0])->orientation2d(); - Vec3r edgeB = (_FEdges[1])->orientation2d(); - Vec2d N1(-edgeA.y(), edgeA.x()); - N1.normalize(); - Vec2d N2(-edgeB.y(), edgeB.x()); - N2.normalize(); - return acos((N1 * N2)); -#endif - if (__A == 0) - return __B->curvature2d_as_angle(); - if (__B == 0) - return __A->curvature2d_as_angle(); - return ((1 - _t2d) * __A->curvature2d_as_angle() + _t2d * __B->curvature2d_as_angle()); +# if 0 + Vec3r edgeA = (_FEdges[0])->orientation2d(); + Vec3r edgeB = (_FEdges[1])->orientation2d(); + Vec2d N1(-edgeA.y(), edgeA.x()); + N1.normalize(); + Vec2d N2(-edgeB.y(), edgeB.x()); + N2.normalize(); + return acos((N1 * N2)); +# endif + if (__A == 0) + return __B->curvature2d_as_angle(); + if (__B == 0) + return __A->curvature2d_as_angle(); + return ((1 - _t2d) * __A->curvature2d_as_angle() + _t2d * __B->curvature2d_as_angle()); } real CurvePoint::curvatureFredo() const { - if (__A == 0) - return __B->curvatureFredo(); - if (__B == 0) - return __A->curvatureFredo(); - return ((1 - _t2d) * __A->curvatureFredo() + _t2d * __B->curvatureFredo()); + if (__A == 0) + return __B->curvatureFredo(); + if (__B == 0) + return __A->curvatureFredo(); + return ((1 - _t2d) * __A->curvatureFredo() + _t2d * __B->curvatureFredo()); } Vec2d CurvePoint::directionFredo () const { - if (__A == 0) - return __B->directionFredo(); - if (__B == 0) - return __A->directionFredo(); - return ((1 - _t2d) * __A->directionFredo() + _t2d * __B->directionFredo()); + if (__A == 0) + return __B->directionFredo(); + if (__B == 0) + return __A->directionFredo(); + return ((1 - _t2d) * __A->directionFredo() + _t2d * __B->directionFredo()); } #endif @@ -504,122 +506,166 @@ Vec2d CurvePoint::directionFredo () const Curve::~Curve() { - if (!_Vertices.empty()) { - for (vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); it != itend; ++it) { - delete (*it); - } - _Vertices.clear(); - } + if (!_Vertices.empty()) { + for (vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); it != itend; + ++it) { + delete (*it); + } + _Vertices.clear(); + } } /*! iterators access */ Curve::point_iterator Curve::points_begin(float step) { - vertex_container::iterator second = _Vertices.begin(); - ++second; - return point_iterator(_Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), _nSegments, step, 0.0f, 0.0f); - //return point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f); + vertex_container::iterator second = _Vertices.begin(); + ++second; + return point_iterator( + _Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), _nSegments, step, 0.0f, 0.0f); + //return point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f); } Curve::const_point_iterator Curve::points_begin(float step) const { - vertex_container::const_iterator second = _Vertices.begin(); - ++second; - return const_point_iterator(_Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), - _nSegments, step, 0.0f, 0.0f); - //return const_point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f); + vertex_container::const_iterator second = _Vertices.begin(); + ++second; + return const_point_iterator( + _Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), _nSegments, step, 0.0f, 0.0f); + //return const_point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f); } Curve::point_iterator Curve::points_end(float step) { - return point_iterator(_Vertices.end(), _Vertices.end(), _Vertices.begin(), _Vertices.end(), - _nSegments, step, 1.0f, _Length); - //return point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f, _Length); + return point_iterator(_Vertices.end(), + _Vertices.end(), + _Vertices.begin(), + _Vertices.end(), + _nSegments, + step, + 1.0f, + _Length); + //return point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f, _Length); } Curve::const_point_iterator Curve::points_end(float step) const { - return const_point_iterator(_Vertices.end(), _Vertices.end(), _Vertices.begin(), _Vertices.end(), - _nSegments, step, 1.0f, _Length); - //return const_point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f, _Length); + return const_point_iterator(_Vertices.end(), + _Vertices.end(), + _Vertices.begin(), + _Vertices.end(), + _nSegments, + step, + 1.0f, + _Length); + //return const_point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f, _Length); } // Adavnced Iterators access Curve::point_iterator Curve::vertices_begin() { - return points_begin(0); + return points_begin(0); } Curve::const_point_iterator Curve::vertices_begin() const { - return points_begin(0); + return points_begin(0); } Curve::point_iterator Curve::vertices_end() { - return points_end(0); + return points_end(0); } Curve::const_point_iterator Curve::vertices_end() const { - return points_end(0); + return points_end(0); } // specialized iterators access CurveInternal::CurvePointIterator Curve::curvePointsBegin(float t) { - vertex_container::iterator second = _Vertices.begin(); - ++second; - return CurveInternal::CurvePointIterator(_Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), - 0, _nSegments, _Length, t, 0.0f, 0.0f); + vertex_container::iterator second = _Vertices.begin(); + ++second; + return CurveInternal::CurvePointIterator(_Vertices.begin(), + second, + _Vertices.begin(), + _Vertices.end(), + 0, + _nSegments, + _Length, + t, + 0.0f, + 0.0f); } CurveInternal::CurvePointIterator Curve::curvePointsEnd(float t) { - vertex_container::iterator last = _Vertices.end(); - --last; - return CurveInternal::CurvePointIterator(last, _Vertices.end(), _Vertices.begin(), _Vertices.end(), - _nSegments, _nSegments, _Length, t, 0.0f, _Length); + vertex_container::iterator last = _Vertices.end(); + --last; + return CurveInternal::CurvePointIterator(last, + _Vertices.end(), + _Vertices.begin(), + _Vertices.end(), + _nSegments, + _nSegments, + _Length, + t, + 0.0f, + _Length); } -CurveInternal::CurvePointIterator Curve::curveVerticesBegin() +CurveInternal::CurvePointIterator Curve::curveVerticesBegin() { - return curvePointsBegin(0); + return curvePointsBegin(0); } CurveInternal::CurvePointIterator Curve::curveVerticesEnd() { - return curvePointsEnd(0); + return curvePointsEnd(0); } Interface0DIterator Curve::pointsBegin(float t) { - vertex_container::iterator second = _Vertices.begin(); - ++second; - Interface0DIterator ret(new CurveInternal::CurvePointIterator(_Vertices.begin(), second, _Vertices.begin(), - _Vertices.end(), 0, _nSegments, _Length, - t, 0.0f, 0.0f)); - return ret; + vertex_container::iterator second = _Vertices.begin(); + ++second; + Interface0DIterator ret(new CurveInternal::CurvePointIterator(_Vertices.begin(), + second, + _Vertices.begin(), + _Vertices.end(), + 0, + _nSegments, + _Length, + t, + 0.0f, + 0.0f)); + return ret; } Interface0DIterator Curve::pointsEnd(float t) { - vertex_container::iterator last = _Vertices.end(); - --last; - Interface0DIterator ret(new CurveInternal::CurvePointIterator(last, _Vertices.end(), _Vertices.begin(), - _Vertices.end(), _nSegments, _nSegments, - _Length, t, 0.0f, _Length)); - return ret; + vertex_container::iterator last = _Vertices.end(); + --last; + Interface0DIterator ret(new CurveInternal::CurvePointIterator(last, + _Vertices.end(), + _Vertices.begin(), + _Vertices.end(), + _nSegments, + _nSegments, + _Length, + t, + 0.0f, + _Length)); + return ret; } Interface0DIterator Curve::verticesBegin() { - return pointsBegin(0); + return pointsBegin(0); } Interface0DIterator Curve::verticesEnd() { - return pointsEnd(0); + return pointsEnd(0); } #if 0 @@ -627,188 +673,188 @@ Vec3r shaded_color(int iCombination = 0) const; Vec3r Curve::orientation2d(point_iterator it) const { - return (*it)->orientation2d(); + return (*it)->orientation2d(); } template Vec3r Curve::orientation2d(int iCombination) const { - return edge_orientation2d_function(this, iCombination); + return edge_orientation2d_function(this, iCombination); } Vec3r Curve::orientation3d(point_iterator it) const { - return (*it)->orientation3d(); + return (*it)->orientation3d(); } Vec3r Curve::orientation3d(int iCombination) const { - return edge_orientation3d_function(this, iCombination); + return edge_orientation3d_function(this, iCombination); } real curvature2d(point_iterator it) const { - return (*it)->curvature2d(); + return (*it)->curvature2d(); } real curvature2d(int iCombination = 0) const; Material Curve::material() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - const Material& mat = (*v)->material(); - for (; v != vend; ++v) { - if ((*v)->material() != mat) - Exception::raiseException(); - } - return mat; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + const Material& mat = (*v)->material(); + for (; v != vend; ++v) { + if ((*v)->material() != mat) + Exception::raiseException(); + } + return mat; } int Curve::qi() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - int qi_ = (*v)->qi(); - for (; v != vend; ++v) { - if ((*v)->qi() != qi_) - Exception::raiseException(); - } - return qi_; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + int qi_ = (*v)->qi(); + for (; v != vend; ++v) { + if ((*v)->qi() != qi_) + Exception::raiseException(); + } + return qi_; } occluder_container::const_iterator occluders_begin() const { - return _FEdgeA->occluders().begin(); + return _FEdgeA->occluders().begin(); } occluder_container::const_iterator occluders_end() const { - return _FEdgeA->occluders().end(); + return _FEdgeA->occluders().end(); } int Curve::occluders_size() const { - return qi(); + return qi(); } bool Curve::occluders_empty() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - bool empty = (*v)->occluders_empty(); - for (; v != vend; ++v) { - if ((*v)->occluders_empty() != empty) - Exception::raiseException(); - } - return empty; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + bool empty = (*v)->occluders_empty(); + for (; v != vend; ++v) { + if ((*v)->occluders_empty() != empty) + Exception::raiseException(); + } + return empty; } const Polygon3r& occludee() const { - return *(_FEdgeA->aFace()); + return *(_FEdgeA->aFace()); } const SShape *Curve::occluded_shape() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - const SShape *sshape = (*v)->occluded_shape(); - for (; v != vend; ++v) { - if ((*v)->occluded_shape() != sshape) - Exception::raiseException(); - } - return sshape; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + const SShape *sshape = (*v)->occluded_shape(); + for (; v != vend; ++v) { + if ((*v)->occluded_shape() != sshape) + Exception::raiseException(); + } + return sshape; } const bool Curve::occludee_empty() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - bool empty = (*v)->occludee_empty(); - for (; v != vend; ++v) { - if ((*v)->occludee_empty() != empty) - Exception::raiseException(); - } - return empty; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + bool empty = (*v)->occludee_empty(); + for (; v != vend; ++v) { + if ((*v)->occludee_empty() != empty) + Exception::raiseException(); + } + return empty; } real Curve::z_discontinuity(int iCombination) const { - return z_discontinuity_edge_function(this, iCombination); + return z_discontinuity_edge_function(this, iCombination); } int Curve::shape_id() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - Id id = (*v)->shape_id(); - for (; v != vend; ++v) { - if ((*v)->shape_id() != id) - Exception::raiseException(); - } - return id.first; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + Id id = (*v)->shape_id(); + for (; v != vend; ++v) { + if ((*v)->shape_id() != id) + Exception::raiseException(); + } + return id.first; } const SShape *Curve::shape() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - const SShape *sshape = (*v)->shape(); - for (; v != vend; ++v) { - if ((*v)->shape() != sshape) - Exception::raiseException(); - } - return sshape; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + const SShape *sshape = (*v)->shape(); + for (; v != vend; ++v) { + if ((*v)->shape() != sshape) + Exception::raiseException(); + } + return sshape; } occluder_container::const_iterator Curve::occluders_begin() const { - const_vertex_iterator v = vertices_begin(); - return (*v)->occluders_begin(); + const_vertex_iterator v = vertices_begin(); + return (*v)->occluders_begin(); } occluder_container::const_iterator Curve::occluders_end() const { - const_vertex_iterator v = vertices_end(); - return (*v)->occluders_end(); + const_vertex_iterator v = vertices_end(); + return (*v)->occluders_end(); } Vec3r Curve::curvature2d_as_vector(int iCombination) const { - return curvature2d_as_vector_edge_function(this, iCombination); + return curvature2d_as_vector_edge_function(this, iCombination); } real Curve::curvature2d_as_angle(int iCombination) const { - return curvature2d_as_angle_edge_function(this, iCombination); + return curvature2d_as_angle_edge_function(this, iCombination); } float Curve::shape_importance(int iCombination) const { - return shape_importance_edge_function(this, iCombination); + return shape_importance_edge_function(this, iCombination); } float Curve::local_average_depth(int iCombination) const { - return local_average_depth_edge_function(this, iCombination); + return local_average_depth_edge_function(this, iCombination); } float Curve::local_depth_variance(int iCombination ) const { - return local_depth_variance_edge_function(this, iCombination); -#if 0 - local_depth_variance_functor functor; - float result; - Evaluate >(&functor, iCombination, result); - return result; -#endif + return local_depth_variance_edge_function(this, iCombination); +# if 0 + local_depth_variance_functor functor; + float result; + Evaluate >(&functor, iCombination, result); + return result; +# endif } real Curve::local_average_density(float sigma, int iCombination ) const { - return density_edge_function(this, iCombination); -#if 0 - density_functor functor; - real result; - Evaluate >(&functor, iCombination, result); - return result; -#endif + return density_edge_function(this, iCombination); +# if 0 + density_functor functor; + real result; + Evaluate >(&functor, iCombination, result); + return result; +# endif } /* UNUSED */ @@ -816,109 +862,109 @@ real Curve::local_average_density(float sigma, int iCombination ) const void Curve::computeCurvatureAndOrientation () { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(), v2, prevV, v0; - Vec2d p0, p1, p2; - Vec3r p; - - p = (*v)->point2d(); - p0 = Vec2d(p[0], p[1]); - prevV = v; - ++v; - p = (*v)->point2d(); - p1 = Vec2d(p[0], p[1]); - Vec2d prevDir(p1 - p0); - - for (; v! = vend; ++v) { - v2 = v; - ++v2; - if (v2 == vend) - break; - Vec3r p2 = (*v2)->point2d(); - - Vec2d BA = p0 - p1; - Vec2d BC = p2 - p1; - real lba = BA.norm(), lbc = BC.norm(); - BA.normalizeSafe(); - BC.normalizeSafe(); - Vec2d normalCurvature = BA + BC; - Vec2d dir = Vec2d(BC - BA); - Vec2d normal = Vec2d(-dir[1], dir[0]); - - normal.normalizeSafe(); - real curvature = normalCurvature * normal; - if (lba + lbc > MY_EPSILON) - curvature /= (0.5 * lba + lbc); - if (dir.norm() < MY_EPSILON) - dir = 0.1 * prevDir; - (*v)->setCurvatureFredo(curvature); - (*v)->setDirectionFredo(dir); - - prevV = v; - p0 = p1; - p1 = p2; - prevDir = dir; - prevDir.normalize(); - } - (*v)->setCurvatureFredo((*prevV)->curvatureFredo()); - (*v)->setDirectionFredo((*v)->point2d() - (*prevV)->point2d()); - v0 = vertices_begin(); - v2 = v0; - ++v2; - (*v0)->setCurvatureFredo((*v2)->curvatureFredo()); - (*v0)->setDirectionFredo((*v2)->point2d() - (*v0)->point2d()); - - //closed curve case one day... - - // - return; - - //numerical degeneracy verification... we'll see later - const_vertex_iterator vLastReliable = vertices_begin(); - - v = vertices_begin(); - p = (*v)->point2d(); - p0 = Vec2d(p[0], p[1]); - prevV = v; - ++v; - p = (*v)->point2d(); - p1 = Vec2d(p[0], p[1]); - bool isReliable = false; - if ((p1 - p0).norm > EPS_CURVA) { - vLastReliable = v; - isReliable = true; - } - - for (; v != vend; ++v) { - v2 = v; - ++v2; - if (v2 == vend) - break; - Vec3r p2 = (*v2)->point2d(); - - Vec2d BA = p0 - p1; - Vec2d BC = p2 - p1; - real lba = BA.norm(), lbc = BC.norm(); - - if ((lba + lbc) < EPS_CURVA) { - isReliable = false; - cerr << "/"; - } - else { - if (!isReliable) { //previous points were not reliable - const_vertex_iterator vfix = vLastReliable; - ++vfix; - for (; vfix != v; ++vfix) { - (*vfix)->setCurvatureFredo((*v)->curvatureFredo()); - (*vfix)->setDirectionFredo((*v)->directionFredo()); - } - } - isReliable = true; - vLastReliable = v; - } - prevV = v; - p0 = p1; - p1 = p2; - } + const_vertex_iterator v = vertices_begin(), vend = vertices_end(), v2, prevV, v0; + Vec2d p0, p1, p2; + Vec3r p; + + p = (*v)->point2d(); + p0 = Vec2d(p[0], p[1]); + prevV = v; + ++v; + p = (*v)->point2d(); + p1 = Vec2d(p[0], p[1]); + Vec2d prevDir(p1 - p0); + + for (; v! = vend; ++v) { + v2 = v; + ++v2; + if (v2 == vend) + break; + Vec3r p2 = (*v2)->point2d(); + + Vec2d BA = p0 - p1; + Vec2d BC = p2 - p1; + real lba = BA.norm(), lbc = BC.norm(); + BA.normalizeSafe(); + BC.normalizeSafe(); + Vec2d normalCurvature = BA + BC; + Vec2d dir = Vec2d(BC - BA); + Vec2d normal = Vec2d(-dir[1], dir[0]); + + normal.normalizeSafe(); + real curvature = normalCurvature * normal; + if (lba + lbc > MY_EPSILON) + curvature /= (0.5 * lba + lbc); + if (dir.norm() < MY_EPSILON) + dir = 0.1 * prevDir; + (*v)->setCurvatureFredo(curvature); + (*v)->setDirectionFredo(dir); + + prevV = v; + p0 = p1; + p1 = p2; + prevDir = dir; + prevDir.normalize(); + } + (*v)->setCurvatureFredo((*prevV)->curvatureFredo()); + (*v)->setDirectionFredo((*v)->point2d() - (*prevV)->point2d()); + v0 = vertices_begin(); + v2 = v0; + ++v2; + (*v0)->setCurvatureFredo((*v2)->curvatureFredo()); + (*v0)->setDirectionFredo((*v2)->point2d() - (*v0)->point2d()); + + //closed curve case one day... + + // + return; + + //numerical degeneracy verification... we'll see later + const_vertex_iterator vLastReliable = vertices_begin(); + + v = vertices_begin(); + p = (*v)->point2d(); + p0 = Vec2d(p[0], p[1]); + prevV = v; + ++v; + p = (*v)->point2d(); + p1 = Vec2d(p[0], p[1]); + bool isReliable = false; + if ((p1 - p0).norm > EPS_CURVA) { + vLastReliable = v; + isReliable = true; + } + + for (; v != vend; ++v) { + v2 = v; + ++v2; + if (v2 == vend) + break; + Vec3r p2 = (*v2)->point2d(); + + Vec2d BA = p0 - p1; + Vec2d BC = p2 - p1; + real lba = BA.norm(), lbc = BC.norm(); + + if ((lba + lbc) < EPS_CURVA) { + isReliable = false; + cerr << "/"; + } + else { + if (!isReliable) { //previous points were not reliable + const_vertex_iterator vfix = vLastReliable; + ++vfix; + for (; vfix != v; ++vfix) { + (*vfix)->setCurvatureFredo((*v)->curvatureFredo()); + (*vfix)->setDirectionFredo((*v)->directionFredo()); + } + } + isReliable = true; + vLastReliable = v; + } + prevV = v; + p0 = p1; + p1 = p2; + } } #endif diff --git a/source/blender/freestyle/intern/stroke/Curve.h b/source/blender/freestyle/intern/stroke/Curve.h index 40c20fb777c..234f9df0e48 100644 --- a/source/blender/freestyle/intern/stroke/Curve.h +++ b/source/blender/freestyle/intern/stroke/Curve.h @@ -36,7 +36,7 @@ #include "../system/BaseIterator.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -60,288 +60,288 @@ using namespace Geometry; * Thus, a CurvePoint is built by lineraly interpolating two SVertex. * CurvePoint can be used as virtual points while querying 0D information along a curve at a given resolution. */ -class CurvePoint : public Interface0D -{ -public: // Implementation of Interface0D - /*! Returns the string "CurvePoint"*/ - virtual string getExactTypeName() const - { - return "CurvePoint"; - } - - // Data access methods - /*! Returns the 3D X coordinate of the point */ - virtual real getX() const - { - return _Point3d.x(); - } - - /*! Returns the 3D Y coordinate of the point */ - virtual real getY() const - { - return _Point3d.y(); - } - - /*! Returns the 3D Z coordinate of the point */ - virtual real getZ() const - { - return _Point3d.z(); - } - - /*! Returns the 3D point. */ - virtual Vec3r getPoint3D() const - { - return _Point3d; - } - - /*! Returns the projected 3D X coordinate of the point */ - virtual real getProjectedX() const - { - return _Point2d.x(); - } - - /*! Returns the projected 3D Y coordinate of the point */ - virtual real getProjectedY() const - { - return _Point2d.y(); - } - - /*! Returns the projected 3D Z coordinate of the point */ - virtual real getProjectedZ() const - { - return _Point2d.z(); - } - - /*! Returns the 2D point. */ - virtual Vec2r getPoint2D() const - { - return Vec2r(_Point2d.x(), _Point2d.y()); - } - - virtual FEdge *getFEdge(Interface0D& inter); - - /*! Returns the CurvePoint's Id */ - virtual Id getId() const - { - Id id; - if (_t2d == 0) - return __A->getId(); - else if (_t2d == 1) - return __B->getId(); - return id; - } - - /*! Returns the CurvePoint's Nature */ - virtual Nature::VertexNature getNature() const - { - Nature::VertexNature nature = Nature::POINT; - if (_t2d == 0) - nature |= __A->getNature(); - else if (_t2d == 1) - nature |= __B->getNature(); - return nature; - } - - /*! Cast the Interface0D in SVertex if it can be. */ - virtual SVertex *castToSVertex() - { - if (_t2d == 0) - return __A; - else if (_t2d == 1) - return __B; - return Interface0D::castToSVertex(); - } - - /*! Cast the Interface0D in ViewVertex if it can be. */ - virtual ViewVertex *castToViewVertex() - { - if (_t2d == 0) - return __A->castToViewVertex(); - else if (_t2d == 1) - return __B->castToViewVertex(); - return Interface0D::castToViewVertex(); - } - - /*! Cast the Interface0D in NonTVertex if it can be. */ - virtual NonTVertex *castToNonTVertex() - { - if (_t2d == 0) - return __A->castToNonTVertex(); - else if (_t2d == 1) - return __B->castToNonTVertex(); - return Interface0D::castToNonTVertex(); - } - - /*! Cast the Interface0D in TVertex if it can be. */ - virtual TVertex *castToTVertex() - { - if (_t2d == 0) - return __A->castToTVertex(); - else if (_t2d == 1) - return __B->castToTVertex(); - return Interface0D::castToTVertex(); - } - -public: - typedef SVertex vertex_type; - -protected: - SVertex *__A; - SVertex *__B; - float _t2d; - //float _t3d; - Vec3r _Point2d; - Vec3r _Point3d; - -public: - /*! Defult Constructor. */ - CurvePoint(); - - /*! Builds a CurvePoint from two SVertex and an interpolation parameter. - * \param iA: - * The first SVertex - * \param iB: - * The second SVertex - * \param t2d: - * A 2D interpolation parameter used to linearly interpolate \a iA and \a iB - */ - CurvePoint(SVertex *iA, SVertex *iB, float t2d); - - /*! Builds a CurvePoint from two CurvePoint and an interpolation parameter. - * \param iA: - * The first CurvePoint - * \param iB: - * The second CurvePoint - * \param t2d: - * The 2D interpolation parameter used to linearly interpolate \a iA and \a iB. - */ - CurvePoint(CurvePoint *iA, CurvePoint *iB, float t2d); - - //CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d); - - /*! Copy Constructor. */ - CurvePoint(const CurvePoint& iBrother); - - /*! Operator = */ - CurvePoint& operator=(const CurvePoint& iBrother); - - /*! Destructor */ - virtual ~CurvePoint() {} - - /*! Operator == */ - bool operator==(const CurvePoint& b) - { - return ((__A == b.__A) && (__B == b.__B) && (_t2d == b._t2d)); - } - - /* accessors */ - /*! Returns the first SVertex upon which the CurvePoint is built. */ - inline SVertex *A() - { - return __A; - } - - /*! Returns the second SVertex upon which the CurvePoint is built. */ - inline SVertex *B() - { - return __B; - } - - /*! Returns the interpolation parameter. */ - inline float t2d() const - { - return _t2d; - } +class CurvePoint : public Interface0D { + public: // Implementation of Interface0D + /*! Returns the string "CurvePoint"*/ + virtual string getExactTypeName() const + { + return "CurvePoint"; + } + + // Data access methods + /*! Returns the 3D X coordinate of the point */ + virtual real getX() const + { + return _Point3d.x(); + } + + /*! Returns the 3D Y coordinate of the point */ + virtual real getY() const + { + return _Point3d.y(); + } + + /*! Returns the 3D Z coordinate of the point */ + virtual real getZ() const + { + return _Point3d.z(); + } + + /*! Returns the 3D point. */ + virtual Vec3r getPoint3D() const + { + return _Point3d; + } + + /*! Returns the projected 3D X coordinate of the point */ + virtual real getProjectedX() const + { + return _Point2d.x(); + } + + /*! Returns the projected 3D Y coordinate of the point */ + virtual real getProjectedY() const + { + return _Point2d.y(); + } + + /*! Returns the projected 3D Z coordinate of the point */ + virtual real getProjectedZ() const + { + return _Point2d.z(); + } + + /*! Returns the 2D point. */ + virtual Vec2r getPoint2D() const + { + return Vec2r(_Point2d.x(), _Point2d.y()); + } + + virtual FEdge *getFEdge(Interface0D &inter); + + /*! Returns the CurvePoint's Id */ + virtual Id getId() const + { + Id id; + if (_t2d == 0) + return __A->getId(); + else if (_t2d == 1) + return __B->getId(); + return id; + } + + /*! Returns the CurvePoint's Nature */ + virtual Nature::VertexNature getNature() const + { + Nature::VertexNature nature = Nature::POINT; + if (_t2d == 0) + nature |= __A->getNature(); + else if (_t2d == 1) + nature |= __B->getNature(); + return nature; + } + + /*! Cast the Interface0D in SVertex if it can be. */ + virtual SVertex *castToSVertex() + { + if (_t2d == 0) + return __A; + else if (_t2d == 1) + return __B; + return Interface0D::castToSVertex(); + } + + /*! Cast the Interface0D in ViewVertex if it can be. */ + virtual ViewVertex *castToViewVertex() + { + if (_t2d == 0) + return __A->castToViewVertex(); + else if (_t2d == 1) + return __B->castToViewVertex(); + return Interface0D::castToViewVertex(); + } + + /*! Cast the Interface0D in NonTVertex if it can be. */ + virtual NonTVertex *castToNonTVertex() + { + if (_t2d == 0) + return __A->castToNonTVertex(); + else if (_t2d == 1) + return __B->castToNonTVertex(); + return Interface0D::castToNonTVertex(); + } + + /*! Cast the Interface0D in TVertex if it can be. */ + virtual TVertex *castToTVertex() + { + if (_t2d == 0) + return __A->castToTVertex(); + else if (_t2d == 1) + return __B->castToTVertex(); + return Interface0D::castToTVertex(); + } + + public: + typedef SVertex vertex_type; + + protected: + SVertex *__A; + SVertex *__B; + float _t2d; + //float _t3d; + Vec3r _Point2d; + Vec3r _Point3d; + + public: + /*! Defult Constructor. */ + CurvePoint(); + + /*! Builds a CurvePoint from two SVertex and an interpolation parameter. + * \param iA: + * The first SVertex + * \param iB: + * The second SVertex + * \param t2d: + * A 2D interpolation parameter used to linearly interpolate \a iA and \a iB + */ + CurvePoint(SVertex *iA, SVertex *iB, float t2d); + + /*! Builds a CurvePoint from two CurvePoint and an interpolation parameter. + * \param iA: + * The first CurvePoint + * \param iB: + * The second CurvePoint + * \param t2d: + * The 2D interpolation parameter used to linearly interpolate \a iA and \a iB. + */ + CurvePoint(CurvePoint *iA, CurvePoint *iB, float t2d); + + //CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d); + + /*! Copy Constructor. */ + CurvePoint(const CurvePoint &iBrother); + + /*! Operator = */ + CurvePoint &operator=(const CurvePoint &iBrother); + + /*! Destructor */ + virtual ~CurvePoint() + { + } + + /*! Operator == */ + bool operator==(const CurvePoint &b) + { + return ((__A == b.__A) && (__B == b.__B) && (_t2d == b._t2d)); + } + + /* accessors */ + /*! Returns the first SVertex upon which the CurvePoint is built. */ + inline SVertex *A() + { + return __A; + } + + /*! Returns the second SVertex upon which the CurvePoint is built. */ + inline SVertex *B() + { + return __B; + } + + /*! Returns the interpolation parameter. */ + inline float t2d() const + { + return _t2d; + } #if 0 - inline const float t3d() const - { - return _t3d; - } + inline const float t3d() const + { + return _t3d; + } #endif - /* modifiers */ - /*! Sets the first SVertex upon which to build the CurvePoint. */ - inline void setA(SVertex *iA) - { - __A = iA; - } - - /*! Sets the second SVertex upon which to build the CurvePoint. */ - inline void setB(SVertex *iB) - { - __B = iB; - } - - /*! Sets the 2D interpolation parameter to use. */ - inline void setT2d(float t) - { - _t2d = t; - } + /* modifiers */ + /*! Sets the first SVertex upon which to build the CurvePoint. */ + inline void setA(SVertex *iA) + { + __A = iA; + } + + /*! Sets the second SVertex upon which to build the CurvePoint. */ + inline void setB(SVertex *iB) + { + __B = iB; + } + + /*! Sets the 2D interpolation parameter to use. */ + inline void setT2d(float t) + { + _t2d = t; + } #if 0 - inline void SetT3d(float t) - { - _t3d = t; - } + inline void SetT3d(float t) + { + _t3d = t; + } #endif - /* Information access interface */ - - FEdge *fedge(); - - inline const Vec3r& point2d() const - { - return _Point2d; - } - - inline const Vec3r& point3d() const - { - return _Point3d; - } - - Vec3r normal() const; - //FrsMaterial material() const; - //Id shape_id() const; - const SShape *shape() const; - //float shape_importance() const; - - //const unsigned qi() const; - occluder_container::const_iterator occluders_begin() const; - occluder_container::const_iterator occluders_end() const; - bool occluders_empty() const; - int occluders_size() const; - const Polygon3r& occludee() const; - const SShape *occluded_shape() const; - const bool occludee_empty() const; - real z_discontinuity() const; + /* Information access interface */ + + FEdge *fedge(); + + inline const Vec3r &point2d() const + { + return _Point2d; + } + + inline const Vec3r &point3d() const + { + return _Point3d; + } + + Vec3r normal() const; + //FrsMaterial material() const; + //Id shape_id() const; + const SShape *shape() const; + //float shape_importance() const; + + //const unsigned qi() const; + occluder_container::const_iterator occluders_begin() const; + occluder_container::const_iterator occluders_end() const; + bool occluders_empty() const; + int occluders_size() const; + const Polygon3r &occludee() const; + const SShape *occluded_shape() const; + const bool occludee_empty() const; + real z_discontinuity() const; #if 0 - float local_average_depth() const; - float local_depth_variance() const; - real local_average_density(float sigma = 2.3f) const; - Vec3r shaded_color() const; - Vec3r orientation2d() const; - Vec3r orientation3d() const; - - real curvature2d() const - { - return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); - } - - Vec3r curvature2d_as_vector() const; - /*! angle in radians */ - real curvature2d_as_angle() const; - - real curvatureFredo() const; - Vec2d directionFredo() const; + float local_average_depth() const; + float local_depth_variance() const; + real local_average_density(float sigma = 2.3f) const; + Vec3r shaded_color() const; + Vec3r orientation2d() const; + Vec3r orientation3d() const; + + real curvature2d() const + { + return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); + } + + Vec3r curvature2d_as_vector() const; + /*! angle in radians */ + real curvature2d_as_angle() const; + + real curvatureFredo() const; + Vec2d directionFredo() const; #endif #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint") #endif }; - /**********************************/ /* */ /* */ @@ -357,236 +357,237 @@ class CurvePoint_nonconst_traits; template class __point_iterator; class CurvePointIterator; -} // end of namespace CurveInternal +} // end of namespace CurveInternal /*! Base class for curves made of CurvePoints. * SVertex is the type of the initial curve vertices. * A Chain is a specialization of a Curve. */ -class Curve : public Interface1D -{ -public: - typedef CurvePoint Vertex; - typedef CurvePoint Point; - typedef Point point_type; - typedef Vertex vertex_type; - typedef deque vertex_container; - - /* Iterator to iterate over a vertex edges */ - - typedef CurveInternal::__point_iterator point_iterator; - typedef CurveInternal::__point_iterator const_point_iterator; - typedef point_iterator vertex_iterator ; - typedef const_point_iterator const_vertex_iterator ; - -protected: - vertex_container _Vertices; - double _Length; - Id _Id; - unsigned _nSegments; // number of segments - -public: - /*! Default Constructor. */ - Curve() - { - _Length = 0; - _Id = 0; - _nSegments = 0; - } - - /*! Builds a Curve from its id */ - Curve(const Id& id) - { - _Length = 0; - _Id = id; - _nSegments = 0; - } - - /*! Copy Constructor. */ - Curve(const Curve& iBrother) - { - _Length = iBrother._Length; - _Vertices = iBrother._Vertices; - _Id = iBrother._Id; - _nSegments = 0; - } - - /*! Destructor. */ - virtual ~Curve(); - - /*! Returns the string "Curve" */ - virtual string getExactTypeName() const - { - return "Curve"; - } +class Curve : public Interface1D { + public: + typedef CurvePoint Vertex; + typedef CurvePoint Point; + typedef Point point_type; + typedef Vertex vertex_type; + typedef deque vertex_container; + + /* Iterator to iterate over a vertex edges */ + + typedef CurveInternal::__point_iterator + point_iterator; + typedef CurveInternal::__point_iterator + const_point_iterator; + typedef point_iterator vertex_iterator; + typedef const_point_iterator const_vertex_iterator; + + protected: + vertex_container _Vertices; + double _Length; + Id _Id; + unsigned _nSegments; // number of segments + + public: + /*! Default Constructor. */ + Curve() + { + _Length = 0; + _Id = 0; + _nSegments = 0; + } + + /*! Builds a Curve from its id */ + Curve(const Id &id) + { + _Length = 0; + _Id = id; + _nSegments = 0; + } + + /*! Copy Constructor. */ + Curve(const Curve &iBrother) + { + _Length = iBrother._Length; + _Vertices = iBrother._Vertices; + _Id = iBrother._Id; + _nSegments = 0; + } + + /*! Destructor. */ + virtual ~Curve(); + + /*! Returns the string "Curve" */ + virtual string getExactTypeName() const + { + return "Curve"; + } #if 0 - /* fredo's curvature storage */ - void computeCurvatureAndOrientation(); + /* fredo's curvature storage */ + void computeCurvatureAndOrientation(); #endif - /*! Adds a single vertex (CurvePoint) at the end of the Curve */ - inline void push_vertex_back(Vertex *iVertex) - { - if (!_Vertices.empty()) { - Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d()); - _Length += vec_tmp.norm(); - ++_nSegments; - } - Vertex *new_vertex = new Vertex(*iVertex); - _Vertices.push_back(new_vertex); - } - - /*! Adds a single vertex (SVertex) at the end of the Curve */ - inline void push_vertex_back(SVertex *iVertex) - { - if (!_Vertices.empty()) { - Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d()); - _Length += vec_tmp.norm(); - ++_nSegments; - } - Vertex *new_vertex = new Vertex(iVertex, 0, 0); - _Vertices.push_back(new_vertex); - } - - /*! Adds a single vertex (CurvePoint) at the front of the Curve */ - inline void push_vertex_front(Vertex *iVertex) - { - if (!_Vertices.empty()) { - Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d()); - _Length += vec_tmp.norm(); - ++_nSegments; - } - Vertex *new_vertex = new Vertex(*iVertex); - _Vertices.push_front(new_vertex); - } - - /*! Adds a single vertex (SVertex) at the front of the Curve */ - inline void push_vertex_front(SVertex *iVertex) - { - if (!_Vertices.empty()) { - Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d()); - _Length += vec_tmp.norm(); - ++_nSegments; - } - Vertex *new_vertex = new Vertex(iVertex, 0, 0); - _Vertices.push_front(new_vertex); - } - - /*! Returns true is the Curve doesn't have any Vertex yet. */ - inline bool empty() const - { - return _Vertices.empty(); - } - - /*! Returns the 2D length of the Curve. */ - inline real getLength2D() const - { - return _Length; - } - - /*! Returns the Id of the 1D element. */ - virtual Id getId() const - { - return _Id; - } - - /*! Returns the number of segments in the polyline constituting the Curve. */ - inline unsigned int nSegments() const - { - return _nSegments; - } - - inline void setId(const Id& id) - { - _Id = id; - } - - /* Information access interface */ + /*! Adds a single vertex (CurvePoint) at the end of the Curve */ + inline void push_vertex_back(Vertex *iVertex) + { + if (!_Vertices.empty()) { + Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d()); + _Length += vec_tmp.norm(); + ++_nSegments; + } + Vertex *new_vertex = new Vertex(*iVertex); + _Vertices.push_back(new_vertex); + } + + /*! Adds a single vertex (SVertex) at the end of the Curve */ + inline void push_vertex_back(SVertex *iVertex) + { + if (!_Vertices.empty()) { + Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d()); + _Length += vec_tmp.norm(); + ++_nSegments; + } + Vertex *new_vertex = new Vertex(iVertex, 0, 0); + _Vertices.push_back(new_vertex); + } + + /*! Adds a single vertex (CurvePoint) at the front of the Curve */ + inline void push_vertex_front(Vertex *iVertex) + { + if (!_Vertices.empty()) { + Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d()); + _Length += vec_tmp.norm(); + ++_nSegments; + } + Vertex *new_vertex = new Vertex(*iVertex); + _Vertices.push_front(new_vertex); + } + + /*! Adds a single vertex (SVertex) at the front of the Curve */ + inline void push_vertex_front(SVertex *iVertex) + { + if (!_Vertices.empty()) { + Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d()); + _Length += vec_tmp.norm(); + ++_nSegments; + } + Vertex *new_vertex = new Vertex(iVertex, 0, 0); + _Vertices.push_front(new_vertex); + } + + /*! Returns true is the Curve doesn't have any Vertex yet. */ + inline bool empty() const + { + return _Vertices.empty(); + } + + /*! Returns the 2D length of the Curve. */ + inline real getLength2D() const + { + return _Length; + } + + /*! Returns the Id of the 1D element. */ + virtual Id getId() const + { + return _Id; + } + + /*! Returns the number of segments in the polyline constituting the Curve. */ + inline unsigned int nSegments() const + { + return _nSegments; + } + + inline void setId(const Id &id) + { + _Id = id; + } + + /* Information access interface */ #if 0 - inline Vec3r shaded_color(int iCombination = 0) const; - inline Vec3r orientation2d(point_iterator it) const; - Vec3r orientation2d(int iCombination = 0) const; - Vec3r orientation3d(point_iterator it) const; - Vec3r orientation3d(int iCombination = 0) const; - - real curvature2d(point_iterator it) const - { - return (*it)->curvature2d(); - } - - real curvature2d(int iCombination = 0) const; - FrsMaterial material() const; - int qi() const; - occluder_container::const_iterator occluders_begin() const; - occluder_container::const_iterator occluders_end() const; - int occluders_size() const; - bool occluders_empty() const; - - const Polygon3r& occludee() const - { - return *(_FEdgeA->aFace()); - } - - const SShape *occluded_shape() const; - const bool occludee_empty() const; - real z_discontinuity(int iCombination = 0) const; - int shape_id() const; - const SShape *shape() const; - float shape_importance(int iCombination = 0) const; - float local_average_depth(int iCombination = 0) const; - float local_depth_variance(int iCombination = 0) const; - real local_average_density(float sigma = 2.3f, int iCombination = 0) const; - Vec3r curvature2d_as_vector(int iCombination = 0) const; - /*! angle in radians */ - real curvature2d_as_angle(int iCombination = 0) const; + inline Vec3r shaded_color(int iCombination = 0) const; + inline Vec3r orientation2d(point_iterator it) const; + Vec3r orientation2d(int iCombination = 0) const; + Vec3r orientation3d(point_iterator it) const; + Vec3r orientation3d(int iCombination = 0) const; + + real curvature2d(point_iterator it) const + { + return (*it)->curvature2d(); + } + + real curvature2d(int iCombination = 0) const; + FrsMaterial material() const; + int qi() const; + occluder_container::const_iterator occluders_begin() const; + occluder_container::const_iterator occluders_end() const; + int occluders_size() const; + bool occluders_empty() const; + + const Polygon3r& occludee() const + { + return *(_FEdgeA->aFace()); + } + + const SShape *occluded_shape() const; + const bool occludee_empty() const; + real z_discontinuity(int iCombination = 0) const; + int shape_id() const; + const SShape *shape() const; + float shape_importance(int iCombination = 0) const; + float local_average_depth(int iCombination = 0) const; + float local_depth_variance(int iCombination = 0) const; + real local_average_density(float sigma = 2.3f, int iCombination = 0) const; + Vec3r curvature2d_as_vector(int iCombination = 0) const; + /*! angle in radians */ + real curvature2d_as_angle(int iCombination = 0) const; #endif - /* advanced iterators access */ - point_iterator points_begin(float step = 0); - const_point_iterator points_begin(float step = 0) const; - point_iterator points_end(float step = 0); - const_point_iterator points_end(float step = 0) const; - - /* methods given for convenience */ - point_iterator vertices_begin(); - const_point_iterator vertices_begin() const; - point_iterator vertices_end(); - const_point_iterator vertices_end() const; - - // specialized iterators access - CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f); - CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f); - - CurveInternal::CurvePointIterator curveVerticesBegin(); - CurveInternal::CurvePointIterator curveVerticesEnd(); - - // Iterators access - /*! Returns an Interface0DIterator pointing onto the first vertex of the Curve and that can iterate - * over the \a vertices of the Curve. - */ - virtual Interface0DIterator verticesBegin(); - - /*! Returns an Interface0DIterator pointing after the last vertex of the Curve and that can iterate - * over the \a vertices of the Curve. - */ - virtual Interface0DIterator verticesEnd(); - - /*! Returns an Interface0DIterator pointing onto the first point of the Curve and that can iterate - * over the \a points of the Curve at any resolution. - * At each iteration a virtual temporary CurvePoint is created. - */ - virtual Interface0DIterator pointsBegin(float t = 0.0f); - - /*! Returns an Interface0DIterator pointing after the last point of the Curve and that can iterate - * over the \a points of the Curve at any resolution. - * At each iteration a virtual temporary CurvePoint is created. - */ - virtual Interface0DIterator pointsEnd(float t = 0.0f); + /* advanced iterators access */ + point_iterator points_begin(float step = 0); + const_point_iterator points_begin(float step = 0) const; + point_iterator points_end(float step = 0); + const_point_iterator points_end(float step = 0) const; + + /* methods given for convenience */ + point_iterator vertices_begin(); + const_point_iterator vertices_begin() const; + point_iterator vertices_end(); + const_point_iterator vertices_end() const; + + // specialized iterators access + CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f); + CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f); + + CurveInternal::CurvePointIterator curveVerticesBegin(); + CurveInternal::CurvePointIterator curveVerticesEnd(); + + // Iterators access + /*! Returns an Interface0DIterator pointing onto the first vertex of the Curve and that can iterate + * over the \a vertices of the Curve. + */ + virtual Interface0DIterator verticesBegin(); + + /*! Returns an Interface0DIterator pointing after the last vertex of the Curve and that can iterate + * over the \a vertices of the Curve. + */ + virtual Interface0DIterator verticesEnd(); + + /*! Returns an Interface0DIterator pointing onto the first point of the Curve and that can iterate + * over the \a points of the Curve at any resolution. + * At each iteration a virtual temporary CurvePoint is created. + */ + virtual Interface0DIterator pointsBegin(float t = 0.0f); + + /*! Returns an Interface0DIterator pointing after the last point of the Curve and that can iterate + * over the \a points of the Curve at any resolution. + * At each iteration a virtual temporary CurvePoint is created. + */ + virtual Interface0DIterator pointsEnd(float t = 0.0f); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve") #endif }; diff --git a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h index 0a56e674936..3cd55facd15 100644 --- a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h @@ -28,20 +28,18 @@ namespace Freestyle { namespace CurveInternal { -class CurvePoint_const_traits : public Const_traits -{ -public: - typedef deque vertex_container; - typedef vertex_container::const_iterator vertex_container_iterator; - typedef SVertex vertex_type; +class CurvePoint_const_traits : public Const_traits { + public: + typedef deque vertex_container; + typedef vertex_container::const_iterator vertex_container_iterator; + typedef SVertex vertex_type; }; -class CurvePoint_nonconst_traits : public Nonconst_traits -{ -public: - typedef deque vertex_container; - typedef vertex_container::iterator vertex_container_iterator; - typedef SVertex vertex_type; +class CurvePoint_nonconst_traits : public Nonconst_traits { + public: + typedef deque vertex_container; + typedef vertex_container::iterator vertex_container_iterator; + typedef SVertex vertex_type; }; /**********************************/ @@ -52,323 +50,327 @@ public: /* */ /**********************************/ - /*! iterator on a curve. Allows an iterating outside initial vertices. A CurvePoint is instanciated an returned * when the iterator is dereferenced. */ template -class __point_iterator : public IteratorBase -{ -public: - typedef __point_iterator Self; - typedef typename Traits::vertex_container_iterator vertex_container_iterator; - typedef typename Traits::vertex_type vertex_type; - typedef CurvePoint Point; - typedef Point point_type; - - typedef __point_iterator iterator; - typedef __point_iterator const_iterator; +class __point_iterator : public IteratorBase { + public: + typedef __point_iterator Self; + typedef typename Traits::vertex_container_iterator vertex_container_iterator; + typedef typename Traits::vertex_type vertex_type; + typedef CurvePoint Point; + typedef Point point_type; + + typedef __point_iterator iterator; + typedef __point_iterator const_iterator; #if 0 - typedef Vertex vertex_type ; - typedef vertex_container_iterator vertex_iterator_type; - typedef CurvePoint Point; - typedef Point point_type; + typedef Vertex vertex_type ; + typedef vertex_container_iterator vertex_iterator_type; + typedef CurvePoint Point; + typedef Point point_type; #endif - typedef IteratorBase parent_class; + typedef IteratorBase parent_class; #if 0 -#if defined(__GNUC__) && (__GNUC__ < 3) - typedef bidirectional_iterator, ptrdiff_t> bidirectional_point_iterator; -#else - typedef iterator, ptrdiff_t> bidirectional_point_iterator; -#endif +# if defined(__GNUC__) && (__GNUC__ < 3) + typedef bidirectional_iterator, ptrdiff_t> bidirectional_point_iterator; +# else + typedef iterator, ptrdiff_t> bidirectional_point_iterator; +# endif #endif - friend class Curve; + friend class Curve; #if 0 - friend class Curve::vertex_iterator; - friend class __point_iterator; - friend class iterator; + friend class Curve::vertex_iterator; + friend class __point_iterator; + friend class iterator; #endif -//protected: -public: - float _CurvilinearLength; - float _step; - vertex_container_iterator __A; - vertex_container_iterator __B; - vertex_container_iterator _begin; - vertex_container_iterator _end; - int _n; - int _currentn; - float _t; - mutable Point *_Point; - -public: - inline __point_iterator(float step = 0.0f) : parent_class() - { - _step = step; - _CurvilinearLength = 0.0f; - _t = 0.0f; - _Point = 0; - _n = 0; - _currentn = 0; - } - - inline __point_iterator(const iterator& iBrother) : parent_class() - { - __A = iBrother.__A; - __B = iBrother.__B; - _begin = iBrother._begin; - _end = iBrother._end; - _CurvilinearLength = iBrother._CurvilinearLength; - _step = iBrother._step; - _t = iBrother._t; - if (iBrother._Point == 0) - _Point = 0; - else - _Point = new Point(*(iBrother._Point)); - _n = iBrother._n; - _currentn = iBrother._currentn; - } - - inline __point_iterator(const const_iterator& iBrother) : parent_class() - { - __A = iBrother.__A; - __B = iBrother.__B; - _begin = iBrother._begin; - _end = iBrother._end; - _CurvilinearLength = iBrother._CurvilinearLength; - _step = iBrother._step; - _t = iBrother._t; - if (iBrother._Point == 0) - _Point = 0; - else - _Point = new Point(*(iBrother._Point)); - _n = iBrother._n; - _currentn = iBrother._currentn; - } - - inline Self& operator=(const Self& iBrother) - { - //((bidirectional_point_iterator*)this)->operator=(iBrother); - __A = iBrother.__A; - __B = iBrother.__B; - _begin = iBrother._begin; - _end = iBrother._end; - _CurvilinearLength = iBrother._CurvilinearLength; - _step = iBrother._step; - _t = iBrother._t; - if (iBrother._Point == 0) - _Point = 0; - else - _Point = new Point(*(iBrother._Point)); - _n = iBrother._n; - _currentn = iBrother._currentn; - return *this; - } - - virtual ~__point_iterator() - { - if (_Point != 0) - delete _Point; - } - -//protected: //FIXME -public: - inline __point_iterator(vertex_container_iterator iA, vertex_container_iterator iB, - vertex_container_iterator ibegin, vertex_container_iterator iend, - int currentn, int n, float step, float t = 0.0f, float iCurvilinearLength = 0.0f) - : parent_class() - { - __A = iA; - __B = iB; - _begin = ibegin; - _end = iend; - _CurvilinearLength = iCurvilinearLength; - _step = step; - _t = t; - _Point = 0; - _n = n; - _currentn = currentn; - } - -public: - // operators - inline Self& operator++() // operator corresponding to ++i - { - increment(); - return *this; - } - - /* Operator corresponding to i++, i.e. it returns the value *and then* increments. - * That’s why we store the value in a temp. - */ - inline Self operator++(int) - { - Self tmp = *this; - increment(); - return tmp; - } - - inline Self& operator--() // operator corresponding to --i - { - decrement(); - return *this; - } - - inline Self operator--(int) // operator corresponding to i-- - { - Self tmp = *this; - decrement(); - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - return ((__A != b.__A) || (__B != b.__B) || (_t != b._t)); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual typename Traits::reference operator*() const - { - if (_Point != 0) { - delete _Point; - _Point = 0; - } - if ((_currentn < 0) || (_currentn >= _n)) - return _Point; // 0 in this case - return (_Point = new Point(*__A, *__B, _t)); - } - - virtual typename Traits::pointer operator->() const - { - return &(operator*()); - } - - virtual bool begin() const - { - if ((__A == _begin) && (_t < (float)M_EPSILON)) - return true; - return false; - } - - virtual bool end() const - { - if ((__B == _end)) - return true; - return false; - } - -protected: - virtual void increment() - { - if (_Point != 0) { - delete _Point; - _Point = 0; - } - if ((_currentn == _n - 1) && (_t == 1.0f)) { - // we're setting the iterator to end - ++__A; - ++__B; - ++_currentn; - _t = 0.0f; - return; - } - - if (0 == _step) { // means we iterate over initial vertices - Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); - _CurvilinearLength += vec_tmp.norm(); - if (_currentn == _n - 1) { - _t = 1.0f; - return; - } - ++__B; - ++__A; - ++_currentn; - return; - } - - // compute the new position: - Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); - float normAB = vec_tmp2.norm(); - - if (normAB > M_EPSILON) { - _CurvilinearLength += _step; - _t = _t + _step / normAB; - } - else { - _t = 1.0f; // AB is a null segment, we're directly at its end - } - //if normAB ~= 0, we don't change these values - if (_t >= 1) { - _CurvilinearLength -= normAB * (_t - 1); - if (_currentn == _n - 1) { - _t = 1.0f; - } - else { - _t = 0.0f; - ++_currentn; - ++__A; - ++__B; - } - } - } - - virtual void decrement() - { - if (_Point != 0) { - delete _Point; - _Point = 0; - } - - if (_t == 0.0f) { // we're at the beginning of the edge - _t = 1.0f; - --_currentn; - --__A; - --__B; - if (_currentn == _n - 1) - return; - } - - if (0 == _step) { // means we iterate over initial vertices - Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); - _CurvilinearLength -= vec_tmp.norm(); - _t = 0; - return; - } - - // compute the new position: - Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); - float normAB = vec_tmp2.norm(); - - if (normAB >M_EPSILON) { - _CurvilinearLength -= _step; - _t = _t - _step / normAB; - } - else { - _t = -1.0f; // We just need a negative value here - } - - // round value - if (fabs(_t) < (float)M_EPSILON) - _t = 0.0f; - if (_t < 0) { - if (_currentn == 0) - _CurvilinearLength = 0.0f; - else - _CurvilinearLength += normAB * (-_t); - _t = 0.0f; - } - } + //protected: + public: + float _CurvilinearLength; + float _step; + vertex_container_iterator __A; + vertex_container_iterator __B; + vertex_container_iterator _begin; + vertex_container_iterator _end; + int _n; + int _currentn; + float _t; + mutable Point *_Point; + + public: + inline __point_iterator(float step = 0.0f) : parent_class() + { + _step = step; + _CurvilinearLength = 0.0f; + _t = 0.0f; + _Point = 0; + _n = 0; + _currentn = 0; + } + + inline __point_iterator(const iterator &iBrother) : parent_class() + { + __A = iBrother.__A; + __B = iBrother.__B; + _begin = iBrother._begin; + _end = iBrother._end; + _CurvilinearLength = iBrother._CurvilinearLength; + _step = iBrother._step; + _t = iBrother._t; + if (iBrother._Point == 0) + _Point = 0; + else + _Point = new Point(*(iBrother._Point)); + _n = iBrother._n; + _currentn = iBrother._currentn; + } + + inline __point_iterator(const const_iterator &iBrother) : parent_class() + { + __A = iBrother.__A; + __B = iBrother.__B; + _begin = iBrother._begin; + _end = iBrother._end; + _CurvilinearLength = iBrother._CurvilinearLength; + _step = iBrother._step; + _t = iBrother._t; + if (iBrother._Point == 0) + _Point = 0; + else + _Point = new Point(*(iBrother._Point)); + _n = iBrother._n; + _currentn = iBrother._currentn; + } + + inline Self &operator=(const Self &iBrother) + { + //((bidirectional_point_iterator*)this)->operator=(iBrother); + __A = iBrother.__A; + __B = iBrother.__B; + _begin = iBrother._begin; + _end = iBrother._end; + _CurvilinearLength = iBrother._CurvilinearLength; + _step = iBrother._step; + _t = iBrother._t; + if (iBrother._Point == 0) + _Point = 0; + else + _Point = new Point(*(iBrother._Point)); + _n = iBrother._n; + _currentn = iBrother._currentn; + return *this; + } + + virtual ~__point_iterator() + { + if (_Point != 0) + delete _Point; + } + + //protected: //FIXME + public: + inline __point_iterator(vertex_container_iterator iA, + vertex_container_iterator iB, + vertex_container_iterator ibegin, + vertex_container_iterator iend, + int currentn, + int n, + float step, + float t = 0.0f, + float iCurvilinearLength = 0.0f) + : parent_class() + { + __A = iA; + __B = iB; + _begin = ibegin; + _end = iend; + _CurvilinearLength = iCurvilinearLength; + _step = step; + _t = t; + _Point = 0; + _n = n; + _currentn = currentn; + } + + public: + // operators + inline Self &operator++() // operator corresponding to ++i + { + increment(); + return *this; + } + + /* Operator corresponding to i++, i.e. it returns the value *and then* increments. + * That’s why we store the value in a temp. + */ + inline Self operator++(int) + { + Self tmp = *this; + increment(); + return tmp; + } + + inline Self &operator--() // operator corresponding to --i + { + decrement(); + return *this; + } + + inline Self operator--(int) // operator corresponding to i-- + { + Self tmp = *this; + decrement(); + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + return ((__A != b.__A) || (__B != b.__B) || (_t != b._t)); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual typename Traits::reference operator*() const + { + if (_Point != 0) { + delete _Point; + _Point = 0; + } + if ((_currentn < 0) || (_currentn >= _n)) + return _Point; // 0 in this case + return (_Point = new Point(*__A, *__B, _t)); + } + + virtual typename Traits::pointer operator->() const + { + return &(operator*()); + } + + virtual bool begin() const + { + if ((__A == _begin) && (_t < (float)M_EPSILON)) + return true; + return false; + } + + virtual bool end() const + { + if ((__B == _end)) + return true; + return false; + } + + protected: + virtual void increment() + { + if (_Point != 0) { + delete _Point; + _Point = 0; + } + if ((_currentn == _n - 1) && (_t == 1.0f)) { + // we're setting the iterator to end + ++__A; + ++__B; + ++_currentn; + _t = 0.0f; + return; + } + + if (0 == _step) { // means we iterate over initial vertices + Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); + _CurvilinearLength += vec_tmp.norm(); + if (_currentn == _n - 1) { + _t = 1.0f; + return; + } + ++__B; + ++__A; + ++_currentn; + return; + } + + // compute the new position: + Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); + float normAB = vec_tmp2.norm(); + + if (normAB > M_EPSILON) { + _CurvilinearLength += _step; + _t = _t + _step / normAB; + } + else { + _t = 1.0f; // AB is a null segment, we're directly at its end + } + //if normAB ~= 0, we don't change these values + if (_t >= 1) { + _CurvilinearLength -= normAB * (_t - 1); + if (_currentn == _n - 1) { + _t = 1.0f; + } + else { + _t = 0.0f; + ++_currentn; + ++__A; + ++__B; + } + } + } + + virtual void decrement() + { + if (_Point != 0) { + delete _Point; + _Point = 0; + } + + if (_t == 0.0f) { // we're at the beginning of the edge + _t = 1.0f; + --_currentn; + --__A; + --__B; + if (_currentn == _n - 1) + return; + } + + if (0 == _step) { // means we iterate over initial vertices + Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); + _CurvilinearLength -= vec_tmp.norm(); + _t = 0; + return; + } + + // compute the new position: + Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); + float normAB = vec_tmp2.norm(); + + if (normAB > M_EPSILON) { + _CurvilinearLength -= _step; + _t = _t - _step / normAB; + } + else { + _t = -1.0f; // We just need a negative value here + } + + // round value + if (fabs(_t) < (float)M_EPSILON) + _t = 0.0f; + if (_t < 0) { + if (_currentn == 0) + _CurvilinearLength = 0.0f; + else + _CurvilinearLength += normAB * (-_t); + _t = 0.0f; + } + } }; -} // end of namespace CurveInternal +} // end of namespace CurveInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_CURVE_ADVANCED_ITERATORS_H__ +#endif // __FREESTYLE_CURVE_ADVANCED_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/CurveIterators.h b/source/blender/freestyle/intern/stroke/CurveIterators.h index 7b13abf9c0f..428ea022dfd 100644 --- a/source/blender/freestyle/intern/stroke/CurveIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveIterators.h @@ -34,260 +34,267 @@ namespace CurveInternal { * when the iterator is dereferenced. */ -class CurvePointIterator : public Interface0DIteratorNested -{ -public: - friend class Freestyle::Curve; - -public: - float _CurvilinearLength; - float _step; - Curve::vertex_container::iterator __A; - Curve::vertex_container::iterator __B; - Curve::vertex_container::iterator _begin; - Curve::vertex_container::iterator _end; - int _n; - int _currentn; - float _t; - mutable CurvePoint _Point; - float _CurveLength; - -public: - inline CurvePointIterator(float step = 0.0f) : Interface0DIteratorNested() - { - _step = step; - _CurvilinearLength = 0.0f; - _t = 0.0f; - //_Point = 0; - _n = 0; - _currentn = 0; - _CurveLength = 0; - } - - inline CurvePointIterator(const CurvePointIterator& iBrother) : Interface0DIteratorNested() - { - __A = iBrother.__A; - __B = iBrother.__B; - _begin = iBrother._begin; - _end = iBrother._end; - _CurvilinearLength = iBrother._CurvilinearLength; - _step = iBrother._step; - _t = iBrother._t; - _Point = iBrother._Point; - _n = iBrother._n; - _currentn = iBrother._currentn; - _CurveLength = iBrother._CurveLength; - } - - inline CurvePointIterator& operator=(const CurvePointIterator& iBrother) - { - __A = iBrother.__A; - __B = iBrother.__B; - _begin = iBrother._begin; - _end = iBrother._end; - _CurvilinearLength = iBrother._CurvilinearLength; - _step = iBrother._step; - _t = iBrother._t; - _Point = iBrother._Point; - _n = iBrother._n; - _currentn = iBrother._currentn; - _CurveLength = iBrother._CurveLength; - return *this; - } - - virtual ~CurvePointIterator() {} - -protected: - inline CurvePointIterator(Curve::vertex_container::iterator iA, Curve::vertex_container::iterator iB, - Curve::vertex_container::iterator ibegin, Curve::vertex_container::iterator iend, - int currentn, int n, float iCurveLength, float step, float t = 0.0f, - float iCurvilinearLength = 0.0f) - : Interface0DIteratorNested() - { - __A = iA; - __B = iB; - _begin = ibegin; - _end = iend; - _CurvilinearLength = iCurvilinearLength; - _step = step; - _t = t; - _n = n; - _currentn = currentn; - _CurveLength = iCurveLength; - } - -public: - virtual CurvePointIterator *copy() const - { - return new CurvePointIterator(*this); - } - - inline Interface0DIterator castToInterface0DIterator() const - { - Interface0DIterator ret(new CurveInternal::CurvePointIterator(*this)); - return ret; - } - - virtual string getExactTypeName() const - { - return "CurvePointIterator"; - } - - // operators - inline CurvePointIterator& operator++() // operator corresponding to ++i - { - increment(); - return *this; - } - - inline CurvePointIterator& operator--() // operator corresponding to --i - { - decrement(); - return *this; - } - - // comparibility - virtual bool operator==(const Interface0DIteratorNested& b) const - { - const CurvePointIterator *it_exact = dynamic_cast(&b); - if (!it_exact) - return false; - return ((__A == it_exact->__A) && (__B == it_exact->__B) && (_t == it_exact->_t)); - } - - // dereferencing - virtual CurvePoint& operator*() - { - return (_Point = CurvePoint(*__A, *__B, _t)); - } - - virtual CurvePoint *operator->() - { - return &(operator*()); - } - - virtual bool isBegin() const - { - if ((__A == _begin) && (_t < (float)M_EPSILON)) - return true; - return false; - } - - virtual bool isEnd() const - { - if (__B == _end) - return true; - return false; - } - -//protected: - virtual int increment() - { - if ((_currentn == _n - 1) && (_t == 1.0f)) { - // we're setting the iterator to end - ++__A; - ++__B; - ++_currentn; - _t = 0.0f; - return 0; - } - - if (0 == _step) { // means we iterate over initial vertices - Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); - _CurvilinearLength += (float)vec_tmp.norm(); - if (_currentn == _n - 1) { - _t = 1.0f; - return 0; - } - ++__B; - ++__A; - ++_currentn; - return 0; - } - - // compute the new position: - Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); - float normAB = (float)vec_tmp2.norm(); - - if (normAB > M_EPSILON) { - _CurvilinearLength += _step; - _t = _t + _step / normAB; - } - else { - _t = 1.0f; // AB is a null segment, we're directly at its end - } - //if normAB ~= 0, we don't change these values - if (_t >= 1) { - _CurvilinearLength -= normAB * (_t - 1); - if (_currentn == _n - 1) { - _t = 1.0f; - } - else { - _t = 0.0f; - ++_currentn; - ++__A; - ++__B; - } - } - return 0; - } - - virtual int decrement() - { - if (_t == 0.0f) { //we're at the beginning of the edge - _t = 1.0f; - --_currentn; - --__A; - --__B; - if (_currentn == _n - 1) - return 0; - } - - if (0 == _step) { // means we iterate over initial vertices - Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); - _CurvilinearLength -= (float)vec_tmp.norm(); - _t = 0; - return 0; - } - - // compute the new position: - Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); - float normAB = (float)vec_tmp2.norm(); - - if (normAB > M_EPSILON) { - _CurvilinearLength -= _step; - _t = _t - _step / normAB; - } - else { - _t = -1.0f; // We just need a negative value here - } - - // round value - if (fabs(_t) < (float)M_EPSILON) - _t = 0.0f; - if (_t < 0) { - if (_currentn == 0) - _CurvilinearLength = 0.0f; - else - _CurvilinearLength += normAB * (-_t); - _t = 0.0f; - } - return 0; - } - - virtual float t() const - { - return _CurvilinearLength; - } - - virtual float u() const - { - return _CurvilinearLength / _CurveLength; - } +class CurvePointIterator : public Interface0DIteratorNested { + public: + friend class Freestyle::Curve; + + public: + float _CurvilinearLength; + float _step; + Curve::vertex_container::iterator __A; + Curve::vertex_container::iterator __B; + Curve::vertex_container::iterator _begin; + Curve::vertex_container::iterator _end; + int _n; + int _currentn; + float _t; + mutable CurvePoint _Point; + float _CurveLength; + + public: + inline CurvePointIterator(float step = 0.0f) : Interface0DIteratorNested() + { + _step = step; + _CurvilinearLength = 0.0f; + _t = 0.0f; + //_Point = 0; + _n = 0; + _currentn = 0; + _CurveLength = 0; + } + + inline CurvePointIterator(const CurvePointIterator &iBrother) : Interface0DIteratorNested() + { + __A = iBrother.__A; + __B = iBrother.__B; + _begin = iBrother._begin; + _end = iBrother._end; + _CurvilinearLength = iBrother._CurvilinearLength; + _step = iBrother._step; + _t = iBrother._t; + _Point = iBrother._Point; + _n = iBrother._n; + _currentn = iBrother._currentn; + _CurveLength = iBrother._CurveLength; + } + + inline CurvePointIterator &operator=(const CurvePointIterator &iBrother) + { + __A = iBrother.__A; + __B = iBrother.__B; + _begin = iBrother._begin; + _end = iBrother._end; + _CurvilinearLength = iBrother._CurvilinearLength; + _step = iBrother._step; + _t = iBrother._t; + _Point = iBrother._Point; + _n = iBrother._n; + _currentn = iBrother._currentn; + _CurveLength = iBrother._CurveLength; + return *this; + } + + virtual ~CurvePointIterator() + { + } + + protected: + inline CurvePointIterator(Curve::vertex_container::iterator iA, + Curve::vertex_container::iterator iB, + Curve::vertex_container::iterator ibegin, + Curve::vertex_container::iterator iend, + int currentn, + int n, + float iCurveLength, + float step, + float t = 0.0f, + float iCurvilinearLength = 0.0f) + : Interface0DIteratorNested() + { + __A = iA; + __B = iB; + _begin = ibegin; + _end = iend; + _CurvilinearLength = iCurvilinearLength; + _step = step; + _t = t; + _n = n; + _currentn = currentn; + _CurveLength = iCurveLength; + } + + public: + virtual CurvePointIterator *copy() const + { + return new CurvePointIterator(*this); + } + + inline Interface0DIterator castToInterface0DIterator() const + { + Interface0DIterator ret(new CurveInternal::CurvePointIterator(*this)); + return ret; + } + + virtual string getExactTypeName() const + { + return "CurvePointIterator"; + } + + // operators + inline CurvePointIterator &operator++() // operator corresponding to ++i + { + increment(); + return *this; + } + + inline CurvePointIterator &operator--() // operator corresponding to --i + { + decrement(); + return *this; + } + + // comparibility + virtual bool operator==(const Interface0DIteratorNested &b) const + { + const CurvePointIterator *it_exact = dynamic_cast(&b); + if (!it_exact) + return false; + return ((__A == it_exact->__A) && (__B == it_exact->__B) && (_t == it_exact->_t)); + } + + // dereferencing + virtual CurvePoint &operator*() + { + return (_Point = CurvePoint(*__A, *__B, _t)); + } + + virtual CurvePoint *operator->() + { + return &(operator*()); + } + + virtual bool isBegin() const + { + if ((__A == _begin) && (_t < (float)M_EPSILON)) + return true; + return false; + } + + virtual bool isEnd() const + { + if (__B == _end) + return true; + return false; + } + + //protected: + virtual int increment() + { + if ((_currentn == _n - 1) && (_t == 1.0f)) { + // we're setting the iterator to end + ++__A; + ++__B; + ++_currentn; + _t = 0.0f; + return 0; + } + + if (0 == _step) { // means we iterate over initial vertices + Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); + _CurvilinearLength += (float)vec_tmp.norm(); + if (_currentn == _n - 1) { + _t = 1.0f; + return 0; + } + ++__B; + ++__A; + ++_currentn; + return 0; + } + + // compute the new position: + Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); + float normAB = (float)vec_tmp2.norm(); + + if (normAB > M_EPSILON) { + _CurvilinearLength += _step; + _t = _t + _step / normAB; + } + else { + _t = 1.0f; // AB is a null segment, we're directly at its end + } + //if normAB ~= 0, we don't change these values + if (_t >= 1) { + _CurvilinearLength -= normAB * (_t - 1); + if (_currentn == _n - 1) { + _t = 1.0f; + } + else { + _t = 0.0f; + ++_currentn; + ++__A; + ++__B; + } + } + return 0; + } + + virtual int decrement() + { + if (_t == 0.0f) { //we're at the beginning of the edge + _t = 1.0f; + --_currentn; + --__A; + --__B; + if (_currentn == _n - 1) + return 0; + } + + if (0 == _step) { // means we iterate over initial vertices + Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d()); + _CurvilinearLength -= (float)vec_tmp.norm(); + _t = 0; + return 0; + } + + // compute the new position: + Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d()); + float normAB = (float)vec_tmp2.norm(); + + if (normAB > M_EPSILON) { + _CurvilinearLength -= _step; + _t = _t - _step / normAB; + } + else { + _t = -1.0f; // We just need a negative value here + } + + // round value + if (fabs(_t) < (float)M_EPSILON) + _t = 0.0f; + if (_t < 0) { + if (_currentn == 0) + _CurvilinearLength = 0.0f; + else + _CurvilinearLength += normAB * (-_t); + _t = 0.0f; + } + return 0; + } + + virtual float t() const + { + return _CurvilinearLength; + } + + virtual float u() const + { + return _CurvilinearLength / _CurveLength; + } }; -} // end of namespace CurveInternal +} // end of namespace CurveInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_CURVE_ITERATORS_H__ +#endif // __FREESTYLE_CURVE_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/Modifiers.h b/source/blender/freestyle/intern/stroke/Modifiers.h index 95b63362bac..ecdfd25c499 100644 --- a/source/blender/freestyle/intern/stroke/Modifiers.h +++ b/source/blender/freestyle/intern/stroke/Modifiers.h @@ -25,7 +25,7 @@ #include "TimeStamp.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -39,35 +39,37 @@ namespace Freestyle { /*! Base class for modifiers. * Modifiers are used in the Operators in order to "mark" the processed Interface1D. */ -template -struct EdgeModifier : public unary_function -{ - /*! Default construction */ - EdgeModifier() : unary_function() {} +template struct EdgeModifier : public unary_function { + /*! Default construction */ + EdgeModifier() : unary_function() + { + } - /*! the () operator */ - virtual void operator()(Edge& iEdge) {} + /*! the () operator */ + virtual void operator()(Edge &iEdge) + { + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:EdgeModifier") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:EdgeModifier") #endif }; /*! Modifier that sets the time stamp of an Interface1D to the time stamp of the system. */ -template -struct TimestampModifier : public EdgeModifier -{ - /*! Default constructor */ - TimestampModifier() : EdgeModifier() {} +template struct TimestampModifier : public EdgeModifier { + /*! Default constructor */ + TimestampModifier() : EdgeModifier() + { + } - /*! The () operator. */ - virtual void operator()(Edge& iEdge) - { - TimeStamp *timestamp = TimeStamp::instance(); - iEdge.setTimeStamp(timestamp->getTimeStamp()); - } + /*! The () operator. */ + virtual void operator()(Edge &iEdge) + { + TimeStamp *timestamp = TimeStamp::instance(); + iEdge.setTimeStamp(timestamp->getTimeStamp()); + } }; } /* namespace Freestyle */ -#endif // MODIFIERS_H +#endif // MODIFIERS_H diff --git a/source/blender/freestyle/intern/stroke/Module.h b/source/blender/freestyle/intern/stroke/Module.h index ca0954df561..3e32361eb45 100644 --- a/source/blender/freestyle/intern/stroke/Module.h +++ b/source/blender/freestyle/intern/stroke/Module.h @@ -26,56 +26,55 @@ #include "StyleModule.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class Module -{ -public: - static void setAlwaysRefresh(bool b = true) - { - getCurrentStyleModule()->setAlwaysRefresh(b); - } +class Module { + public: + static void setAlwaysRefresh(bool b = true) + { + getCurrentStyleModule()->setAlwaysRefresh(b); + } - static void setCausal(bool b = true) - { - getCurrentStyleModule()->setCausal(b); - } + static void setCausal(bool b = true) + { + getCurrentStyleModule()->setCausal(b); + } - static void setDrawable(bool b = true) - { - getCurrentStyleModule()->setDrawable(b); - } + static void setDrawable(bool b = true) + { + getCurrentStyleModule()->setDrawable(b); + } - static bool getAlwaysRefresh() - { - return getCurrentStyleModule()->getAlwaysRefresh(); - } + static bool getAlwaysRefresh() + { + return getCurrentStyleModule()->getAlwaysRefresh(); + } - static bool getCausal() - { - return getCurrentStyleModule()->getCausal(); - } + static bool getCausal() + { + return getCurrentStyleModule()->getCausal(); + } - static bool getDrawable() - { - return getCurrentStyleModule()->getDrawable(); - } + static bool getDrawable() + { + return getCurrentStyleModule()->getDrawable(); + } -private: - static StyleModule *getCurrentStyleModule() - { - Canvas *canvas = Canvas::getInstance(); - return canvas->getCurrentStyleModule(); - } + private: + static StyleModule *getCurrentStyleModule() + { + Canvas *canvas = Canvas::getInstance(); + return canvas->getCurrentStyleModule(); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Module") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Module") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_MODULE_H__ +#endif // __FREESTYLE_MODULE_H__ diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp index e9f6ff02f77..2c8a83e2518 100644 --- a/source/blender/freestyle/intern/stroke/Operators.cpp +++ b/source/blender/freestyle/intern/stroke/Operators.cpp @@ -37,1228 +37,1242 @@ Operators::I1DContainer Operators::_current_chains_set; Operators::I1DContainer *Operators::_current_set = NULL; Operators::StrokesContainer Operators::_current_strokes_set; -int Operators::select(UnaryPredicate1D& pred) +int Operators::select(UnaryPredicate1D &pred) { - if (!_current_set) - return 0; - if (_current_set->empty()) - return 0; - I1DContainer new_set; - I1DContainer rejected; - Functions1D::ChainingTimeStampF1D cts; - Functions1D::TimeStampF1D ts; - I1DContainer::iterator it = _current_set->begin(); - I1DContainer::iterator itbegin = it; - while (it != _current_set->end()) { - Interface1D *i1d = *it; - cts(*i1d); // mark everyone's chaining time stamp anyway - if (pred(*i1d) < 0) { - new_set.clear(); - rejected.clear(); - return -1; - } - if (pred.result) { - new_set.push_back(i1d); - ts(*i1d); - } - else { - rejected.push_back(i1d); - } - ++it; - } - if ((*itbegin)->getExactTypeName() != "ViewEdge") { - for (it = rejected.begin(); it != rejected.end(); ++it) - delete *it; - } - rejected.clear(); - _current_set->clear(); - *_current_set = new_set; - return 0; + if (!_current_set) + return 0; + if (_current_set->empty()) + return 0; + I1DContainer new_set; + I1DContainer rejected; + Functions1D::ChainingTimeStampF1D cts; + Functions1D::TimeStampF1D ts; + I1DContainer::iterator it = _current_set->begin(); + I1DContainer::iterator itbegin = it; + while (it != _current_set->end()) { + Interface1D *i1d = *it; + cts(*i1d); // mark everyone's chaining time stamp anyway + if (pred(*i1d) < 0) { + new_set.clear(); + rejected.clear(); + return -1; + } + if (pred.result) { + new_set.push_back(i1d); + ts(*i1d); + } + else { + rejected.push_back(i1d); + } + ++it; + } + if ((*itbegin)->getExactTypeName() != "ViewEdge") { + for (it = rejected.begin(); it != rejected.end(); ++it) + delete *it; + } + rejected.clear(); + _current_set->clear(); + *_current_set = new_set; + return 0; } -int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred, UnaryFunction1D_void& modifier) +int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, + UnaryPredicate1D &pred, + UnaryFunction1D_void &modifier) { - if (_current_view_edges_set.empty()) - return 0; - - unsigned id = 0; - ViewEdge *edge; - I1DContainer new_chains_set; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred(**it_edge) < 0) - goto error; - if (pred.result) - continue; - - edge = dynamic_cast(*it_edge); - it.setBegin(edge); - it.setCurrentEdge(edge); - - Chain *new_chain = new Chain(id); - ++id; - while (true) { - new_chain->push_viewedge_back(*it, it.getOrientation()); - if (modifier(**it) < 0) { - delete new_chain; - goto error; - } - ++it; - if (it.isEnd()) - break; - if (pred(**it) < 0) { - delete new_chain; - goto error; - } - if (pred.result) - break; - } - new_chains_set.push_back(new_chain); - } - - if (!new_chains_set.empty()) { - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - _current_chains_set.push_back(*it); - } - new_chains_set.clear(); - _current_set = &_current_chains_set; - } - return 0; + if (_current_view_edges_set.empty()) + return 0; + + unsigned id = 0; + ViewEdge *edge; + I1DContainer new_chains_set; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) { + if (pred(**it_edge) < 0) + goto error; + if (pred.result) + continue; + + edge = dynamic_cast(*it_edge); + it.setBegin(edge); + it.setCurrentEdge(edge); + + Chain *new_chain = new Chain(id); + ++id; + while (true) { + new_chain->push_viewedge_back(*it, it.getOrientation()); + if (modifier(**it) < 0) { + delete new_chain; + goto error; + } + ++it; + if (it.isEnd()) + break; + if (pred(**it) < 0) { + delete new_chain; + goto error; + } + if (pred.result) + break; + } + new_chains_set.push_back(new_chain); + } + + if (!new_chains_set.empty()) { + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + _current_chains_set.push_back(*it); + } + new_chains_set.clear(); + _current_set = &_current_chains_set; + } + return 0; error: - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - delete (*it); - } - new_chains_set.clear(); - return -1; + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + delete (*it); + } + new_chains_set.clear(); + return -1; } -int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred) +int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred) { - if (_current_view_edges_set.empty()) - return 0; - - unsigned id = 0; - Functions1D::IncrementChainingTimeStampF1D ts; - Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); - ViewEdge *edge; - I1DContainer new_chains_set; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred(**it_edge) < 0) - goto error; - if (pred.result) - continue; - if (pred_ts(**it_edge) < 0) - goto error; - if (pred_ts.result) - continue; - - edge = dynamic_cast(*it_edge); - it.setBegin(edge); - it.setCurrentEdge(edge); - - Chain *new_chain = new Chain(id); - ++id; - while (true) { - new_chain->push_viewedge_back(*it, it.getOrientation()); - ts(**it); - ++it; - if (it.isEnd()) - break; - if (pred(**it) < 0) { - delete new_chain; - goto error; - } - if (pred.result) - break; - if (pred_ts(**it) < 0) { - delete new_chain; - goto error; - } - if (pred_ts.result) - break; - } - new_chains_set.push_back(new_chain); - } - - if (!new_chains_set.empty()) { - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - _current_chains_set.push_back(*it); - } - new_chains_set.clear(); - _current_set = &_current_chains_set; - } - return 0; + if (_current_view_edges_set.empty()) + return 0; + + unsigned id = 0; + Functions1D::IncrementChainingTimeStampF1D ts; + Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); + ViewEdge *edge; + I1DContainer new_chains_set; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) { + if (pred(**it_edge) < 0) + goto error; + if (pred.result) + continue; + if (pred_ts(**it_edge) < 0) + goto error; + if (pred_ts.result) + continue; + + edge = dynamic_cast(*it_edge); + it.setBegin(edge); + it.setCurrentEdge(edge); + + Chain *new_chain = new Chain(id); + ++id; + while (true) { + new_chain->push_viewedge_back(*it, it.getOrientation()); + ts(**it); + ++it; + if (it.isEnd()) + break; + if (pred(**it) < 0) { + delete new_chain; + goto error; + } + if (pred.result) + break; + if (pred_ts(**it) < 0) { + delete new_chain; + goto error; + } + if (pred_ts.result) + break; + } + new_chains_set.push_back(new_chain); + } + + if (!new_chains_set.empty()) { + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + _current_chains_set.push_back(*it); + } + new_chains_set.clear(); + _current_set = &_current_chains_set; + } + return 0; error: - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - delete (*it); - } - new_chains_set.clear(); - return -1; + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + delete (*it); + } + new_chains_set.clear(); + return -1; } - #if 0 void Operators::bidirectionalChain(ViewEdgeIterator& it, UnaryPredicate1D& pred, UnaryFunction1D_void& modifier) { - if (_current_view_edges_set.empty()) - return; - - unsigned id = 0; - ViewEdge *edge; - Chain *new_chain; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred(**it_edge)) - continue; - - edge = dynamic_cast(*it_edge); - it.setBegin(edge); - it.setCurrentEdge(edge); - - Chain *new_chain = new Chain(id); - ++id; -#if 0 // FIXME - ViewEdgeIterator it_back(it); - --it_back; -#endif - do { - new_chain->push_viewedge_back(*it, it.getOrientation()); - modifier(**it); - ++it; - } while (!it.isEnd() && !pred(**it)); - it.setBegin(edge); - it.setCurrentEdge(edge); - --it; - while (!it.isEnd() && !pred(**it)) { - new_chain->push_viewedge_front(*it, it.getOrientation()); - modifier(**it); - --it; - } - - _current_chains_set.push_back(new_chain); - } - - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; + if (_current_view_edges_set.empty()) + return; + + unsigned id = 0; + ViewEdge *edge; + Chain *new_chain; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) + { + if (pred(**it_edge)) + continue; + + edge = dynamic_cast(*it_edge); + it.setBegin(edge); + it.setCurrentEdge(edge); + + Chain *new_chain = new Chain(id); + ++id; +# if 0 // FIXME + ViewEdgeIterator it_back(it); + --it_back; +# endif + do { + new_chain->push_viewedge_back(*it, it.getOrientation()); + modifier(**it); + ++it; + } while (!it.isEnd() && !pred(**it)); + it.setBegin(edge); + it.setCurrentEdge(edge); + --it; + while (!it.isEnd() && !pred(**it)) { + new_chain->push_viewedge_front(*it, it.getOrientation()); + modifier(**it); + --it; + } + + _current_chains_set.push_back(new_chain); + } + + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; } void Operators::bidirectionalChain(ViewEdgeIterator& it, UnaryPredicate1D& pred) { - if (_current_view_edges_set.empty()) - return; - - unsigned id = 0; - Functions1D::IncrementChainingTimeStampF1D ts; - Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); - - ViewEdge *edge; - Chain *new_chain; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred(**it_edge) || pred_ts(**it_edge)) - continue; - - edge = dynamic_cast(*it_edge); - it.setBegin(edge); - it.setCurrentEdge(edge); - - Chain *new_chain = new Chain(id); - ++id; -#if 0 //FIXME - ViewEdgeIterator it_back(it); - --it_back; -#endif - do { - new_chain->push_viewedge_back(*it, it.getOrientation()); - ts(**it); - ++it; - } while (!it.isEnd() && !pred(**it) && !pred_ts(**it)); - it.setBegin(edge); - it.setCurrentEdge(edge); - --it; - while (!it.isEnd() && !pred(**it) && !pred_ts(**it)) { - new_chain->push_viewedge_front(*it, it.getOrientation()); - ts(**it); - --it; - } - - _current_chains_set.push_back(new_chain); - } - - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; + if (_current_view_edges_set.empty()) + return; + + unsigned id = 0; + Functions1D::IncrementChainingTimeStampF1D ts; + Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); + + ViewEdge *edge; + Chain *new_chain; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) + { + if (pred(**it_edge) || pred_ts(**it_edge)) + continue; + + edge = dynamic_cast(*it_edge); + it.setBegin(edge); + it.setCurrentEdge(edge); + + Chain *new_chain = new Chain(id); + ++id; +# if 0 //FIXME + ViewEdgeIterator it_back(it); + --it_back; +# endif + do { + new_chain->push_viewedge_back(*it, it.getOrientation()); + ts(**it); + ++it; + } while (!it.isEnd() && !pred(**it) && !pred_ts(**it)); + it.setBegin(edge); + it.setCurrentEdge(edge); + --it; + while (!it.isEnd() && !pred(**it) && !pred_ts(**it)) { + new_chain->push_viewedge_front(*it, it.getOrientation()); + ts(**it); + --it; + } + + _current_chains_set.push_back(new_chain); + } + + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; } #endif -int Operators::bidirectionalChain(ChainingIterator& it, UnaryPredicate1D& pred) +int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred) { - if (_current_view_edges_set.empty()) - return 0; - - unsigned id = 0; - Functions1D::IncrementChainingTimeStampF1D ts; - Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); - ViewEdge *edge; - I1DContainer new_chains_set; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred(**it_edge) < 0) - goto error; - if (pred.result) - continue; - if (pred_ts(**it_edge) < 0) - goto error; - if (pred_ts.result) - continue; - - edge = dynamic_cast(*it_edge); - // re-init iterator - it.setBegin(edge); - it.setCurrentEdge(edge); - it.setOrientation(true); - if (it.init() < 0) - goto error; - - Chain *new_chain = new Chain(id); - ++id; + if (_current_view_edges_set.empty()) + return 0; + + unsigned id = 0; + Functions1D::IncrementChainingTimeStampF1D ts; + Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); + ViewEdge *edge; + I1DContainer new_chains_set; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) { + if (pred(**it_edge) < 0) + goto error; + if (pred.result) + continue; + if (pred_ts(**it_edge) < 0) + goto error; + if (pred_ts.result) + continue; + + edge = dynamic_cast(*it_edge); + // re-init iterator + it.setBegin(edge); + it.setCurrentEdge(edge); + it.setOrientation(true); + if (it.init() < 0) + goto error; + + Chain *new_chain = new Chain(id); + ++id; #if 0 // FIXME - ViewEdgeIterator it_back(it); - --it_back; + ViewEdgeIterator it_back(it); + --it_back; #endif - while (true) { - new_chain->push_viewedge_back(*it, it.getOrientation()); - ts(**it); - if (it.increment() < 0) { - delete new_chain; - goto error; - } - if (it.isEnd()) - break; - if (pred(**it) < 0) { - delete new_chain; - goto error; - } - if (pred.result) - break; - } - it.setBegin(edge); - it.setCurrentEdge(edge); - it.setOrientation(true); - if (it.decrement() < 0) { - delete new_chain; - goto error; - } - while (!it.isEnd()) { - if (pred(**it) < 0) { - delete new_chain; - goto error; - } - if (pred.result) - break; - new_chain->push_viewedge_front(*it, it.getOrientation()); - ts(**it); - if (it.decrement() < 0) { - delete new_chain; - goto error; - } - } - new_chains_set.push_back(new_chain); - } - - if (!new_chains_set.empty()) { - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - _current_chains_set.push_back(*it); - } - new_chains_set.clear(); - _current_set = &_current_chains_set; - } - return 0; + while (true) { + new_chain->push_viewedge_back(*it, it.getOrientation()); + ts(**it); + if (it.increment() < 0) { + delete new_chain; + goto error; + } + if (it.isEnd()) + break; + if (pred(**it) < 0) { + delete new_chain; + goto error; + } + if (pred.result) + break; + } + it.setBegin(edge); + it.setCurrentEdge(edge); + it.setOrientation(true); + if (it.decrement() < 0) { + delete new_chain; + goto error; + } + while (!it.isEnd()) { + if (pred(**it) < 0) { + delete new_chain; + goto error; + } + if (pred.result) + break; + new_chain->push_viewedge_front(*it, it.getOrientation()); + ts(**it); + if (it.decrement() < 0) { + delete new_chain; + goto error; + } + } + new_chains_set.push_back(new_chain); + } + + if (!new_chains_set.empty()) { + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + _current_chains_set.push_back(*it); + } + new_chains_set.clear(); + _current_set = &_current_chains_set; + } + return 0; error: - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - delete (*it); - } - new_chains_set.clear(); - return -1; + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + delete (*it); + } + new_chains_set.clear(); + return -1; } -int Operators::bidirectionalChain(ChainingIterator& it) +int Operators::bidirectionalChain(ChainingIterator &it) { - if (_current_view_edges_set.empty()) - return 0; - - unsigned id = 0; - Functions1D::IncrementChainingTimeStampF1D ts; - Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); - ViewEdge *edge; - I1DContainer new_chains_set; - - for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); - it_edge != _current_view_edges_set.end(); - ++it_edge) - { - if (pred_ts(**it_edge) < 0) - goto error; - if (pred_ts.result) - continue; - - edge = dynamic_cast(*it_edge); - // re-init iterator - it.setBegin(edge); - it.setCurrentEdge(edge); - it.setOrientation(true); - if (it.init() < 0) - goto error; - - Chain *new_chain = new Chain(id); - ++id; + if (_current_view_edges_set.empty()) + return 0; + + unsigned id = 0; + Functions1D::IncrementChainingTimeStampF1D ts; + Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1); + ViewEdge *edge; + I1DContainer new_chains_set; + + for (I1DContainer::iterator it_edge = _current_view_edges_set.begin(); + it_edge != _current_view_edges_set.end(); + ++it_edge) { + if (pred_ts(**it_edge) < 0) + goto error; + if (pred_ts.result) + continue; + + edge = dynamic_cast(*it_edge); + // re-init iterator + it.setBegin(edge); + it.setCurrentEdge(edge); + it.setOrientation(true); + if (it.init() < 0) + goto error; + + Chain *new_chain = new Chain(id); + ++id; #if 0 // FIXME - ViewEdgeIterator it_back(it); - --it_back; + ViewEdgeIterator it_back(it); + --it_back; #endif - do { - new_chain->push_viewedge_back(*it, it.getOrientation()); - ts(**it); - if (it.increment() < 0) { // FIXME - delete new_chain; - goto error; - } - } while (!it.isEnd()); - it.setBegin(edge); - it.setCurrentEdge(edge); - it.setOrientation(true); - if (it.decrement() < 0) { // FIXME - delete new_chain; - goto error; - } - while (!it.isEnd()) { - new_chain->push_viewedge_front(*it, it.getOrientation()); - ts(**it); - if (it.decrement() < 0) { // FIXME - delete new_chain; - goto error; - } - } - new_chains_set.push_back(new_chain); - } - - if (!new_chains_set.empty()) { - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - _current_chains_set.push_back(*it); - } - new_chains_set.clear(); - _current_set = &_current_chains_set; - } - return 0; + do { + new_chain->push_viewedge_back(*it, it.getOrientation()); + ts(**it); + if (it.increment() < 0) { // FIXME + delete new_chain; + goto error; + } + } while (!it.isEnd()); + it.setBegin(edge); + it.setCurrentEdge(edge); + it.setOrientation(true); + if (it.decrement() < 0) { // FIXME + delete new_chain; + goto error; + } + while (!it.isEnd()) { + new_chain->push_viewedge_front(*it, it.getOrientation()); + ts(**it); + if (it.decrement() < 0) { // FIXME + delete new_chain; + goto error; + } + } + new_chains_set.push_back(new_chain); + } + + if (!new_chains_set.empty()) { + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + _current_chains_set.push_back(*it); + } + new_chains_set.clear(); + _current_set = &_current_chains_set; + } + return 0; error: - for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { - delete (*it); - } - new_chains_set.clear(); - return -1; + for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) { + delete (*it); + } + new_chains_set.clear(); + return -1; } -int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling) +int Operators::sequentialSplit(UnaryPredicate0D &pred, float sampling) { - if (_current_chains_set.empty()) { - cerr << "Warning: current set empty" << endl; - return 0; - } - CurvePoint *point; - Chain *new_curve; - I1DContainer splitted_chains; - Interface0DIterator first; - Interface0DIterator end; - Interface0DIterator last; - Interface0DIterator it; - I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); - for (; cit != citend; ++cit) { - Id currentId = (*cit)->getId(); - new_curve = new Chain(currentId); - first = (*cit)->pointsBegin(sampling); - end = (*cit)->pointsEnd(sampling); - last = end; - --last; - it = first; - - point = dynamic_cast(&(*it)); - new_curve->push_vertex_back(point); - ++it; - for (; it != end; ++it) { - point = dynamic_cast(&(*it)); - new_curve->push_vertex_back(point); - if (pred(it) < 0) { - delete new_curve; - goto error; - } - if (pred.result && (it != last)) { - splitted_chains.push_back(new_curve); - currentId.setSecond(currentId.getSecond() + 1); - new_curve = new Chain(currentId); - new_curve->push_vertex_back(point); - } - } - if (new_curve->nSegments() == 0) { - delete new_curve; - return 0; - } - - splitted_chains.push_back(new_curve); - } - - // Update the current set of chains: - cit = _current_chains_set.begin(); - for (; cit != citend; ++cit) { - delete (*cit); - } - _current_chains_set.clear(); + if (_current_chains_set.empty()) { + cerr << "Warning: current set empty" << endl; + return 0; + } + CurvePoint *point; + Chain *new_curve; + I1DContainer splitted_chains; + Interface0DIterator first; + Interface0DIterator end; + Interface0DIterator last; + Interface0DIterator it; + I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); + for (; cit != citend; ++cit) { + Id currentId = (*cit)->getId(); + new_curve = new Chain(currentId); + first = (*cit)->pointsBegin(sampling); + end = (*cit)->pointsEnd(sampling); + last = end; + --last; + it = first; + + point = dynamic_cast(&(*it)); + new_curve->push_vertex_back(point); + ++it; + for (; it != end; ++it) { + point = dynamic_cast(&(*it)); + new_curve->push_vertex_back(point); + if (pred(it) < 0) { + delete new_curve; + goto error; + } + if (pred.result && (it != last)) { + splitted_chains.push_back(new_curve); + currentId.setSecond(currentId.getSecond() + 1); + new_curve = new Chain(currentId); + new_curve->push_vertex_back(point); + } + } + if (new_curve->nSegments() == 0) { + delete new_curve; + return 0; + } + + splitted_chains.push_back(new_curve); + } + + // Update the current set of chains: + cit = _current_chains_set.begin(); + for (; cit != citend; ++cit) { + delete (*cit); + } + _current_chains_set.clear(); #if 0 - _current_chains_set = splitted_chains; + _current_chains_set = splitted_chains; #else - for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { - if ((*cit)->getLength2D() < M_EPSILON) { - delete (*cit); - continue; - } - _current_chains_set.push_back(*cit); - } + for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { + if ((*cit)->getLength2D() < M_EPSILON) { + delete (*cit); + continue; + } + _current_chains_set.push_back(*cit); + } #endif - splitted_chains.clear(); + splitted_chains.clear(); - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; - return 0; + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; + return 0; error: - cit = splitted_chains.begin(); - citend = splitted_chains.end(); - for (; cit != citend; ++cit) { - delete (*cit); - } - splitted_chains.clear(); - return -1; + cit = splitted_chains.begin(); + citend = splitted_chains.end(); + for (; cit != citend; ++cit) { + delete (*cit); + } + splitted_chains.clear(); + return -1; } -int Operators::sequentialSplit(UnaryPredicate0D& startingPred, UnaryPredicate0D& stoppingPred, float sampling) +int Operators::sequentialSplit(UnaryPredicate0D &startingPred, + UnaryPredicate0D &stoppingPred, + float sampling) { - if (_current_chains_set.empty()) { - cerr << "Warning: current set empty" << endl; - return 0; - } - CurvePoint *point; - Chain *new_curve; - I1DContainer splitted_chains; - Interface0DIterator first; - Interface0DIterator end; - Interface0DIterator last; - Interface0DIterator itStart; - Interface0DIterator itStop; - I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); - for (; cit != citend; ++cit) { - Id currentId = (*cit)->getId(); - first = (*cit)->pointsBegin(sampling); - end = (*cit)->pointsEnd(sampling); - last = end; - --last; - itStart = first; - do { - itStop = itStart; - ++itStop; - - new_curve = new Chain(currentId); - currentId.setSecond(currentId.getSecond() + 1); - - point = dynamic_cast(&(*itStart)); - new_curve->push_vertex_back(point); - do { - point = dynamic_cast(&(*itStop)); - new_curve->push_vertex_back(point); - ++itStop; - if (itStop == end) - break; - if (stoppingPred(itStop) < 0) { - delete new_curve; - goto error; - } - } while (!stoppingPred.result); - if (itStop != end) { - point = dynamic_cast(&(*itStop)); - new_curve->push_vertex_back(point); - } - if (new_curve->nSegments() == 0) { - delete new_curve; - } - else { - splitted_chains.push_back(new_curve); - } - // find next start - do { - ++itStart; - if (itStart == end) - break; - if (startingPred(itStart) < 0) - goto error; - } while (!startingPred.result); - } while ((itStart != end) && (itStart != last)); - } - - // Update the current set of chains: - cit = _current_chains_set.begin(); - for (; cit != citend; ++cit) { - delete (*cit); - } - _current_chains_set.clear(); + if (_current_chains_set.empty()) { + cerr << "Warning: current set empty" << endl; + return 0; + } + CurvePoint *point; + Chain *new_curve; + I1DContainer splitted_chains; + Interface0DIterator first; + Interface0DIterator end; + Interface0DIterator last; + Interface0DIterator itStart; + Interface0DIterator itStop; + I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); + for (; cit != citend; ++cit) { + Id currentId = (*cit)->getId(); + first = (*cit)->pointsBegin(sampling); + end = (*cit)->pointsEnd(sampling); + last = end; + --last; + itStart = first; + do { + itStop = itStart; + ++itStop; + + new_curve = new Chain(currentId); + currentId.setSecond(currentId.getSecond() + 1); + + point = dynamic_cast(&(*itStart)); + new_curve->push_vertex_back(point); + do { + point = dynamic_cast(&(*itStop)); + new_curve->push_vertex_back(point); + ++itStop; + if (itStop == end) + break; + if (stoppingPred(itStop) < 0) { + delete new_curve; + goto error; + } + } while (!stoppingPred.result); + if (itStop != end) { + point = dynamic_cast(&(*itStop)); + new_curve->push_vertex_back(point); + } + if (new_curve->nSegments() == 0) { + delete new_curve; + } + else { + splitted_chains.push_back(new_curve); + } + // find next start + do { + ++itStart; + if (itStart == end) + break; + if (startingPred(itStart) < 0) + goto error; + } while (!startingPred.result); + } while ((itStart != end) && (itStart != last)); + } + + // Update the current set of chains: + cit = _current_chains_set.begin(); + for (; cit != citend; ++cit) { + delete (*cit); + } + _current_chains_set.clear(); #if 0 - _current_chains_set = splitted_chains; + _current_chains_set = splitted_chains; #else - for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { - if ((*cit)->getLength2D() < M_EPSILON) { - delete (*cit); - continue; - } - _current_chains_set.push_back(*cit); - } + for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { + if ((*cit)->getLength2D() < M_EPSILON) { + delete (*cit); + continue; + } + _current_chains_set.push_back(*cit); + } #endif - splitted_chains.clear(); + splitted_chains.clear(); - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; - return 0; + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; + return 0; error: - cit = splitted_chains.begin(); - citend = splitted_chains.end(); - for (; cit != citend; ++cit) { - delete (*cit); - } - splitted_chains.clear(); - return -1; + cit = splitted_chains.begin(); + citend = splitted_chains.end(); + for (; cit != citend; ++cit) { + delete (*cit); + } + splitted_chains.clear(); + return -1; } // Internal function -static int __recursiveSplit(Chain *_curve, UnaryFunction0D& func, UnaryPredicate1D& pred, float sampling, - Operators::I1DContainer& newChains, Operators::I1DContainer& splitted_chains) +static int __recursiveSplit(Chain *_curve, + UnaryFunction0D &func, + UnaryPredicate1D &pred, + float sampling, + Operators::I1DContainer &newChains, + Operators::I1DContainer &splitted_chains) { - if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) { - newChains.push_back(_curve); - return 0; - } - - CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling); - CurveInternal::CurvePointIterator second = first; - ++second; - CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling); - CurveInternal::CurvePointIterator it = second; - CurveInternal::CurvePointIterator split = second; - Interface0DIterator it0d = it.castToInterface0DIterator(); - real _min = FLT_MAX; // func(it0d); - ++it; - CurveInternal::CurvePointIterator next = it; - ++next; - - bool bsplit = false; - for (; ((it != end) && (next != end)); ++it, ++next) { - it0d = it.castToInterface0DIterator(); - if (func(it0d) < 0) - return -1; - if (func.result < _min) { - _min = func.result; - split = it; - bsplit = true; - } - } - - if (!bsplit) { // we didn't find any minimum - newChains.push_back(_curve); - return 0; - } - - // retrieves the current splitting id - Id *newId = _curve->getSplittingId(); - if (newId == 0) { - newId = new Id(_curve->getId()); - _curve->setSplittingId(newId); - } - - Chain *new_curve_a = new Chain(*newId); - newId->setSecond(newId->getSecond() + 1); - new_curve_a->setSplittingId(newId); - Chain *new_curve_b = new Chain(*newId); - newId->setSecond(newId->getSecond() + 1); - new_curve_b->setSplittingId(newId); - - CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(), vitend = _curve->curveVerticesEnd(); - CurveInternal::CurvePointIterator vnext = vit; - ++vnext; - - for (; (vit != vitend) && (vnext != vitend) && (vnext._CurvilinearLength < split._CurvilinearLength); - ++vit, ++vnext) - { - new_curve_a->push_vertex_back(&(*vit)); - } - if ((vit == vitend) || (vnext == vitend)) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "The split takes place in bad location" << endl; - } - newChains.push_back(_curve); - delete new_curve_a; - delete new_curve_b; - return 0; - } - - // build the two resulting chains - new_curve_a->push_vertex_back(&(*vit)); - new_curve_a->push_vertex_back(&(*split)); - new_curve_b->push_vertex_back(&(*split)); - - for (vit = vnext; vit != vitend; ++vit) - new_curve_b->push_vertex_back(&(*vit)); - - // let's check whether one or two of the two new curves satisfy the stopping condition or not. - // (if one of them satisfies it, we don't split) - if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) { - delete new_curve_a; - delete new_curve_b; - return -1; - } - if (pred.result) { - // we don't actually create these two chains - newChains.push_back(_curve); - delete new_curve_a; - delete new_curve_b; - return 0; - } - // here we know we'll split _curve: - splitted_chains.push_back(_curve); - - __recursiveSplit(new_curve_a, func, pred, sampling, newChains, splitted_chains); - __recursiveSplit(new_curve_b, func, pred, sampling, newChains, splitted_chains); - return 0; + if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) { + newChains.push_back(_curve); + return 0; + } + + CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling); + CurveInternal::CurvePointIterator second = first; + ++second; + CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling); + CurveInternal::CurvePointIterator it = second; + CurveInternal::CurvePointIterator split = second; + Interface0DIterator it0d = it.castToInterface0DIterator(); + real _min = FLT_MAX; // func(it0d); + ++it; + CurveInternal::CurvePointIterator next = it; + ++next; + + bool bsplit = false; + for (; ((it != end) && (next != end)); ++it, ++next) { + it0d = it.castToInterface0DIterator(); + if (func(it0d) < 0) + return -1; + if (func.result < _min) { + _min = func.result; + split = it; + bsplit = true; + } + } + + if (!bsplit) { // we didn't find any minimum + newChains.push_back(_curve); + return 0; + } + + // retrieves the current splitting id + Id *newId = _curve->getSplittingId(); + if (newId == 0) { + newId = new Id(_curve->getId()); + _curve->setSplittingId(newId); + } + + Chain *new_curve_a = new Chain(*newId); + newId->setSecond(newId->getSecond() + 1); + new_curve_a->setSplittingId(newId); + Chain *new_curve_b = new Chain(*newId); + newId->setSecond(newId->getSecond() + 1); + new_curve_b->setSplittingId(newId); + + CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(), + vitend = _curve->curveVerticesEnd(); + CurveInternal::CurvePointIterator vnext = vit; + ++vnext; + + for (; (vit != vitend) && (vnext != vitend) && + (vnext._CurvilinearLength < split._CurvilinearLength); + ++vit, ++vnext) { + new_curve_a->push_vertex_back(&(*vit)); + } + if ((vit == vitend) || (vnext == vitend)) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "The split takes place in bad location" << endl; + } + newChains.push_back(_curve); + delete new_curve_a; + delete new_curve_b; + return 0; + } + + // build the two resulting chains + new_curve_a->push_vertex_back(&(*vit)); + new_curve_a->push_vertex_back(&(*split)); + new_curve_b->push_vertex_back(&(*split)); + + for (vit = vnext; vit != vitend; ++vit) + new_curve_b->push_vertex_back(&(*vit)); + + // let's check whether one or two of the two new curves satisfy the stopping condition or not. + // (if one of them satisfies it, we don't split) + if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) { + delete new_curve_a; + delete new_curve_b; + return -1; + } + if (pred.result) { + // we don't actually create these two chains + newChains.push_back(_curve); + delete new_curve_a; + delete new_curve_b; + return 0; + } + // here we know we'll split _curve: + splitted_chains.push_back(_curve); + + __recursiveSplit(new_curve_a, func, pred, sampling, newChains, splitted_chains); + __recursiveSplit(new_curve_b, func, pred, sampling, newChains, splitted_chains); + return 0; } -int Operators::recursiveSplit(UnaryFunction0D& func, UnaryPredicate1D& pred, float sampling) +int Operators::recursiveSplit(UnaryFunction0D &func, + UnaryPredicate1D &pred, + float sampling) { - if (_current_chains_set.empty()) { - cerr << "Warning: current set empty" << endl; - return 0; - } - - Chain *currentChain = 0; - I1DContainer splitted_chains; - I1DContainer newChains; - I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); - for (; cit != citend; ++cit) { - currentChain = dynamic_cast(*cit); - if (!currentChain) - continue; - // let's check the first one: - if (pred(*currentChain) < 0) - return -1; - if (!pred.result) { - __recursiveSplit(currentChain, func, pred, sampling, newChains, splitted_chains); - } - else { - newChains.push_back(currentChain); - } - } - // Update the current set of chains: - if (!splitted_chains.empty()) { - for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { - delete (*cit); - } - splitted_chains.clear(); - } - - _current_chains_set.clear(); + if (_current_chains_set.empty()) { + cerr << "Warning: current set empty" << endl; + return 0; + } + + Chain *currentChain = 0; + I1DContainer splitted_chains; + I1DContainer newChains; + I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); + for (; cit != citend; ++cit) { + currentChain = dynamic_cast(*cit); + if (!currentChain) + continue; + // let's check the first one: + if (pred(*currentChain) < 0) + return -1; + if (!pred.result) { + __recursiveSplit(currentChain, func, pred, sampling, newChains, splitted_chains); + } + else { + newChains.push_back(currentChain); + } + } + // Update the current set of chains: + if (!splitted_chains.empty()) { + for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { + delete (*cit); + } + splitted_chains.clear(); + } + + _current_chains_set.clear(); #if 0 - _current_chains_set = newChains; + _current_chains_set = newChains; #else - for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) { - if ((*cit)->getLength2D() < M_EPSILON) { - delete (*cit); - continue; - } - _current_chains_set.push_back(*cit); - } + for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) { + if ((*cit)->getLength2D() < M_EPSILON) { + delete (*cit); + continue; + } + _current_chains_set.push_back(*cit); + } #endif - newChains.clear(); + newChains.clear(); - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; - return 0; + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; + return 0; } // recursive split with pred 0D -static int __recursiveSplit(Chain *_curve, UnaryFunction0D& func, UnaryPredicate0D& pred0d, - UnaryPredicate1D& pred, float sampling, - Operators::I1DContainer& newChains, Operators::I1DContainer& splitted_chains) +static int __recursiveSplit(Chain *_curve, + UnaryFunction0D &func, + UnaryPredicate0D &pred0d, + UnaryPredicate1D &pred, + float sampling, + Operators::I1DContainer &newChains, + Operators::I1DContainer &splitted_chains) { - if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) { - newChains.push_back(_curve); - return 0; - } - - CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling); - CurveInternal::CurvePointIterator second = first; - ++second; - CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling); - CurveInternal::CurvePointIterator it = second; - CurveInternal::CurvePointIterator split = second; - Interface0DIterator it0d = it.castToInterface0DIterator(); + if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) { + newChains.push_back(_curve); + return 0; + } + + CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling); + CurveInternal::CurvePointIterator second = first; + ++second; + CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling); + CurveInternal::CurvePointIterator it = second; + CurveInternal::CurvePointIterator split = second; + Interface0DIterator it0d = it.castToInterface0DIterator(); #if 0 - real _min = func(it0d); - ++it; + real _min = func(it0d); + ++it; #endif - real _min = FLT_MAX; - ++it; - real mean = 0.f; - //soc unused - real variance = 0.0f; - unsigned count = 0; - CurveInternal::CurvePointIterator next = it; - ++next; - - bool bsplit = false; - for (; ((it != end) && (next != end)); ++it, ++next) { - ++count; - it0d = it.castToInterface0DIterator(); - if (pred0d(it0d) < 0) - return -1; - if (!pred0d.result) - continue; - if (func(it0d) < 0) - return -1; - mean += func.result; - if (func.result < _min) { - _min = func.result; - split = it; - bsplit = true; - } - } - mean /= (float)count; - - //if ((!bsplit) || (mean - _min > mean)) { // we didn't find any minimum - if (!bsplit) { // we didn't find any minimum - newChains.push_back(_curve); - return 0; - } - - // retrieves the current splitting id - Id *newId = _curve->getSplittingId(); - if (newId == NULL) { - newId = new Id(_curve->getId()); - _curve->setSplittingId(newId); - } - - Chain *new_curve_a = new Chain(*newId); - newId->setSecond(newId->getSecond() + 1); - new_curve_a->setSplittingId(newId); - Chain *new_curve_b = new Chain(*newId); - newId->setSecond(newId->getSecond() + 1); - new_curve_b->setSplittingId(newId); - - CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(), vitend = _curve->curveVerticesEnd(); - CurveInternal::CurvePointIterator vnext = vit; - ++vnext; - - for (; - (vit != vitend) && (vnext != vitend) && (vnext._CurvilinearLength < split._CurvilinearLength); - ++vit, ++vnext) - { - new_curve_a->push_vertex_back(&(*vit)); - } - if ((vit == vitend) || (vnext == vitend)) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "The split takes place in bad location" << endl; - } - newChains.push_back(_curve); - delete new_curve_a; - delete new_curve_b; - return 0; - } - - // build the two resulting chains - new_curve_a->push_vertex_back(&(*vit)); - new_curve_a->push_vertex_back(&(*split)); - new_curve_b->push_vertex_back(&(*split)); - - for (vit = vnext; vit != vitend; ++vit) - new_curve_b->push_vertex_back(&(*vit)); - - // let's check whether one or two of the two new curves satisfy the stopping condition or not. - // (if one of them satisfies it, we don't split) - if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) { - delete new_curve_a; - delete new_curve_b; - return -1; - } - if (pred.result) { - // we don't actually create these two chains - newChains.push_back(_curve); - delete new_curve_a; - delete new_curve_b; - return 0; - } - // here we know we'll split _curve: - splitted_chains.push_back(_curve); - - __recursiveSplit(new_curve_a, func, pred0d, pred, sampling, newChains, splitted_chains); - __recursiveSplit(new_curve_b, func, pred0d, pred, sampling, newChains, splitted_chains); - return 0; + real _min = FLT_MAX; + ++it; + real mean = 0.f; + //soc unused - real variance = 0.0f; + unsigned count = 0; + CurveInternal::CurvePointIterator next = it; + ++next; + + bool bsplit = false; + for (; ((it != end) && (next != end)); ++it, ++next) { + ++count; + it0d = it.castToInterface0DIterator(); + if (pred0d(it0d) < 0) + return -1; + if (!pred0d.result) + continue; + if (func(it0d) < 0) + return -1; + mean += func.result; + if (func.result < _min) { + _min = func.result; + split = it; + bsplit = true; + } + } + mean /= (float)count; + + //if ((!bsplit) || (mean - _min > mean)) { // we didn't find any minimum + if (!bsplit) { // we didn't find any minimum + newChains.push_back(_curve); + return 0; + } + + // retrieves the current splitting id + Id *newId = _curve->getSplittingId(); + if (newId == NULL) { + newId = new Id(_curve->getId()); + _curve->setSplittingId(newId); + } + + Chain *new_curve_a = new Chain(*newId); + newId->setSecond(newId->getSecond() + 1); + new_curve_a->setSplittingId(newId); + Chain *new_curve_b = new Chain(*newId); + newId->setSecond(newId->getSecond() + 1); + new_curve_b->setSplittingId(newId); + + CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(), + vitend = _curve->curveVerticesEnd(); + CurveInternal::CurvePointIterator vnext = vit; + ++vnext; + + for (; (vit != vitend) && (vnext != vitend) && + (vnext._CurvilinearLength < split._CurvilinearLength); + ++vit, ++vnext) { + new_curve_a->push_vertex_back(&(*vit)); + } + if ((vit == vitend) || (vnext == vitend)) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "The split takes place in bad location" << endl; + } + newChains.push_back(_curve); + delete new_curve_a; + delete new_curve_b; + return 0; + } + + // build the two resulting chains + new_curve_a->push_vertex_back(&(*vit)); + new_curve_a->push_vertex_back(&(*split)); + new_curve_b->push_vertex_back(&(*split)); + + for (vit = vnext; vit != vitend; ++vit) + new_curve_b->push_vertex_back(&(*vit)); + + // let's check whether one or two of the two new curves satisfy the stopping condition or not. + // (if one of them satisfies it, we don't split) + if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) { + delete new_curve_a; + delete new_curve_b; + return -1; + } + if (pred.result) { + // we don't actually create these two chains + newChains.push_back(_curve); + delete new_curve_a; + delete new_curve_b; + return 0; + } + // here we know we'll split _curve: + splitted_chains.push_back(_curve); + + __recursiveSplit(new_curve_a, func, pred0d, pred, sampling, newChains, splitted_chains); + __recursiveSplit(new_curve_b, func, pred0d, pred, sampling, newChains, splitted_chains); + return 0; } -int Operators::recursiveSplit(UnaryFunction0D& func, UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, +int Operators::recursiveSplit(UnaryFunction0D &func, + UnaryPredicate0D &pred0d, + UnaryPredicate1D &pred, float sampling) { - if (_current_chains_set.empty()) { - cerr << "Warning: current set empty" << endl; - return 0; - } - - Chain *currentChain = 0; - I1DContainer splitted_chains; - I1DContainer newChains; - I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); - for (; cit != citend; ++cit) { - currentChain = dynamic_cast(*cit); - if (!currentChain) - continue; - // let's check the first one: - if (pred(*currentChain) < 0) - return -1; - if (!pred.result) { - __recursiveSplit(currentChain, func, pred0d, pred, sampling, newChains, splitted_chains); - } - else { - newChains.push_back(currentChain); - } - } - // Update the current set of chains: - if (!splitted_chains.empty()) { - for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { - delete (*cit); - } - splitted_chains.clear(); - } - - _current_chains_set.clear(); + if (_current_chains_set.empty()) { + cerr << "Warning: current set empty" << endl; + return 0; + } + + Chain *currentChain = 0; + I1DContainer splitted_chains; + I1DContainer newChains; + I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end(); + for (; cit != citend; ++cit) { + currentChain = dynamic_cast(*cit); + if (!currentChain) + continue; + // let's check the first one: + if (pred(*currentChain) < 0) + return -1; + if (!pred.result) { + __recursiveSplit(currentChain, func, pred0d, pred, sampling, newChains, splitted_chains); + } + else { + newChains.push_back(currentChain); + } + } + // Update the current set of chains: + if (!splitted_chains.empty()) { + for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) { + delete (*cit); + } + splitted_chains.clear(); + } + + _current_chains_set.clear(); #if 0 - _current_chains_set = newChains; + _current_chains_set = newChains; #else - for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) { - if ((*cit)->getLength2D() < M_EPSILON) { - delete (*cit); - continue; - } - _current_chains_set.push_back(*cit); - } + for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) { + if ((*cit)->getLength2D() < M_EPSILON) { + delete (*cit); + continue; + } + _current_chains_set.push_back(*cit); + } #endif - newChains.clear(); + newChains.clear(); - if (!_current_chains_set.empty()) - _current_set = &_current_chains_set; - return 0; + if (!_current_chains_set.empty()) + _current_set = &_current_chains_set; + return 0; } // Internal class -class PredicateWrapper -{ -public: - inline PredicateWrapper(BinaryPredicate1D& pred) - { - _pred = &pred; - } - - inline bool operator()(Interface1D *i1, Interface1D *i2) - { - if (i1 == i2) - return false; - if ((*_pred)(*i1, *i2) < 0) - throw std::runtime_error("comparison failed"); - return _pred->result; - } - -private: - BinaryPredicate1D *_pred; +class PredicateWrapper { + public: + inline PredicateWrapper(BinaryPredicate1D &pred) + { + _pred = &pred; + } + + inline bool operator()(Interface1D *i1, Interface1D *i2) + { + if (i1 == i2) + return false; + if ((*_pred)(*i1, *i2) < 0) + throw std::runtime_error("comparison failed"); + return _pred->result; + } + + private: + BinaryPredicate1D *_pred; }; -int Operators::sort(BinaryPredicate1D& pred) +int Operators::sort(BinaryPredicate1D &pred) { - if (!_current_set) - return 0; - PredicateWrapper wrapper(pred); - try { - std::sort(_current_set->begin(), _current_set->end(), wrapper); - } - catch (std::runtime_error &e) { - cerr << "Warning: Operator.sort(): " << e.what() << endl; - return -1; - } - return 0; + if (!_current_set) + return 0; + PredicateWrapper wrapper(pred); + try { + std::sort(_current_set->begin(), _current_set->end(), wrapper); + } + catch (std::runtime_error &e) { + cerr << "Warning: Operator.sort(): " << e.what() << endl; + return -1; + } + return 0; } -static Stroke *createStroke(Interface1D& inter) +static Stroke *createStroke(Interface1D &inter) { - Stroke *stroke = new Stroke; - stroke->setId(inter.getId()); - - float currentCurvilignAbscissa = 0.0f; - - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - Interface0DIterator itfirst = it; - - Vec2r current(it->getPoint2D()); - Vec2r previous = current; - SVertex *sv; - CurvePoint *cp; - StrokeVertex *stroke_vertex = NULL; - bool hasSingularity = false; - - do { - cp = dynamic_cast(&(*it)); - if (!cp) { - sv = dynamic_cast(&(*it)); - if (!sv) { - cerr << "Warning: unexpected Vertex type" << endl; - continue; - } - stroke_vertex = new StrokeVertex(sv); - } - else { - stroke_vertex = new StrokeVertex(cp); - } - current = stroke_vertex->getPoint2D(); - Vec2r vec_tmp(current - previous); - real dist = vec_tmp.norm(); - if (dist < 1.0e-6) - hasSingularity = true; - currentCurvilignAbscissa += dist; - stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); - stroke->push_back(stroke_vertex); - previous = current; - ++it; - } while ((it != itend) && (it != itfirst)); - - if (it == itfirst) { - // Add last vertex: - cp = dynamic_cast(&(*it)); - if (!cp) { - sv = dynamic_cast(&(*it)); - if (!sv) - cerr << "Warning: unexpected Vertex type" << endl; - else - stroke_vertex = new StrokeVertex(sv); - } - else { - stroke_vertex = new StrokeVertex(cp); - } - current = stroke_vertex->getPoint2D(); - Vec2r vec_tmp(current - previous); - real dist = vec_tmp.norm(); - if (dist < 1.0e-6) - hasSingularity = true; - currentCurvilignAbscissa += dist; - stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); - stroke->push_back(stroke_vertex); - } - // Discard the stroke if the number of stroke vertices is less than two - if (stroke->strokeVerticesSize() < 2) { - delete stroke; - return NULL; - } - stroke->setLength(currentCurvilignAbscissa); - if (hasSingularity) { - // Try to address singular points such that the distance between two subsequent vertices - // are smaller than epsilon. - StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator vnext = v; - ++vnext; - Vec2r next((*v).getPoint()); - while (!vnext.isEnd()) { - current = next; - next = (*vnext).getPoint(); - if ((next - current).norm() < 1.0e-6) { - StrokeInternal::StrokeVertexIterator vprevious = v; - if (!vprevious.isBegin()) - --vprevious; - - // collect a set of overlapping vertices - std::vector overlapping_vertices; - overlapping_vertices.push_back(&(*v)); - do { - overlapping_vertices.push_back(&(*vnext)); - current = next; - ++v; - ++vnext; - if (vnext.isEnd()) - break; - next = (*vnext).getPoint(); - } while ((next - current).norm() < 1.0e-6); - - Vec2r target; - bool reverse; - if (!vnext.isEnd()) { - target = (*vnext).getPoint(); - reverse = false; - } - else if (!vprevious.isBegin()) { - target = (*vprevious).getPoint(); - reverse = true; - } - else { - // Discard the stroke because all stroke vertices are overlapping - delete stroke; - return NULL; - } - current = overlapping_vertices.front()->getPoint(); - Vec2r dir(target - current); - real dist = dir.norm(); - real len = 1.0e-3; // default offset length - int nvert = overlapping_vertices.size(); - if (dist < len * nvert) { - len = dist / nvert; - } - dir.normalize(); - Vec2r offset(dir * len); - // add the offset to the overlapping vertices - StrokeVertex *sv; - std::vector::iterator it = overlapping_vertices.begin(); - if (!reverse) { - for (int n = 0; n < nvert; n++) { - sv = (*it); - sv->setPoint(sv->getPoint() + offset * (n + 1)); - ++it; - } - } - else { - for (int n = 0; n < nvert; n++) { - sv = (*it); - sv->setPoint(sv->getPoint() + offset * (nvert - n)); - ++it; - } - } - - if (vnext.isEnd()) - break; - } - ++v; - ++vnext; - } - } - { - // Check if the stroke no longer contains singular points - Interface0DIterator v = stroke->verticesBegin(); - Interface0DIterator vnext = v; - ++vnext; - Vec2r next((*v).getPoint2D()); - bool warning = false; - while (!vnext.isEnd()) { - current = next; - next = (*vnext).getPoint2D(); - if ((next - current).norm() < 1.0e-6) { - warning = true; - break; - } - ++v; - ++vnext; - } - if (warning && G.debug & G_DEBUG_FREESTYLE) { - printf("Warning: stroke contains singular points.\n"); - } - } - return stroke; + Stroke *stroke = new Stroke; + stroke->setId(inter.getId()); + + float currentCurvilignAbscissa = 0.0f; + + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + Interface0DIterator itfirst = it; + + Vec2r current(it->getPoint2D()); + Vec2r previous = current; + SVertex *sv; + CurvePoint *cp; + StrokeVertex *stroke_vertex = NULL; + bool hasSingularity = false; + + do { + cp = dynamic_cast(&(*it)); + if (!cp) { + sv = dynamic_cast(&(*it)); + if (!sv) { + cerr << "Warning: unexpected Vertex type" << endl; + continue; + } + stroke_vertex = new StrokeVertex(sv); + } + else { + stroke_vertex = new StrokeVertex(cp); + } + current = stroke_vertex->getPoint2D(); + Vec2r vec_tmp(current - previous); + real dist = vec_tmp.norm(); + if (dist < 1.0e-6) + hasSingularity = true; + currentCurvilignAbscissa += dist; + stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); + stroke->push_back(stroke_vertex); + previous = current; + ++it; + } while ((it != itend) && (it != itfirst)); + + if (it == itfirst) { + // Add last vertex: + cp = dynamic_cast(&(*it)); + if (!cp) { + sv = dynamic_cast(&(*it)); + if (!sv) + cerr << "Warning: unexpected Vertex type" << endl; + else + stroke_vertex = new StrokeVertex(sv); + } + else { + stroke_vertex = new StrokeVertex(cp); + } + current = stroke_vertex->getPoint2D(); + Vec2r vec_tmp(current - previous); + real dist = vec_tmp.norm(); + if (dist < 1.0e-6) + hasSingularity = true; + currentCurvilignAbscissa += dist; + stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa); + stroke->push_back(stroke_vertex); + } + // Discard the stroke if the number of stroke vertices is less than two + if (stroke->strokeVerticesSize() < 2) { + delete stroke; + return NULL; + } + stroke->setLength(currentCurvilignAbscissa); + if (hasSingularity) { + // Try to address singular points such that the distance between two subsequent vertices + // are smaller than epsilon. + StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator vnext = v; + ++vnext; + Vec2r next((*v).getPoint()); + while (!vnext.isEnd()) { + current = next; + next = (*vnext).getPoint(); + if ((next - current).norm() < 1.0e-6) { + StrokeInternal::StrokeVertexIterator vprevious = v; + if (!vprevious.isBegin()) + --vprevious; + + // collect a set of overlapping vertices + std::vector overlapping_vertices; + overlapping_vertices.push_back(&(*v)); + do { + overlapping_vertices.push_back(&(*vnext)); + current = next; + ++v; + ++vnext; + if (vnext.isEnd()) + break; + next = (*vnext).getPoint(); + } while ((next - current).norm() < 1.0e-6); + + Vec2r target; + bool reverse; + if (!vnext.isEnd()) { + target = (*vnext).getPoint(); + reverse = false; + } + else if (!vprevious.isBegin()) { + target = (*vprevious).getPoint(); + reverse = true; + } + else { + // Discard the stroke because all stroke vertices are overlapping + delete stroke; + return NULL; + } + current = overlapping_vertices.front()->getPoint(); + Vec2r dir(target - current); + real dist = dir.norm(); + real len = 1.0e-3; // default offset length + int nvert = overlapping_vertices.size(); + if (dist < len * nvert) { + len = dist / nvert; + } + dir.normalize(); + Vec2r offset(dir * len); + // add the offset to the overlapping vertices + StrokeVertex *sv; + std::vector::iterator it = overlapping_vertices.begin(); + if (!reverse) { + for (int n = 0; n < nvert; n++) { + sv = (*it); + sv->setPoint(sv->getPoint() + offset * (n + 1)); + ++it; + } + } + else { + for (int n = 0; n < nvert; n++) { + sv = (*it); + sv->setPoint(sv->getPoint() + offset * (nvert - n)); + ++it; + } + } + + if (vnext.isEnd()) + break; + } + ++v; + ++vnext; + } + } + { + // Check if the stroke no longer contains singular points + Interface0DIterator v = stroke->verticesBegin(); + Interface0DIterator vnext = v; + ++vnext; + Vec2r next((*v).getPoint2D()); + bool warning = false; + while (!vnext.isEnd()) { + current = next; + next = (*vnext).getPoint2D(); + if ((next - current).norm() < 1.0e-6) { + warning = true; + break; + } + ++v; + ++vnext; + } + if (warning && G.debug & G_DEBUG_FREESTYLE) { + printf("Warning: stroke contains singular points.\n"); + } + } + return stroke; } - -inline int applyShading(Stroke& stroke, vector& shaders) +inline int applyShading(Stroke &stroke, vector &shaders) { - for (vector::iterator it = shaders.begin(); it != shaders.end(); ++it) { - if ((*it)->shade(stroke) < 0) { - return -1; - } - } - return 0; + for (vector::iterator it = shaders.begin(); it != shaders.end(); ++it) { + if ((*it)->shade(stroke) < 0) { + return -1; + } + } + return 0; } -int Operators::create(UnaryPredicate1D& pred, vector shaders) +int Operators::create(UnaryPredicate1D &pred, vector shaders) { - //Canvas* canvas = Canvas::getInstance(); - if (!_current_set) { - cerr << "Warning: current set empty" << endl; - return 0; - } - StrokesContainer new_strokes_set; - for (Operators::I1DContainer::iterator it = _current_set->begin(); it != _current_set->end(); ++it) { - if (pred(**it) < 0) - goto error; - if (!pred.result) - continue; - - Stroke *stroke = createStroke(**it); - if (stroke) { - if (applyShading(*stroke, shaders) < 0) { - delete stroke; - goto error; - } - //canvas->RenderStroke(stroke); - new_strokes_set.push_back(stroke); - } - } - - for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it) { - _current_strokes_set.push_back(*it); - } - new_strokes_set.clear(); - return 0; + //Canvas* canvas = Canvas::getInstance(); + if (!_current_set) { + cerr << "Warning: current set empty" << endl; + return 0; + } + StrokesContainer new_strokes_set; + for (Operators::I1DContainer::iterator it = _current_set->begin(); it != _current_set->end(); + ++it) { + if (pred(**it) < 0) + goto error; + if (!pred.result) + continue; + + Stroke *stroke = createStroke(**it); + if (stroke) { + if (applyShading(*stroke, shaders) < 0) { + delete stroke; + goto error; + } + //canvas->RenderStroke(stroke); + new_strokes_set.push_back(stroke); + } + } + + for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); + ++it) { + _current_strokes_set.push_back(*it); + } + new_strokes_set.clear(); + return 0; error: - for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it) { - delete (*it); - } - new_strokes_set.clear(); - return -1; + for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); + ++it) { + delete (*it); + } + new_strokes_set.clear(); + return -1; } void Operators::reset(bool removeStrokes) { - ViewMap *vm = ViewMap::getInstance(); - if (!vm) { - cerr << "Error: no ViewMap computed yet" << endl; - return; - } - _current_view_edges_set.clear(); - for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end(); ++it) - delete *it; - _current_chains_set.clear(); - - ViewMap::viewedges_container& vedges = vm->ViewEdges(); - ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); - for (; ve != veend; ++ve) { - if ((*ve)->getLength2D() < M_EPSILON) - continue; - _current_view_edges_set.push_back(*ve); - } - _current_set = &_current_view_edges_set; - if (removeStrokes) - _current_strokes_set.clear(); + ViewMap *vm = ViewMap::getInstance(); + if (!vm) { + cerr << "Error: no ViewMap computed yet" << endl; + return; + } + _current_view_edges_set.clear(); + for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end(); + ++it) + delete *it; + _current_chains_set.clear(); + + ViewMap::viewedges_container &vedges = vm->ViewEdges(); + ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); + for (; ve != veend; ++ve) { + if ((*ve)->getLength2D() < M_EPSILON) + continue; + _current_view_edges_set.push_back(*ve); + } + _current_set = &_current_view_edges_set; + if (removeStrokes) + _current_strokes_set.clear(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Operators.h b/source/blender/freestyle/intern/stroke/Operators.h index 6c3d9413038..9d63108a813 100644 --- a/source/blender/freestyle/intern/stroke/Operators.h +++ b/source/blender/freestyle/intern/stroke/Operators.h @@ -37,7 +37,7 @@ #include "../view_map/ViewMap.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -48,225 +48,235 @@ namespace Freestyle { */ class Operators { -public: - typedef vector I1DContainer; - typedef vector StrokesContainer; - - // - // Operators - // - //////////////////////////////////////////////// - - /*! Selects the ViewEdges of the ViewMap verifying a specified condition. - * \param pred: The predicate expressing this condition - */ - static int select(UnaryPredicate1D& pred); - - /*! Builds a set of chains from the current set of ViewEdges. - * Each ViewEdge of the current list starts a new chain. The chaining operator then iterates over the ViewEdges - * of the ViewMap using the user specified iterator. - * This operator only iterates using the increment operator and is therefore unidirectional. - * \param it: - * The iterator on the ViewEdges of the ViewMap. It contains the chaining rule. - * \param pred: - * The predicate on the ViewEdge that expresses the stopping condition. - * \param modifier: - * A function that takes a ViewEdge as argument and that is used to modify the processed ViewEdge - * state (the timestamp incrementation is a typical illustration of such a modifier) - */ - static int chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred, UnaryFunction1D_void& modifier); - - /*! Builds a set of chains from the current set of ViewEdges. - * Each ViewEdge of the current list starts a new chain. The chaining operator then iterates over the ViewEdges - * of the ViewMap using the user specified iterator. - * This operator only iterates using the increment operator and is therefore unidirectional. - * This chaining operator is different from the previous one because it doesn't take any modifier as argument. - * Indeed, the time stamp (insuring that a ViewEdge is processed one time) is automatically managed in this case. - * \param it: - * The iterator on the ViewEdges of the ViewMap. It contains the chaining rule. - * \param pred: - * The predicate on the ViewEdge that expresses the stopping condition. - */ - static int chain(ViewEdgeInternal::ViewEdgeIterator& it, UnaryPredicate1D& pred); - - /*! Builds a set of chains from the current set of ViewEdges. - * Each ViewEdge of the current list potentially starts a new chain. The chaining operator then iterates over - * the ViewEdges of the ViewMap using the user specified iterator. - * This operator iterates both using the increment and decrement operators and is therefore bidirectional. - * This operator works with a ChainingIterator which contains the chaining rules. It is this last one which can - * be told to chain only edges that belong to the selection or not to process twice a ViewEdge during the chaining. - * Each time a ViewEdge is added to a chain, its chaining time stamp is incremented. This allows you to keep track - * of the number of chains to which a ViewEdge belongs to. - * \param it: - * The ChainingIterator on the ViewEdges of the ViewMap. It contains the chaining rule. - * \param pred: - * The predicate on the ViewEdge that expresses the stopping condition. - */ - static int bidirectionalChain(ChainingIterator& it, UnaryPredicate1D& pred); - - /*! The only difference with the above bidirectional chaining algorithm is that we don't need to pass a stopping - * criterion. This might be desirable when the stopping criterion is already contained in the iterator definition. - * Builds a set of chains from the current set of ViewEdges. - * Each ViewEdge of the current list potentially starts a new chain. The chaining operator then iterates over - * the ViewEdges of the ViewMap using the user specified iterator. - * This operator iterates both using the increment and decrement operators and is therefore bidirectional. - * This operator works with a ChainingIterator which contains the chaining rules. It is this last one which can be - * told to chain only edges that belong to the selection or not to process twice a ViewEdge during the chaining. - * Each time a ViewEdge is added to a chain, its chaining time stamp is incremented. This allows you to keep track - * of the number of chains to which a ViewEdge belongs to. - * \param it: - * The ChainingIterator on the ViewEdges of the ViewMap. It contains the chaining rule. - */ - static int bidirectionalChain(ChainingIterator& it); - - /*! Splits each chain of the current set of chains in a sequential way. - * The points of each chain are processed (with a specified sampling) sequentially. - * Each time a user specified starting condition is verified, a new chain begins and ends as soon as a - * user-defined stopping predicate is verified. - * This allows chains overlapping rather than chains partitioning. - * The first point of the initial chain is the first point of one of the resulting chains. - * The splitting ends when no more chain can start. - * \param startingPred: - * The predicate on a point that expresses the starting condition - * \param stoppingPred: - * The predicate on a point that expresses the stopping condition - * \param sampling: - * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually - * resampled, a virtual point only progresses along the curve using this resolution) - */ - static int sequentialSplit(UnaryPredicate0D& startingPred, UnaryPredicate0D& stoppingPred, float sampling = 0.0f); - - /*! Splits each chain of the current set of chains in a sequential way. - * The points of each chain are processed (with a specified sampling) sequentially and each time a user - * specified condition is verified, the chain is split into two chains. - * The resulting set of chains is a partition of the initial chain - * \param pred: - * The predicate on a point that expresses the splitting condition - * \param sampling: - * The resolution used to sample the chain for the predicate evaluation. (The chain is not actually - * resampled, a virtual point only progresses along the curve using this resolution) - */ - static int sequentialSplit(UnaryPredicate0D& pred, float sampling = 0.0f); - - /*! Splits the current set of chains in a recursive way. - * We process the points of each chain (with a specified sampling) to find the point minimizing a specified - * function. The chain is split in two at this point and the two new chains are processed in the same way. - * The recursivity level is controlled through a predicate 1D that expresses a stopping condition - * on the chain that is about to be processed. - * \param func: - * The Unary Function evaluated at each point of the chain. - * The splitting point is the point minimizing this function - * \param pred: - * The Unary Predicate ex pressing the recursivity stopping condition. - * This predicate is evaluated for each curve before it actually gets split. - * If pred(chain) is true, the curve won't be split anymore. - * \param sampling: - * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually - * resampled, a virtual point only progresses along the curve using this resolution) - */ - static int recursiveSplit(UnaryFunction0D& func, UnaryPredicate1D& pred, float sampling = 0); - - /*! Splits the current set of chains in a recursive way. - * We process the points of each chain (with a specified sampling) to find the point minimizing a specified - * function. The chain is split in two at this point and the two new chains are processed in the same way. - * The user can specify a 0D predicate to make a first selection on the points that can potentially be split. - * A point that doesn't verify the 0D predicate won't be candidate in realizing the min. - * The recursivity level is controlled through a predicate 1D that expresses a stopping condition - * on the chain that is about to be processed. - * \param func: - * The Unary Function evaluated at each point of the chain. - * The splitting point is the point minimizing this function - * \param pred0d: - * The Unary Predicate 0D used to select the candidate points where the split can occur. - * For example, it is very likely that would rather have your chain splitting around its middle point - * than around one of its extremities. A 0D predicate working on the curvilinear abscissa allows - * to add this kind of constraints. - * \param pred: - * The Unary Predicate ex pressing the recursivity stopping condition. - * This predicate is evaluated for each curve before it actually gets split. - * If pred(chain) is true, the curve won't be split anymore. - * \param sampling: - * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually - * resampled, a virtual point only progresses along the curve using this resolution) - */ - static int recursiveSplit(UnaryFunction0D& func, UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, - float sampling = 0.0f); - - /*! Sorts the current set of chains (or viewedges) according to the comparison predicate given as argument. - * \param pred: - * The binary predicate used for the comparison - */ - static int sort(BinaryPredicate1D& pred); - - /*! Creates and shades the strokes from the current set of chains. - * A predicate can be specified to make a selection pass on the chains. - * \param pred: - * The predicate that a chain must verify in order to be transform as a stroke - * \param shaders: - * The list of shaders used to shade the strokes - */ - static int create(UnaryPredicate1D& pred, vector shaders); - - // - // Data access - // - //////////////////////////////////////////////// - - static ViewEdge *getViewEdgeFromIndex(unsigned i) - { - return dynamic_cast(_current_view_edges_set[i]); - } - - static Chain *getChainFromIndex(unsigned i) - { - return dynamic_cast(_current_chains_set[i]); - } - - static Stroke *getStrokeFromIndex(unsigned i) - { - return _current_strokes_set[i]; - } - - static unsigned getViewEdgesSize() - { - return _current_view_edges_set.size(); - } - - static unsigned getChainsSize() - { - return _current_chains_set.size(); - } - - static unsigned getStrokesSize() - { - return _current_strokes_set.size(); - } - - // - // Not exported in Python - // - ////////////////////////////////////////////////// - - static StrokesContainer *getStrokesSet() - { - return &_current_strokes_set; - } - - static void reset(bool removeStrokes=true); - -private: - Operators() {} - - static I1DContainer _current_view_edges_set; - static I1DContainer _current_chains_set; - static I1DContainer *_current_set; - static StrokesContainer _current_strokes_set; + public: + typedef vector I1DContainer; + typedef vector StrokesContainer; + + // + // Operators + // + //////////////////////////////////////////////// + + /*! Selects the ViewEdges of the ViewMap verifying a specified condition. + * \param pred: The predicate expressing this condition + */ + static int select(UnaryPredicate1D &pred); + + /*! Builds a set of chains from the current set of ViewEdges. + * Each ViewEdge of the current list starts a new chain. The chaining operator then iterates over the ViewEdges + * of the ViewMap using the user specified iterator. + * This operator only iterates using the increment operator and is therefore unidirectional. + * \param it: + * The iterator on the ViewEdges of the ViewMap. It contains the chaining rule. + * \param pred: + * The predicate on the ViewEdge that expresses the stopping condition. + * \param modifier: + * A function that takes a ViewEdge as argument and that is used to modify the processed ViewEdge + * state (the timestamp incrementation is a typical illustration of such a modifier) + */ + static int chain(ViewEdgeInternal::ViewEdgeIterator &it, + UnaryPredicate1D &pred, + UnaryFunction1D_void &modifier); + + /*! Builds a set of chains from the current set of ViewEdges. + * Each ViewEdge of the current list starts a new chain. The chaining operator then iterates over the ViewEdges + * of the ViewMap using the user specified iterator. + * This operator only iterates using the increment operator and is therefore unidirectional. + * This chaining operator is different from the previous one because it doesn't take any modifier as argument. + * Indeed, the time stamp (insuring that a ViewEdge is processed one time) is automatically managed in this case. + * \param it: + * The iterator on the ViewEdges of the ViewMap. It contains the chaining rule. + * \param pred: + * The predicate on the ViewEdge that expresses the stopping condition. + */ + static int chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred); + + /*! Builds a set of chains from the current set of ViewEdges. + * Each ViewEdge of the current list potentially starts a new chain. The chaining operator then iterates over + * the ViewEdges of the ViewMap using the user specified iterator. + * This operator iterates both using the increment and decrement operators and is therefore bidirectional. + * This operator works with a ChainingIterator which contains the chaining rules. It is this last one which can + * be told to chain only edges that belong to the selection or not to process twice a ViewEdge during the chaining. + * Each time a ViewEdge is added to a chain, its chaining time stamp is incremented. This allows you to keep track + * of the number of chains to which a ViewEdge belongs to. + * \param it: + * The ChainingIterator on the ViewEdges of the ViewMap. It contains the chaining rule. + * \param pred: + * The predicate on the ViewEdge that expresses the stopping condition. + */ + static int bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred); + + /*! The only difference with the above bidirectional chaining algorithm is that we don't need to pass a stopping + * criterion. This might be desirable when the stopping criterion is already contained in the iterator definition. + * Builds a set of chains from the current set of ViewEdges. + * Each ViewEdge of the current list potentially starts a new chain. The chaining operator then iterates over + * the ViewEdges of the ViewMap using the user specified iterator. + * This operator iterates both using the increment and decrement operators and is therefore bidirectional. + * This operator works with a ChainingIterator which contains the chaining rules. It is this last one which can be + * told to chain only edges that belong to the selection or not to process twice a ViewEdge during the chaining. + * Each time a ViewEdge is added to a chain, its chaining time stamp is incremented. This allows you to keep track + * of the number of chains to which a ViewEdge belongs to. + * \param it: + * The ChainingIterator on the ViewEdges of the ViewMap. It contains the chaining rule. + */ + static int bidirectionalChain(ChainingIterator &it); + + /*! Splits each chain of the current set of chains in a sequential way. + * The points of each chain are processed (with a specified sampling) sequentially. + * Each time a user specified starting condition is verified, a new chain begins and ends as soon as a + * user-defined stopping predicate is verified. + * This allows chains overlapping rather than chains partitioning. + * The first point of the initial chain is the first point of one of the resulting chains. + * The splitting ends when no more chain can start. + * \param startingPred: + * The predicate on a point that expresses the starting condition + * \param stoppingPred: + * The predicate on a point that expresses the stopping condition + * \param sampling: + * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually + * resampled, a virtual point only progresses along the curve using this resolution) + */ + static int sequentialSplit(UnaryPredicate0D &startingPred, + UnaryPredicate0D &stoppingPred, + float sampling = 0.0f); + + /*! Splits each chain of the current set of chains in a sequential way. + * The points of each chain are processed (with a specified sampling) sequentially and each time a user + * specified condition is verified, the chain is split into two chains. + * The resulting set of chains is a partition of the initial chain + * \param pred: + * The predicate on a point that expresses the splitting condition + * \param sampling: + * The resolution used to sample the chain for the predicate evaluation. (The chain is not actually + * resampled, a virtual point only progresses along the curve using this resolution) + */ + static int sequentialSplit(UnaryPredicate0D &pred, float sampling = 0.0f); + + /*! Splits the current set of chains in a recursive way. + * We process the points of each chain (with a specified sampling) to find the point minimizing a specified + * function. The chain is split in two at this point and the two new chains are processed in the same way. + * The recursivity level is controlled through a predicate 1D that expresses a stopping condition + * on the chain that is about to be processed. + * \param func: + * The Unary Function evaluated at each point of the chain. + * The splitting point is the point minimizing this function + * \param pred: + * The Unary Predicate ex pressing the recursivity stopping condition. + * This predicate is evaluated for each curve before it actually gets split. + * If pred(chain) is true, the curve won't be split anymore. + * \param sampling: + * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually + * resampled, a virtual point only progresses along the curve using this resolution) + */ + static int recursiveSplit(UnaryFunction0D &func, + UnaryPredicate1D &pred, + float sampling = 0); + + /*! Splits the current set of chains in a recursive way. + * We process the points of each chain (with a specified sampling) to find the point minimizing a specified + * function. The chain is split in two at this point and the two new chains are processed in the same way. + * The user can specify a 0D predicate to make a first selection on the points that can potentially be split. + * A point that doesn't verify the 0D predicate won't be candidate in realizing the min. + * The recursivity level is controlled through a predicate 1D that expresses a stopping condition + * on the chain that is about to be processed. + * \param func: + * The Unary Function evaluated at each point of the chain. + * The splitting point is the point minimizing this function + * \param pred0d: + * The Unary Predicate 0D used to select the candidate points where the split can occur. + * For example, it is very likely that would rather have your chain splitting around its middle point + * than around one of its extremities. A 0D predicate working on the curvilinear abscissa allows + * to add this kind of constraints. + * \param pred: + * The Unary Predicate ex pressing the recursivity stopping condition. + * This predicate is evaluated for each curve before it actually gets split. + * If pred(chain) is true, the curve won't be split anymore. + * \param sampling: + * The resolution used to sample the chain for the predicates evaluation. (The chain is not actually + * resampled, a virtual point only progresses along the curve using this resolution) + */ + static int recursiveSplit(UnaryFunction0D &func, + UnaryPredicate0D &pred0d, + UnaryPredicate1D &pred, + float sampling = 0.0f); + + /*! Sorts the current set of chains (or viewedges) according to the comparison predicate given as argument. + * \param pred: + * The binary predicate used for the comparison + */ + static int sort(BinaryPredicate1D &pred); + + /*! Creates and shades the strokes from the current set of chains. + * A predicate can be specified to make a selection pass on the chains. + * \param pred: + * The predicate that a chain must verify in order to be transform as a stroke + * \param shaders: + * The list of shaders used to shade the strokes + */ + static int create(UnaryPredicate1D &pred, vector shaders); + + // + // Data access + // + //////////////////////////////////////////////// + + static ViewEdge *getViewEdgeFromIndex(unsigned i) + { + return dynamic_cast(_current_view_edges_set[i]); + } + + static Chain *getChainFromIndex(unsigned i) + { + return dynamic_cast(_current_chains_set[i]); + } + + static Stroke *getStrokeFromIndex(unsigned i) + { + return _current_strokes_set[i]; + } + + static unsigned getViewEdgesSize() + { + return _current_view_edges_set.size(); + } + + static unsigned getChainsSize() + { + return _current_chains_set.size(); + } + + static unsigned getStrokesSize() + { + return _current_strokes_set.size(); + } + + // + // Not exported in Python + // + ////////////////////////////////////////////////// + + static StrokesContainer *getStrokesSet() + { + return &_current_strokes_set; + } + + static void reset(bool removeStrokes = true); + + private: + Operators() + { + } + + static I1DContainer _current_view_edges_set; + static I1DContainer _current_chains_set; + static I1DContainer *_current_set; + static StrokesContainer _current_strokes_set; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Operators") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Operators") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_OPERATORS_H__ +#endif // __FREESTYLE_OPERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp index 3cdf7904998..20dac647cdc 100644 --- a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp @@ -26,72 +26,73 @@ namespace Freestyle { PSStrokeRenderer::PSStrokeRenderer(const char *iFileName) : StrokeRenderer() { - if (!iFileName) - iFileName = "freestyle.ps"; - // open the stream: - _ofstream.open(iFileName, ios::out); - if (!_ofstream.is_open()) { - cerr << "couldn't open the output file " << iFileName << endl; - } - _ofstream << "%!PS-Adobe-2.0 EPSF-2.0" << endl; - _ofstream << "%%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl; - _ofstream << "%%BoundingBox: " << 0 << " "<< 0 << " " << Canvas::getInstance()->width() << " " << - Canvas::getInstance()->height() << endl; - _ofstream << "%%EndComments" << endl; + if (!iFileName) + iFileName = "freestyle.ps"; + // open the stream: + _ofstream.open(iFileName, ios::out); + if (!_ofstream.is_open()) { + cerr << "couldn't open the output file " << iFileName << endl; + } + _ofstream << "%!PS-Adobe-2.0 EPSF-2.0" << endl; + _ofstream << "%%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl; + _ofstream << "%%BoundingBox: " << 0 << " " << 0 << " " << Canvas::getInstance()->width() << " " + << Canvas::getInstance()->height() << endl; + _ofstream << "%%EndComments" << endl; } PSStrokeRenderer::~PSStrokeRenderer() { - Close(); + Close(); } void PSStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { - RenderStrokeRepBasic(iStrokeRep); + RenderStrokeRepBasic(iStrokeRep); } void PSStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const { - vector& strips = iStrokeRep->getStrips(); - Strip::vertex_container::iterator v[3]; - StrokeVertexRep *svRep[3]; - Vec3r color[3]; - for (vector::iterator s = strips.begin(), send = strips.end(); s != send; ++s) { - Strip::vertex_container& vertices = (*s)->vertices(); - v[0] = vertices.begin(); - v[1] = v[0]; - ++(v[1]); - v[2] = v[1]; - ++(v[2]); + vector &strips = iStrokeRep->getStrips(); + Strip::vertex_container::iterator v[3]; + StrokeVertexRep *svRep[3]; + Vec3r color[3]; + for (vector::iterator s = strips.begin(), send = strips.end(); s != send; ++s) { + Strip::vertex_container &vertices = (*s)->vertices(); + v[0] = vertices.begin(); + v[1] = v[0]; + ++(v[1]); + v[2] = v[1]; + ++(v[2]); - while (v[2] != vertices.end()) { - svRep[0] = *(v[0]); - svRep[1] = *(v[1]); - svRep[2] = *(v[2]); + while (v[2] != vertices.end()) { + svRep[0] = *(v[0]); + svRep[1] = *(v[1]); + svRep[2] = *(v[2]); - color[0] = svRep[0]->color(); - //color[1] = svRep[1]->color(); - //color[2] = svRep[2]->color(); + color[0] = svRep[0]->color(); + //color[1] = svRep[1]->color(); + //color[2] = svRep[2]->color(); - _ofstream << "newpath" << endl; - _ofstream << (color[0])[0] << " " << (color[0])[1] << " " << (color[0])[2] << " setrgbcolor" <point2d()[0] << " " <point2d()[1] << " moveto" << endl; - _ofstream << svRep[1]->point2d()[0] << " " <point2d()[1] << " lineto" << endl; - _ofstream << svRep[2]->point2d()[0] << " " <point2d()[1] << " lineto" << endl; - _ofstream << "closepath" << endl; - _ofstream << "fill" << endl; + _ofstream << "newpath" << endl; + _ofstream << (color[0])[0] << " " << (color[0])[1] << " " << (color[0])[2] << " setrgbcolor" + << endl; + _ofstream << svRep[0]->point2d()[0] << " " << svRep[0]->point2d()[1] << " moveto" << endl; + _ofstream << svRep[1]->point2d()[0] << " " << svRep[1]->point2d()[1] << " lineto" << endl; + _ofstream << svRep[2]->point2d()[0] << " " << svRep[2]->point2d()[1] << " lineto" << endl; + _ofstream << "closepath" << endl; + _ofstream << "fill" << endl; - ++v[0]; - ++v[1]; - ++v[2]; - } - } + ++v[0]; + ++v[1]; + ++v[2]; + } + } } void PSStrokeRenderer::Close() { - if (_ofstream.is_open()) - _ofstream.close(); + if (_ofstream.is_open()) + _ofstream.close(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h index e24188be2f9..7ddd3d3e4c0 100644 --- a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h +++ b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h @@ -38,23 +38,22 @@ namespace Freestyle { /* */ /**********************************/ -class PSStrokeRenderer : public StrokeRenderer -{ -public: - PSStrokeRenderer(const char *iFileName = NULL); - virtual ~PSStrokeRenderer(); +class PSStrokeRenderer : public StrokeRenderer { + public: + PSStrokeRenderer(const char *iFileName = NULL); + virtual ~PSStrokeRenderer(); - /*! Renders a stroke rep */ - virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; - virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; + /*! Renders a stroke rep */ + virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; + virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; - /*! Closes the output PS file */ - void Close(); + /*! Closes the output PS file */ + void Close(); -protected: - mutable ofstream _ofstream; + protected: + mutable ofstream _ofstream; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_PS_STROKE_RENDERER_H__ +#endif // __FREESTYLE_PS_STROKE_RENDERER_H__ diff --git a/source/blender/freestyle/intern/stroke/Predicates0D.cpp b/source/blender/freestyle/intern/stroke/Predicates0D.cpp index e0263abd387..e28a847df26 100644 --- a/source/blender/freestyle/intern/stroke/Predicates0D.cpp +++ b/source/blender/freestyle/intern/stroke/Predicates0D.cpp @@ -24,14 +24,14 @@ namespace Freestyle { -int UnaryPredicate0D::operator()(Interface0DIterator& it) +int UnaryPredicate0D::operator()(Interface0DIterator &it) { - return Director_BPy_UnaryPredicate0D___call__(this, it); + return Director_BPy_UnaryPredicate0D___call__(this, it); } -int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2) +int BinaryPredicate0D::operator()(Interface0D &inter1, Interface0D &inter2) { - return Director_BPy_BinaryPredicate0D___call__(this, inter1, inter2); + return Director_BPy_BinaryPredicate0D___call__(this, inter1, inter2); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Predicates0D.h b/source/blender/freestyle/intern/stroke/Predicates0D.h index 4309c942218..f511c0ceade 100644 --- a/source/blender/freestyle/intern/stroke/Predicates0D.h +++ b/source/blender/freestyle/intern/stroke/Predicates0D.h @@ -25,7 +25,7 @@ #include "../view_map/Functions0D.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -41,40 +41,40 @@ namespace Freestyle { * The UnaryPredicate0D is used by calling its () operator. * Any inherited class must overload the () operator. */ -class UnaryPredicate0D -{ -public: - bool result; - void *py_up0D; - - /*! Default constructor. */ - UnaryPredicate0D() - { - py_up0D = 0; - } - - /*! Destructor. */ - virtual ~UnaryPredicate0D() {} - - /*! Returns the string of the name of the UnaryPredicate0D. */ - virtual string getName() const - { - return "UnaryPredicate0D"; - } - - /*! The () operator. Must be overload by inherited classes. - * \param it: - * The Interface0DIterator pointing onto the Interface0D at which we wish to evaluate the predicate. - * \return true if the condition is satisfied, false otherwise. - */ - virtual int operator()(Interface0DIterator& it); +class UnaryPredicate0D { + public: + bool result; + void *py_up0D; + + /*! Default constructor. */ + UnaryPredicate0D() + { + py_up0D = 0; + } + + /*! Destructor. */ + virtual ~UnaryPredicate0D() + { + } + + /*! Returns the string of the name of the UnaryPredicate0D. */ + virtual string getName() const + { + return "UnaryPredicate0D"; + } + + /*! The () operator. Must be overload by inherited classes. + * \param it: + * The Interface0DIterator pointing onto the Interface0D at which we wish to evaluate the predicate. + * \return true if the condition is satisfied, false otherwise. + */ + virtual int operator()(Interface0DIterator &it); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate0D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate0D") #endif }; - // // BinaryPredicate0D (base class for predicates in 0D) // @@ -85,43 +85,43 @@ public: * It evaluates a relation between 2 Interface0D and returns true or false. * It is used by calling the () operator. */ -class BinaryPredicate0D -{ -public: - bool result; - void *py_bp0D; - - /*! Default constructor. */ - BinaryPredicate0D() - { - py_bp0D = 0; - } - - /*! Destructor. */ - virtual ~BinaryPredicate0D() {} - - /*! Returns the string of the name of the binary predicate. */ - virtual string getName() const - { - return "BinaryPredicate0D"; - } - - /*! The () operator. Must be overload by inherited classes. - * It evaluates a relation between 2 Interface0D. - * \param inter1: - * The first Interface0D. - * \param inter2: - * The second Interface0D. - * \return true or false. - */ - virtual int operator()(Interface0D& inter1, Interface0D& inter2); +class BinaryPredicate0D { + public: + bool result; + void *py_bp0D; + + /*! Default constructor. */ + BinaryPredicate0D() + { + py_bp0D = 0; + } + + /*! Destructor. */ + virtual ~BinaryPredicate0D() + { + } + + /*! Returns the string of the name of the binary predicate. */ + virtual string getName() const + { + return "BinaryPredicate0D"; + } + + /*! The () operator. Must be overload by inherited classes. + * It evaluates a relation between 2 Interface0D. + * \param inter1: + * The first Interface0D. + * \param inter2: + * The second Interface0D. + * \return true or false. + */ + virtual int operator()(Interface0D &inter1, Interface0D &inter2); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate0D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate0D") #endif }; - // // Predicates definitions // @@ -131,50 +131,52 @@ namespace Predicates0D { // TrueUP0D /*! Returns true any time */ -class TrueUP0D : public UnaryPredicate0D -{ -public: - /*! Default constructor. */ - TrueUP0D() {} - - /*! Returns the string "TrueUP0D"*/ - string getName() const - { - return "TrueUP0D"; - } - - /*! The () operator. */ - int operator()(Interface0DIterator&) - { - result = true; - return 0; - } +class TrueUP0D : public UnaryPredicate0D { + public: + /*! Default constructor. */ + TrueUP0D() + { + } + + /*! Returns the string "TrueUP0D"*/ + string getName() const + { + return "TrueUP0D"; + } + + /*! The () operator. */ + int operator()(Interface0DIterator &) + { + result = true; + return 0; + } }; // FalseUP0D /*! Returns false any time */ -class FalseUP0D : public UnaryPredicate0D -{ -public: - /*! Default constructor. */ - FalseUP0D() {} - - /*! Returns the string "FalseUP0D"*/ - string getName() const - { - return "FalseUP0D"; - } - - /*! The () operator. */ - int operator()(Interface0DIterator&) - { - result = false; - return 0; - } +class FalseUP0D : public UnaryPredicate0D { + public: + /*! Default constructor. */ + FalseUP0D() + { + } + + /*! Returns the string "FalseUP0D"*/ + string getName() const + { + return "FalseUP0D"; + } + + /*! The () operator. */ + int operator()(Interface0DIterator &) + { + result = false; + return 0; + } }; -} // end of namespace Predicates0D +} // end of namespace Predicates0D } /* namespace Freestyle */ -#endif // __FREESTYLE_PREDICATES_0D_H__ +#endif // __FREESTYLE_PREDICATES_0D_H__ diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.cpp b/source/blender/freestyle/intern/stroke/Predicates1D.cpp index b00443bf404..e3b3fefd448 100644 --- a/source/blender/freestyle/intern/stroke/Predicates1D.cpp +++ b/source/blender/freestyle/intern/stroke/Predicates1D.cpp @@ -24,14 +24,14 @@ namespace Freestyle { -int UnaryPredicate1D::operator()(Interface1D& inter) +int UnaryPredicate1D::operator()(Interface1D &inter) { - return Director_BPy_UnaryPredicate1D___call__(this, inter); + return Director_BPy_UnaryPredicate1D___call__(this, inter); } -int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2) +int BinaryPredicate1D::operator()(Interface1D &inter1, Interface1D &inter2) { - return Director_BPy_BinaryPredicate1D___call__(this, inter1, inter2); + return Director_BPy_BinaryPredicate1D___call__(this, inter1, inter2); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h index 0501e33bcf0..be70907b51b 100644 --- a/source/blender/freestyle/intern/stroke/Predicates1D.h +++ b/source/blender/freestyle/intern/stroke/Predicates1D.h @@ -32,7 +32,7 @@ #include "../view_map/Functions1D.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -48,40 +48,40 @@ namespace Freestyle { * The UnaryPredicate1D is used by calling its () operator. * Any inherited class must overload the () operator. */ -class UnaryPredicate1D -{ -public: - bool result; - void *py_up1D; - - /*! Default constructor. */ - UnaryPredicate1D() - { - py_up1D = NULL; - } - - /*! Destructor. */ - virtual ~UnaryPredicate1D() {} - - /*! Returns the string of the name of the UnaryPredicate1D. */ - virtual string getName() const - { - return "UnaryPredicate1D"; - } - - /*! The () operator. Must be overload by inherited classes. - * \param inter: - * The Interface1D on which we wish to evaluate the predicate. - * \return true if the condition is satisfied, false otherwise. - */ - virtual int operator()(Interface1D& inter); +class UnaryPredicate1D { + public: + bool result; + void *py_up1D; + + /*! Default constructor. */ + UnaryPredicate1D() + { + py_up1D = NULL; + } + + /*! Destructor. */ + virtual ~UnaryPredicate1D() + { + } + + /*! Returns the string of the name of the UnaryPredicate1D. */ + virtual string getName() const + { + return "UnaryPredicate1D"; + } + + /*! The () operator. Must be overload by inherited classes. + * \param inter: + * The Interface1D on which we wish to evaluate the predicate. + * \return true if the condition is satisfied, false otherwise. + */ + virtual int operator()(Interface1D &inter); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate1D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate1D") #endif }; - // // BinaryPredicate1D (base class for predicates in 1D) // @@ -92,43 +92,43 @@ public: * It evaluates a relation between 2 Interface1D and returns true or false. * It is used by calling the () operator. */ -class BinaryPredicate1D -{ -public: - bool result; - void *py_bp1D; - - /*! Default constructor. */ - BinaryPredicate1D() - { - py_bp1D = NULL; - } - - /*! Destructor. */ - virtual ~BinaryPredicate1D() {} - - /*! Returns the string of the name of the binary predicate. */ - virtual string getName() const - { - return "BinaryPredicate1D"; - } - - /*! The () operator. Must be overload by inherited classes. - * It evaluates a relation between 2 Interface1D. - * \param inter1: - * The first Interface1D. - * \param inter2: - * The second Interface1D. - * \return true or false. - */ - virtual int operator()(Interface1D& inter1, Interface1D& inter2); +class BinaryPredicate1D { + public: + bool result; + void *py_bp1D; + + /*! Default constructor. */ + BinaryPredicate1D() + { + py_bp1D = NULL; + } + + /*! Destructor. */ + virtual ~BinaryPredicate1D() + { + } + + /*! Returns the string of the name of the binary predicate. */ + virtual string getName() const + { + return "BinaryPredicate1D"; + } + + /*! The () operator. Must be overload by inherited classes. + * It evaluates a relation between 2 Interface1D. + * \param inter1: + * The first Interface1D. + * \param inter2: + * The second Interface1D. + * \return true or false. + */ + virtual int operator()(Interface1D &inter1, Interface1D &inter2); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D") #endif }; - // // Predicates definitions // @@ -138,313 +138,311 @@ namespace Predicates1D { // TrueUP1D /*! Returns true */ -class TrueUP1D : public UnaryPredicate1D -{ -public: - /*! Constructor */ - TrueUP1D() {} - - /*! Returns the string "TrueUP1D"*/ - string getName() const - { - return "TrueUP1D"; - } - - /*! the () operator */ - int operator()(Interface1D&) - { - result = true; - return 0; - } +class TrueUP1D : public UnaryPredicate1D { + public: + /*! Constructor */ + TrueUP1D() + { + } + + /*! Returns the string "TrueUP1D"*/ + string getName() const + { + return "TrueUP1D"; + } + + /*! the () operator */ + int operator()(Interface1D &) + { + result = true; + return 0; + } }; // FalseUP1D /*! Returns false */ -class FalseUP1D : public UnaryPredicate1D -{ -public: - /*! Constructor */ - FalseUP1D() {} - - /*! Returns the string "FalseUP1D"*/ - string getName() const - { - return "FalseUP1D"; - } - - /*! the () operator */ - int operator()(Interface1D&) - { - result = false; - return 0; - } +class FalseUP1D : public UnaryPredicate1D { + public: + /*! Constructor */ + FalseUP1D() + { + } + + /*! Returns the string "FalseUP1D"*/ + string getName() const + { + return "FalseUP1D"; + } + + /*! the () operator */ + int operator()(Interface1D &) + { + result = false; + return 0; + } }; // QuantitativeInvisibilityUP1D /*! Returns true if the Quantitative Invisibility evaluated at an Interface1D, using the QuantitativeInvisibilityF1D * functor, equals a certain user-defined value. */ -class QuantitativeInvisibilityUP1D : public UnaryPredicate1D -{ -public: - /*! Builds the Predicate. - * \param qi: - * The Quantitative Invisibility you want the Interface1D to have - */ - QuantitativeInvisibilityUP1D(unsigned qi = 0) : _qi(qi) {} - - /*! Returns the string "QuantitativeInvisibilityUP1D" */ - string getName() const - { - return "QuantitativeInvisibilityUP1D"; - } - - /*! the () operator */ - int operator()(Interface1D& inter) - { - Functions1D::QuantitativeInvisibilityF1D func; - if (func(inter) < 0) - return -1; - result = (func.result == _qi); - return 0; - } - -private: - unsigned _qi; +class QuantitativeInvisibilityUP1D : public UnaryPredicate1D { + public: + /*! Builds the Predicate. + * \param qi: + * The Quantitative Invisibility you want the Interface1D to have + */ + QuantitativeInvisibilityUP1D(unsigned qi = 0) : _qi(qi) + { + } + + /*! Returns the string "QuantitativeInvisibilityUP1D" */ + string getName() const + { + return "QuantitativeInvisibilityUP1D"; + } + + /*! the () operator */ + int operator()(Interface1D &inter) + { + Functions1D::QuantitativeInvisibilityF1D func; + if (func(inter) < 0) + return -1; + result = (func.result == _qi); + return 0; + } + + private: + unsigned _qi; }; // ContourUP1D /*! Returns true if the Interface1D is a contour. * An Interface1D is a contour if it is borded by a different shape on each of its sides. */ -class ContourUP1D : public UnaryPredicate1D -{ -private: - Functions1D::CurveNatureF1D _getNature; - -public: - /*! Returns the string "ContourUP1D"*/ - string getName() const - { - return "ContourUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - if (_getNature(inter) < 0) - return -1; - if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { - Interface0DIterator it = inter.verticesBegin(); - for (; !it.isEnd(); ++it) { - if (Functions0D::getOccludeeF0D(it) != Functions0D::getShapeF0D(it)) { - result = true; - return 0; - } - } - } - result = false; - return 0; - } +class ContourUP1D : public UnaryPredicate1D { + private: + Functions1D::CurveNatureF1D _getNature; + + public: + /*! Returns the string "ContourUP1D"*/ + string getName() const + { + return "ContourUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + if (_getNature(inter) < 0) + return -1; + if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { + Interface0DIterator it = inter.verticesBegin(); + for (; !it.isEnd(); ++it) { + if (Functions0D::getOccludeeF0D(it) != Functions0D::getShapeF0D(it)) { + result = true; + return 0; + } + } + } + result = false; + return 0; + } }; // ExternalContourUP1D /*! Returns true if the Interface1D is an external contour. * An Interface1D is an external contour if it is borded by no shape on one of its sides. */ -class ExternalContourUP1D : public UnaryPredicate1D -{ -private: - Functions1D::CurveNatureF1D _getNature; - -public: - /*! Returns the string "ExternalContourUP1D" */ - string getName() const - { - return "ExternalContourUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - if (_getNature(inter) < 0) - return -1; - if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { - set occluded; - Functions1D::getOccludeeF1D(inter, occluded); - for (set::iterator os = occluded.begin(), osend = occluded.end(); os != osend; ++os) { - if ((*os) == 0) { - result = true; - return 0; - } - } - } - result = false; - return 0; - } +class ExternalContourUP1D : public UnaryPredicate1D { + private: + Functions1D::CurveNatureF1D _getNature; + + public: + /*! Returns the string "ExternalContourUP1D" */ + string getName() const + { + return "ExternalContourUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + if (_getNature(inter) < 0) + return -1; + if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) { + set occluded; + Functions1D::getOccludeeF1D(inter, occluded); + for (set::iterator os = occluded.begin(), osend = occluded.end(); os != osend; + ++os) { + if ((*os) == 0) { + result = true; + return 0; + } + } + } + result = false; + return 0; + } }; // EqualToTimeStampUP1D /*! Returns true if the Interface1D's time stamp is equal to a certain user-defined value. */ -class EqualToTimeStampUP1D : public UnaryPredicate1D -{ -protected: - unsigned _timeStamp; - -public: - EqualToTimeStampUP1D(unsigned ts) : UnaryPredicate1D() - { - _timeStamp = ts; - } - - /*! Returns the string "EqualToTimeStampUP1D"*/ - string getName() const - { - return "EqualToTimeStampUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - result = (inter.getTimeStamp() == _timeStamp); - return 0; - } +class EqualToTimeStampUP1D : public UnaryPredicate1D { + protected: + unsigned _timeStamp; + + public: + EqualToTimeStampUP1D(unsigned ts) : UnaryPredicate1D() + { + _timeStamp = ts; + } + + /*! Returns the string "EqualToTimeStampUP1D"*/ + string getName() const + { + return "EqualToTimeStampUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + result = (inter.getTimeStamp() == _timeStamp); + return 0; + } }; // EqualToChainingTimeStampUP1D /*! Returns true if the Interface1D's time stamp is equal to a certain user-defined value. */ -class EqualToChainingTimeStampUP1D : public UnaryPredicate1D -{ -protected: - unsigned _timeStamp; - -public: - EqualToChainingTimeStampUP1D(unsigned ts) : UnaryPredicate1D() - { - _timeStamp = ts; - } - - /*! Returns the string "EqualToChainingTimeStampUP1D"*/ - string getName() const - { - return "EqualToChainingTimeStampUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - ViewEdge *edge = dynamic_cast(&inter); - if (!edge) { - result = false; - return 0; - } - result = (edge->getChainingTimeStamp() >= _timeStamp); - return 0; - } +class EqualToChainingTimeStampUP1D : public UnaryPredicate1D { + protected: + unsigned _timeStamp; + + public: + EqualToChainingTimeStampUP1D(unsigned ts) : UnaryPredicate1D() + { + _timeStamp = ts; + } + + /*! Returns the string "EqualToChainingTimeStampUP1D"*/ + string getName() const + { + return "EqualToChainingTimeStampUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + ViewEdge *edge = dynamic_cast(&inter); + if (!edge) { + result = false; + return 0; + } + result = (edge->getChainingTimeStamp() >= _timeStamp); + return 0; + } }; // ShapeUP1D /*! Returns true if the shape to which the Interface1D belongs to has the same Id as the one specified by the user. */ -class ShapeUP1D: public UnaryPredicate1D -{ -private: - Id _id; - -public: - /*! Builds the Predicate. - * \param idFirst: - * The first Id component. - * \param idSecond: - * The second Id component. - */ - ShapeUP1D(unsigned idFirst, unsigned idSecond = 0) : UnaryPredicate1D() - { - _id = Id(idFirst, idSecond); - } - - /*! Returns the string "ShapeUP1D"*/ - string getName() const - { - return "ShapeUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - set shapes; - Functions1D::getShapeF1D(inter, shapes); - for (set::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) { - if ((*s)->getId() == _id) { - result = true; - return 0; - } - } - result = false; - return 0; - } +class ShapeUP1D : public UnaryPredicate1D { + private: + Id _id; + + public: + /*! Builds the Predicate. + * \param idFirst: + * The first Id component. + * \param idSecond: + * The second Id component. + */ + ShapeUP1D(unsigned idFirst, unsigned idSecond = 0) : UnaryPredicate1D() + { + _id = Id(idFirst, idSecond); + } + + /*! Returns the string "ShapeUP1D"*/ + string getName() const + { + return "ShapeUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + set shapes; + Functions1D::getShapeF1D(inter, shapes); + for (set::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) { + if ((*s)->getId() == _id) { + result = true; + return 0; + } + } + result = false; + return 0; + } }; // WithinImageBoundaryUP1D /*! Returns true if the Interface1D is (partly) within the image boundary. */ -class WithinImageBoundaryUP1D: public UnaryPredicate1D -{ -private: - real _xmin, _ymin, _xmax, _ymax; - -public: - /*! Builds the Predicate. - * \param xmin: - * The X lower bound of the image boundary. - * \param ymin: - * The Y lower bound of the image boundary. - * \param xmax: - * The X upper bound of the image boundary. - * \param ymax: - * The Y upper bound of the image boundary. - */ - WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax) - : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax) - { - } - - /*! Returns the string "WithinImageBoundaryUP1D" */ - string getName() const - { - return "WithinImageBoundaryUP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& inter) - { - // 1st pass: check if a point is within the image boundary. - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) { - real x = (*it).getProjectedX(); - real y = (*it).getProjectedY(); - if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) { - result = true; - return 0; - } - } - // 2nd pass: check if a line segment intersects with the image boundary. - it = inter.verticesBegin(); - if (it != itend) { - Vec2r pmin(_xmin, _ymin); - Vec2r pmax(_xmax, _ymax); - Vec2r prev((*it).getPoint2D()); - ++it; - for (; it != itend; ++it) { - Vec2r p((*it).getPoint2D()); - if (GeomUtils::intersect2dSeg2dArea (pmin, pmax, prev, p)) { - result = true; - return 0; - } - prev = p; - } - } - result = false; - return 0; - } +class WithinImageBoundaryUP1D : public UnaryPredicate1D { + private: + real _xmin, _ymin, _xmax, _ymax; + + public: + /*! Builds the Predicate. + * \param xmin: + * The X lower bound of the image boundary. + * \param ymin: + * The Y lower bound of the image boundary. + * \param xmax: + * The X upper bound of the image boundary. + * \param ymax: + * The Y upper bound of the image boundary. + */ + WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax) + : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax) + { + } + + /*! Returns the string "WithinImageBoundaryUP1D" */ + string getName() const + { + return "WithinImageBoundaryUP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &inter) + { + // 1st pass: check if a point is within the image boundary. + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) { + real x = (*it).getProjectedX(); + real y = (*it).getProjectedY(); + if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) { + result = true; + return 0; + } + } + // 2nd pass: check if a line segment intersects with the image boundary. + it = inter.verticesBegin(); + if (it != itend) { + Vec2r pmin(_xmin, _ymin); + Vec2r pmax(_xmax, _ymax); + Vec2r prev((*it).getPoint2D()); + ++it; + for (; it != itend; ++it) { + Vec2r p((*it).getPoint2D()); + if (GeomUtils::intersect2dSeg2dArea(pmin, pmax, prev, p)) { + result = true; + return 0; + } + prev = p; + } + } + result = false; + return 0; + } }; // @@ -454,129 +452,125 @@ public: // TrueBP1D /*! Returns true. */ -class TrueBP1D : public BinaryPredicate1D -{ -public: - /*! Returns the string "TrueBP1D" */ - string getName() const - { - return "TrueBP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& /*i1*/, Interface1D& /*i2*/) - { - result = true; - return 0; - } +class TrueBP1D : public BinaryPredicate1D { + public: + /*! Returns the string "TrueBP1D" */ + string getName() const + { + return "TrueBP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/) + { + result = true; + return 0; + } }; // FalseBP1D /*! Returns false. */ -class FalseBP1D : public BinaryPredicate1D -{ -public: - /*! Returns the string "FalseBP1D" */ - string getName() const - { - return "FalseBP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& /*i1*/, Interface1D& /*i2*/) - { - result = false; - return 0; - } +class FalseBP1D : public BinaryPredicate1D { + public: + /*! Returns the string "FalseBP1D" */ + string getName() const + { + return "FalseBP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/) + { + result = false; + return 0; + } }; // Length2DBP1D /*! Returns true if the 2D length of the Interface1D i1 is less than the 2D length of the Interface1D i2. */ -class Length2DBP1D : public BinaryPredicate1D -{ -public: - /*! Returns the string "Length2DBP1D" */ - string getName() const - { - return "Length2DBP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& i1, Interface1D& i2) - { - result = (i1.getLength2D() > i2.getLength2D()); - return 0; - } +class Length2DBP1D : public BinaryPredicate1D { + public: + /*! Returns the string "Length2DBP1D" */ + string getName() const + { + return "Length2DBP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &i1, Interface1D &i2) + { + result = (i1.getLength2D() > i2.getLength2D()); + return 0; + } }; // SameShapeIdBP1D /*! Returns true if the Interface1D i1 and i2 belong to the same shape. */ -class SameShapeIdBP1D : public BinaryPredicate1D -{ -public: - /*! Returns the string "SameShapeIdBP1D" */ - string getName() const - { - return "SameShapeIdBP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& i1, Interface1D& i2) - { - set shapes1; - Functions1D::getShapeF1D(i1, shapes1); - set shapes2; - Functions1D::getShapeF1D(i2, shapes2); - // FIXME:// n2 algo, can do better... - for (set::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) { - Id current = (*s)->getId(); - for (set::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end; ++s2) { - if ((*s2)->getId() == current) { - result = true; - return 0; - } - } - } - result = false; - return 0; - } +class SameShapeIdBP1D : public BinaryPredicate1D { + public: + /*! Returns the string "SameShapeIdBP1D" */ + string getName() const + { + return "SameShapeIdBP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &i1, Interface1D &i2) + { + set shapes1; + Functions1D::getShapeF1D(i1, shapes1); + set shapes2; + Functions1D::getShapeF1D(i2, shapes2); + // FIXME:// n2 algo, can do better... + for (set::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) { + Id current = (*s)->getId(); + for (set::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end; + ++s2) { + if ((*s2)->getId() == current) { + result = true; + return 0; + } + } + } + result = false; + return 0; + } }; // ViewMapGradientNormBP1D /*! Returns true if the evaluation of the Gradient norm Function is higher for Interface1D i1 than for i2. */ -class ViewMapGradientNormBP1D : public BinaryPredicate1D -{ -private: - Functions1D::GetViewMapGradientNormF1D _func; - -public: - ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0) - : BinaryPredicate1D(), _func(level, iType, sampling) - { - } - - /*! Returns the string "ViewMapGradientNormBP1D" */ - string getName() const - { - return "ViewMapGradientNormBP1D"; - } - - /*! The () operator. */ - int operator()(Interface1D& i1, Interface1D& i2) - { - if (_func(i1) < 0) - return -1; - real n1 = _func.result; - if (_func(i2) < 0) - return -1; - real n2 = _func.result; - result = (n1 > n2); - return 0; - } +class ViewMapGradientNormBP1D : public BinaryPredicate1D { + private: + Functions1D::GetViewMapGradientNormF1D _func; + + public: + ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0) + : BinaryPredicate1D(), _func(level, iType, sampling) + { + } + + /*! Returns the string "ViewMapGradientNormBP1D" */ + string getName() const + { + return "ViewMapGradientNormBP1D"; + } + + /*! The () operator. */ + int operator()(Interface1D &i1, Interface1D &i2) + { + if (_func(i1) < 0) + return -1; + real n1 = _func.result; + if (_func(i2) < 0) + return -1; + real n2 = _func.result; + result = (n1 > n2); + return 0; + } }; -} // end of namespace Predicates1D +} // end of namespace Predicates1D } /* namespace Freestyle */ -#endif // __FREESTYLE_PREDICATES_1D_H__ +#endif // __FREESTYLE_PREDICATES_1D_H__ diff --git a/source/blender/freestyle/intern/stroke/QInformationMap.h b/source/blender/freestyle/intern/stroke/QInformationMap.h index 7cb93321233..99393a8949c 100644 --- a/source/blender/freestyle/intern/stroke/QInformationMap.h +++ b/source/blender/freestyle/intern/stroke/QInformationMap.h @@ -28,37 +28,36 @@ namespace Freestyle { -class QInformationMap : public InformationMap -{ -private: - QImage _map; // the image or a piece of image - -public: - QInformationMap(); - QInformationMap(const QImage&); - QInformationMap(const QInformationMap&); - QInformationMap& operator=(const QInformationMap&); - - //float getSmoothedPixel(int x, int y, float sigma = 0.2f);1 - virtual float getMean(int x, int y); - virtual void retrieveMeanAndVariance(int x, int y, float &oMean, float &oVariance); - - inline const QImage& map() const - { - return _map; - } - - inline void setMap(const QImage& iMap, float iw, float ih) - { - _map = iMap.copy(); - _w = iw; - _h = ih; - } - -protected: - virtual float computeGaussian(int x, int y); +class QInformationMap : public InformationMap { + private: + QImage _map; // the image or a piece of image + + public: + QInformationMap(); + QInformationMap(const QImage &); + QInformationMap(const QInformationMap &); + QInformationMap &operator=(const QInformationMap &); + + //float getSmoothedPixel(int x, int y, float sigma = 0.2f);1 + virtual float getMean(int x, int y); + virtual void retrieveMeanAndVariance(int x, int y, float &oMean, float &oVariance); + + inline const QImage &map() const + { + return _map; + } + + inline void setMap(const QImage &iMap, float iw, float ih) + { + _map = iMap.copy(); + _w = iw; + _h = ih; + } + + protected: + virtual float computeGaussian(int x, int y); }; } /* namespace Freestyle */ -#endif // __FREESTYLE_Q_INFORMATION_MAP_H__ +#endif // __FREESTYLE_Q_INFORMATION_MAP_H__ diff --git a/source/blender/freestyle/intern/stroke/Stroke.cpp b/source/blender/freestyle/intern/stroke/Stroke.cpp index 1cd363a15a5..7b6e53138bb 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.cpp +++ b/source/blender/freestyle/intern/stroke/Stroke.cpp @@ -39,276 +39,285 @@ namespace Freestyle { StrokeAttribute::StrokeAttribute() { - int i; - _alpha = 1.0f; - _thickness[0] = 1.0f; - _thickness[1] = 1.0f; - for (i = 0; i < 3; ++i) - _color[i] = 0.2f; - _color[0] = 0.8f; - _userAttributesReal = NULL; - _userAttributesVec2f = NULL; - _userAttributesVec3f = NULL; - _visible = true; -} - -StrokeAttribute::StrokeAttribute(const StrokeAttribute& iBrother) -{ - _alpha = iBrother._alpha; - _thickness[0] = iBrother._thickness[0]; - _thickness[1] = iBrother._thickness[1]; - for (int i = 0; i < 3; ++i) - _color[i] = iBrother._color[i]; - _visible = iBrother._visible; - if (iBrother._userAttributesReal) - _userAttributesReal = new realMap(*iBrother._userAttributesReal); - else - _userAttributesReal = NULL; - if (iBrother._userAttributesVec2f) - _userAttributesVec2f = new Vec2fMap(*iBrother._userAttributesVec2f); - else - _userAttributesVec2f = NULL; - if (iBrother._userAttributesVec3f) - _userAttributesVec3f = new Vec3fMap(*iBrother._userAttributesVec3f); - else - _userAttributesVec3f = NULL; -} - -StrokeAttribute::StrokeAttribute(float iRColor, float iGColor, float iBColor, float iAlpha, - float iRThickness, float iLThickness) -{ - _color[0] = iRColor; - _color[1] = iGColor; - _color[2] = iBColor; - - _alpha = iAlpha; - - _thickness[0] = iRThickness; - _thickness[1] = iLThickness; - - _visible = true; - - _userAttributesReal = NULL; - _userAttributesVec2f = NULL; - _userAttributesVec3f = NULL; -} - -StrokeAttribute::StrokeAttribute(const StrokeAttribute& a1, const StrokeAttribute& a2, float t) -{ - _alpha = (1 - t) * a1._alpha + t * a2._alpha; - _thickness[0] = (1 - t) * a1._thickness[0] + t * a2._thickness[0]; - _thickness[1] = (1 - t) * a1._thickness[1] + t * a2._thickness[1]; - for (int i = 0; i < 3; ++i) - _color[i] = (1 - t) * a1._color[i] + t * a2._color[i]; - - _visible = a1.isVisible(); - - // FIXME: to be checked (and enhanced) - if ((a1._userAttributesReal) && (a2._userAttributesReal)) { - if (a1._userAttributesReal->size() == a2._userAttributesReal->size()) { - _userAttributesReal = new realMap; - realMap::iterator it1 = a1._userAttributesReal->begin(), it1end = a1._userAttributesReal->end(); - realMap::iterator it2 = a2._userAttributesReal->begin(); - for (; it1 != it1end; ++it1, ++it2) { - (*_userAttributesReal)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); - } - } - } - else { - _userAttributesReal = NULL; - } - if ((a1._userAttributesVec2f) && (a2._userAttributesVec2f)) { - if (a1._userAttributesVec2f->size() == a2._userAttributesVec2f->size()) { - _userAttributesVec2f = new Vec2fMap; - Vec2fMap::iterator it1 = a1._userAttributesVec2f->begin(), it1end = a1._userAttributesVec2f->end(); - Vec2fMap::iterator it2 = a2._userAttributesVec2f->begin(); - for (; it1 != it1end; ++it1, ++it2) { - (*_userAttributesVec2f)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); - } - } - } - else { - _userAttributesVec2f = NULL; - } - if ((a1._userAttributesVec3f) && (a2._userAttributesVec3f)) { - if (a1._userAttributesVec3f->size() == a2._userAttributesVec3f->size()) { - _userAttributesVec3f = new Vec3fMap; - Vec3fMap::iterator it1 = a1._userAttributesVec3f->begin(), it1end = a1._userAttributesVec3f->end(); - Vec3fMap::iterator it2 = a2._userAttributesVec3f->begin(); - for (; it1 != it1end; ++it1, ++it2) { - (*_userAttributesVec3f)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); - } - } - } - else { - _userAttributesVec3f = NULL; - } + int i; + _alpha = 1.0f; + _thickness[0] = 1.0f; + _thickness[1] = 1.0f; + for (i = 0; i < 3; ++i) + _color[i] = 0.2f; + _color[0] = 0.8f; + _userAttributesReal = NULL; + _userAttributesVec2f = NULL; + _userAttributesVec3f = NULL; + _visible = true; +} + +StrokeAttribute::StrokeAttribute(const StrokeAttribute &iBrother) +{ + _alpha = iBrother._alpha; + _thickness[0] = iBrother._thickness[0]; + _thickness[1] = iBrother._thickness[1]; + for (int i = 0; i < 3; ++i) + _color[i] = iBrother._color[i]; + _visible = iBrother._visible; + if (iBrother._userAttributesReal) + _userAttributesReal = new realMap(*iBrother._userAttributesReal); + else + _userAttributesReal = NULL; + if (iBrother._userAttributesVec2f) + _userAttributesVec2f = new Vec2fMap(*iBrother._userAttributesVec2f); + else + _userAttributesVec2f = NULL; + if (iBrother._userAttributesVec3f) + _userAttributesVec3f = new Vec3fMap(*iBrother._userAttributesVec3f); + else + _userAttributesVec3f = NULL; +} + +StrokeAttribute::StrokeAttribute(float iRColor, + float iGColor, + float iBColor, + float iAlpha, + float iRThickness, + float iLThickness) +{ + _color[0] = iRColor; + _color[1] = iGColor; + _color[2] = iBColor; + + _alpha = iAlpha; + + _thickness[0] = iRThickness; + _thickness[1] = iLThickness; + + _visible = true; + + _userAttributesReal = NULL; + _userAttributesVec2f = NULL; + _userAttributesVec3f = NULL; +} + +StrokeAttribute::StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribute &a2, float t) +{ + _alpha = (1 - t) * a1._alpha + t * a2._alpha; + _thickness[0] = (1 - t) * a1._thickness[0] + t * a2._thickness[0]; + _thickness[1] = (1 - t) * a1._thickness[1] + t * a2._thickness[1]; + for (int i = 0; i < 3; ++i) + _color[i] = (1 - t) * a1._color[i] + t * a2._color[i]; + + _visible = a1.isVisible(); + + // FIXME: to be checked (and enhanced) + if ((a1._userAttributesReal) && (a2._userAttributesReal)) { + if (a1._userAttributesReal->size() == a2._userAttributesReal->size()) { + _userAttributesReal = new realMap; + realMap::iterator it1 = a1._userAttributesReal->begin(), + it1end = a1._userAttributesReal->end(); + realMap::iterator it2 = a2._userAttributesReal->begin(); + for (; it1 != it1end; ++it1, ++it2) { + (*_userAttributesReal)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); + } + } + } + else { + _userAttributesReal = NULL; + } + if ((a1._userAttributesVec2f) && (a2._userAttributesVec2f)) { + if (a1._userAttributesVec2f->size() == a2._userAttributesVec2f->size()) { + _userAttributesVec2f = new Vec2fMap; + Vec2fMap::iterator it1 = a1._userAttributesVec2f->begin(), + it1end = a1._userAttributesVec2f->end(); + Vec2fMap::iterator it2 = a2._userAttributesVec2f->begin(); + for (; it1 != it1end; ++it1, ++it2) { + (*_userAttributesVec2f)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); + } + } + } + else { + _userAttributesVec2f = NULL; + } + if ((a1._userAttributesVec3f) && (a2._userAttributesVec3f)) { + if (a1._userAttributesVec3f->size() == a2._userAttributesVec3f->size()) { + _userAttributesVec3f = new Vec3fMap; + Vec3fMap::iterator it1 = a1._userAttributesVec3f->begin(), + it1end = a1._userAttributesVec3f->end(); + Vec3fMap::iterator it2 = a2._userAttributesVec3f->begin(); + for (; it1 != it1end; ++it1, ++it2) { + (*_userAttributesVec3f)[(*it1).first] = ((1 - t) * (*it1).second + t * (*it2).second); + } + } + } + else { + _userAttributesVec3f = NULL; + } } StrokeAttribute::~StrokeAttribute() { - if (_userAttributesReal) { - _userAttributesReal->clear(); - delete _userAttributesReal; - } - if (_userAttributesVec2f) { - _userAttributesVec2f->clear(); - delete _userAttributesVec2f; - } - if (_userAttributesVec3f) { - _userAttributesVec3f->clear(); - delete _userAttributesVec3f; - } -} - -StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute& iBrother) -{ - int i; - _alpha = iBrother._alpha; - _thickness[0] = iBrother._thickness[0]; - _thickness[1] = iBrother._thickness[1]; - for (i = 0; i < 3; ++i) - _color[i] = iBrother._color[i]; - _visible = iBrother._visible; - if (iBrother._userAttributesReal) { - if (!_userAttributesReal) - _userAttributesReal = new realMap; - _userAttributesReal = new realMap(*(iBrother._userAttributesReal)); - } - else { - _userAttributesReal = NULL; - } - if (iBrother._userAttributesVec2f) { - if (!_userAttributesVec2f) - _userAttributesVec2f = new Vec2fMap; - _userAttributesVec2f = new Vec2fMap(*(iBrother._userAttributesVec2f)); - } - else { - _userAttributesVec2f = NULL; - } - if (iBrother._userAttributesVec3f) { - if (!_userAttributesVec3f) - _userAttributesVec3f = new Vec3fMap; - _userAttributesVec3f = new Vec3fMap(*(iBrother._userAttributesVec3f)); - } - else { - _userAttributesVec3f = NULL; - } - return *this; + if (_userAttributesReal) { + _userAttributesReal->clear(); + delete _userAttributesReal; + } + if (_userAttributesVec2f) { + _userAttributesVec2f->clear(); + delete _userAttributesVec2f; + } + if (_userAttributesVec3f) { + _userAttributesVec3f->clear(); + delete _userAttributesVec3f; + } +} + +StrokeAttribute &StrokeAttribute::operator=(const StrokeAttribute &iBrother) +{ + int i; + _alpha = iBrother._alpha; + _thickness[0] = iBrother._thickness[0]; + _thickness[1] = iBrother._thickness[1]; + for (i = 0; i < 3; ++i) + _color[i] = iBrother._color[i]; + _visible = iBrother._visible; + if (iBrother._userAttributesReal) { + if (!_userAttributesReal) + _userAttributesReal = new realMap; + _userAttributesReal = new realMap(*(iBrother._userAttributesReal)); + } + else { + _userAttributesReal = NULL; + } + if (iBrother._userAttributesVec2f) { + if (!_userAttributesVec2f) + _userAttributesVec2f = new Vec2fMap; + _userAttributesVec2f = new Vec2fMap(*(iBrother._userAttributesVec2f)); + } + else { + _userAttributesVec2f = NULL; + } + if (iBrother._userAttributesVec3f) { + if (!_userAttributesVec3f) + _userAttributesVec3f = new Vec3fMap; + _userAttributesVec3f = new Vec3fMap(*(iBrother._userAttributesVec3f)); + } + else { + _userAttributesVec3f = NULL; + } + return *this; } float StrokeAttribute::getAttributeReal(const char *iName) const { - if (!_userAttributesReal) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no real attribute was defined" << endl; - } - return 0.0f; - } - realMap::iterator a = _userAttributesReal->find(iName); - if (a == _userAttributesReal->end()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no real attribute was added with the name " << iName << endl; - } - return 0.0f; - } - return (*a).second; + if (!_userAttributesReal) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no real attribute was defined" << endl; + } + return 0.0f; + } + realMap::iterator a = _userAttributesReal->find(iName); + if (a == _userAttributesReal->end()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no real attribute was added with the name " << iName + << endl; + } + return 0.0f; + } + return (*a).second; } Vec2f StrokeAttribute::getAttributeVec2f(const char *iName) const { - if (!_userAttributesVec2f) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no Vec2f attribute was defined" << endl; - } - return 0; - } - Vec2fMap::iterator a = _userAttributesVec2f->find(iName); - if (a == _userAttributesVec2f->end()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no Vec2f attribute was added with the name " << iName << endl; - } - return 0; - } - return (*a).second; + if (!_userAttributesVec2f) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no Vec2f attribute was defined" << endl; + } + return 0; + } + Vec2fMap::iterator a = _userAttributesVec2f->find(iName); + if (a == _userAttributesVec2f->end()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no Vec2f attribute was added with the name " << iName + << endl; + } + return 0; + } + return (*a).second; } Vec3f StrokeAttribute::getAttributeVec3f(const char *iName) const { - if (!_userAttributesVec3f) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no Vec3f attribute was defined" << endl; - } - return 0; - } - Vec3fMap::iterator a = _userAttributesVec3f->find(iName); - if (a == _userAttributesVec3f->end()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "StrokeAttribute warning: no Vec3f attribute was added with the name " << iName << endl; - } - return 0; - } - return (*a).second; + if (!_userAttributesVec3f) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no Vec3f attribute was defined" << endl; + } + return 0; + } + Vec3fMap::iterator a = _userAttributesVec3f->find(iName); + if (a == _userAttributesVec3f->end()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "StrokeAttribute warning: no Vec3f attribute was added with the name " << iName + << endl; + } + return 0; + } + return (*a).second; } bool StrokeAttribute::isAttributeAvailableReal(const char *iName) const { - if (!_userAttributesReal) { - return false; - } - realMap::iterator a = _userAttributesReal->find(iName); - if (a == _userAttributesReal->end()) { - return false; - } - return true; + if (!_userAttributesReal) { + return false; + } + realMap::iterator a = _userAttributesReal->find(iName); + if (a == _userAttributesReal->end()) { + return false; + } + return true; } bool StrokeAttribute::isAttributeAvailableVec2f(const char *iName) const { - if (!_userAttributesVec2f) { - return false; - } - Vec2fMap::iterator a = _userAttributesVec2f->find(iName); - if (a == _userAttributesVec2f->end()) { - return false; - } - return true; + if (!_userAttributesVec2f) { + return false; + } + Vec2fMap::iterator a = _userAttributesVec2f->find(iName); + if (a == _userAttributesVec2f->end()) { + return false; + } + return true; } bool StrokeAttribute::isAttributeAvailableVec3f(const char *iName) const { - if (!_userAttributesVec3f) { - return false; - } - Vec3fMap::iterator a = _userAttributesVec3f->find(iName); - if (a == _userAttributesVec3f->end()) { - return false; - } - return true; + if (!_userAttributesVec3f) { + return false; + } + Vec3fMap::iterator a = _userAttributesVec3f->find(iName); + if (a == _userAttributesVec3f->end()) { + return false; + } + return true; } void StrokeAttribute::setAttributeReal(const char *iName, float att) { - if (!_userAttributesReal) - _userAttributesReal = new realMap; - (*_userAttributesReal)[iName] = att; + if (!_userAttributesReal) + _userAttributesReal = new realMap; + (*_userAttributesReal)[iName] = att; } -void StrokeAttribute::setAttributeVec2f(const char *iName, const Vec2f& att) +void StrokeAttribute::setAttributeVec2f(const char *iName, const Vec2f &att) { - if (!_userAttributesVec2f) - _userAttributesVec2f = new Vec2fMap; - (*_userAttributesVec2f)[iName] = att; + if (!_userAttributesVec2f) + _userAttributesVec2f = new Vec2fMap; + (*_userAttributesVec2f)[iName] = att; } -void StrokeAttribute::setAttributeVec3f(const char *iName, const Vec3f& att) +void StrokeAttribute::setAttributeVec3f(const char *iName, const Vec3f &att) { - if (!_userAttributesVec3f) - _userAttributesVec3f = new Vec3fMap; - (*_userAttributesVec3f)[iName] = att; + if (!_userAttributesVec3f) + _userAttributesVec3f = new Vec3fMap; + (*_userAttributesVec3f)[iName] = att; } - /**********************************/ /* */ /* */ @@ -319,59 +328,60 @@ void StrokeAttribute::setAttributeVec3f(const char *iName, const Vec3f& att) StrokeVertex::StrokeVertex() : CurvePoint() { - _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; + _CurvilignAbscissa = 0.0f; + _StrokeLength = 0.0f; } -StrokeVertex::StrokeVertex(const StrokeVertex& iBrother) : CurvePoint(iBrother) +StrokeVertex::StrokeVertex(const StrokeVertex &iBrother) : CurvePoint(iBrother) { - _Attribute = iBrother._Attribute; - _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; + _Attribute = iBrother._Attribute; + _CurvilignAbscissa = 0.0f; + _StrokeLength = 0.0f; } StrokeVertex::StrokeVertex(SVertex *iSVertex) : CurvePoint(iSVertex, 0, 0.0f) { - _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; + _CurvilignAbscissa = 0.0f; + _StrokeLength = 0.0f; } StrokeVertex::StrokeVertex(CurvePoint *iPoint) : CurvePoint(*iPoint) { - _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; + _CurvilignAbscissa = 0.0f; + _StrokeLength = 0.0f; } StrokeVertex::StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3) : CurvePoint(iA, iB, t3) { - // interpolate attributes: - _Attribute = StrokeAttribute(iA->attribute(), iB->attribute(), t3); - _CurvilignAbscissa = (1 - t3) * iA->curvilinearAbscissa() + t3 * iB->curvilinearAbscissa(); - _StrokeLength = iA->strokeLength(); + // interpolate attributes: + _Attribute = StrokeAttribute(iA->attribute(), iB->attribute(), t3); + _CurvilignAbscissa = (1 - t3) * iA->curvilinearAbscissa() + t3 * iB->curvilinearAbscissa(); + _StrokeLength = iA->strokeLength(); } -StrokeVertex::StrokeVertex(SVertex *iSVertex, const StrokeAttribute& iAttribute) : CurvePoint(iSVertex, 0, 0.0f) +StrokeVertex::StrokeVertex(SVertex *iSVertex, const StrokeAttribute &iAttribute) + : CurvePoint(iSVertex, 0, 0.0f) { - _Attribute = iAttribute; - _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; + _Attribute = iAttribute; + _CurvilignAbscissa = 0.0f; + _StrokeLength = 0.0f; } -StrokeVertex::~StrokeVertex() {} +StrokeVertex::~StrokeVertex() +{ +} -StrokeVertex& StrokeVertex::operator=(const StrokeVertex& iBrother) +StrokeVertex &StrokeVertex::operator=(const StrokeVertex &iBrother) { - ((CurvePoint *)this)->operator=(iBrother); - _Attribute = iBrother._Attribute; + ((CurvePoint *)this)->operator=(iBrother); + _Attribute = iBrother._Attribute; - _CurvilignAbscissa = 0.0f; + _CurvilignAbscissa = 0.0f; - _StrokeLength = 0.0f; - return *this; + _StrokeLength = 0.0f; + return *this; } - - /**********************************/ /* */ /* */ @@ -382,437 +392,446 @@ StrokeVertex& StrokeVertex::operator=(const StrokeVertex& iBrother) Stroke::Stroke() { - _Length = 0; - _id = 0; - _sampling = FLT_MAX; - //_mediumType = DEFAULT_STROKE; - _mediumType = OPAQUE_MEDIUM; - _textureId = 0; - _textureStep = 1.0; - for (int a = 0; a < MAX_MTEX; a++) { - _mtex[a] = NULL; - } - _nodeTree = NULL; - _tips = false; - _rep = NULL; -} - -Stroke::Stroke(const Stroke& iBrother) -{ - for (vertex_container::const_iterator v = iBrother._Vertices.begin(), vend = iBrother._Vertices.end(); - v != vend; - v++) - { - _Vertices.push_back(*v); - } - _Length = 0; - _id = iBrother._id; - _ViewEdges = iBrother._ViewEdges; - _sampling = iBrother._sampling; - _mediumType = iBrother._mediumType; - _textureId = iBrother._textureId; - _textureStep = iBrother._textureStep; - for (int a = 0; a < MAX_MTEX; a++) { - _mtex[a] = iBrother._mtex[a]; - } - _nodeTree = iBrother._nodeTree; - _tips = iBrother._tips; - if (iBrother._rep) - _rep = new StrokeRep(*(iBrother._rep)); - else - _rep = NULL; + _Length = 0; + _id = 0; + _sampling = FLT_MAX; + //_mediumType = DEFAULT_STROKE; + _mediumType = OPAQUE_MEDIUM; + _textureId = 0; + _textureStep = 1.0; + for (int a = 0; a < MAX_MTEX; a++) { + _mtex[a] = NULL; + } + _nodeTree = NULL; + _tips = false; + _rep = NULL; +} + +Stroke::Stroke(const Stroke &iBrother) +{ + for (vertex_container::const_iterator v = iBrother._Vertices.begin(), + vend = iBrother._Vertices.end(); + v != vend; + v++) { + _Vertices.push_back(*v); + } + _Length = 0; + _id = iBrother._id; + _ViewEdges = iBrother._ViewEdges; + _sampling = iBrother._sampling; + _mediumType = iBrother._mediumType; + _textureId = iBrother._textureId; + _textureStep = iBrother._textureStep; + for (int a = 0; a < MAX_MTEX; a++) { + _mtex[a] = iBrother._mtex[a]; + } + _nodeTree = iBrother._nodeTree; + _tips = iBrother._tips; + if (iBrother._rep) + _rep = new StrokeRep(*(iBrother._rep)); + else + _rep = NULL; } Stroke::~Stroke() { - if (!_Vertices.empty()) { - for (vertex_container::iterator v = _Vertices.begin(), vend = _Vertices.end(); v != vend; v++) { - delete (*v); - } - _Vertices.clear(); - } - - _ViewEdges.clear(); - if (_rep) { - delete _rep; - _rep = NULL; - } -} - -Stroke& Stroke::operator=(const Stroke& iBrother) -{ - if (!_Vertices.empty()) - _Vertices.clear(); - - for (vertex_container::const_iterator v = iBrother._Vertices.begin(), vend = iBrother._Vertices.end(); - v != vend; - v++) - { - _Vertices.push_back(*v); - } - _Length = iBrother._Length; - _id = iBrother._id; - _ViewEdges = iBrother._ViewEdges; - _sampling = iBrother._sampling; - if (_rep) - delete _rep; - if (iBrother._rep) - _rep = new StrokeRep(*(iBrother._rep)); - else - _rep = NULL; - return *this; + if (!_Vertices.empty()) { + for (vertex_container::iterator v = _Vertices.begin(), vend = _Vertices.end(); v != vend; + v++) { + delete (*v); + } + _Vertices.clear(); + } + + _ViewEdges.clear(); + if (_rep) { + delete _rep; + _rep = NULL; + } +} + +Stroke &Stroke::operator=(const Stroke &iBrother) +{ + if (!_Vertices.empty()) + _Vertices.clear(); + + for (vertex_container::const_iterator v = iBrother._Vertices.begin(), + vend = iBrother._Vertices.end(); + v != vend; + v++) { + _Vertices.push_back(*v); + } + _Length = iBrother._Length; + _id = iBrother._id; + _ViewEdges = iBrother._ViewEdges; + _sampling = iBrother._sampling; + if (_rep) + delete _rep; + if (iBrother._rep) + _rep = new StrokeRep(*(iBrother._rep)); + else + _rep = NULL; + return *this; } void Stroke::setLength(float iLength) { - _Length = iLength; - for (vertex_container::iterator v = _Vertices.begin(), vend = _Vertices.end(); v != vend; ++v) { - (*v)->setStrokeLength(iLength); - } + _Length = iLength; + for (vertex_container::iterator v = _Vertices.begin(), vend = _Vertices.end(); v != vend; ++v) { + (*v)->setStrokeLength(iLength); + } } float Stroke::ComputeSampling(int iNVertices) { - if (iNVertices <= (int)_Vertices.size()) //soc - return _sampling; - - float sampling = _Length / (float)(iNVertices - _Vertices.size() + 1); - return sampling; -} - -class StrokeSegment -{ -public: - StrokeInternal::StrokeVertexIterator _begin; - StrokeInternal::StrokeVertexIterator _end; - float _length; - int _n; - float _sampling; - bool _resampled; - - StrokeSegment(StrokeInternal::StrokeVertexIterator ibegin, StrokeInternal::StrokeVertexIterator iend, - float ilength, int in, float isampling) - { - _begin = ibegin; - _end = iend; - _length = ilength; - _n = in; - _sampling = isampling; - _resampled = false; - } + if (iNVertices <= (int)_Vertices.size()) //soc + return _sampling; + + float sampling = _Length / (float)(iNVertices - _Vertices.size() + 1); + return sampling; +} + +class StrokeSegment { + public: + StrokeInternal::StrokeVertexIterator _begin; + StrokeInternal::StrokeVertexIterator _end; + float _length; + int _n; + float _sampling; + bool _resampled; + + StrokeSegment(StrokeInternal::StrokeVertexIterator ibegin, + StrokeInternal::StrokeVertexIterator iend, + float ilength, + int in, + float isampling) + { + _begin = ibegin; + _end = iend; + _length = ilength; + _n = in; + _sampling = isampling; + _resampled = false; + } }; int Stroke::Resample(int iNPoints) { - int NPointsToAdd = iNPoints - strokeVerticesSize(); - if (NPointsToAdd <= 0) - return 0; - - StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator next = it; - ++next; - StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd(); - - vertex_container newVertices; - real t = 0.0f; - StrokeVertex *newVertex = NULL; - vector strokeSegments; - int N = 0; - float meanlength = 0; - int nsegments = 0; - while ((it != itend) && (next != itend)) { - Vec2r a((it)->getPoint()); - Vec2r b((next)->getPoint()); - Vec2r vec_tmp(b - a); - real norm_var = vec_tmp.norm(); - int numberOfPointsToAdd = (int)floor(NPointsToAdd * norm_var / _Length); - float csampling = norm_var / (float)(numberOfPointsToAdd + 1); - strokeSegments.push_back(StrokeSegment(it, next, norm_var, numberOfPointsToAdd, csampling)); - N += numberOfPointsToAdd; - meanlength += norm_var; - ++nsegments; - ++it; - ++next; - } - meanlength /= (float)nsegments; - - // if we don't have enough points let's resample finer some segments - bool checkEveryone = false; - bool resampled; - while (N < NPointsToAdd) { - resampled = false; - for (vector::iterator s = strokeSegments.begin(), send = strokeSegments.end(); s != send; ++s) { - if (s->_sampling == 0.0f) - continue; - - if (s->_resampled == false) { - if ((!checkEveryone) && (s->_length < meanlength)) - continue; - //resample - s->_n = s->_n + 1; - s->_sampling = s->_length / (float)(s->_n + 1); - s->_resampled = resampled = true; - N++; - if (N == NPointsToAdd) - break; - } - } - if (checkEveryone && !resampled) - break; - checkEveryone = true; - } - if (N < NPointsToAdd) { - // fatal error, likely because _Length is inconsistent with the stroke length computed with the vertices - return -1; - } - //actually resample: - for (vector::iterator s = strokeSegments.begin(), send = strokeSegments.end(); s != send; ++s) { - newVertices.push_back(&(*(s->_begin))); - if (s->_sampling < _sampling) - _sampling = s->_sampling; - - t = s->_sampling / s->_length; - for (int i = 0; i < s->_n; ++i) { - newVertex = new StrokeVertex(&(*(s->_begin)), &(*(s->_end)), t); - newVertices.push_back(newVertex); - t += s->_sampling / s->_length; - } - it = s->_begin; - next = s->_end; - } - - // add last: - ++it; - ++next; - if ((it != itend) && (next == itend)/* && (t == 0.0f)*/) - newVertices.push_back(&(*it)); - - int newsize = newVertices.size(); - if (newsize != iNPoints) - cerr << "Warning: incorrect points number" << endl; - - _Vertices.clear(); - _Vertices = newVertices; - newVertices.clear(); - - return 0; + int NPointsToAdd = iNPoints - strokeVerticesSize(); + if (NPointsToAdd <= 0) + return 0; + + StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator next = it; + ++next; + StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd(); + + vertex_container newVertices; + real t = 0.0f; + StrokeVertex *newVertex = NULL; + vector strokeSegments; + int N = 0; + float meanlength = 0; + int nsegments = 0; + while ((it != itend) && (next != itend)) { + Vec2r a((it)->getPoint()); + Vec2r b((next)->getPoint()); + Vec2r vec_tmp(b - a); + real norm_var = vec_tmp.norm(); + int numberOfPointsToAdd = (int)floor(NPointsToAdd * norm_var / _Length); + float csampling = norm_var / (float)(numberOfPointsToAdd + 1); + strokeSegments.push_back(StrokeSegment(it, next, norm_var, numberOfPointsToAdd, csampling)); + N += numberOfPointsToAdd; + meanlength += norm_var; + ++nsegments; + ++it; + ++next; + } + meanlength /= (float)nsegments; + + // if we don't have enough points let's resample finer some segments + bool checkEveryone = false; + bool resampled; + while (N < NPointsToAdd) { + resampled = false; + for (vector::iterator s = strokeSegments.begin(), send = strokeSegments.end(); + s != send; + ++s) { + if (s->_sampling == 0.0f) + continue; + + if (s->_resampled == false) { + if ((!checkEveryone) && (s->_length < meanlength)) + continue; + //resample + s->_n = s->_n + 1; + s->_sampling = s->_length / (float)(s->_n + 1); + s->_resampled = resampled = true; + N++; + if (N == NPointsToAdd) + break; + } + } + if (checkEveryone && !resampled) + break; + checkEveryone = true; + } + if (N < NPointsToAdd) { + // fatal error, likely because _Length is inconsistent with the stroke length computed with the vertices + return -1; + } + //actually resample: + for (vector::iterator s = strokeSegments.begin(), send = strokeSegments.end(); + s != send; + ++s) { + newVertices.push_back(&(*(s->_begin))); + if (s->_sampling < _sampling) + _sampling = s->_sampling; + + t = s->_sampling / s->_length; + for (int i = 0; i < s->_n; ++i) { + newVertex = new StrokeVertex(&(*(s->_begin)), &(*(s->_end)), t); + newVertices.push_back(newVertex); + t += s->_sampling / s->_length; + } + it = s->_begin; + next = s->_end; + } + + // add last: + ++it; + ++next; + if ((it != itend) && (next == itend) /* && (t == 0.0f)*/) + newVertices.push_back(&(*it)); + + int newsize = newVertices.size(); + if (newsize != iNPoints) + cerr << "Warning: incorrect points number" << endl; + + _Vertices.clear(); + _Vertices = newVertices; + newVertices.clear(); + + return 0; } int Stroke::Resample(float iSampling) { - //cerr << "old size :" << strokeVerticesSize() << endl; - if (iSampling == 0) - return 0; - if (iSampling >= _sampling) - return 0; - - _sampling = iSampling; - // Resample... - //real curvilinearLength = 0.0f; - vertex_container newVertices; - real t = 0.0f; - const real limit = 0.99; - StrokeVertex *newVertex = NULL; - StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator next = it; - ++next; - StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd(); - while ((it != itend) && (next != itend)) { - newVertices.push_back(&(*it)); - Vec2r a((it)->getPoint()); - Vec2r b((next)->getPoint()); - Vec2r vec_tmp(b - a); - real norm_var = vec_tmp.norm(); - if (norm_var <= _sampling) { - //curvilinearLength += norm_var; - ++it; - ++next; - continue; - } - - //curvilinearLength += _sampling; - t = _sampling / norm_var; - while (t < limit) { - newVertex = new StrokeVertex(&(*it), &(*next), t); - //newVertex->setCurvilinearAbscissa(curvilinearLength); - newVertices.push_back(newVertex); - t = t + _sampling / norm_var; - } - ++it; - ++next; - } - // add last: - if ((it != itend) && (next == itend)/* && (t == 0.f)*/) - newVertices.push_back(&(*it)); - - _Vertices.clear(); - _Vertices = newVertices; - newVertices.clear(); - - return 0; + //cerr << "old size :" << strokeVerticesSize() << endl; + if (iSampling == 0) + return 0; + if (iSampling >= _sampling) + return 0; + + _sampling = iSampling; + // Resample... + //real curvilinearLength = 0.0f; + vertex_container newVertices; + real t = 0.0f; + const real limit = 0.99; + StrokeVertex *newVertex = NULL; + StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator next = it; + ++next; + StrokeInternal::StrokeVertexIterator itend = strokeVerticesEnd(); + while ((it != itend) && (next != itend)) { + newVertices.push_back(&(*it)); + Vec2r a((it)->getPoint()); + Vec2r b((next)->getPoint()); + Vec2r vec_tmp(b - a); + real norm_var = vec_tmp.norm(); + if (norm_var <= _sampling) { + //curvilinearLength += norm_var; + ++it; + ++next; + continue; + } + + //curvilinearLength += _sampling; + t = _sampling / norm_var; + while (t < limit) { + newVertex = new StrokeVertex(&(*it), &(*next), t); + //newVertex->setCurvilinearAbscissa(curvilinearLength); + newVertices.push_back(newVertex); + t = t + _sampling / norm_var; + } + ++it; + ++next; + } + // add last: + if ((it != itend) && (next == itend) /* && (t == 0.f)*/) + newVertices.push_back(&(*it)); + + _Vertices.clear(); + _Vertices = newVertices; + newVertices.clear(); + + return 0; } void Stroke::RemoveAllVertices() { - vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); - for (; it != itend; ++it) - delete (*it); - _Vertices.clear(); - UpdateLength(); + vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); + for (; it != itend; ++it) + delete (*it); + _Vertices.clear(); + UpdateLength(); } void Stroke::RemoveVertex(StrokeVertex *iVertex) { - vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); - for (; it != itend; ++it) { - if ((*it) == iVertex) { - delete iVertex; - it = _Vertices.erase(it); // it is now the element just after the erased element - break; - } - } - UpdateLength(); + vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); + for (; it != itend; ++it) { + if ((*it) == iVertex) { + delete iVertex; + it = _Vertices.erase(it); // it is now the element just after the erased element + break; + } + } + UpdateLength(); } void Stroke::InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next) { - vertex_container::iterator itnext = next.getIt(); - _Vertices.insert(itnext, iVertex); - UpdateLength(); + vertex_container::iterator itnext = next.getIt(); + _Vertices.insert(itnext, iVertex); + UpdateLength(); } void Stroke::UpdateLength() { - // recompute curvilinear abscissa and stroke length - float curvabsc = 0.0f; - vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); - vertex_container::iterator previous = it; - for (; it != itend; ++it) { - curvabsc += ((*it)->getPoint() - (*previous)->getPoint()).norm(); - (*it)->setCurvilinearAbscissa(curvabsc); - previous = it; - } - _Length = curvabsc; - for (it = _Vertices.begin(); it != itend; ++it) { - (*it)->setStrokeLength(_Length); - } + // recompute curvilinear abscissa and stroke length + float curvabsc = 0.0f; + vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); + vertex_container::iterator previous = it; + for (; it != itend; ++it) { + curvabsc += ((*it)->getPoint() - (*previous)->getPoint()).norm(); + (*it)->setCurvilinearAbscissa(curvabsc); + previous = it; + } + _Length = curvabsc; + for (it = _Vertices.begin(); it != itend; ++it) { + (*it)->setStrokeLength(_Length); + } } //! embedding vertex iterator Stroke::const_vertex_iterator Stroke::vertices_begin() const { - return const_vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); + return const_vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); } Stroke::const_vertex_iterator Stroke::vertices_end() const { - return const_vertex_iterator(_Vertices.end(), _Vertices.begin(), _Vertices.end()); + return const_vertex_iterator(_Vertices.end(), _Vertices.begin(), _Vertices.end()); } Stroke::vertex_iterator Stroke::vertices_end() { - return vertex_iterator(_Vertices.end(), _Vertices.begin(), _Vertices.end()); + return vertex_iterator(_Vertices.end(), _Vertices.begin(), _Vertices.end()); } StrokeInternal::StrokeVertexIterator Stroke::strokeVerticesBegin(float t) { - if ((t != 0) && (t < _sampling)) - Resample(t); - return StrokeInternal::StrokeVertexIterator(this->_Vertices.begin(), this->_Vertices.begin(), - this->_Vertices.end()); + if ((t != 0) && (t < _sampling)) + Resample(t); + return StrokeInternal::StrokeVertexIterator( + this->_Vertices.begin(), this->_Vertices.begin(), this->_Vertices.end()); } StrokeInternal::StrokeVertexIterator Stroke::strokeVerticesEnd() { - return StrokeInternal::StrokeVertexIterator(this->_Vertices.end(), this->_Vertices.begin(), this->_Vertices.end()); + return StrokeInternal::StrokeVertexIterator( + this->_Vertices.end(), this->_Vertices.begin(), this->_Vertices.end()); } Interface0DIterator Stroke::verticesBegin() { -Interface0DIterator ret(new StrokeInternal::StrokeVertexIterator(this->_Vertices.begin(), this->_Vertices.begin(), - this->_Vertices.end())); -return ret; + Interface0DIterator ret(new StrokeInternal::StrokeVertexIterator( + this->_Vertices.begin(), this->_Vertices.begin(), this->_Vertices.end())); + return ret; } Interface0DIterator Stroke::verticesEnd() { - Interface0DIterator ret(new StrokeInternal::StrokeVertexIterator(this->_Vertices.end(), this->_Vertices.begin(), - this->_Vertices.end())); - return ret; + Interface0DIterator ret(new StrokeInternal::StrokeVertexIterator( + this->_Vertices.end(), this->_Vertices.begin(), this->_Vertices.end())); + return ret; } Interface0DIterator Stroke::pointsBegin(float /*t*/) { - return verticesBegin(); // FIXME + return verticesBegin(); // FIXME } Interface0DIterator Stroke::pointsEnd(float /*t*/) { - return verticesEnd(); + return verticesEnd(); } void Stroke::ScaleThickness(float iFactor) { - for (vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); it != itend; ++it) { - StrokeAttribute& attr = (*it)->attribute(); - attr.setThickness(iFactor * attr.getThicknessR(), iFactor * attr.getThicknessL()); - } + for (vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); it != itend; + ++it) { + StrokeAttribute &attr = (*it)->attribute(); + attr.setThickness(iFactor * attr.getThicknessR(), iFactor * attr.getThicknessL()); + } } void Stroke::Render(const StrokeRenderer *iRenderer) { - if (!_rep) - _rep = new StrokeRep(this); - iRenderer->RenderStrokeRep(_rep); + if (!_rep) + _rep = new StrokeRep(this); + iRenderer->RenderStrokeRep(_rep); } void Stroke::RenderBasic(const StrokeRenderer *iRenderer) { - if (!_rep) - _rep = new StrokeRep(this); - iRenderer->RenderStrokeRep(_rep); + if (!_rep) + _rep = new StrokeRep(this); + iRenderer->RenderStrokeRep(_rep); } Stroke::vertex_iterator Stroke::vertices_begin(float sampling) { - // Resample if necessary - if ((sampling != 0) && (sampling < _sampling)) - Resample(sampling); - return vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); - //return _Vertices.begin(); + // Resample if necessary + if ((sampling != 0) && (sampling < _sampling)) + Resample(sampling); + return vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); + //return _Vertices.begin(); } #if 0 Stroke::vertex_iterator Stroke::vertices_last() { - vertex_iterator res = vertices_begin(); - vertex_iterator next = res; - ++next; - while (!next.end()) { - ++next; - ++res; - } - return res; + vertex_iterator res = vertices_begin(); + vertex_iterator next = res; + ++next; + while (!next.end()) { + ++next; + ++res; + } + return res; } Stroke::const_vertex_iterator Stroke::vertices_last() const { - const_vertex_iterator res = vertices_begin(); - const_vertex_iterator next = res; - ++next; - while (!next.end()) { - ++next; - ++res; - } - return res; + const_vertex_iterator res = vertices_begin(); + const_vertex_iterator next = res; + ++next; + while (!next.end()) { + ++next; + ++res; + } + return res; } Stroke::vertex_container::reverse_iterator Stroke::vertices_last(float sampling) { - // Resample if necessary - if (sampling < _sampling) - Resample(sampling); - return _Vertices.rbegin(); + // Resample if necessary + if (sampling < _sampling) + Resample(sampling); + return _Vertices.rbegin(); } @@ -820,146 +839,146 @@ inline Vec3r shaded_color(int iCombination = 0) const; inline Vec<3, real> Stroke::orientation2d(const_vertex_iterator it) const { - return iterator_edge_orientation2d_function(this, it); + return iterator_edge_orientation2d_function(this, it); } Vec3r Stroke::orientation2d(int iCombination) const { - return edge_orientation2d_function(*this, iCombination); + return edge_orientation2d_function(*this, iCombination); } inline Vec3r Stroke::orientation3d(const_vertex_iterator it) const { - return iterator_edge_orientation3d_function(*this, it); + return iterator_edge_orientation3d_function(*this, it); } Vec3r Stroke::orientation3d(int iCombination) const { - return edge_orientation3d_function(*this, iCombination); + return edge_orientation3d_function(*this, iCombination); } Material Stroke::material() const { - const_vertex_iterator v = vertices_begin(), vend = strokeVerticesEnd(); - Material mat = (*v)->material(); - for (; v != vend; ++v) { - if (mat != (*v)->material()) - Exception::raiseException(); - } - return mat; + const_vertex_iterator v = vertices_begin(), vend = strokeVerticesEnd(); + Material mat = (*v)->material(); + for (; v != vend; ++v) { + if (mat != (*v)->material()) + Exception::raiseException(); + } + return mat; } int Stroke::qi() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - int qi_= (*v)->qi(); - for (; v != vend; ++v) { - if ((*v)->qi() != qi_) - Exception::raiseException(); - } - return qi_; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + int qi_= (*v)->qi(); + for (; v != vend; ++v) { + if ((*v)->qi() != qi_) + Exception::raiseException(); + } + return qi_; } inline occluder_container::const_iterator occluders_begin() const { - return _FEdgeA->occluders().begin(); + return _FEdgeA->occluders().begin(); } inline occluder_container::const_iterator occluders_end() const { - return _FEdgeA->occluders().end(); + return _FEdgeA->occluders().end(); } int Stroke::occluders_size() const { - return qi(); + return qi(); } bool Stroke::occluders_empty() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - bool empty = (*v)->occluders_empty(); - for (; v != vend; ++v) { - if ((*v)->occluders_empty() != empty) - Exception::raiseException(); - } - return empty; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + bool empty = (*v)->occluders_empty(); + for (; v != vend; ++v) { + if ((*v)->occluders_empty() != empty) + Exception::raiseException(); + } + return empty; } -#if 0 +# if 0 inline const polygon3d& occludee() const { - return *(_FEdgeA->aFace()); + return *(_FEdgeA->aFace()); } -#endif +# endif const SShape *Stroke::occluded_shape() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - const SShape *sshape = (*v)->occluded_shape(); - for (; v != vend; ++v) { - if ((*v)->occluded_shape() != sshape) - Exception::raiseException(); - } - return sshape; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + const SShape *sshape = (*v)->occluded_shape(); + for (; v != vend; ++v) { + if ((*v)->occluded_shape() != sshape) + Exception::raiseException(); + } + return sshape; } const bool Stroke::occludee_empty() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - bool empty = (*v)->occludee_empty(); - for (; v != vend; ++v) { - if ((*v)->occludee_empty() != empty) - Exception::raiseException(); - } - return empty; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + bool empty = (*v)->occludee_empty(); + for (; v != vend; ++v) { + if ((*v)->occludee_empty() != empty) + Exception::raiseException(); + } + return empty; } const SShape *Stroke::shape() const { - const_vertex_iterator v = vertices_begin(), vend = vertices_end(); - const SShape *sshape = (*v)->shape(); - for (; v != vend; ++v) { - if ((*v)->shape() != sshape) - Exception::raiseException(); - } - return sshape; + const_vertex_iterator v = vertices_begin(), vend = vertices_end(); + const SShape *sshape = (*v)->shape(); + for (; v != vend; ++v) { + if ((*v)->shape() != sshape) + Exception::raiseException(); + } + return sshape; } real Stroke::z_discontinuity(int iCombination) const { - return z_discontinuity_edge_function(*this, iCombination); + return z_discontinuity_edge_function(*this, iCombination); } Vec3r Stroke::curvature2d_as_vector(int iCombination) const { - return curvature2d_as_vector_edge_function(*this, iCombination); + return curvature2d_as_vector_edge_function(*this, iCombination); } real Stroke::curvature2d_as_angle(int iCombination) const { - return curvature2d_as_angle_edge_function(*this, iCombination); + return curvature2d_as_angle_edge_function(*this, iCombination); } float Stroke::shape_importance(int iCombination) const { - return shape_importance_edge_function(*this, iCombination); + return shape_importance_edge_function(*this, iCombination); } float Stroke::local_average_depth(int iCombination ) const { - return local_average_depth_edge_function(*this, iCombination); + return local_average_depth_edge_function(*this, iCombination); } float Stroke::local_depth_variance(int iCombination) const { - return local_depth_variance_edge_function(*this, iCombination); + return local_depth_variance_edge_function(*this, iCombination); } real Stroke::local_average_density(float sigma , int iCombination ) const { - return density_edge_function(*this, iCombination); + return density_edge_function(*this, iCombination); } #endif diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index bc335b2252e..3eae5e91b6a 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -34,7 +34,7 @@ #include "../system/StringUtils.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif extern "C" { @@ -43,7 +43,7 @@ struct bNodeTree; } #ifndef MAX_MTEX -#define MAX_MTEX 18 +# define MAX_MTEX 18 #endif namespace Freestyle { @@ -56,427 +56,428 @@ namespace Freestyle { /*! Class to define an attribute associated to a Stroke Vertex. * This attribute stores the color, alpha and thickness values for a Stroke Vertex. */ -class StrokeAttribute -{ -public: - /*! default constructor */ - StrokeAttribute(); - - /*! Copy constructor */ - StrokeAttribute(const StrokeAttribute& iBrother); - - /*! Builds a stroke vertex attribute from a set of parameters. - * \param iRColor: - * The Red Component value. - * \param iGColor: - * The Green Component value. - * \param iBColor: - * The Blue Component value. - * \param iAlpha: - * The transparency value - * \param iRThickness: - * The thickness of the stroke on the right - * \param iLThickness: - * The Thickness of the stroke on the left - */ - StrokeAttribute(float iRColor, float iGColor, float iBColor, float iAlpha, float iRThickness, float iLThickness); - - /*! Interpolation constructor. - * Builds a StrokeAttribute from two StrokeAttributes and an interpolation parameter. - * \param a1: - * The first Attribute. - * \param a2: - * The second parameter. - * \param t: - * The interpolation parameter. - */ - StrokeAttribute(const StrokeAttribute& a1, const StrokeAttribute& a2, float t); - - /*! destructor */ - virtual ~StrokeAttribute(); - - /* operators */ - /*! operator = */ - StrokeAttribute& operator=(const StrokeAttribute& iBrother); - - /* accessors */ - /*! Returns the attribute's color. - * \return The array of 3 floats containing the R,G,B values of the attribute's color. - */ - inline const float *getColor() const - { - return _color; - } - - /*! Returns the R color component. */ - inline const float getColorR() const - { - return _color[0]; - } - - /*! Returns the G color component. */ - inline const float getColorG() const - { - return _color[1]; - } - - /*! Returns the B color component. */ - inline const float getColorB() const - { - return _color[2]; - } - - /*! Returns the RGB color components. */ - inline Vec3f getColorRGB() const - { - return Vec3f(_color[0], _color[1], _color[2]); - } - - /*! Returns the alpha color component. */ - inline float getAlpha() const - { - return _alpha; - } - - /*! Returns the attribute's thickness. - * \return an array of 2 floats. the first value is the thickness on the right of the vertex when following - * the stroke, the second one is the thickness on the left. - */ - inline const float *getThickness() const - { - return _thickness; - } - - /*! Returns the thickness on the right of the vertex when following the stroke. */ - inline const float getThicknessR() const - { - return _thickness[0]; - } - - /*! Returns the thickness on the left of the vertex when following the stroke. */ - inline const float getThicknessL() const - { - return _thickness[1]; - } - - /*! Returns the thickness on the right and on the left of the vertex when following the stroke. */ - inline Vec2f getThicknessRL() const - { - return Vec2f(_thickness[0], _thickness[1]); - } - - /*! Returns true if the strokevertex is visible, false otherwise */ - inline bool isVisible() const - { - return _visible; - } - - /*! Returns an attribute of type real - * \param iName: - * The name of the attribute - */ - float getAttributeReal(const char *iName) const; - - /*! Returns an attribute of type Vec2f - * \param iName: - * The name of the attribute - */ - Vec2f getAttributeVec2f(const char *iName) const; - - /*! Returns an attribute of type Vec3f - * \param iName: - * The name of the attribute - */ - Vec3f getAttributeVec3f(const char *iName) const; - - /*! Checks whether the attribute iName is availbale */ - bool isAttributeAvailableReal(const char *iName) const; - - /*! Checks whether the attribute iName is availbale */ - bool isAttributeAvailableVec2f(const char *iName) const; - - /*! Checks whether the attribute iName is availbale */ - bool isAttributeAvailableVec3f(const char *iName) const; - - /* modifiers */ - /*! sets the attribute's color. - * \param r: - * The new R value. - * \param g: - * The new G value. - * \param b: - * The new B value. - */ - inline void setColor(float r, float g, float b) - { - _color[0] = r; - _color[1] = g; - _color[2] = b; - } - - /*! sets the attribute's color. - * \param iRGB: - * The new RGB values. - */ - inline void setColor(const Vec3f& iRGB) - { - _color[0] = iRGB[0]; - _color[1] = iRGB[1]; - _color[2] = iRGB[2]; - } - - /*! sets the attribute's alpha value. - * \param alpha: - * The new alpha value. - */ - inline void setAlpha(float alpha) - { - _alpha = alpha; - } - - /*! sets the attribute's thickness. - * \param tr: - * The thickness on the right of the vertex when following the stroke. - * \param tl: - * The thickness on the left of the vertex when following the stroke. - */ - inline void setThickness(float tr, float tl) - { - _thickness[0] = tr; - _thickness[1] = tl; - } - - /*! sets the attribute's thickness. - * \param tRL: - * The thickness on the right and on the left of the vertex when following the stroke. - */ - inline void setThickness(const Vec2f& tRL) - { - _thickness[0] = tRL[0]; - _thickness[1] = tRL[1]; - } - - /*! sets the visible flag. True means visible. */ - inline void setVisible(bool iVisible) - { - _visible = iVisible; - } - - /*! Adds a user defined attribute of type real - * If there is no attribute of name iName, it is added. - * Otherwise, the new value replaces the old one. - * \param iName: - * The name of the attribute - * \param att: - * The attribute's value - */ - void setAttributeReal(const char *iName, float att); - - /*! Adds a user defined attribute of type Vec2f - * If there is no attribute of name iName, it is added. - * Otherwise, the new value replaces the old one. - * \param iName: - * The name of the attribute - * \param att: - * The attribute's value - */ - void setAttributeVec2f(const char *iName, const Vec2f& att); - - /*! Adds a user defined attribute of type Vec3f - * If there is no attribute of name iName, it is added. - * Otherwise, the new value replaces the old one. - * \param iName: - * The name of the attribute - * \param att: - * The attribute's value - */ - void setAttributeVec3f(const char *iName, const Vec3f& att); - -private: - typedef std::map realMap; - typedef std::map Vec2fMap; - typedef std::map Vec3fMap; - - //! the color - float _color[3]; - //! alpha - float _alpha; - //! the thickness on the right and on the left of the backbone vertex (the stroke is oriented) - float _thickness[2]; - bool _visible; - realMap *_userAttributesReal; - Vec2fMap *_userAttributesVec2f; - Vec3fMap *_userAttributesVec3f; +class StrokeAttribute { + public: + /*! default constructor */ + StrokeAttribute(); + + /*! Copy constructor */ + StrokeAttribute(const StrokeAttribute &iBrother); + + /*! Builds a stroke vertex attribute from a set of parameters. + * \param iRColor: + * The Red Component value. + * \param iGColor: + * The Green Component value. + * \param iBColor: + * The Blue Component value. + * \param iAlpha: + * The transparency value + * \param iRThickness: + * The thickness of the stroke on the right + * \param iLThickness: + * The Thickness of the stroke on the left + */ + StrokeAttribute(float iRColor, + float iGColor, + float iBColor, + float iAlpha, + float iRThickness, + float iLThickness); + + /*! Interpolation constructor. + * Builds a StrokeAttribute from two StrokeAttributes and an interpolation parameter. + * \param a1: + * The first Attribute. + * \param a2: + * The second parameter. + * \param t: + * The interpolation parameter. + */ + StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribute &a2, float t); + + /*! destructor */ + virtual ~StrokeAttribute(); + + /* operators */ + /*! operator = */ + StrokeAttribute &operator=(const StrokeAttribute &iBrother); + + /* accessors */ + /*! Returns the attribute's color. + * \return The array of 3 floats containing the R,G,B values of the attribute's color. + */ + inline const float *getColor() const + { + return _color; + } + + /*! Returns the R color component. */ + inline const float getColorR() const + { + return _color[0]; + } + + /*! Returns the G color component. */ + inline const float getColorG() const + { + return _color[1]; + } + + /*! Returns the B color component. */ + inline const float getColorB() const + { + return _color[2]; + } + + /*! Returns the RGB color components. */ + inline Vec3f getColorRGB() const + { + return Vec3f(_color[0], _color[1], _color[2]); + } + + /*! Returns the alpha color component. */ + inline float getAlpha() const + { + return _alpha; + } + + /*! Returns the attribute's thickness. + * \return an array of 2 floats. the first value is the thickness on the right of the vertex when following + * the stroke, the second one is the thickness on the left. + */ + inline const float *getThickness() const + { + return _thickness; + } + + /*! Returns the thickness on the right of the vertex when following the stroke. */ + inline const float getThicknessR() const + { + return _thickness[0]; + } + + /*! Returns the thickness on the left of the vertex when following the stroke. */ + inline const float getThicknessL() const + { + return _thickness[1]; + } + + /*! Returns the thickness on the right and on the left of the vertex when following the stroke. */ + inline Vec2f getThicknessRL() const + { + return Vec2f(_thickness[0], _thickness[1]); + } + + /*! Returns true if the strokevertex is visible, false otherwise */ + inline bool isVisible() const + { + return _visible; + } + + /*! Returns an attribute of type real + * \param iName: + * The name of the attribute + */ + float getAttributeReal(const char *iName) const; + + /*! Returns an attribute of type Vec2f + * \param iName: + * The name of the attribute + */ + Vec2f getAttributeVec2f(const char *iName) const; + + /*! Returns an attribute of type Vec3f + * \param iName: + * The name of the attribute + */ + Vec3f getAttributeVec3f(const char *iName) const; + + /*! Checks whether the attribute iName is availbale */ + bool isAttributeAvailableReal(const char *iName) const; + + /*! Checks whether the attribute iName is availbale */ + bool isAttributeAvailableVec2f(const char *iName) const; + + /*! Checks whether the attribute iName is availbale */ + bool isAttributeAvailableVec3f(const char *iName) const; + + /* modifiers */ + /*! sets the attribute's color. + * \param r: + * The new R value. + * \param g: + * The new G value. + * \param b: + * The new B value. + */ + inline void setColor(float r, float g, float b) + { + _color[0] = r; + _color[1] = g; + _color[2] = b; + } + + /*! sets the attribute's color. + * \param iRGB: + * The new RGB values. + */ + inline void setColor(const Vec3f &iRGB) + { + _color[0] = iRGB[0]; + _color[1] = iRGB[1]; + _color[2] = iRGB[2]; + } + + /*! sets the attribute's alpha value. + * \param alpha: + * The new alpha value. + */ + inline void setAlpha(float alpha) + { + _alpha = alpha; + } + + /*! sets the attribute's thickness. + * \param tr: + * The thickness on the right of the vertex when following the stroke. + * \param tl: + * The thickness on the left of the vertex when following the stroke. + */ + inline void setThickness(float tr, float tl) + { + _thickness[0] = tr; + _thickness[1] = tl; + } + + /*! sets the attribute's thickness. + * \param tRL: + * The thickness on the right and on the left of the vertex when following the stroke. + */ + inline void setThickness(const Vec2f &tRL) + { + _thickness[0] = tRL[0]; + _thickness[1] = tRL[1]; + } + + /*! sets the visible flag. True means visible. */ + inline void setVisible(bool iVisible) + { + _visible = iVisible; + } + + /*! Adds a user defined attribute of type real + * If there is no attribute of name iName, it is added. + * Otherwise, the new value replaces the old one. + * \param iName: + * The name of the attribute + * \param att: + * The attribute's value + */ + void setAttributeReal(const char *iName, float att); + + /*! Adds a user defined attribute of type Vec2f + * If there is no attribute of name iName, it is added. + * Otherwise, the new value replaces the old one. + * \param iName: + * The name of the attribute + * \param att: + * The attribute's value + */ + void setAttributeVec2f(const char *iName, const Vec2f &att); + + /*! Adds a user defined attribute of type Vec3f + * If there is no attribute of name iName, it is added. + * Otherwise, the new value replaces the old one. + * \param iName: + * The name of the attribute + * \param att: + * The attribute's value + */ + void setAttributeVec3f(const char *iName, const Vec3f &att); + + private: + typedef std::map realMap; + typedef std::map Vec2fMap; + typedef std::map Vec3fMap; + + //! the color + float _color[3]; + //! alpha + float _alpha; + //! the thickness on the right and on the left of the backbone vertex (the stroke is oriented) + float _thickness[2]; + bool _visible; + realMap *_userAttributesReal; + Vec2fMap *_userAttributesVec2f; + Vec3fMap *_userAttributesVec3f; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeAttribute") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeAttribute") #endif }; - // // StrokeVertex // //////////////////////////////////////////////////////// /*! Class to define a stroke vertex. */ -class StrokeVertex : public CurvePoint -{ -public: // Implementation of Interface0D - /*! Returns the string "StrokeVertex" */ - virtual string getExactTypeName() const - { - return "StrokeVertex"; - } - -private: - StrokeAttribute _Attribute; //! The attribute associated to the vertex - float _CurvilignAbscissa; //! the curvilign abscissa - float _StrokeLength; // stroke length - -public: - /*! default constructor */ - StrokeVertex(); - - /*! Copy constructor */ - StrokeVertex(const StrokeVertex& iBrother); - - /*! Builds a stroke vertex from a SVertex */ - StrokeVertex(SVertex *iSVertex); - - /*! Builds a stroke vertex from a CurvePoint */ - StrokeVertex(CurvePoint *iPoint); - - /*! Builds Stroke Vertex from 2 stroke vertices and an interpolation parameter*/ - StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3); - - /*! Builds a stroke from a view vertex and an attribute */ - StrokeVertex(SVertex *iSVertex, const StrokeAttribute& iAttribute); - - /*! destructor */ - virtual ~StrokeVertex(); - - /* operators */ - /*! operator = */ - StrokeVertex& operator=(const StrokeVertex& iBrother); - - /* accessors */ - /*! Returns the 2D point x coordinate */ - inline real x() const - { - return _Point2d[0]; - } - - /*! Returns the 2D point y coordinate */ - inline real y() const - { - return _Point2d[1]; - } - - /*! Returns the 2D point coordinates as a Vec2r */ - inline Vec2r getPoint() const - { - return getPoint2D(); - } - - /*! Returns the ith 2D point coordinate (i=0 or 1)*/ - inline real operator[](const int i) const - { - return _Point2d[i]; - } - - /*! Returns the StrokeAttribute for this StrokeVertex */ - inline const StrokeAttribute& attribute() const - { - return _Attribute; - } - - /*! Returns a non-const reference to the StrokeAttribute of this StrokeVertex */ - inline StrokeAttribute& attribute() - { - return _Attribute; - } - - /*! Returns the curvilinear abscissa */ - inline float curvilinearAbscissa() const - { - return _CurvilignAbscissa; - } - - /*! Returns the length of the Stroke to which this StrokeVertex belongs */ - inline float strokeLength() const - { - return _StrokeLength; - } - - /*! Returns the curvilinear abscissa of this StrokeVertex in the Stroke */ - inline float u() const - { - return _CurvilignAbscissa / _StrokeLength; - } - - /* modifiers */ - /*! sets the 2D x value */ - inline void setX(real x) - { - _Point2d[0] = x; - } - - /*! sets the 2D y value */ - inline void setY(real y) - { - _Point2d[1] = y; - } - - /*! sets the 2D x and y values */ - inline void setPoint(real x, real y) - { - _Point2d[0] = x; - _Point2d[1] = y; - } - - /*! sets the 2D x and y values */ - inline void setPoint(const Vec2r& p) - { - _Point2d[0] = p[0]; - _Point2d[1] = p[1]; - } - - /*! Returns a reference to the ith 2D point coordinate (i=0 or 1) */ - inline real& operator[](const int i) - { - return _Point2d[i]; - } - - /*! sets the attribute. */ - inline void setAttribute(const StrokeAttribute& iAttribute) - { - _Attribute = iAttribute; - } - - /*! sets the curvilinear abscissa of this StrokeVertex in the Stroke */ - inline void setCurvilinearAbscissa(float iAbscissa) - { - _CurvilignAbscissa = iAbscissa; - } - - /*! sets the Stroke's length (it's only a value stored by the Stroke Vertex, it won't change the real - * Stroke's length.) - */ - inline void setStrokeLength(float iLength) - { - _StrokeLength = iLength; - } - - /* interface definition */ - /* inherited */ +class StrokeVertex : public CurvePoint { + public: // Implementation of Interface0D + /*! Returns the string "StrokeVertex" */ + virtual string getExactTypeName() const + { + return "StrokeVertex"; + } + + private: + StrokeAttribute _Attribute; //! The attribute associated to the vertex + float _CurvilignAbscissa; //! the curvilign abscissa + float _StrokeLength; // stroke length + + public: + /*! default constructor */ + StrokeVertex(); + + /*! Copy constructor */ + StrokeVertex(const StrokeVertex &iBrother); + + /*! Builds a stroke vertex from a SVertex */ + StrokeVertex(SVertex *iSVertex); + + /*! Builds a stroke vertex from a CurvePoint */ + StrokeVertex(CurvePoint *iPoint); + + /*! Builds Stroke Vertex from 2 stroke vertices and an interpolation parameter*/ + StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3); + + /*! Builds a stroke from a view vertex and an attribute */ + StrokeVertex(SVertex *iSVertex, const StrokeAttribute &iAttribute); + + /*! destructor */ + virtual ~StrokeVertex(); + + /* operators */ + /*! operator = */ + StrokeVertex &operator=(const StrokeVertex &iBrother); + + /* accessors */ + /*! Returns the 2D point x coordinate */ + inline real x() const + { + return _Point2d[0]; + } + + /*! Returns the 2D point y coordinate */ + inline real y() const + { + return _Point2d[1]; + } + + /*! Returns the 2D point coordinates as a Vec2r */ + inline Vec2r getPoint() const + { + return getPoint2D(); + } + + /*! Returns the ith 2D point coordinate (i=0 or 1)*/ + inline real operator[](const int i) const + { + return _Point2d[i]; + } + + /*! Returns the StrokeAttribute for this StrokeVertex */ + inline const StrokeAttribute &attribute() const + { + return _Attribute; + } + + /*! Returns a non-const reference to the StrokeAttribute of this StrokeVertex */ + inline StrokeAttribute &attribute() + { + return _Attribute; + } + + /*! Returns the curvilinear abscissa */ + inline float curvilinearAbscissa() const + { + return _CurvilignAbscissa; + } + + /*! Returns the length of the Stroke to which this StrokeVertex belongs */ + inline float strokeLength() const + { + return _StrokeLength; + } + + /*! Returns the curvilinear abscissa of this StrokeVertex in the Stroke */ + inline float u() const + { + return _CurvilignAbscissa / _StrokeLength; + } + + /* modifiers */ + /*! sets the 2D x value */ + inline void setX(real x) + { + _Point2d[0] = x; + } + + /*! sets the 2D y value */ + inline void setY(real y) + { + _Point2d[1] = y; + } + + /*! sets the 2D x and y values */ + inline void setPoint(real x, real y) + { + _Point2d[0] = x; + _Point2d[1] = y; + } + + /*! sets the 2D x and y values */ + inline void setPoint(const Vec2r &p) + { + _Point2d[0] = p[0]; + _Point2d[1] = p[1]; + } + + /*! Returns a reference to the ith 2D point coordinate (i=0 or 1) */ + inline real &operator[](const int i) + { + return _Point2d[i]; + } + + /*! sets the attribute. */ + inline void setAttribute(const StrokeAttribute &iAttribute) + { + _Attribute = iAttribute; + } + + /*! sets the curvilinear abscissa of this StrokeVertex in the Stroke */ + inline void setCurvilinearAbscissa(float iAbscissa) + { + _CurvilignAbscissa = iAbscissa; + } + + /*! sets the Stroke's length (it's only a value stored by the Stroke Vertex, it won't change the real + * Stroke's length.) + */ + inline void setStrokeLength(float iLength) + { + _StrokeLength = iLength; + } + + /* interface definition */ + /* inherited */ #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertex") #endif }; - // // Stroke // @@ -492,400 +493,404 @@ class vertex_nonconst_traits; template class vertex_iterator_base; class StrokeVertexIterator; -} // end of namespace StrokeInternal +} // end of namespace StrokeInternal /*! Class to define a stroke. * A stroke is made of a set of 2D vertices (StrokeVertex), regularly spaced out. * This set of vertices defines the stroke's backbone geometry. * Each of these stroke vertices defines the stroke's shape and appearance at this vertex position. */ -class Stroke : public Interface1D -{ -public: // Implementation of Interface1D - /*! Returns the string "Stroke" */ - virtual string getExactTypeName() const - { - return "Stroke"; - } - - // Data access methods - - /*! Returns the Id of the Stroke */ - virtual Id getId() const - { - return _id; - } - - /*! The different blending modes available to similate the interaction media-medium. */ - typedef enum { - DRY_MEDIUM, /*!< To simulate a dry medium such as Pencil or Charcoal.*/ - HUMID_MEDIUM, /*!< To simulate ink painting (color subtraction blending).*/ - OPAQUE_MEDIUM, /*!< To simulate an opaque medium (oil, spray...).*/ - } MediumType; - -public: - typedef std::deque vertex_container; // the vertices container - typedef std::vector viewedge_container; // the viewedges container - typedef StrokeInternal::vertex_iterator_base vertex_iterator; - typedef StrokeInternal::vertex_iterator_base const_vertex_iterator; - -public: - //typedef StrokeVertex vertex_type; - -private: - vertex_container _Vertices; //! The stroke's backbone vertices - Id _id; - float _Length; // The stroke length - viewedge_container _ViewEdges; - float _sampling; - float _textureStep; - // StrokeRenderer *_renderer; // mark implementation OpenGL renderer - MediumType _mediumType; - unsigned int _textureId; - MTex *_mtex[MAX_MTEX]; - bNodeTree *_nodeTree; - bool _tips; - StrokeRep *_rep; - Vec2r _extremityOrientations[2]; // the orientations of the first and last extermity - -public: - /*! default constructor */ - Stroke(); - - /*! copy constructor */ - Stroke(const Stroke& iBrother); - - /*! Builds a stroke from a set of StrokeVertex. - * This constructor is templated by an iterator type. - * This iterator type must allow the vertices parsing using the ++ operator. - * \param iBegin: - * The iterator pointing to the first vertex. - * \param iEnd: - * The iterator pointing to the end of the vertex list. - */ - template - Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd); - - /*! Destructor */ - virtual ~Stroke(); - - /* operators */ - /*! operator = */ - Stroke& operator=(const Stroke& iBrother); - - /*! Compute the sampling needed to get iNVertices vertices. - * If the specified number of vertices is less than the actual number of vertices, the actual sampling value - * is returned. (To remove Vertices, use the RemoveVertex() method of this class). - * \param iNVertices: - * The number of StrokeVertices we eventually want in our Stroke. - * \return the sampling that must be used in the Resample(float) method. - * \see Resample(int) - * \see Resample(float) - */ - float ComputeSampling(int iNVertices); - - /*! Resampling method. - * Resamples the curve so that it eventually has iNPoints. That means it is going to add iNPoints-vertices_size, - * if vertices_size is the number of points we already have. - * If vertices_size >= iNPoints, no resampling is done. - * \param iNPoints: - * The number of vertices we eventually want in our stroke. - */ - int Resample(int iNPoints); - - /*! Resampling method. - * Resamples the curve with a given sampling. - * If this sampling is < to the actual sampling value, no resampling is done. - * \param iSampling: - * The new sampling value. - */ - int Resample(float iSampling); - - /*! Removes all vertices from the Stroke. - */ - void RemoveAllVertices(); - - /*! Removes the stroke vertex iVertex - * from the stroke. - * The length and curvilinear abscissa are updated - * consequently. - */ - void RemoveVertex(StrokeVertex *iVertex); - - /*! Inserts the stroke vertex iVertex in the stroke before next. - * The length, curvilinear abscissa are updated consequently. - * \param iVertex: - * The StrokeVertex to insert in the Stroke. - * \param next: - * A StrokeVertexIterator pointing to the StrokeVeretx before which iVertex must be inserted. - */ - void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next); - - /*! Updates the 2D length of the Stroke */ - void UpdateLength(); - - /* Render method */ - void ScaleThickness(float iFactor); - void Render(const StrokeRenderer *iRenderer); - void RenderBasic(const StrokeRenderer *iRenderer); - - /* Iterator definition */ - - /* accessors */ - /*! Returns the 2D length of the Stroke */ - inline real getLength2D() const - { - return _Length; - } - - /*! Returns a reference to the time stamp value of the stroke. */ - /*! Returns the MediumType used for this Stroke. */ - inline MediumType getMediumType() const - { - return _mediumType; - } - - /*! Returns the id of the texture used to simulate th marks system for this Stroke */ - inline unsigned int getTextureId() {return _textureId;} - - /*! Returns the spacing of texture coordinates along the stroke lenght */ - inline float getTextureStep() {return _textureStep;} - - /*! Returns the texture used at given index to simulate the marks system for this Stroke */ - inline MTex *getMTex(int idx) { - return _mtex[idx]; - } - - /*! Return the shader node tree to define textures. */ - inline bNodeTree *getNodeTree() - { - return _nodeTree; - } - - /*! Returns true if this Stroke has textures assigned, false otherwise. */ - inline bool hasTex() const - { - return (_mtex[0] != NULL) || _nodeTree; - } - - /*! Returns true if this Stroke uses a texture with tips, false otherwise. */ - inline bool hasTips() const - { - return _tips; - } - - /* these advanced iterators are used only in C++ */ - inline int vertices_size() const - { - return _Vertices.size(); - } - - inline viewedge_container::const_iterator viewedges_begin() const - { - return _ViewEdges.begin(); - } - - inline viewedge_container::iterator viewedges_begin() - { - return _ViewEdges.begin(); - } - - inline viewedge_container::const_iterator viewedges_end() const - { - return _ViewEdges.end(); - } - - inline viewedge_container::iterator viewedges_end() - { - return _ViewEdges.end(); - } - - inline int viewedges_size() const - { - return _ViewEdges.size(); - } - - inline Vec2r getBeginningOrientation() const - { - return _extremityOrientations[0]; - } - - inline real getBeginningOrientationX() const - { - return _extremityOrientations[0].x(); - } - - inline real getBeginningOrientationY() const - { - return _extremityOrientations[0].y(); - } - - inline Vec2r getEndingOrientation() const - { - return _extremityOrientations[1]; - } - - inline real getEndingOrientationX() const - { - return _extremityOrientations[1].x(); - } - - inline real getEndingOrientationY() const - { - return _extremityOrientations[1].y(); - } - - - /* modifiers */ - /*! sets the Id of the Stroke. */ - inline void setId(const Id& id) - { - _id = id; - } - - /*! sets the 2D length of the Stroke. */ - void setLength(float iLength); - - /*! sets the medium type that must be used for this Stroke. */ - inline void setMediumType(MediumType iType) - { - _mediumType = iType; - } - - /*! sets the texture id to be used to simulate the marks system for this Stroke. */ - inline void setTextureId(unsigned int id) - { - _textureId = id; - } - - /*! sets the spacing of texture coordinates along the stroke lenght. */ - inline void setTextureStep(float step) - { - _textureStep = step; - } - - /*! assigns a blender texture to the first available slot. */ - inline int setMTex(MTex *mtex) - { - for (int a = 0; a < MAX_MTEX; a++) { - if (!_mtex[a]) { - _mtex[a] = mtex; - return 0; - } - } - return -1; /* no free slots */ - } - - /*! assigns a node tree (of new shading nodes) to define textures. */ - inline void setNodeTree(bNodeTree *iNodeTree) - { - _nodeTree = iNodeTree; - } - - /*! sets the flag telling whether this stroke is using a texture with tips or not. */ - inline void setTips(bool iTips) - { - _tips = iTips; - } - - inline void push_back(StrokeVertex *iVertex) - { - _Vertices.push_back(iVertex); - } - - inline void push_front(StrokeVertex *iVertex) - { - _Vertices.push_front(iVertex); - } - - inline void AddViewEdge(ViewEdge *iViewEdge) - { - _ViewEdges.push_back(iViewEdge); - } - - inline void setBeginningOrientation(const Vec2r& iOrientation) - { - _extremityOrientations[0] = iOrientation; - } - - inline void setBeginningOrientation(real x, real y) - { - _extremityOrientations[0] = Vec2r(x, y); - } - - inline void setEndingOrientation(const Vec2r& iOrientation) - { - _extremityOrientations[1] = iOrientation; - } - - inline void setEndingOrientation(real x, real y) - { - _extremityOrientations[1] = Vec2r(x, y); - } - - /* Information access interface */ - - // embedding vertex iterator - const_vertex_iterator vertices_begin() const; - vertex_iterator vertices_begin(float t = 0.0f); - const_vertex_iterator vertices_end() const; - vertex_iterator vertices_end(); - - /*! Returns a StrokeVertexIterator pointing on the first StrokeVertex of the Stroke. One can specify a sampling - * value to resample the Stroke on the fly if needed. - * \param t: - * The resampling value with which we want our Stroke to be resampled. - * If 0 is specified, no resampling is done. - */ - StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t = 0.0f); - - /*! Returns a StrokeVertexIterator pointing after the last StrokeVertex of the Stroke. */ - StrokeInternal::StrokeVertexIterator strokeVerticesEnd(); - - /*! Returns the number of StrokeVertex constituting the Stroke. */ - inline unsigned int strokeVerticesSize() const - { - return _Vertices.size(); - } - - /*! Returns the i-th StrokeVertex constituting the Stroke. */ - inline StrokeVertex& strokeVerticeAt(unsigned int i) - { - return *(_Vertices.at(i)); - } - - // Iterator access (Interface1D) - /*! Returns an Interface0DIterator pointing on the first StrokeVertex of the Stroke. */ - virtual Interface0DIterator verticesBegin(); - - /*! Returns an Interface0DIterator pointing after the last StrokeVertex of the Stroke. */ - virtual Interface0DIterator verticesEnd(); - - virtual Interface0DIterator pointsBegin(float t = 0.0f); - virtual Interface0DIterator pointsEnd(float t = 0.0f); +class Stroke : public Interface1D { + public: // Implementation of Interface1D + /*! Returns the string "Stroke" */ + virtual string getExactTypeName() const + { + return "Stroke"; + } + + // Data access methods + + /*! Returns the Id of the Stroke */ + virtual Id getId() const + { + return _id; + } + + /*! The different blending modes available to similate the interaction media-medium. */ + typedef enum { + DRY_MEDIUM, /*!< To simulate a dry medium such as Pencil or Charcoal.*/ + HUMID_MEDIUM, /*!< To simulate ink painting (color subtraction blending).*/ + OPAQUE_MEDIUM, /*!< To simulate an opaque medium (oil, spray...).*/ + } MediumType; + + public: + typedef std::deque vertex_container; // the vertices container + typedef std::vector viewedge_container; // the viewedges container + typedef StrokeInternal::vertex_iterator_base + vertex_iterator; + typedef StrokeInternal::vertex_iterator_base + const_vertex_iterator; + + public: + //typedef StrokeVertex vertex_type; + + private: + vertex_container _Vertices; //! The stroke's backbone vertices + Id _id; + float _Length; // The stroke length + viewedge_container _ViewEdges; + float _sampling; + float _textureStep; + // StrokeRenderer *_renderer; // mark implementation OpenGL renderer + MediumType _mediumType; + unsigned int _textureId; + MTex *_mtex[MAX_MTEX]; + bNodeTree *_nodeTree; + bool _tips; + StrokeRep *_rep; + Vec2r _extremityOrientations[2]; // the orientations of the first and last extermity + + public: + /*! default constructor */ + Stroke(); + + /*! copy constructor */ + Stroke(const Stroke &iBrother); + + /*! Builds a stroke from a set of StrokeVertex. + * This constructor is templated by an iterator type. + * This iterator type must allow the vertices parsing using the ++ operator. + * \param iBegin: + * The iterator pointing to the first vertex. + * \param iEnd: + * The iterator pointing to the end of the vertex list. + */ + template Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd); + + /*! Destructor */ + virtual ~Stroke(); + + /* operators */ + /*! operator = */ + Stroke &operator=(const Stroke &iBrother); + + /*! Compute the sampling needed to get iNVertices vertices. + * If the specified number of vertices is less than the actual number of vertices, the actual sampling value + * is returned. (To remove Vertices, use the RemoveVertex() method of this class). + * \param iNVertices: + * The number of StrokeVertices we eventually want in our Stroke. + * \return the sampling that must be used in the Resample(float) method. + * \see Resample(int) + * \see Resample(float) + */ + float ComputeSampling(int iNVertices); + + /*! Resampling method. + * Resamples the curve so that it eventually has iNPoints. That means it is going to add iNPoints-vertices_size, + * if vertices_size is the number of points we already have. + * If vertices_size >= iNPoints, no resampling is done. + * \param iNPoints: + * The number of vertices we eventually want in our stroke. + */ + int Resample(int iNPoints); + + /*! Resampling method. + * Resamples the curve with a given sampling. + * If this sampling is < to the actual sampling value, no resampling is done. + * \param iSampling: + * The new sampling value. + */ + int Resample(float iSampling); + + /*! Removes all vertices from the Stroke. + */ + void RemoveAllVertices(); + + /*! Removes the stroke vertex iVertex + * from the stroke. + * The length and curvilinear abscissa are updated + * consequently. + */ + void RemoveVertex(StrokeVertex *iVertex); + + /*! Inserts the stroke vertex iVertex in the stroke before next. + * The length, curvilinear abscissa are updated consequently. + * \param iVertex: + * The StrokeVertex to insert in the Stroke. + * \param next: + * A StrokeVertexIterator pointing to the StrokeVeretx before which iVertex must be inserted. + */ + void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next); + + /*! Updates the 2D length of the Stroke */ + void UpdateLength(); + + /* Render method */ + void ScaleThickness(float iFactor); + void Render(const StrokeRenderer *iRenderer); + void RenderBasic(const StrokeRenderer *iRenderer); + + /* Iterator definition */ + + /* accessors */ + /*! Returns the 2D length of the Stroke */ + inline real getLength2D() const + { + return _Length; + } + + /*! Returns a reference to the time stamp value of the stroke. */ + /*! Returns the MediumType used for this Stroke. */ + inline MediumType getMediumType() const + { + return _mediumType; + } + + /*! Returns the id of the texture used to simulate th marks system for this Stroke */ + inline unsigned int getTextureId() + { + return _textureId; + } + + /*! Returns the spacing of texture coordinates along the stroke lenght */ + inline float getTextureStep() + { + return _textureStep; + } + + /*! Returns the texture used at given index to simulate the marks system for this Stroke */ + inline MTex *getMTex(int idx) + { + return _mtex[idx]; + } + + /*! Return the shader node tree to define textures. */ + inline bNodeTree *getNodeTree() + { + return _nodeTree; + } + + /*! Returns true if this Stroke has textures assigned, false otherwise. */ + inline bool hasTex() const + { + return (_mtex[0] != NULL) || _nodeTree; + } + + /*! Returns true if this Stroke uses a texture with tips, false otherwise. */ + inline bool hasTips() const + { + return _tips; + } + + /* these advanced iterators are used only in C++ */ + inline int vertices_size() const + { + return _Vertices.size(); + } + + inline viewedge_container::const_iterator viewedges_begin() const + { + return _ViewEdges.begin(); + } + + inline viewedge_container::iterator viewedges_begin() + { + return _ViewEdges.begin(); + } + + inline viewedge_container::const_iterator viewedges_end() const + { + return _ViewEdges.end(); + } + + inline viewedge_container::iterator viewedges_end() + { + return _ViewEdges.end(); + } + + inline int viewedges_size() const + { + return _ViewEdges.size(); + } + + inline Vec2r getBeginningOrientation() const + { + return _extremityOrientations[0]; + } + + inline real getBeginningOrientationX() const + { + return _extremityOrientations[0].x(); + } + + inline real getBeginningOrientationY() const + { + return _extremityOrientations[0].y(); + } + + inline Vec2r getEndingOrientation() const + { + return _extremityOrientations[1]; + } + + inline real getEndingOrientationX() const + { + return _extremityOrientations[1].x(); + } + + inline real getEndingOrientationY() const + { + return _extremityOrientations[1].y(); + } + + /* modifiers */ + /*! sets the Id of the Stroke. */ + inline void setId(const Id &id) + { + _id = id; + } + + /*! sets the 2D length of the Stroke. */ + void setLength(float iLength); + + /*! sets the medium type that must be used for this Stroke. */ + inline void setMediumType(MediumType iType) + { + _mediumType = iType; + } + + /*! sets the texture id to be used to simulate the marks system for this Stroke. */ + inline void setTextureId(unsigned int id) + { + _textureId = id; + } + + /*! sets the spacing of texture coordinates along the stroke lenght. */ + inline void setTextureStep(float step) + { + _textureStep = step; + } + + /*! assigns a blender texture to the first available slot. */ + inline int setMTex(MTex *mtex) + { + for (int a = 0; a < MAX_MTEX; a++) { + if (!_mtex[a]) { + _mtex[a] = mtex; + return 0; + } + } + return -1; /* no free slots */ + } + + /*! assigns a node tree (of new shading nodes) to define textures. */ + inline void setNodeTree(bNodeTree *iNodeTree) + { + _nodeTree = iNodeTree; + } + + /*! sets the flag telling whether this stroke is using a texture with tips or not. */ + inline void setTips(bool iTips) + { + _tips = iTips; + } + + inline void push_back(StrokeVertex *iVertex) + { + _Vertices.push_back(iVertex); + } + + inline void push_front(StrokeVertex *iVertex) + { + _Vertices.push_front(iVertex); + } + + inline void AddViewEdge(ViewEdge *iViewEdge) + { + _ViewEdges.push_back(iViewEdge); + } + + inline void setBeginningOrientation(const Vec2r &iOrientation) + { + _extremityOrientations[0] = iOrientation; + } + + inline void setBeginningOrientation(real x, real y) + { + _extremityOrientations[0] = Vec2r(x, y); + } + + inline void setEndingOrientation(const Vec2r &iOrientation) + { + _extremityOrientations[1] = iOrientation; + } + + inline void setEndingOrientation(real x, real y) + { + _extremityOrientations[1] = Vec2r(x, y); + } + + /* Information access interface */ + + // embedding vertex iterator + const_vertex_iterator vertices_begin() const; + vertex_iterator vertices_begin(float t = 0.0f); + const_vertex_iterator vertices_end() const; + vertex_iterator vertices_end(); + + /*! Returns a StrokeVertexIterator pointing on the first StrokeVertex of the Stroke. One can specify a sampling + * value to resample the Stroke on the fly if needed. + * \param t: + * The resampling value with which we want our Stroke to be resampled. + * If 0 is specified, no resampling is done. + */ + StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t = 0.0f); + + /*! Returns a StrokeVertexIterator pointing after the last StrokeVertex of the Stroke. */ + StrokeInternal::StrokeVertexIterator strokeVerticesEnd(); + + /*! Returns the number of StrokeVertex constituting the Stroke. */ + inline unsigned int strokeVerticesSize() const + { + return _Vertices.size(); + } + + /*! Returns the i-th StrokeVertex constituting the Stroke. */ + inline StrokeVertex &strokeVerticeAt(unsigned int i) + { + return *(_Vertices.at(i)); + } + + // Iterator access (Interface1D) + /*! Returns an Interface0DIterator pointing on the first StrokeVertex of the Stroke. */ + virtual Interface0DIterator verticesBegin(); + + /*! Returns an Interface0DIterator pointing after the last StrokeVertex of the Stroke. */ + virtual Interface0DIterator verticesEnd(); + + virtual Interface0DIterator pointsBegin(float t = 0.0f); + virtual Interface0DIterator pointsEnd(float t = 0.0f); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Stroke") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Stroke") #endif }; - // // Implementation // //////////////////////////////////////////////////////// - template Stroke::Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd) { - for (InputVertexIterator v = iBegin, vend = iEnd; v != vend; v++) { - _Vertices.push_back(*v); - } - _Length = 0; - _id = 0; + for (InputVertexIterator v = iBegin, vend = iEnd; v != vend; v++) { + _Vertices.push_back(*v); + } + _Length = 0; + _id = 0; } } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_H__ +#endif // __FREESTYLE_STROKE_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeAdvancedIterators.h b/source/blender/freestyle/intern/stroke/StrokeAdvancedIterators.h index 8362c293558..e9d4659f320 100644 --- a/source/blender/freestyle/intern/stroke/StrokeAdvancedIterators.h +++ b/source/blender/freestyle/intern/stroke/StrokeAdvancedIterators.h @@ -28,154 +28,155 @@ namespace Freestyle { namespace StrokeInternal { -class vertex_const_traits : public Const_traits -{ -public: - typedef std::deque vertex_container; - typedef vertex_container::const_iterator vertex_container_iterator; +class vertex_const_traits : public Const_traits { + public: + typedef std::deque vertex_container; + typedef vertex_container::const_iterator vertex_container_iterator; }; -class vertex_nonconst_traits : public Nonconst_traits -{ -public: - typedef std::deque vertex_container; //! the vertices container - typedef vertex_container::iterator vertex_container_iterator; +class vertex_nonconst_traits : public Nonconst_traits { + public: + typedef std::deque vertex_container; //! the vertices container + typedef vertex_container::iterator vertex_container_iterator; }; - template -class vertex_iterator_base : public IteratorBase -{ -public: - typedef vertex_iterator_base Self; - -protected: - typedef IteratorBase parent_class; - typedef typename Traits::vertex_container_iterator vertex_container_iterator; - typedef vertex_iterator_base iterator; - typedef vertex_iterator_base const_iterator; - -//protected: -public: - vertex_container_iterator _it; - vertex_container_iterator _begin; - vertex_container_iterator _end; - -public: - friend class Stroke; - //friend class vertex_iterator; - - inline vertex_iterator_base() : parent_class() {} - - inline vertex_iterator_base(const iterator& iBrother) : parent_class() - { - _it = iBrother._it; - _begin = iBrother._begin; - _end = iBrother._end; - } - - inline vertex_iterator_base(const const_iterator& iBrother) : parent_class() - { - _it = iBrother._it; - _begin = iBrother._begin; - _end = iBrother._end; - } - -//protected: //FIXME -public: - inline vertex_iterator_base(vertex_container_iterator it, vertex_container_iterator begin, - vertex_container_iterator end) - : parent_class() - { - _it = it; - _begin = begin; - _end = end; - } - -public: - virtual ~vertex_iterator_base() {} - - virtual bool begin() const - { - return (_it == _begin) ? true : false; - } - - virtual bool end() const - { - return (_it == _end) ? true : false; - } - - // operators - inline Self& operator++() // operator corresponding to ++i - { - ++_it; - return *(this); - } - - /* Operator corresponding to i++, i.e. which returns the value *and then* increments. - * That's why we store the value in a temp. - */ - inline Self operator++(int) - { - Self tmp = *this; - ++_it; - return tmp; - } - - inline Self& operator--() // operator corresponding to --i - { - --_it; - return *(this); - } - - inline Self operator--(int) - { - Self tmp = *this; - --_it; - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - return (_it != b._it); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual typename Traits::reference operator*() const - { - return *(_it); - } - - virtual typename Traits::pointer operator->() const - { - return &(operator*()); - } - - /*! accessors */ - inline vertex_container_iterator it() const - { - return _it; - } - - inline vertex_container_iterator getBegin() const - { - return _begin; - } - - inline vertex_container_iterator getEnd() const - { - return _end; - } +class vertex_iterator_base : public IteratorBase { + public: + typedef vertex_iterator_base Self; + + protected: + typedef IteratorBase parent_class; + typedef typename Traits::vertex_container_iterator vertex_container_iterator; + typedef vertex_iterator_base iterator; + typedef vertex_iterator_base const_iterator; + + //protected: + public: + vertex_container_iterator _it; + vertex_container_iterator _begin; + vertex_container_iterator _end; + + public: + friend class Stroke; + //friend class vertex_iterator; + + inline vertex_iterator_base() : parent_class() + { + } + + inline vertex_iterator_base(const iterator &iBrother) : parent_class() + { + _it = iBrother._it; + _begin = iBrother._begin; + _end = iBrother._end; + } + + inline vertex_iterator_base(const const_iterator &iBrother) : parent_class() + { + _it = iBrother._it; + _begin = iBrother._begin; + _end = iBrother._end; + } + + //protected: //FIXME + public: + inline vertex_iterator_base(vertex_container_iterator it, + vertex_container_iterator begin, + vertex_container_iterator end) + : parent_class() + { + _it = it; + _begin = begin; + _end = end; + } + + public: + virtual ~vertex_iterator_base() + { + } + + virtual bool begin() const + { + return (_it == _begin) ? true : false; + } + + virtual bool end() const + { + return (_it == _end) ? true : false; + } + + // operators + inline Self &operator++() // operator corresponding to ++i + { + ++_it; + return *(this); + } + + /* Operator corresponding to i++, i.e. which returns the value *and then* increments. + * That's why we store the value in a temp. + */ + inline Self operator++(int) + { + Self tmp = *this; + ++_it; + return tmp; + } + + inline Self &operator--() // operator corresponding to --i + { + --_it; + return *(this); + } + + inline Self operator--(int) + { + Self tmp = *this; + --_it; + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + return (_it != b._it); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual typename Traits::reference operator*() const + { + return *(_it); + } + + virtual typename Traits::pointer operator->() const + { + return &(operator*()); + } + + /*! accessors */ + inline vertex_container_iterator it() const + { + return _it; + } + + inline vertex_container_iterator getBegin() const + { + return _begin; + } + + inline vertex_container_iterator getEnd() const + { + return _end; + } }; -} // end of namespace StrokeInternal +} // end of namespace StrokeInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_ADVANCED_ITERATORS_H__ +#endif // __FREESTYLE_STROKE_ADVANCED_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeIO.cpp b/source/blender/freestyle/intern/stroke/StrokeIO.cpp index 9b428a81d1e..686313cd04e 100644 --- a/source/blender/freestyle/intern/stroke/StrokeIO.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeIO.cpp @@ -25,44 +25,43 @@ namespace Freestyle { -ostream& operator<<(ostream& out, const StrokeAttribute& iStrokeAttribute) +ostream &operator<<(ostream &out, const StrokeAttribute &iStrokeAttribute) { - out << " StrokeAttribute" << endl; - out << " color : (" << iStrokeAttribute.getColorR() << "," << iStrokeAttribute.getColorG() << - "," << iStrokeAttribute.getColorB() << ")" << endl; - out << " alpha : " << iStrokeAttribute.getAlpha() << endl; - out << " thickness : " << iStrokeAttribute.getThicknessR() << ", " << iStrokeAttribute.getThicknessL() << - endl; - out << " visible : " << iStrokeAttribute.isVisible() << endl; - return out; + out << " StrokeAttribute" << endl; + out << " color : (" << iStrokeAttribute.getColorR() << "," + << iStrokeAttribute.getColorG() << "," << iStrokeAttribute.getColorB() << ")" << endl; + out << " alpha : " << iStrokeAttribute.getAlpha() << endl; + out << " thickness : " << iStrokeAttribute.getThicknessR() << ", " + << iStrokeAttribute.getThicknessL() << endl; + out << " visible : " << iStrokeAttribute.isVisible() << endl; + return out; } -ostream& operator<<(ostream& out, const StrokeVertex& iStrokeVertex) +ostream &operator<<(ostream &out, const StrokeVertex &iStrokeVertex) { - out << " StrokeVertex" << endl; - out << " id : " << iStrokeVertex.getId() << endl; - out << " curvilinear length : " << iStrokeVertex.curvilinearAbscissa() << endl; - out << " 2d coordinates : (" << iStrokeVertex.getProjectedX() << "," << iStrokeVertex.getProjectedY() << - "," << iStrokeVertex.getProjectedZ() << ")" << endl; - out << " 3d coordinates : (" << iStrokeVertex.getX() << "," << iStrokeVertex.getY() << - "," << iStrokeVertex.getZ() << ")" << endl; - out << iStrokeVertex.attribute() << endl; - return out; + out << " StrokeVertex" << endl; + out << " id : " << iStrokeVertex.getId() << endl; + out << " curvilinear length : " << iStrokeVertex.curvilinearAbscissa() << endl; + out << " 2d coordinates : (" << iStrokeVertex.getProjectedX() << "," + << iStrokeVertex.getProjectedY() << "," << iStrokeVertex.getProjectedZ() << ")" << endl; + out << " 3d coordinates : (" << iStrokeVertex.getX() << "," << iStrokeVertex.getY() << "," + << iStrokeVertex.getZ() << ")" << endl; + out << iStrokeVertex.attribute() << endl; + return out; } -ostream& operator<<(ostream& out, const Stroke& iStroke) +ostream &operator<<(ostream &out, const Stroke &iStroke) { - out << "Stroke" << endl; - out << " id : " << iStroke.getId() << endl; - out << " length : " << iStroke.getLength2D() << endl; - out << " medium type : " << iStroke.getMediumType() << endl; - for (Stroke::const_vertex_iterator v = iStroke.vertices_begin(), vend = iStroke.vertices_end(); - v != vend; - ++v) - { - out << *(*v) << endl; - } - return out; + out << "Stroke" << endl; + out << " id : " << iStroke.getId() << endl; + out << " length : " << iStroke.getLength2D() << endl; + out << " medium type : " << iStroke.getMediumType() << endl; + for (Stroke::const_vertex_iterator v = iStroke.vertices_begin(), vend = iStroke.vertices_end(); + v != vend; + ++v) { + out << *(*v) << endl; + } + return out; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeIO.h b/source/blender/freestyle/intern/stroke/StrokeIO.h index 7ce5091e9fe..ae38847f8cc 100644 --- a/source/blender/freestyle/intern/stroke/StrokeIO.h +++ b/source/blender/freestyle/intern/stroke/StrokeIO.h @@ -30,12 +30,12 @@ namespace Freestyle { -ostream& operator<<(ostream& out, const StrokeAttribute& iStrokeAttribute); +ostream &operator<<(ostream &out, const StrokeAttribute &iStrokeAttribute); -ostream& operator<<(ostream& out, const StrokeVertex& iStrokeVertex); +ostream &operator<<(ostream &out, const StrokeVertex &iStrokeVertex); -ostream& operator<<(ostream& out, const Stroke& iStroke); +ostream &operator<<(ostream &out, const Stroke &iStroke); } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_IO_H__ +#endif // __FREESTYLE_STROKE_IO_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeIterators.h b/source/blender/freestyle/intern/stroke/StrokeIterators.h index d64fbdfd83c..1999b028424 100644 --- a/source/blender/freestyle/intern/stroke/StrokeIterators.h +++ b/source/blender/freestyle/intern/stroke/StrokeIterators.h @@ -46,187 +46,190 @@ namespace StrokeInternal { * \code it2 = it1 \endcode where \a it1 and \a it2 are 2 StrokeVertexIterator. * Otherwise, incrementing \a it1 will also increment \a it2. */ -class StrokeVertexIterator : public Interface0DIteratorNested -{ -public: - /*! Default constructor. */ - StrokeVertexIterator() {} - - /*! Copy constructor. */ - StrokeVertexIterator(const StrokeVertexIterator& vi) - { - _it = vi._it; - _begin = vi._begin; - _end = vi._end; - } - - StrokeVertexIterator(const Stroke::vertex_container::iterator& it, - const Stroke::vertex_container::iterator& begin, - const Stroke::vertex_container::iterator& end) - { - _it = it; - _begin = begin; - _end = end; - } - - virtual ~StrokeVertexIterator() {} - - /*! Casts this StrokeVertexIterator into an Interface0DIterator. - * Useful for any call to a function of the type UnaryFunction0D. - */ - inline Interface0DIterator castToInterface0DIterator() const - { - Interface0DIterator ret(new StrokeVertexIterator(*this)); - return ret; - } - - /*! operator= - * \attention In the scripting language, you must call \code it2 = StrokeVertexIterator(it1) \endcode instead of - * \code it2 = it1 \endcode where \a it1 and \a it2 are 2 StrokeVertexIterator. - * Otherwise, incrementing \a it1 will also increment \a it2. - */ - StrokeVertexIterator& operator=(const StrokeVertexIterator& vi) - { - _it = vi._it; - _begin = vi._begin; - _end = vi._end; - return *this; - } - - /*! Returns the string "StrokeVertexIterator". */ - virtual string getExactTypeName() const - { - return "StrokeVertexIterator"; - } - - /*! Returns a reference to the pointed StrokeVertex. - * In the scripting language, you must call "getObject()"instead. - */ - virtual StrokeVertex& operator*() - { - return **_it; - } - - /*! Returns a pointer to the pointed StrokeVertex. - * Can't be called in the scripting language. - */ - virtual StrokeVertex *operator->() - { - return &(operator*()); - } - - /*! Increments. In the scripting language, call "increment()". */ - virtual StrokeVertexIterator& operator++() - { - increment(); - return *this; - } - - /*! Increments. In the scripting language, call "increment()". */ - virtual StrokeVertexIterator operator++(int) - { - StrokeVertexIterator ret(*this); - increment(); - return ret; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - virtual StrokeVertexIterator& operator--() - { - decrement(); - return *this; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - virtual StrokeVertexIterator operator--(int) - { - StrokeVertexIterator ret(*this); - decrement(); - return ret; - } - - /*! Increments. */ - virtual int increment() - { - ++_it; - return 0; - } - - /*! Decrements. */ - virtual int decrement() - { - --_it; - return 0; - } - - /*! Returns true if the pointed StrokeVertex is the first of the Stroke. */ - bool isBegin() const - { - return _it == _begin; - } - - /*! Returns true if the pointed StrokeVertex is the final valid StrokeVertex of the Stroke. */ - bool atLast() - { - if (_it == _end) - return false; - - ++_it; - bool result = (_it == _end); - --_it; - return result; - } - - /*! Returns true if the pointed StrokeVertex is after the last StrokeVertex of the Stroke. */ - bool isEnd() const - { - return _it == _end; - } - - /*! operator == */ - virtual bool operator==(const Interface0DIteratorNested& it) const - { - const StrokeVertexIterator *it_exact = dynamic_cast(&it); - if (!it_exact) - return false; - return (_it == it_exact->_it); - } - - /*! Returns the curvilinear abscissa of the current point */ - virtual float t() const - { - return (*_it)->curvilinearAbscissa(); - } - - /*! Returns the point's parameter in the stroke */ - virtual float u() const - { - return (*_it)->u(); - } - - /*! Cloning method */ - virtual StrokeVertexIterator *copy() const - { - return new StrokeVertexIterator(*this); - } - - // - // Not exported in Python - // - ////////////////////////////////////////////////// - const Stroke::vertex_container::iterator& getIt() - { - return _it; - } - -private: - Stroke::vertex_container::iterator _it; - Stroke::vertex_container::iterator _begin; - Stroke::vertex_container::iterator _end; +class StrokeVertexIterator : public Interface0DIteratorNested { + public: + /*! Default constructor. */ + StrokeVertexIterator() + { + } + + /*! Copy constructor. */ + StrokeVertexIterator(const StrokeVertexIterator &vi) + { + _it = vi._it; + _begin = vi._begin; + _end = vi._end; + } + + StrokeVertexIterator(const Stroke::vertex_container::iterator &it, + const Stroke::vertex_container::iterator &begin, + const Stroke::vertex_container::iterator &end) + { + _it = it; + _begin = begin; + _end = end; + } + + virtual ~StrokeVertexIterator() + { + } + + /*! Casts this StrokeVertexIterator into an Interface0DIterator. + * Useful for any call to a function of the type UnaryFunction0D. + */ + inline Interface0DIterator castToInterface0DIterator() const + { + Interface0DIterator ret(new StrokeVertexIterator(*this)); + return ret; + } + + /*! operator= + * \attention In the scripting language, you must call \code it2 = StrokeVertexIterator(it1) \endcode instead of + * \code it2 = it1 \endcode where \a it1 and \a it2 are 2 StrokeVertexIterator. + * Otherwise, incrementing \a it1 will also increment \a it2. + */ + StrokeVertexIterator &operator=(const StrokeVertexIterator &vi) + { + _it = vi._it; + _begin = vi._begin; + _end = vi._end; + return *this; + } + + /*! Returns the string "StrokeVertexIterator". */ + virtual string getExactTypeName() const + { + return "StrokeVertexIterator"; + } + + /*! Returns a reference to the pointed StrokeVertex. + * In the scripting language, you must call "getObject()"instead. + */ + virtual StrokeVertex &operator*() + { + return **_it; + } + + /*! Returns a pointer to the pointed StrokeVertex. + * Can't be called in the scripting language. + */ + virtual StrokeVertex *operator->() + { + return &(operator*()); + } + + /*! Increments. In the scripting language, call "increment()". */ + virtual StrokeVertexIterator &operator++() + { + increment(); + return *this; + } + + /*! Increments. In the scripting language, call "increment()". */ + virtual StrokeVertexIterator operator++(int) + { + StrokeVertexIterator ret(*this); + increment(); + return ret; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + virtual StrokeVertexIterator &operator--() + { + decrement(); + return *this; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + virtual StrokeVertexIterator operator--(int) + { + StrokeVertexIterator ret(*this); + decrement(); + return ret; + } + + /*! Increments. */ + virtual int increment() + { + ++_it; + return 0; + } + + /*! Decrements. */ + virtual int decrement() + { + --_it; + return 0; + } + + /*! Returns true if the pointed StrokeVertex is the first of the Stroke. */ + bool isBegin() const + { + return _it == _begin; + } + + /*! Returns true if the pointed StrokeVertex is the final valid StrokeVertex of the Stroke. */ + bool atLast() + { + if (_it == _end) + return false; + + ++_it; + bool result = (_it == _end); + --_it; + return result; + } + + /*! Returns true if the pointed StrokeVertex is after the last StrokeVertex of the Stroke. */ + bool isEnd() const + { + return _it == _end; + } + + /*! operator == */ + virtual bool operator==(const Interface0DIteratorNested &it) const + { + const StrokeVertexIterator *it_exact = dynamic_cast(&it); + if (!it_exact) + return false; + return (_it == it_exact->_it); + } + + /*! Returns the curvilinear abscissa of the current point */ + virtual float t() const + { + return (*_it)->curvilinearAbscissa(); + } + + /*! Returns the point's parameter in the stroke */ + virtual float u() const + { + return (*_it)->u(); + } + + /*! Cloning method */ + virtual StrokeVertexIterator *copy() const + { + return new StrokeVertexIterator(*this); + } + + // + // Not exported in Python + // + ////////////////////////////////////////////////// + const Stroke::vertex_container::iterator &getIt() + { + return _it; + } + + private: + Stroke::vertex_container::iterator _it; + Stroke::vertex_container::iterator _begin; + Stroke::vertex_container::iterator _end; }; -} // end of namespace StrokeInternal +} // end of namespace StrokeInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_ITERATORS_H__ +#endif // __FREESTYLE_STROKE_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp index 3976c56ffe2..f1680279889 100644 --- a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp @@ -27,35 +27,41 @@ namespace Freestyle { StrokeLayer::~StrokeLayer() { - clear(); + clear(); } void StrokeLayer::ScaleThickness(float iFactor) { - for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) { - (*s)->ScaleThickness(iFactor); - } + for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); + s != send; + ++s) { + (*s)->ScaleThickness(iFactor); + } } void StrokeLayer::Render(const StrokeRenderer *iRenderer) { - for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) { - (*s)->Render(iRenderer); - } + for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); + s != send; + ++s) { + (*s)->Render(iRenderer); + } } void StrokeLayer::RenderBasic(const StrokeRenderer *iRenderer) { - for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) { - (*s)->RenderBasic(iRenderer); - } + for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); + s != send; + ++s) { + (*s)->RenderBasic(iRenderer); + } } void StrokeLayer::clear() { - for (stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) - delete *s; - _strokes.clear(); + for (stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) + delete *s; + _strokes.clear(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeLayer.h b/source/blender/freestyle/intern/stroke/StrokeLayer.h index 1eef44e6c91..ecb98025875 100644 --- a/source/blender/freestyle/intern/stroke/StrokeLayer.h +++ b/source/blender/freestyle/intern/stroke/StrokeLayer.h @@ -25,81 +25,82 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { class Stroke; class StrokeRenderer; -class StrokeLayer -{ -public: - typedef std::deque stroke_container; - -protected: - stroke_container _strokes; - -public: - StrokeLayer() {} - - StrokeLayer(const stroke_container& iStrokes) - { - _strokes = iStrokes; - } - - StrokeLayer(const StrokeLayer& iBrother) - { - _strokes = iBrother._strokes; - } - - virtual ~StrokeLayer(); - - /*! Render method */ - void ScaleThickness(float iFactor); - void Render(const StrokeRenderer *iRenderer); - void RenderBasic(const StrokeRenderer *iRenderer); - - /*! clears the layer */ - void clear(); - - /*! accessors */ - inline stroke_container::iterator strokes_begin() - { - return _strokes.begin(); - } - - inline stroke_container::iterator strokes_end() - { - return _strokes.end(); - } - - inline int strokes_size() const - { - return _strokes.size(); - } - - inline bool empty() const - { - return _strokes.empty(); - } - - /*! modifiers */ - inline void setStrokes(stroke_container& iStrokes) - { - _strokes = iStrokes; - } - - inline void AddStroke(Stroke *iStroke) - { - _strokes.push_back(iStroke); - } +class StrokeLayer { + public: + typedef std::deque stroke_container; + + protected: + stroke_container _strokes; + + public: + StrokeLayer() + { + } + + StrokeLayer(const stroke_container &iStrokes) + { + _strokes = iStrokes; + } + + StrokeLayer(const StrokeLayer &iBrother) + { + _strokes = iBrother._strokes; + } + + virtual ~StrokeLayer(); + + /*! Render method */ + void ScaleThickness(float iFactor); + void Render(const StrokeRenderer *iRenderer); + void RenderBasic(const StrokeRenderer *iRenderer); + + /*! clears the layer */ + void clear(); + + /*! accessors */ + inline stroke_container::iterator strokes_begin() + { + return _strokes.begin(); + } + + inline stroke_container::iterator strokes_end() + { + return _strokes.end(); + } + + inline int strokes_size() const + { + return _strokes.size(); + } + + inline bool empty() const + { + return _strokes.empty(); + } + + /*! modifiers */ + inline void setStrokes(stroke_container &iStrokes) + { + _strokes = iStrokes; + } + + inline void AddStroke(Stroke *iStroke) + { + _strokes.push_back(iStroke); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeLayer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeLayer") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_LAYER_H__ +#endif // __FREESTYLE_STROKE_LAYER_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp index 303b6c67984..530a7644bfa 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRenderer.cpp @@ -37,17 +37,20 @@ namespace Freestyle { TextureManager *StrokeRenderer::_textureManager = 0; -StrokeRenderer::StrokeRenderer() {} +StrokeRenderer::StrokeRenderer() +{ +} -StrokeRenderer::~StrokeRenderer() {} +StrokeRenderer::~StrokeRenderer() +{ +} bool StrokeRenderer::loadTextures() { - _textureManager->load(); - return true; + _textureManager->load(); + return true; } - /**********************************/ /* */ /* */ @@ -56,7 +59,6 @@ bool StrokeRenderer::loadTextures() /* */ /**********************************/ - TextureManager *TextureManager::_pInstance = 0; string TextureManager::_patterns_path; @@ -65,61 +67,61 @@ string TextureManager::_brushes_path; TextureManager::TextureManager() { - _hasLoadedTextures = false; - _pInstance = this; - _defaultTextureId = 0; + _hasLoadedTextures = false; + _pInstance = this; + _defaultTextureId = 0; } TextureManager::~TextureManager() { - if (!_brushesMap.empty()) - _brushesMap.clear(); - _pInstance = 0; + if (!_brushesMap.empty()) + _brushesMap.clear(); + _pInstance = 0; } void TextureManager::load() { - if (_hasLoadedTextures) - return; - loadStandardBrushes(); - _hasLoadedTextures = true; + if (_hasLoadedTextures) + return; + loadStandardBrushes(); + _hasLoadedTextures = true; } unsigned TextureManager::getBrushTextureIndex(string name, Stroke::MediumType loadingMode) { - BrushTexture bt(name, loadingMode); - brushesMap::iterator b = _brushesMap.find(bt); - if (b == _brushesMap.end()) { - unsigned texId = loadBrush(name, loadingMode); - _brushesMap[bt] = texId; - return texId; - // XXX! - cerr << "brush file " << name << " not found" << endl; - return 0; - } - else { - return _brushesMap[bt]; - } + BrushTexture bt(name, loadingMode); + brushesMap::iterator b = _brushesMap.find(bt); + if (b == _brushesMap.end()) { + unsigned texId = loadBrush(name, loadingMode); + _brushesMap[bt] = texId; + return texId; + // XXX! + cerr << "brush file " << name << " not found" << endl; + return 0; + } + else { + return _brushesMap[bt]; + } } -void TextureManager::Options::setPatternsPath(const string& path) +void TextureManager::Options::setPatternsPath(const string &path) { - _patterns_path = path; + _patterns_path = path; } string TextureManager::Options::getPatternsPath() { - return _patterns_path; + return _patterns_path; } -void TextureManager::Options::setBrushesPath(const string& path) +void TextureManager::Options::setBrushesPath(const string &path) { - _brushes_path = path; + _brushes_path = path; } string TextureManager::Options::getBrushesPath() { - return _brushes_path; + return _brushes_path; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeRenderer.h b/source/blender/freestyle/intern/stroke/StrokeRenderer.h index 35e206a73c0..03e6893b578 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRenderer.h +++ b/source/blender/freestyle/intern/stroke/StrokeRenderer.h @@ -34,7 +34,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -47,72 +47,67 @@ namespace Freestyle { /* */ /**********************************/ - /*! Class to load textures */ -class TextureManager -{ -public: - TextureManager (); - virtual ~TextureManager (); - - static TextureManager *getInstance() - { - return _pInstance; - } - - void load(); - unsigned getBrushTextureIndex(string name, Stroke::MediumType iType = Stroke::OPAQUE_MEDIUM); - - inline bool hasLoaded() const - { - return _hasLoadedTextures; - } - - inline unsigned int getDefaultTextureId() const - { - return _defaultTextureId; - } - - struct Options - { - static void setPatternsPath(const string& path); - static string getPatternsPath(); - - static void setBrushesPath(const string& path); - static string getBrushesPath(); - }; - -protected: - virtual void loadStandardBrushes() = 0; - virtual unsigned loadBrush(string fileName, Stroke::MediumType = Stroke::OPAQUE_MEDIUM) = 0; - - typedef std::pair BrushTexture; - struct cmpBrushTexture - { - bool operator()(const BrushTexture& bt1, const BrushTexture& bt2) const - { - int r = strcmp(bt1.first.c_str(), bt2.first.c_str()); - if (r != 0) - return (r < 0); - else - return (bt1.second < bt2.second); - } - }; - typedef std::map brushesMap; - - static TextureManager *_pInstance; - bool _hasLoadedTextures; - brushesMap _brushesMap; - static string _patterns_path; - static string _brushes_path; - unsigned int _defaultTextureId; +class TextureManager { + public: + TextureManager(); + virtual ~TextureManager(); + + static TextureManager *getInstance() + { + return _pInstance; + } + + void load(); + unsigned getBrushTextureIndex(string name, Stroke::MediumType iType = Stroke::OPAQUE_MEDIUM); + + inline bool hasLoaded() const + { + return _hasLoadedTextures; + } + + inline unsigned int getDefaultTextureId() const + { + return _defaultTextureId; + } + + struct Options { + static void setPatternsPath(const string &path); + static string getPatternsPath(); + + static void setBrushesPath(const string &path); + static string getBrushesPath(); + }; + + protected: + virtual void loadStandardBrushes() = 0; + virtual unsigned loadBrush(string fileName, Stroke::MediumType = Stroke::OPAQUE_MEDIUM) = 0; + + typedef std::pair BrushTexture; + struct cmpBrushTexture { + bool operator()(const BrushTexture &bt1, const BrushTexture &bt2) const + { + int r = strcmp(bt1.first.c_str(), bt2.first.c_str()); + if (r != 0) + return (r < 0); + else + return (bt1.second < bt2.second); + } + }; + typedef std::map brushesMap; + + static TextureManager *_pInstance; + bool _hasLoadedTextures; + brushesMap _brushesMap; + static string _patterns_path; + static string _brushes_path; + unsigned int _defaultTextureId; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TextureManager") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TextureManager") #endif }; - /**********************************/ /* */ /* */ @@ -122,28 +117,27 @@ protected: /**********************************/ /*! Class to render a stroke. Creates a triangle strip and stores it strip is lazily created at the first rendering */ -class StrokeRenderer -{ -public: - StrokeRenderer(); - virtual ~StrokeRenderer(); +class StrokeRenderer { + public: + StrokeRenderer(); + virtual ~StrokeRenderer(); - /*! Renders a stroke rep */ - virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const = 0; - virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const = 0; + /*! Renders a stroke rep */ + virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const = 0; + virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const = 0; - // initializes the texture manager - // lazy, checks if it has already been done - static bool loadTextures(); + // initializes the texture manager + // lazy, checks if it has already been done + static bool loadTextures(); - //static unsigned int getTextureIndex(unsigned int index); - static TextureManager *_textureManager; + //static unsigned int getTextureIndex(unsigned int index); + static TextureManager *_textureManager; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRenderer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRenderer") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_RENDERER_H__ +#endif // __FREESTYLE_STROKE_RENDERER_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index 9a593c93b08..026a7b2fc8f 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -35,53 +35,58 @@ namespace Freestyle { // STROKE VERTEX REP ///////////////////////////////////// -StrokeVertexRep::StrokeVertexRep(const StrokeVertexRep& iBrother) +StrokeVertexRep::StrokeVertexRep(const StrokeVertexRep &iBrother) { - _point2d = iBrother._point2d; - _texCoord = iBrother._texCoord; - _texCoord_w_tips = iBrother._texCoord_w_tips; - _color = iBrother._color; - _alpha = iBrother._alpha; + _point2d = iBrother._point2d; + _texCoord = iBrother._texCoord; + _texCoord_w_tips = iBrother._texCoord_w_tips; + _color = iBrother._color; + _alpha = iBrother._alpha; } // // STRIP ///////////////////////////////////// -Strip::Strip(const vector& iStrokeVertices, bool hasTex, bool beginTip, bool endTip, float texStep) +Strip::Strip(const vector &iStrokeVertices, + bool hasTex, + bool beginTip, + bool endTip, + float texStep) { - createStrip(iStrokeVertices); + createStrip(iStrokeVertices); - setVertexColor(iStrokeVertices); + setVertexColor(iStrokeVertices); - if (hasTex) { - // We compute both kinds of coordinates to use different kinds of textures - computeTexCoord(iStrokeVertices, texStep); - computeTexCoordWithTips(iStrokeVertices, beginTip, endTip, texStep); - } + if (hasTex) { + // We compute both kinds of coordinates to use different kinds of textures + computeTexCoord(iStrokeVertices, texStep); + computeTexCoordWithTips(iStrokeVertices, beginTip, endTip, texStep); + } } -Strip::Strip(const Strip& iBrother) +Strip::Strip(const Strip &iBrother) { - if (!iBrother._vertices.empty()) { - for (vertex_container::const_iterator v = iBrother._vertices.begin(), vend = iBrother._vertices.end(); - v != vend; - ++v) - { - _vertices.push_back(new StrokeVertexRep(**v)); - } - } - _averageThickness = iBrother._averageThickness; + if (!iBrother._vertices.empty()) { + for (vertex_container::const_iterator v = iBrother._vertices.begin(), + vend = iBrother._vertices.end(); + v != vend; + ++v) { + _vertices.push_back(new StrokeVertexRep(**v)); + } + } + _averageThickness = iBrother._averageThickness; } Strip::~Strip() { - if (!_vertices.empty()) { - for (vertex_container::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; ++v) { - delete (*v); - } - _vertices.clear(); - } + if (!_vertices.empty()) { + for (vertex_container::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; + ++v) { + delete (*v); + } + _vertices.clear(); + } } ////////////////////////// @@ -93,594 +98,605 @@ Strip::~Strip() #define MAX_RATIO_LENGTH_SINGU 2 #define HUGE_COORD 1.0e4 -static bool notValid (Vec2r p) +static bool notValid(Vec2r p) { - return (p[0] != p[0]) || (p[1] != p[1]) || (fabs(p[0]) > HUGE_COORD) || (fabs(p[1]) > HUGE_COORD) || - (p[0] < -HUGE_COORD) || (p[1] < -HUGE_COORD); + return (p[0] != p[0]) || (p[1] != p[1]) || (fabs(p[0]) > HUGE_COORD) || + (fabs(p[1]) > HUGE_COORD) || (p[0] < -HUGE_COORD) || (p[1] < -HUGE_COORD); } #if 0 static real crossP(const Vec2r& A, const Vec2r& B) { - return A[0] * B[1] - A[1] * B[0]; + return A[0] * B[1] - A[1] * B[0]; } #endif -void Strip::createStrip (const vector& iStrokeVertices) +void Strip::createStrip(const vector &iStrokeVertices) { - //computeParameterization(); - if (iStrokeVertices.size() < 2) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: strip has less than 2 vertices" << endl; - } - return; - } - _vertices.reserve(2 * iStrokeVertices.size()); - if (!_vertices.empty()) { - for (vertex_container::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; ++v) { - delete (*v); - } - _vertices.clear(); - } - _averageThickness = 0.0; - - vector::const_iterator v, vend, v2, vPrev; - StrokeVertex *sv, *sv2, *svPrev; - int orientationErrors = 0; - - //special case of first vertex - v2 = v = iStrokeVertices.begin(); - ++v2; - sv = *v; - vPrev = v; //in case the stroke has only 2 vertices; - sv2 = *v2; - Vec2r dir(sv2->getPoint() - sv->getPoint()); - Vec2r orthDir(-dir[1], dir[0]); - if (orthDir.norm() > ZERO) - orthDir.normalize(); - Vec2r stripDir(orthDir); - // check whether the orientation was user defined - if (sv->attribute().isAttributeAvailableVec2f("orientation")) { - Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); - if (userDir.norm() > 1e-6) { - userDir.normalize(); - real dp = userDir * orthDir; - if (dp < 0) - userDir = userDir * (-1.0f); - stripDir = userDir; - } - else { - ++orientationErrors; - } - } - const float *thickness = sv->attribute().getThickness(); - _vertices.push_back(new StrokeVertexRep(sv->getPoint() + thickness[1] * stripDir)); - _vertices.push_back(new StrokeVertexRep(sv->getPoint() - thickness[0] * stripDir)); + //computeParameterization(); + if (iStrokeVertices.size() < 2) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: strip has less than 2 vertices" << endl; + } + return; + } + _vertices.reserve(2 * iStrokeVertices.size()); + if (!_vertices.empty()) { + for (vertex_container::iterator v = _vertices.begin(), vend = _vertices.end(); v != vend; + ++v) { + delete (*v); + } + _vertices.clear(); + } + _averageThickness = 0.0; + + vector::const_iterator v, vend, v2, vPrev; + StrokeVertex *sv, *sv2, *svPrev; + int orientationErrors = 0; + + //special case of first vertex + v2 = v = iStrokeVertices.begin(); + ++v2; + sv = *v; + vPrev = v; //in case the stroke has only 2 vertices; + sv2 = *v2; + Vec2r dir(sv2->getPoint() - sv->getPoint()); + Vec2r orthDir(-dir[1], dir[0]); + if (orthDir.norm() > ZERO) + orthDir.normalize(); + Vec2r stripDir(orthDir); + // check whether the orientation was user defined + if (sv->attribute().isAttributeAvailableVec2f("orientation")) { + Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); + if (userDir.norm() > 1e-6) { + userDir.normalize(); + real dp = userDir * orthDir; + if (dp < 0) + userDir = userDir * (-1.0f); + stripDir = userDir; + } + else { + ++orientationErrors; + } + } + const float *thickness = sv->attribute().getThickness(); + _vertices.push_back(new StrokeVertexRep(sv->getPoint() + thickness[1] * stripDir)); + _vertices.push_back(new StrokeVertexRep(sv->getPoint() - thickness[0] * stripDir)); #if 0 - Vec2r userDir = _stroke->getBeginningOrientation(); - if (userDir != Vec2r(0, 0)) { - userDir.normalize(); - real o1 = (orthDir * userDir); - real o2 = crossP(orthDir, userDir); - real orientation = o1 * o2; - if (orientation > 0) { - // then the vertex to move is v0 - if (o1 > 0) - _vertex[0] = _vertex[1] + userDir; - else - _vertex[0] = _vertex[1] - userDir; - } - if (orientation < 0) { - // then we must move v1 - if (o1 < 0) - _vertex[1] = _vertex[0] + userDir; - else - _vertex[1] = _vertex[0] - userDir; - } - } + Vec2r userDir = _stroke->getBeginningOrientation(); + if (userDir != Vec2r(0, 0)) { + userDir.normalize(); + real o1 = (orthDir * userDir); + real o2 = crossP(orthDir, userDir); + real orientation = o1 * o2; + if (orientation > 0) { + // then the vertex to move is v0 + if (o1 > 0) + _vertex[0] = _vertex[1] + userDir; + else + _vertex[0] = _vertex[1] - userDir; + } + if (orientation < 0) { + // then we must move v1 + if (o1 < 0) + _vertex[1] = _vertex[0] + userDir; + else + _vertex[1] = _vertex[0] - userDir; + } + } #endif - int i = 2; // 2 because we have already processed the first vertex - - for (vend = iStrokeVertices.end(), ++v, ++v2; v2 != vend; vPrev = v++, ++v2) { - sv = (*v); - sv2 = (*v2); - svPrev = (*vPrev); - Vec2r p(sv->getPoint()), p2(sv2->getPoint()), pPrev(svPrev->getPoint()); - - //direction and orthogonal vector to the next segment - Vec2r dir(p2 - p); - float dirNorm = dir.norm(); - dir.normalize(); - Vec2r orthDir(-dir[1], dir[0]); - Vec2r stripDir = orthDir; - if (sv->attribute().isAttributeAvailableVec2f("orientation")) { - Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); - if (userDir.norm() > 1e-6) { - userDir.normalize(); - real dp = userDir * orthDir; - if (dp < 0) - userDir = userDir * (-1.0f); - stripDir = userDir; - } - else { - ++orientationErrors; - } - } - - //direction and orthogonal vector to the previous segment - Vec2r dirPrev(p - pPrev); - float dirPrevNorm = dirPrev.norm(); - dirPrev.normalize(); - Vec2r orthDirPrev(-dirPrev[1], dirPrev[0]); - Vec2r stripDirPrev = orthDirPrev; - if (svPrev->attribute().isAttributeAvailableVec2f("orientation")) { - Vec2r userDir = svPrev->attribute().getAttributeVec2f("orientation"); - if (userDir.norm() > 1e-6) { - userDir.normalize(); - real dp = userDir * orthDir; - if (dp < 0) - userDir = userDir * (-1.0f); - stripDirPrev = userDir; - } - else { - ++orientationErrors; - } - } - - const float *thickness = sv->attribute().getThickness(); - _averageThickness += thickness[0] + thickness[1]; - Vec2r pInter; - int interResult; - - interResult = GeomUtils::intersect2dLine2dLine(Vec2r(pPrev + thickness[1] * stripDirPrev), - Vec2r(p + thickness[1] * stripDirPrev), - Vec2r(p + thickness[1] * stripDir), - Vec2r(p2 + thickness[1] * stripDir), - pInter); - if (interResult == GeomUtils::DO_INTERSECT) - _vertices.push_back(new StrokeVertexRep(pInter)); - else - _vertices.push_back(new StrokeVertexRep(p + thickness[1] * stripDir)); - ++i; - - interResult = GeomUtils::intersect2dLine2dLine(Vec2r(pPrev - thickness[0] * stripDirPrev), - Vec2r(p - thickness[0] * stripDirPrev), - Vec2r(p - thickness[0] * stripDir), - Vec2r(p2 - thickness[0] * stripDir), - pInter); - if (interResult == GeomUtils::DO_INTERSECT) - _vertices.push_back(new StrokeVertexRep(pInter)); - else - _vertices.push_back(new StrokeVertexRep(p - thickness[0] * stripDir)); - ++i; - - // if the angle is obtuse, we simply average the directions to avoid the singularity - stripDir = stripDir + stripDirPrev; - if ((dirNorm < ZERO) || (dirPrevNorm < ZERO) || (stripDir.norm() < ZERO)) { - stripDir[0] = 0; - stripDir[1] = 0; - } - else { - stripDir.normalize(); - } - - Vec2r vec_tmp(_vertices[i - 2]->point2d() - p); - if ((vec_tmp.norm() > thickness[1] * MAX_RATIO_LENGTH_SINGU) || (dirNorm < ZERO) || (dirPrevNorm < ZERO) || - notValid(_vertices[i - 2]->point2d()) || (fabs(stripDir * dir) < EPS_SINGULARITY_RENDERER)) - { - _vertices[i - 2]->setPoint2d(p + thickness[1] * stripDir); - } - - vec_tmp = _vertices[i - 1]->point2d() - p; - if ((vec_tmp.norm() > thickness[0] * MAX_RATIO_LENGTH_SINGU) || (dirNorm < ZERO) || (dirPrevNorm < ZERO) || - notValid(_vertices[i - 1]->point2d()) || (fabs(stripDir * dir) < EPS_SINGULARITY_RENDERER)) - { - _vertices[i - 1]->setPoint2d(p - thickness[0] * stripDir); - } - } // end of for - - //special case of last vertex - sv = *v; - sv2 = *vPrev; - dir = Vec2r(sv->getPoint() - sv2->getPoint()); - orthDir = Vec2r(-dir[1], dir[0]); - if (orthDir.norm() > ZERO) - orthDir.normalize(); - Vec2r stripDirLast(orthDir); - // check whether the orientation was user defined - if (sv->attribute().isAttributeAvailableVec2f("orientation")) { - Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); - if (userDir.norm() > 1e-6) { - userDir.normalize(); - real dp = userDir * orthDir; - if (dp < 0) - userDir = userDir * (-1.0f); - stripDirLast = userDir; - } - else { - ++orientationErrors; - } - } - const float *thicknessLast = sv->attribute().getThickness(); - _vertices.push_back(new StrokeVertexRep(sv->getPoint() + thicknessLast[1] * stripDirLast)); - ++i; - _vertices.push_back(new StrokeVertexRep(sv->getPoint() - thicknessLast[0] * stripDirLast)); - ++i; + int i = 2; // 2 because we have already processed the first vertex + + for (vend = iStrokeVertices.end(), ++v, ++v2; v2 != vend; vPrev = v++, ++v2) { + sv = (*v); + sv2 = (*v2); + svPrev = (*vPrev); + Vec2r p(sv->getPoint()), p2(sv2->getPoint()), pPrev(svPrev->getPoint()); + + //direction and orthogonal vector to the next segment + Vec2r dir(p2 - p); + float dirNorm = dir.norm(); + dir.normalize(); + Vec2r orthDir(-dir[1], dir[0]); + Vec2r stripDir = orthDir; + if (sv->attribute().isAttributeAvailableVec2f("orientation")) { + Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); + if (userDir.norm() > 1e-6) { + userDir.normalize(); + real dp = userDir * orthDir; + if (dp < 0) + userDir = userDir * (-1.0f); + stripDir = userDir; + } + else { + ++orientationErrors; + } + } + + //direction and orthogonal vector to the previous segment + Vec2r dirPrev(p - pPrev); + float dirPrevNorm = dirPrev.norm(); + dirPrev.normalize(); + Vec2r orthDirPrev(-dirPrev[1], dirPrev[0]); + Vec2r stripDirPrev = orthDirPrev; + if (svPrev->attribute().isAttributeAvailableVec2f("orientation")) { + Vec2r userDir = svPrev->attribute().getAttributeVec2f("orientation"); + if (userDir.norm() > 1e-6) { + userDir.normalize(); + real dp = userDir * orthDir; + if (dp < 0) + userDir = userDir * (-1.0f); + stripDirPrev = userDir; + } + else { + ++orientationErrors; + } + } + + const float *thickness = sv->attribute().getThickness(); + _averageThickness += thickness[0] + thickness[1]; + Vec2r pInter; + int interResult; + + interResult = GeomUtils::intersect2dLine2dLine(Vec2r(pPrev + thickness[1] * stripDirPrev), + Vec2r(p + thickness[1] * stripDirPrev), + Vec2r(p + thickness[1] * stripDir), + Vec2r(p2 + thickness[1] * stripDir), + pInter); + if (interResult == GeomUtils::DO_INTERSECT) + _vertices.push_back(new StrokeVertexRep(pInter)); + else + _vertices.push_back(new StrokeVertexRep(p + thickness[1] * stripDir)); + ++i; + + interResult = GeomUtils::intersect2dLine2dLine(Vec2r(pPrev - thickness[0] * stripDirPrev), + Vec2r(p - thickness[0] * stripDirPrev), + Vec2r(p - thickness[0] * stripDir), + Vec2r(p2 - thickness[0] * stripDir), + pInter); + if (interResult == GeomUtils::DO_INTERSECT) + _vertices.push_back(new StrokeVertexRep(pInter)); + else + _vertices.push_back(new StrokeVertexRep(p - thickness[0] * stripDir)); + ++i; + + // if the angle is obtuse, we simply average the directions to avoid the singularity + stripDir = stripDir + stripDirPrev; + if ((dirNorm < ZERO) || (dirPrevNorm < ZERO) || (stripDir.norm() < ZERO)) { + stripDir[0] = 0; + stripDir[1] = 0; + } + else { + stripDir.normalize(); + } + + Vec2r vec_tmp(_vertices[i - 2]->point2d() - p); + if ((vec_tmp.norm() > thickness[1] * MAX_RATIO_LENGTH_SINGU) || (dirNorm < ZERO) || + (dirPrevNorm < ZERO) || notValid(_vertices[i - 2]->point2d()) || + (fabs(stripDir * dir) < EPS_SINGULARITY_RENDERER)) { + _vertices[i - 2]->setPoint2d(p + thickness[1] * stripDir); + } + + vec_tmp = _vertices[i - 1]->point2d() - p; + if ((vec_tmp.norm() > thickness[0] * MAX_RATIO_LENGTH_SINGU) || (dirNorm < ZERO) || + (dirPrevNorm < ZERO) || notValid(_vertices[i - 1]->point2d()) || + (fabs(stripDir * dir) < EPS_SINGULARITY_RENDERER)) { + _vertices[i - 1]->setPoint2d(p - thickness[0] * stripDir); + } + } // end of for + + //special case of last vertex + sv = *v; + sv2 = *vPrev; + dir = Vec2r(sv->getPoint() - sv2->getPoint()); + orthDir = Vec2r(-dir[1], dir[0]); + if (orthDir.norm() > ZERO) + orthDir.normalize(); + Vec2r stripDirLast(orthDir); + // check whether the orientation was user defined + if (sv->attribute().isAttributeAvailableVec2f("orientation")) { + Vec2r userDir = sv->attribute().getAttributeVec2f("orientation"); + if (userDir.norm() > 1e-6) { + userDir.normalize(); + real dp = userDir * orthDir; + if (dp < 0) + userDir = userDir * (-1.0f); + stripDirLast = userDir; + } + else { + ++orientationErrors; + } + } + const float *thicknessLast = sv->attribute().getThickness(); + _vertices.push_back(new StrokeVertexRep(sv->getPoint() + thicknessLast[1] * stripDirLast)); + ++i; + _vertices.push_back(new StrokeVertexRep(sv->getPoint() - thicknessLast[0] * stripDirLast)); + ++i; #if 0 - int n = i - 1; - // check whether the orientation of the extremity was user defined - userDir = _stroke->getEndingOrientation(); - if (userDir != Vec2r(0, 0)) { - userDir.normalize(); - real o1 = (orthDir * userDir); - real o2 = crossP(orthDir, userDir); - real orientation = o1 * o2; - if (orientation > 0) { - // then the vertex to move is vn - if (o1 < 0) - _vertex[n] = _vertex[n - 1] + userDir; - else - _vertex[n] = _vertex[n - 1] - userDir; - } - if (orientation < 0) { - // then we must move vn-1 - if (o1 > 0) - _vertex[n - 1] = _vertex[n] + userDir; - else - _vertex[n - 1] = _vertex[n] - userDir; - } - } + int n = i - 1; + // check whether the orientation of the extremity was user defined + userDir = _stroke->getEndingOrientation(); + if (userDir != Vec2r(0, 0)) { + userDir.normalize(); + real o1 = (orthDir * userDir); + real o2 = crossP(orthDir, userDir); + real orientation = o1 * o2; + if (orientation > 0) { + // then the vertex to move is vn + if (o1 < 0) + _vertex[n] = _vertex[n - 1] + userDir; + else + _vertex[n] = _vertex[n - 1] - userDir; + } + if (orientation < 0) { + // then we must move vn-1 + if (o1 > 0) + _vertex[n - 1] = _vertex[n] + userDir; + else + _vertex[n - 1] = _vertex[n] - userDir; + } + } #endif - _averageThickness /= float(iStrokeVertices.size() - 2); - //I did not use the first and last vertex for the average - if (iStrokeVertices.size() < 3) - _averageThickness = 0.5 * (thicknessLast[1] + thicknessLast[0] + thickness[0] + thickness[1]); - - if (orientationErrors > 0) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: " << orientationErrors <<" invalid zero-length orientation vector(s) found.\n"; - } - } - - if (i != 2 * (int)iStrokeVertices.size()) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: problem with stripe size\n"; - } - } - - cleanUpSingularities (iStrokeVertices); + _averageThickness /= float(iStrokeVertices.size() - 2); + //I did not use the first and last vertex for the average + if (iStrokeVertices.size() < 3) + _averageThickness = 0.5 * (thicknessLast[1] + thicknessLast[0] + thickness[0] + thickness[1]); + + if (orientationErrors > 0) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: " << orientationErrors + << " invalid zero-length orientation vector(s) found.\n"; + } + } + + if (i != 2 * (int)iStrokeVertices.size()) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: problem with stripe size\n"; + } + } + + cleanUpSingularities(iStrokeVertices); } // CLEAN UP ///////////////////////// -void Strip::cleanUpSingularities (const vector& iStrokeVertices) +void Strip::cleanUpSingularities(const vector &iStrokeVertices) { - int k; - int sizeStrip = _vertices.size(); - - for (k = 0; k < sizeStrip; k++) { - if (notValid(_vertices[k]->point2d())) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: strip vertex " << k << " non valid" << endl; - } - return; - } - } - - //return; - if (iStrokeVertices.size() < 2) - return; - int i = 0, j; - vector::const_iterator v, vend, v2; - StrokeVertex *sv, *sv2; - - bool singu1 = false, singu2 = false; - int timeSinceSingu1 = 0, timeSinceSingu2 = 0; - - //special case of first vertex - v = iStrokeVertices.begin(); - for (vend = iStrokeVertices.end(); v != vend; v++) { - v2 = v; - ++v2; - if (v2 == vend) - break; - sv = (*v); - sv2 = (*v2); - Vec2r p(sv->getPoint()), p2(sv2->getPoint()); - - Vec2r dir(p2 - p); - if (dir.norm() > ZERO) - dir.normalize(); - Vec2r dir1, dir2; - dir1 = _vertices[2 * i + 2]->point2d() - _vertices[2 * i]->point2d(); - dir2 = _vertices[2 * i + 3]->point2d() - _vertices[2 * i + 1]->point2d(); - - if ((dir1 * dir) < -ZERO) { - singu1 = true; - timeSinceSingu1++; - } - else { - if (singu1) { - int toto = i - timeSinceSingu1; - if (toto < 0) - cerr << "Stephane dit \"Toto\"" << endl; - //traverse all the vertices of the singularity and average them - Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu1; j <= i; j++) - avP = Vec2r(avP + _vertices[2 * j]->point2d()); - avP = Vec2r(1.0 / float(timeSinceSingu1 + 1) * avP); - for (j = i - timeSinceSingu1; j <= i; j++) - _vertices[2 * j]->setPoint2d(avP); - //_vertex[2 * j] = _vertex[2 * i]; - singu1 = false; - timeSinceSingu1 = 0; - } - } - if ((dir2 * dir) < -ZERO) { - singu2 = true; - timeSinceSingu2++; - } - else { - if (singu2) { - int toto = i - timeSinceSingu2; - if (toto < 0) - cerr << "Stephane dit \"Toto\"" << endl; - //traverse all the vertices of the singularity and average them - Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu2; j <= i; j++) - avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); - avP = Vec2r(1.0 / float(timeSinceSingu2 + 1) * avP); - for (j = i - timeSinceSingu2; j <= i; j++) - _vertices[2 * j + 1]->setPoint2d(avP); - //_vertex[2 * j + 1] = _vertex[2 * i + 1]; - singu2 = false; - timeSinceSingu2 = 0; - } - } - i++; - } - - if (singu1) { - //traverse all the vertices of the singularity and average them - Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu1; j < i; j++) - avP = Vec2r(avP + _vertices[2 * j]->point2d()); - avP = Vec2r(1.0 / float(timeSinceSingu1) * avP); - for (j = i - timeSinceSingu1; j < i; j++) - _vertices[2 * j]->setPoint2d(avP); - } - if (singu2) { - //traverse all the vertices of the singularity and average them - Vec2r avP(0.0, 0.0); - for (j = i - timeSinceSingu2; j < i; j++) - avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); - avP = Vec2r(1.0 / float(timeSinceSingu2) * avP); - for (j = i - timeSinceSingu2; j < i; j++) - _vertices[2 * j + 1]->setPoint2d(avP); - } - - for (k = 0; k < sizeStrip; k++) { - if (notValid(_vertices[k]->point2d())) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: strip vertex " << k << " non valid after cleanup" << endl; - } - return; - } - } + int k; + int sizeStrip = _vertices.size(); + + for (k = 0; k < sizeStrip; k++) { + if (notValid(_vertices[k]->point2d())) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: strip vertex " << k << " non valid" << endl; + } + return; + } + } + + //return; + if (iStrokeVertices.size() < 2) + return; + int i = 0, j; + vector::const_iterator v, vend, v2; + StrokeVertex *sv, *sv2; + + bool singu1 = false, singu2 = false; + int timeSinceSingu1 = 0, timeSinceSingu2 = 0; + + //special case of first vertex + v = iStrokeVertices.begin(); + for (vend = iStrokeVertices.end(); v != vend; v++) { + v2 = v; + ++v2; + if (v2 == vend) + break; + sv = (*v); + sv2 = (*v2); + Vec2r p(sv->getPoint()), p2(sv2->getPoint()); + + Vec2r dir(p2 - p); + if (dir.norm() > ZERO) + dir.normalize(); + Vec2r dir1, dir2; + dir1 = _vertices[2 * i + 2]->point2d() - _vertices[2 * i]->point2d(); + dir2 = _vertices[2 * i + 3]->point2d() - _vertices[2 * i + 1]->point2d(); + + if ((dir1 * dir) < -ZERO) { + singu1 = true; + timeSinceSingu1++; + } + else { + if (singu1) { + int toto = i - timeSinceSingu1; + if (toto < 0) + cerr << "Stephane dit \"Toto\"" << endl; + //traverse all the vertices of the singularity and average them + Vec2r avP(0.0, 0.0); + for (j = i - timeSinceSingu1; j <= i; j++) + avP = Vec2r(avP + _vertices[2 * j]->point2d()); + avP = Vec2r(1.0 / float(timeSinceSingu1 + 1) * avP); + for (j = i - timeSinceSingu1; j <= i; j++) + _vertices[2 * j]->setPoint2d(avP); + //_vertex[2 * j] = _vertex[2 * i]; + singu1 = false; + timeSinceSingu1 = 0; + } + } + if ((dir2 * dir) < -ZERO) { + singu2 = true; + timeSinceSingu2++; + } + else { + if (singu2) { + int toto = i - timeSinceSingu2; + if (toto < 0) + cerr << "Stephane dit \"Toto\"" << endl; + //traverse all the vertices of the singularity and average them + Vec2r avP(0.0, 0.0); + for (j = i - timeSinceSingu2; j <= i; j++) + avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); + avP = Vec2r(1.0 / float(timeSinceSingu2 + 1) * avP); + for (j = i - timeSinceSingu2; j <= i; j++) + _vertices[2 * j + 1]->setPoint2d(avP); + //_vertex[2 * j + 1] = _vertex[2 * i + 1]; + singu2 = false; + timeSinceSingu2 = 0; + } + } + i++; + } + + if (singu1) { + //traverse all the vertices of the singularity and average them + Vec2r avP(0.0, 0.0); + for (j = i - timeSinceSingu1; j < i; j++) + avP = Vec2r(avP + _vertices[2 * j]->point2d()); + avP = Vec2r(1.0 / float(timeSinceSingu1) * avP); + for (j = i - timeSinceSingu1; j < i; j++) + _vertices[2 * j]->setPoint2d(avP); + } + if (singu2) { + //traverse all the vertices of the singularity and average them + Vec2r avP(0.0, 0.0); + for (j = i - timeSinceSingu2; j < i; j++) + avP = Vec2r(avP + _vertices[2 * j + 1]->point2d()); + avP = Vec2r(1.0 / float(timeSinceSingu2) * avP); + for (j = i - timeSinceSingu2; j < i; j++) + _vertices[2 * j + 1]->setPoint2d(avP); + } + + for (k = 0; k < sizeStrip; k++) { + if (notValid(_vertices[k]->point2d())) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: strip vertex " << k << " non valid after cleanup" << endl; + } + return; + } + } } - // Vertex color (RGBA) //////////////////////////////// -void Strip::setVertexColor (const vector& iStrokeVertices) +void Strip::setVertexColor(const vector &iStrokeVertices) { - vector::const_iterator v, vend; - StrokeVertex *sv; - int i = 0; - for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) { - sv = (*v); - _vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB())); - _vertices[i]->setAlpha(sv->attribute().getAlpha()); - i++; - _vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB())); - _vertices[i]->setAlpha(sv->attribute().getAlpha()); - i++; + vector::const_iterator v, vend; + StrokeVertex *sv; + int i = 0; + for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) { + sv = (*v); + _vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB())); + _vertices[i]->setAlpha(sv->attribute().getAlpha()); + i++; + _vertices[i]->setColor(Vec3r(sv->attribute().getColorRGB())); + _vertices[i]->setAlpha(sv->attribute().getAlpha()); + i++; #if 0 - cerr << "col=("<attribute().getColor()[0] << ", " - << sv->attribute().getColor()[1] << ", " << sv->attribute().getColor()[2] << ")" << endl; + cerr << "col=("<attribute().getColor()[0] << ", " + << sv->attribute().getColor()[1] << ", " << sv->attribute().getColor()[2] << ")" << endl; #endif - } + } } - // Texture coordinates //////////////////////////////// -void Strip::computeTexCoord (const vector& iStrokeVertices, float texStep) +void Strip::computeTexCoord(const vector &iStrokeVertices, float texStep) { - vector::const_iterator v, vend; - StrokeVertex *sv; - int i = 0; - for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) { - sv = (*v); - _vertices[i]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 0)); - i++; - _vertices[i]->setTexCoord(Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), -1)); - i++; - } + vector::const_iterator v, vend; + StrokeVertex *sv; + int i = 0; + for (v = iStrokeVertices.begin(), vend = iStrokeVertices.end(); v != vend; v++) { + sv = (*v); + _vertices[i]->setTexCoord( + Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), 0)); + i++; + _vertices[i]->setTexCoord( + Vec2r((real)(sv->curvilinearAbscissa() / (_averageThickness * texStep)), -1)); + i++; + } } -void Strip::computeTexCoordWithTips (const vector& iStrokeVertices, bool tipBegin, bool tipEnd, float texStep) +void Strip::computeTexCoordWithTips(const vector &iStrokeVertices, + bool tipBegin, + bool tipEnd, + float texStep) { - vector::const_iterator v, vend; - StrokeVertex *sv = NULL; - StrokeVertexRep *tvRep[2] = {NULL}; - - float l, fact, t; - float u = 0, uPrev = 0; - int tiles; - int i = 0; - float spacedThickness = _averageThickness * texStep; - - v = iStrokeVertices.begin(); - vend = iStrokeVertices.end(); - l = (*v)->strokeLength() / spacedThickness; - tiles = int(l + 0.5); // round to the nearest - fact = (float(tiles) + 0.5) / l; + vector::const_iterator v, vend; + StrokeVertex *sv = NULL; + StrokeVertexRep *tvRep[2] = {NULL}; + + float l, fact, t; + float u = 0, uPrev = 0; + int tiles; + int i = 0; + float spacedThickness = _averageThickness * texStep; + + v = iStrokeVertices.begin(); + vend = iStrokeVertices.end(); + l = (*v)->strokeLength() / spacedThickness; + tiles = int(l + 0.5); // round to the nearest + fact = (float(tiles) + 0.5) / l; #if 0 - cerr << "l=" << l << " tiles=" << tiles << " _averageThicnkess=" - << _averageThickness << " strokeLength=" << (*v)->strokeLength() << endl; + cerr << "l=" << l << " tiles=" << tiles << " _averageThicnkess=" + << _averageThickness << " strokeLength=" << (*v)->strokeLength() << endl; #endif - vector::iterator currentSV = _vertices.begin(); - StrokeVertexRep *svRep; - if (tipBegin) { - for (; v != vend; v++) { - sv = (*v); - svRep = *currentSV; - u = sv->curvilinearAbscissa() / spacedThickness * fact; - if (u > 0.25) - break; - - svRep->setTexCoord(Vec2r((real)u, -0.5), true); - i++; - ++currentSV; - - svRep = *currentSV; - svRep->setTexCoord(Vec2r((real)u, -1), true); - i++; - ++currentSV; - uPrev = u; - } - - if (v != vend && i >= 2) { - // first transition vertex - if (fabs(u - uPrev) > ZERO) - t = (0.25 - uPrev) / (u - uPrev); - else - t = 0; - for (int k = 0; k < 2; k++) { - tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d()); - tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord()); - // v coord is -0.5 for tvRep[0], -1.0 for tvRep[1] - tvRep[k]->setTexCoord(Vec2r(0.25, -0.5 * (k + 1)), true); - tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB())); - tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha()); - i++; - } - for (int k = 0; k < 2; k++) { - currentSV = _vertices.insert(currentSV, tvRep[k]); - ++currentSV; - } - - // copy the vertices with different texture coordinates - for (int k = 0; k < 2; k++) { - tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2])); - // v coord is 0.0 for tvRep[0], -0.5 for tvRep[1] - tvRep[k]->setTexCoord(Vec2r(0.0, -0.5 * k), true); - i++; - } - for (int k = 0; k < 2; k++) { - currentSV = _vertices.insert(currentSV, tvRep[k]); - ++currentSV; - } - } - } - uPrev = 0; - - // body of the stroke - for (; v != vend; v++) { - sv = (*v); - svRep = *currentSV; - u = sv->curvilinearAbscissa() / spacedThickness * fact - 0.25; - if (u > tiles) - break; - - svRep->setTexCoord(Vec2r((real)u, 0), true); - i++; - ++currentSV; - - svRep = *currentSV; - svRep->setTexCoord(Vec2r((real)u, -0.5), true); - i++; - ++currentSV; - - uPrev = u; - } - - if (tipEnd) { - if (v != vend && i >= 2) { - // second transition vertex - if (fabs(u - uPrev) > ZERO) - t = (float(tiles) - uPrev) / (u - uPrev); - else - t = 0; - for (int k = 0; k < 2; k++) { - tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + t * _vertices[i]->point2d()); - tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + t * _vertices[i]->texCoord()); - // v coord is 0.0 for tvRep[0], -0.5 for tvRep[1] - tvRep[k]->setTexCoord(Vec2r((real)tiles, -0.5 * k), true); - tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + t * Vec3r(sv->attribute().getColorRGB())); - tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha()); - i++; - } - for (int k = 0; k < 2; k++) { - currentSV = _vertices.insert(currentSV, tvRep[k]); - ++currentSV; - } - - // copy the vertices with different texture coordinates - for (int k = 0; k < 2; k++) { - tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2])); - // v coord is -0.5 for tvRep[0], -1.0 for tvRep[1] - tvRep[k]->setTexCoord(Vec2r(0.75, -0.5 * (k + 1)), true); - i++; - } - for (int k = 0; k < 2; k++) { - currentSV = _vertices.insert(currentSV, tvRep[k]); - ++currentSV; - } - } - - // end tip - for (; v != vend; v++) { - sv = (*v); - svRep = *currentSV; - u = 0.75 + sv->curvilinearAbscissa() / spacedThickness * fact - float(tiles) - 0.25; - - svRep->setTexCoord(Vec2r((real)u, -0.5), true); - i++; - ++currentSV; - - svRep = *currentSV; - svRep->setTexCoord(Vec2r((real)u, -1), true); - i++; - ++currentSV; - } - } + vector::iterator currentSV = _vertices.begin(); + StrokeVertexRep *svRep; + if (tipBegin) { + for (; v != vend; v++) { + sv = (*v); + svRep = *currentSV; + u = sv->curvilinearAbscissa() / spacedThickness * fact; + if (u > 0.25) + break; + + svRep->setTexCoord(Vec2r((real)u, -0.5), true); + i++; + ++currentSV; + + svRep = *currentSV; + svRep->setTexCoord(Vec2r((real)u, -1), true); + i++; + ++currentSV; + uPrev = u; + } + + if (v != vend && i >= 2) { + // first transition vertex + if (fabs(u - uPrev) > ZERO) + t = (0.25 - uPrev) / (u - uPrev); + else + t = 0; + for (int k = 0; k < 2; k++) { + tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + + t * _vertices[i]->point2d()); + tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + + t * _vertices[i]->texCoord()); + // v coord is -0.5 for tvRep[0], -1.0 for tvRep[1] + tvRep[k]->setTexCoord(Vec2r(0.25, -0.5 * (k + 1)), true); + tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + + t * Vec3r(sv->attribute().getColorRGB())); + tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha()); + i++; + } + for (int k = 0; k < 2; k++) { + currentSV = _vertices.insert(currentSV, tvRep[k]); + ++currentSV; + } + + // copy the vertices with different texture coordinates + for (int k = 0; k < 2; k++) { + tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2])); + // v coord is 0.0 for tvRep[0], -0.5 for tvRep[1] + tvRep[k]->setTexCoord(Vec2r(0.0, -0.5 * k), true); + i++; + } + for (int k = 0; k < 2; k++) { + currentSV = _vertices.insert(currentSV, tvRep[k]); + ++currentSV; + } + } + } + uPrev = 0; + + // body of the stroke + for (; v != vend; v++) { + sv = (*v); + svRep = *currentSV; + u = sv->curvilinearAbscissa() / spacedThickness * fact - 0.25; + if (u > tiles) + break; + + svRep->setTexCoord(Vec2r((real)u, 0), true); + i++; + ++currentSV; + + svRep = *currentSV; + svRep->setTexCoord(Vec2r((real)u, -0.5), true); + i++; + ++currentSV; + + uPrev = u; + } + + if (tipEnd) { + if (v != vend && i >= 2) { + // second transition vertex + if (fabs(u - uPrev) > ZERO) + t = (float(tiles) - uPrev) / (u - uPrev); + else + t = 0; + for (int k = 0; k < 2; k++) { + tvRep[k] = new StrokeVertexRep((1 - t) * _vertices[i - 2]->point2d() + + t * _vertices[i]->point2d()); + tvRep[k]->setTexCoord((1 - t) * _vertices[i - 2]->texCoord() + + t * _vertices[i]->texCoord()); + // v coord is 0.0 for tvRep[0], -0.5 for tvRep[1] + tvRep[k]->setTexCoord(Vec2r((real)tiles, -0.5 * k), true); + tvRep[k]->setColor((1 - t) * _vertices[i - 2]->color() + + t * Vec3r(sv->attribute().getColorRGB())); + tvRep[k]->setAlpha((1 - t) * _vertices[i - 2]->alpha() + t * sv->attribute().getAlpha()); + i++; + } + for (int k = 0; k < 2; k++) { + currentSV = _vertices.insert(currentSV, tvRep[k]); + ++currentSV; + } + + // copy the vertices with different texture coordinates + for (int k = 0; k < 2; k++) { + tvRep[k] = new StrokeVertexRep(*(_vertices[i - 2])); + // v coord is -0.5 for tvRep[0], -1.0 for tvRep[1] + tvRep[k]->setTexCoord(Vec2r(0.75, -0.5 * (k + 1)), true); + i++; + } + for (int k = 0; k < 2; k++) { + currentSV = _vertices.insert(currentSV, tvRep[k]); + ++currentSV; + } + } + + // end tip + for (; v != vend; v++) { + sv = (*v); + svRep = *currentSV; + u = 0.75 + sv->curvilinearAbscissa() / spacedThickness * fact - float(tiles) - 0.25; + + svRep->setTexCoord(Vec2r((real)u, -0.5), true); + i++; + ++currentSV; + + svRep = *currentSV; + svRep->setTexCoord(Vec2r((real)u, -1), true); + i++; + ++currentSV; + } + } #if 0 - cerr << "u=" << u << " i=" << i << "/" << _sizeStrip << endl; + cerr << "u=" << u << " i=" << i << "/" << _sizeStrip << endl; - for (i = 0; i < _sizeStrip; i++) - _alpha[i] = 1.0; + for (i = 0; i < _sizeStrip; i++) + _alpha[i] = 1.0; - for (i = 0; i < _sizeStrip; i++) - cerr << "(" << _texCoord[i][0] << ", " << _texCoord[i][1] << ") "; - cerr << endl; + for (i = 0; i < _sizeStrip; i++) + cerr << "(" << _texCoord[i][0] << ", " << _texCoord[i][1] << ") "; + cerr << endl; - Vec2r vec_tmp; - for (i = 0; i < _sizeStrip / 2; i++) - vec_tmp = _vertex[2 * i] - _vertex[2 * i + 1]; - if (vec_tmp.norm() > 4 * _averageThickness) - cerr << "Warning (from Fredo): There is a pb in the texture coordinates computation" << endl; + Vec2r vec_tmp; + for (i = 0; i < _sizeStrip / 2; i++) + vec_tmp = _vertex[2 * i] - _vertex[2 * i + 1]; + if (vec_tmp.norm() > 4 * _averageThickness) + cerr << "Warning (from Fredo): There is a pb in the texture coordinates computation" << endl; #endif } @@ -690,128 +706,127 @@ void Strip::computeTexCoordWithTips (const vector& iStrokeVertice StrokeRep::StrokeRep() { - _stroke = 0; - _strokeType = Stroke::OPAQUE_MEDIUM; - _nodeTree = NULL; - _hasTex = false; - _textureStep = 1.0; - for (int a = 0; a < MAX_MTEX; a++) { - _mtex[a] = NULL; - } - TextureManager *ptm = TextureManager::getInstance(); - if (ptm) - _textureId = ptm->getDefaultTextureId(); + _stroke = 0; + _strokeType = Stroke::OPAQUE_MEDIUM; + _nodeTree = NULL; + _hasTex = false; + _textureStep = 1.0; + for (int a = 0; a < MAX_MTEX; a++) { + _mtex[a] = NULL; + } + TextureManager *ptm = TextureManager::getInstance(); + if (ptm) + _textureId = ptm->getDefaultTextureId(); #if 0 - _averageTextureAlpha = 0.5; //default value - if (_strokeType == OIL_STROKE) - _averageTextureAlpha = 0.75; - if (_strokeType >= NO_BLEND_STROKE) - _averageTextureAlpha = 1.0 + _averageTextureAlpha = 0.5; //default value + if (_strokeType == OIL_STROKE) + _averageTextureAlpha = 0.75; + if (_strokeType >= NO_BLEND_STROKE) + _averageTextureAlpha = 1.0 #endif } StrokeRep::StrokeRep(Stroke *iStroke) { - _stroke = iStroke; - _strokeType = iStroke->getMediumType(); - _nodeTree = iStroke->getNodeTree(); - _hasTex = iStroke->hasTex(); - _textureId = iStroke->getTextureId(); - _textureStep = iStroke->getTextureStep(); - for (int a = 0; a < MAX_MTEX; a++) { - if (iStroke->getMTex(a)) { - _mtex[a] = iStroke->getMTex(a); - } - else { - _mtex[a] = NULL; - } - } - if (_textureId == 0) { - TextureManager *ptm = TextureManager::getInstance(); - if (ptm) - _textureId = ptm->getDefaultTextureId(); - } + _stroke = iStroke; + _strokeType = iStroke->getMediumType(); + _nodeTree = iStroke->getNodeTree(); + _hasTex = iStroke->hasTex(); + _textureId = iStroke->getTextureId(); + _textureStep = iStroke->getTextureStep(); + for (int a = 0; a < MAX_MTEX; a++) { + if (iStroke->getMTex(a)) { + _mtex[a] = iStroke->getMTex(a); + } + else { + _mtex[a] = NULL; + } + } + if (_textureId == 0) { + TextureManager *ptm = TextureManager::getInstance(); + if (ptm) + _textureId = ptm->getDefaultTextureId(); + } #if 0 - _averageTextureAlpha = 0.5; //default value - if (_strokeType == OIL_STROKE) - _averageTextureAlpha = 0.75; - if (_strokeType >= NO_BLEND_STROKE) - _averageTextureAlpha = 1.0; + _averageTextureAlpha = 0.5; //default value + if (_strokeType == OIL_STROKE) + _averageTextureAlpha = 0.75; + if (_strokeType >= NO_BLEND_STROKE) + _averageTextureAlpha = 1.0; #endif - create(); + create(); } -StrokeRep::StrokeRep(const StrokeRep& iBrother) +StrokeRep::StrokeRep(const StrokeRep &iBrother) { - //soc unused - int i = 0; - _stroke = iBrother._stroke; - _strokeType = iBrother._strokeType; - _textureId = iBrother._textureId; - _textureStep = iBrother._textureStep; - _nodeTree = iBrother._nodeTree; - _hasTex = iBrother._hasTex; - for (int a = 0; a < MAX_MTEX; a++) { - if (iBrother._mtex[a]) { - _mtex[a] = iBrother._mtex[a]; - } - else { - _mtex[a] = NULL; - } - } - for (vector::const_iterator s = iBrother._strips.begin(), send = iBrother._strips.end(); - s != send; - ++s) - { - _strips.push_back(new Strip(**s)); - } + //soc unused - int i = 0; + _stroke = iBrother._stroke; + _strokeType = iBrother._strokeType; + _textureId = iBrother._textureId; + _textureStep = iBrother._textureStep; + _nodeTree = iBrother._nodeTree; + _hasTex = iBrother._hasTex; + for (int a = 0; a < MAX_MTEX; a++) { + if (iBrother._mtex[a]) { + _mtex[a] = iBrother._mtex[a]; + } + else { + _mtex[a] = NULL; + } + } + for (vector::const_iterator s = iBrother._strips.begin(), send = iBrother._strips.end(); + s != send; + ++s) { + _strips.push_back(new Strip(**s)); + } } StrokeRep::~StrokeRep() { - if (!_strips.empty()) { - for (vector::iterator s = _strips.begin(), send = _strips.end(); s != send; ++s) { - delete (*s); - } - _strips.clear(); - } + if (!_strips.empty()) { + for (vector::iterator s = _strips.begin(), send = _strips.end(); s != send; ++s) { + delete (*s); + } + _strips.clear(); + } } void StrokeRep::create() { - vector strip; - StrokeInternal::StrokeVertexIterator v = _stroke->strokeVerticesBegin(); - StrokeInternal::StrokeVertexIterator vend = _stroke->strokeVerticesEnd(); - - bool first = true; - bool end = false; - while (v != vend) { - while ((v != vend) && (!(*v).attribute().isVisible())) { - ++v; - first = false; - } - while ((v != vend) && ((*v).attribute().isVisible())) { - strip.push_back(&(*v)); - ++v; - } - if (v != vend) { - // add the last vertex and create - strip.push_back(&(*v)); - } - else { - end = true; - } - if ((!strip.empty()) && (strip.size() > 1)) { - _strips.push_back(new Strip(strip, _hasTex, first, end, _textureStep)); - strip.clear(); - } - first = false; - } + vector strip; + StrokeInternal::StrokeVertexIterator v = _stroke->strokeVerticesBegin(); + StrokeInternal::StrokeVertexIterator vend = _stroke->strokeVerticesEnd(); + + bool first = true; + bool end = false; + while (v != vend) { + while ((v != vend) && (!(*v).attribute().isVisible())) { + ++v; + first = false; + } + while ((v != vend) && ((*v).attribute().isVisible())) { + strip.push_back(&(*v)); + ++v; + } + if (v != vend) { + // add the last vertex and create + strip.push_back(&(*v)); + } + else { + end = true; + } + if ((!strip.empty()) && (strip.size() > 1)) { + _strips.push_back(new Strip(strip, _hasTex, first, end, _textureStep)); + strip.clear(); + } + first = false; + } } void StrokeRep::Render(const StrokeRenderer *iRenderer) { - iRenderer->RenderStrokeRep(this); + iRenderer->RenderStrokeRep(this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.h b/source/blender/freestyle/intern/stroke/StrokeRep.h index 3c14d9fa75a..5d58b10184f 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.h +++ b/source/blender/freestyle/intern/stroke/StrokeRep.h @@ -27,11 +27,11 @@ #include "../geometry/Geom.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif extern "C" { -#include "DNA_material_types.h" // for MAX_MTEX +#include "DNA_material_types.h" // for MAX_MTEX struct bNodeTree; } @@ -41,235 +41,242 @@ using namespace Geometry; #if 0 //symbolic constant to call the appropriate renderers and textures -#define NO_TEXTURE_WITH_BLEND_STROKE -2 -#define NO_TEXTURE_STROKE -1 -#define PSEUDO_CHARCOAL_STROKE 0 -#define WASH_BRUSH_STROKE 1 -#define OIL_STROKE 2 -#define NO_BLEND_STROKE 3 -#define CHARCOAL_MIN_STROKE 4 -#define BRUSH_MIN_STROKE 5 -#define OPAQUE_DRY_STROKE 6 -#define OPAQUE_STROKE 7 +# define NO_TEXTURE_WITH_BLEND_STROKE -2 +# define NO_TEXTURE_STROKE -1 +# define PSEUDO_CHARCOAL_STROKE 0 +# define WASH_BRUSH_STROKE 1 +# define OIL_STROKE 2 +# define NO_BLEND_STROKE 3 +# define CHARCOAL_MIN_STROKE 4 +# define BRUSH_MIN_STROKE 5 +# define OPAQUE_DRY_STROKE 6 +# define OPAQUE_STROKE 7 -#define DEFAULT_STROKE 0 +# define DEFAULT_STROKE 0 -#define NUMBER_STROKE_RENDERER 8 +# define NUMBER_STROKE_RENDERER 8 #endif -class StrokeVertexRep -{ -public: - StrokeVertexRep() {} - - StrokeVertexRep(const Vec2r& iPoint2d) - { - _point2d = iPoint2d; - } - - StrokeVertexRep(const StrokeVertexRep& iBrother); - - virtual ~StrokeVertexRep() {} - - inline Vec2r& point2d() - { - return _point2d; - } - - inline Vec2r& texCoord(bool tips=false) - { - if (tips) { - return _texCoord_w_tips; - } - else - return _texCoord; - } - - inline Vec3r& color() - { - return _color; - } - - inline float alpha() - { - return _alpha; - } - - inline void setPoint2d(const Vec2r& p) - { - _point2d = p; - } - - inline void setTexCoord(const Vec2r& p, bool tips=false) - { - if (tips) { - _texCoord_w_tips = p; - } - else { - _texCoord = p; - } - } - - inline void setColor(const Vec3r& p) - { - _color = p; - } - - inline void setAlpha(float a) - { - _alpha = a; - } - -protected: - Vec2r _point2d; - Vec2r _texCoord; - Vec2r _texCoord_w_tips; - Vec3r _color; - float _alpha; +class StrokeVertexRep { + public: + StrokeVertexRep() + { + } + + StrokeVertexRep(const Vec2r &iPoint2d) + { + _point2d = iPoint2d; + } + + StrokeVertexRep(const StrokeVertexRep &iBrother); + + virtual ~StrokeVertexRep() + { + } + + inline Vec2r &point2d() + { + return _point2d; + } + + inline Vec2r &texCoord(bool tips = false) + { + if (tips) { + return _texCoord_w_tips; + } + else + return _texCoord; + } + + inline Vec3r &color() + { + return _color; + } + + inline float alpha() + { + return _alpha; + } + + inline void setPoint2d(const Vec2r &p) + { + _point2d = p; + } + + inline void setTexCoord(const Vec2r &p, bool tips = false) + { + if (tips) { + _texCoord_w_tips = p; + } + else { + _texCoord = p; + } + } + + inline void setColor(const Vec3r &p) + { + _color = p; + } + + inline void setAlpha(float a) + { + _alpha = a; + } + + protected: + Vec2r _point2d; + Vec2r _texCoord; + Vec2r _texCoord_w_tips; + Vec3r _color; + float _alpha; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep") #endif }; -class Strip -{ -public: - typedef std::vector vertex_container; - -protected: - vertex_container _vertices; - float _averageThickness; - -public: - Strip(const std::vector& iStrokeVertices, bool hasTex = false, - bool tipBegin = false, bool tipEnd = false, float texStep = 1.0); - Strip(const Strip& iBrother); - virtual ~Strip(); - -protected: - void createStrip(const std::vector& iStrokeVertices); - void cleanUpSingularities(const std::vector& iStrokeVertices); - void setVertexColor (const std::vector& iStrokeVertices); - void computeTexCoord (const std::vector& iStrokeVertices, float texStep); - void computeTexCoordWithTips (const std::vector& iStrokeVertices, bool tipBegin, bool tipEnd, float texStep); - -public: - inline int sizeStrip() const - { - return _vertices.size(); - } - - inline vertex_container& vertices() - { - return _vertices; - } +class Strip { + public: + typedef std::vector vertex_container; + + protected: + vertex_container _vertices; + float _averageThickness; + + public: + Strip(const std::vector &iStrokeVertices, + bool hasTex = false, + bool tipBegin = false, + bool tipEnd = false, + float texStep = 1.0); + Strip(const Strip &iBrother); + virtual ~Strip(); + + protected: + void createStrip(const std::vector &iStrokeVertices); + void cleanUpSingularities(const std::vector &iStrokeVertices); + void setVertexColor(const std::vector &iStrokeVertices); + void computeTexCoord(const std::vector &iStrokeVertices, float texStep); + void computeTexCoordWithTips(const std::vector &iStrokeVertices, + bool tipBegin, + bool tipEnd, + float texStep); + + public: + inline int sizeStrip() const + { + return _vertices.size(); + } + + inline vertex_container &vertices() + { + return _vertices; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip") #endif }; -class StrokeRep -{ -protected: - Stroke *_stroke; - vector _strips; - Stroke::MediumType _strokeType; - unsigned int _textureId; - float _textureStep; - MTex *_mtex[MAX_MTEX]; - bNodeTree *_nodeTree; - Material *_material; - bool _hasTex; - - // float _averageTextureAlpha; - -public: - StrokeRep(); - StrokeRep(const StrokeRep&); - StrokeRep(Stroke *iStroke); - virtual ~StrokeRep(); - - /*! Creates the strips */ - virtual void create(); - - /*! Renders the stroke using a Renderer */ - virtual void Render(const StrokeRenderer *iRenderer); - - /*! accessors */ - inline Stroke::MediumType getMediumType() const - { - return _strokeType; - } - - inline unsigned getTextureId() const - { - return _textureId; - } - - inline MTex *getMTex(int idx) const - { - return _mtex[idx]; - } - - inline Material *getMaterial() const - { - return _material; - } - - inline bNodeTree *getNodeTree() const - { - return _nodeTree; - } - - inline bool hasTex() const - { - return _hasTex; - } - - inline vector& getStrips() - { - return _strips; - } - - inline unsigned int getNumberOfStrips() const - { - return _strips.size(); - } - - inline Stroke *getStroke() - { - return _stroke; - } - - /*! modifiers */ - inline void setMediumType(Stroke::MediumType itype) - { - _strokeType = itype; - } - - inline void setTextureId(unsigned textureId) - { - _textureId = textureId; - } - - inline void setMaterial(Material *mat) - { - _material = mat; - } - /* - inline void setMTex(int idx, MTex *mtex_ptr) - { - _mtex[idx] = mtex_ptr; - }*/ +class StrokeRep { + protected: + Stroke *_stroke; + vector _strips; + Stroke::MediumType _strokeType; + unsigned int _textureId; + float _textureStep; + MTex *_mtex[MAX_MTEX]; + bNodeTree *_nodeTree; + Material *_material; + bool _hasTex; + + // float _averageTextureAlpha; + + public: + StrokeRep(); + StrokeRep(const StrokeRep &); + StrokeRep(Stroke *iStroke); + virtual ~StrokeRep(); + + /*! Creates the strips */ + virtual void create(); + + /*! Renders the stroke using a Renderer */ + virtual void Render(const StrokeRenderer *iRenderer); + + /*! accessors */ + inline Stroke::MediumType getMediumType() const + { + return _strokeType; + } + + inline unsigned getTextureId() const + { + return _textureId; + } + + inline MTex *getMTex(int idx) const + { + return _mtex[idx]; + } + + inline Material *getMaterial() const + { + return _material; + } + + inline bNodeTree *getNodeTree() const + { + return _nodeTree; + } + + inline bool hasTex() const + { + return _hasTex; + } + + inline vector &getStrips() + { + return _strips; + } + + inline unsigned int getNumberOfStrips() const + { + return _strips.size(); + } + + inline Stroke *getStroke() + { + return _stroke; + } + + /*! modifiers */ + inline void setMediumType(Stroke::MediumType itype) + { + _strokeType = itype; + } + + inline void setTextureId(unsigned textureId) + { + _textureId = textureId; + } + + inline void setMaterial(Material *mat) + { + _material = mat; + } + /* + inline void setMTex(int idx, MTex *mtex_ptr) + { + _mtex[idx] = mtex_ptr; + }*/ #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_REP_H__ +#endif // __FREESTYLE_STROKE_REP_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeShader.cpp b/source/blender/freestyle/intern/stroke/StrokeShader.cpp index 31a212a29f4..b37e137b6f6 100644 --- a/source/blender/freestyle/intern/stroke/StrokeShader.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeShader.cpp @@ -24,9 +24,9 @@ namespace Freestyle { -int StrokeShader::shade(Stroke& ioStroke) const +int StrokeShader::shade(Stroke &ioStroke) const { - return Director_BPy_StrokeShader_shade( const_cast(this), ioStroke); + return Director_BPy_StrokeShader_shade(const_cast(this), ioStroke); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeShader.h b/source/blender/freestyle/intern/stroke/StrokeShader.h index 8b4837746e0..3f312395559 100644 --- a/source/blender/freestyle/intern/stroke/StrokeShader.h +++ b/source/blender/freestyle/intern/stroke/StrokeShader.h @@ -26,7 +26,7 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -60,43 +60,44 @@ class Stroke; * v != vend; * ++v) * { - * StrokeAttribute& att = v->attribute(); - * // perform any attribute modification here... + * StrokeAttribute& att = v->attribute(); + * // perform any attribute modification here... * } * \endcode */ -class StrokeShader -{ -public: - void *py_ss; - - /*! Default constructor. */ - StrokeShader() - { - py_ss = 0; - } - - /*! Destructor. */ - virtual ~StrokeShader() {} - - /*! Returns the string corresponding to the shader's name. */ - virtual string getName() const - { - return "StrokeShader"; - } - - /*! The shading method. This method must be overloaded by inherited classes. - * \param ioStroke: - * The stroke we wish to shade. this Stroke is modified by the Shader (which typically - * modifies the Stroke's attribute's values such as Color, Thickness, Geometry...) - */ - virtual int shade(Stroke& ioStroke) const; +class StrokeShader { + public: + void *py_ss; + + /*! Default constructor. */ + StrokeShader() + { + py_ss = 0; + } + + /*! Destructor. */ + virtual ~StrokeShader() + { + } + + /*! Returns the string corresponding to the shader's name. */ + virtual string getName() const + { + return "StrokeShader"; + } + + /*! The shading method. This method must be overloaded by inherited classes. + * \param ioStroke: + * The stroke we wish to shade. this Stroke is modified by the Shader (which typically + * modifies the Stroke's attribute's values such as Color, Thickness, Geometry...) + */ + virtual int shade(Stroke &ioStroke) const; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeShader") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeShader") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_SHADERS_H__ +#endif // __FREESTYLE_STROKE_SHADERS_H__ diff --git a/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp b/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp index bebab7f1bf3..e135f83cfef 100644 --- a/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeTesselator.cpp @@ -30,56 +30,56 @@ namespace Freestyle { LineRep *StrokeTesselator::Tesselate(Stroke *iStroke) { - if (0 == iStroke) - return 0; + if (0 == iStroke) + return 0; - LineRep *line; - line = new OrientedLineRep(); + LineRep *line; + line = new OrientedLineRep(); - Stroke::vertex_iterator v, vend; - if (2 == iStroke->vertices_size()) { - line->setStyle(LineRep::LINES); - v = iStroke->vertices_begin(); - StrokeVertex *svA = (*v); - v++; - StrokeVertex *svB = (*v); - Vec3r A((*svA)[0], (*svA)[1], 0); - Vec3r B((*svB)[0], (*svB)[1], 0); - line->AddVertex(A); - line->AddVertex(B); - } - else { - if (_overloadFrsMaterial) - line->setFrsMaterial(_FrsMaterial); + Stroke::vertex_iterator v, vend; + if (2 == iStroke->vertices_size()) { + line->setStyle(LineRep::LINES); + v = iStroke->vertices_begin(); + StrokeVertex *svA = (*v); + v++; + StrokeVertex *svB = (*v); + Vec3r A((*svA)[0], (*svA)[1], 0); + Vec3r B((*svB)[0], (*svB)[1], 0); + line->AddVertex(A); + line->AddVertex(B); + } + else { + if (_overloadFrsMaterial) + line->setFrsMaterial(_FrsMaterial); - line->setStyle(LineRep::LINE_STRIP); + line->setStyle(LineRep::LINE_STRIP); - for (v = iStroke->vertices_begin(), vend = iStroke->vertices_end(); v != vend; v++) { - StrokeVertex *sv = (*v); - Vec3r V((*sv)[0], (*sv)[1], 0); - line->AddVertex(V); - } - } - line->setId(iStroke->getId()); - line->ComputeBBox(); + for (v = iStroke->vertices_begin(), vend = iStroke->vertices_end(); v != vend; v++) { + StrokeVertex *sv = (*v); + Vec3r V((*sv)[0], (*sv)[1], 0); + line->AddVertex(V); + } + } + line->setId(iStroke->getId()); + line->ComputeBBox(); - return line; + return line; } template NodeGroup *StrokeTesselator::Tesselate(StrokeVertexIterator begin, StrokeVertexIterator end) { - NodeGroup *group = new NodeGroup; - NodeShape *tshape = new NodeShape; - group->AddChild(tshape); - //tshape->material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f); - tshape->setFrsMaterial(_FrsMaterial); + NodeGroup *group = new NodeGroup; + NodeShape *tshape = new NodeShape; + group->AddChild(tshape); + //tshape->material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f); + tshape->setFrsMaterial(_FrsMaterial); - for (StrokeVertexIterator c = begin, cend = end; c != cend; c++) { - tshape->AddRep(Tesselate((*c))); - } + for (StrokeVertexIterator c = begin, cend = end; c != cend; c++) { + tshape->AddRep(Tesselate((*c))); + } - return group; + return group; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/StrokeTesselator.h b/source/blender/freestyle/intern/stroke/StrokeTesselator.h index 228935f2ab5..8cece705ed4 100644 --- a/source/blender/freestyle/intern/stroke/StrokeTesselator.h +++ b/source/blender/freestyle/intern/stroke/StrokeTesselator.h @@ -27,51 +27,51 @@ #include "../scene_graph/LineRep.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class StrokeTesselator -{ -public: - inline StrokeTesselator() - { - _FrsMaterial.setDiffuse(0, 0, 0, 1); - _overloadFrsMaterial = false; - } - - virtual ~StrokeTesselator() {} - - /*! Builds a line rep contained from a Stroke */ - LineRep *Tesselate(Stroke *iStroke); - - /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup - * from a set of strokes. - */ - template - NodeGroup *Tesselate(StrokeIterator begin, StrokeIterator end); - - inline void setFrsMaterial(const FrsMaterial& iMaterial) - { - _FrsMaterial = iMaterial; - _overloadFrsMaterial = true; - } - - inline const FrsMaterial& frs_material() const - { - return _FrsMaterial; - } - -private: - FrsMaterial _FrsMaterial; - bool _overloadFrsMaterial; +class StrokeTesselator { + public: + inline StrokeTesselator() + { + _FrsMaterial.setDiffuse(0, 0, 0, 1); + _overloadFrsMaterial = false; + } + + virtual ~StrokeTesselator() + { + } + + /*! Builds a line rep contained from a Stroke */ + LineRep *Tesselate(Stroke *iStroke); + + /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup + * from a set of strokes. + */ + template NodeGroup *Tesselate(StrokeIterator begin, StrokeIterator end); + + inline void setFrsMaterial(const FrsMaterial &iMaterial) + { + _FrsMaterial = iMaterial; + _overloadFrsMaterial = true; + } + + inline const FrsMaterial &frs_material() const + { + return _FrsMaterial; + } + + private: + FrsMaterial _FrsMaterial; + bool _overloadFrsMaterial; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeTesselator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeTesselator") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STROKE_TESSELATOR_H__ +#endif // __FREESTYLE_STROKE_TESSELATOR_H__ diff --git a/source/blender/freestyle/intern/stroke/StyleModule.h b/source/blender/freestyle/intern/stroke/StyleModule.h index fe902299f9f..64095e971d6 100644 --- a/source/blender/freestyle/intern/stroke/StyleModule.h +++ b/source/blender/freestyle/intern/stroke/StyleModule.h @@ -33,150 +33,152 @@ #include "../system/StringUtils.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; namespace Freestyle { -class StyleModule -{ -public: - StyleModule(const string& file_name, Interpreter *inter) : _file_name(file_name) - { - _always_refresh = false; - _causal = false; - _drawable = true; - _modified = true; - _displayed = true; - _inter = inter; - } - - virtual ~StyleModule() {} - - StrokeLayer *execute() - { - if (!_inter) { - cerr << "Error: no interpreter was found to execute the script" << endl; - return NULL; - } - - if (!_drawable) { - cerr << "Error: not drawable" << endl; - return NULL; - } - - Operators::reset(); - - if (interpret()) { - cerr << "Error: interpretation failed" << endl; - Operators::reset(); - return NULL; - } - - Operators::StrokesContainer *strokes_set = Operators::getStrokesSet(); - if (strokes_set->empty()) { - cerr << "Error: strokes set empty" << endl; - Operators::reset(); - return NULL; - } - - StrokeLayer *sl = new StrokeLayer; - for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end(); ++it) - sl->AddStroke(*it); - - Operators::reset(); - return sl; - } - -protected: - virtual int interpret() - { - return _inter->interpretFile(_file_name); - } - -public: - // accessors - const string getFileName() const - { - return _file_name; - } - - bool getAlwaysRefresh() const - { - return _always_refresh; - } - - bool getCausal() const - { - return _causal; - } - - bool getDrawable() const - { - return _drawable; - } - - bool getModified() const - { - return _modified; - } - - bool getDisplayed() const - { - return _displayed; - } - - // modifiers - void setFileName(const string& file_name) - { - _file_name = file_name; - } - - void setAlwaysRefresh(bool b = true) - { - _always_refresh = b; - } - - void setCausal(bool b = true) - { - _causal = b; - } - - void setDrawable(bool b = true) - { - _drawable = b; - } - - void setModified(bool b = true) - { - if (_always_refresh) - return; - _modified = b; - } - - void setDisplayed(bool b = true) - { - _displayed = b; - } - -private: - string _file_name; - bool _always_refresh; - bool _causal; - bool _drawable; - bool _modified; - bool _displayed; - -protected: - Interpreter *_inter; +class StyleModule { + public: + StyleModule(const string &file_name, Interpreter *inter) : _file_name(file_name) + { + _always_refresh = false; + _causal = false; + _drawable = true; + _modified = true; + _displayed = true; + _inter = inter; + } + + virtual ~StyleModule() + { + } + + StrokeLayer *execute() + { + if (!_inter) { + cerr << "Error: no interpreter was found to execute the script" << endl; + return NULL; + } + + if (!_drawable) { + cerr << "Error: not drawable" << endl; + return NULL; + } + + Operators::reset(); + + if (interpret()) { + cerr << "Error: interpretation failed" << endl; + Operators::reset(); + return NULL; + } + + Operators::StrokesContainer *strokes_set = Operators::getStrokesSet(); + if (strokes_set->empty()) { + cerr << "Error: strokes set empty" << endl; + Operators::reset(); + return NULL; + } + + StrokeLayer *sl = new StrokeLayer; + for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end(); + ++it) + sl->AddStroke(*it); + + Operators::reset(); + return sl; + } + + protected: + virtual int interpret() + { + return _inter->interpretFile(_file_name); + } + + public: + // accessors + const string getFileName() const + { + return _file_name; + } + + bool getAlwaysRefresh() const + { + return _always_refresh; + } + + bool getCausal() const + { + return _causal; + } + + bool getDrawable() const + { + return _drawable; + } + + bool getModified() const + { + return _modified; + } + + bool getDisplayed() const + { + return _displayed; + } + + // modifiers + void setFileName(const string &file_name) + { + _file_name = file_name; + } + + void setAlwaysRefresh(bool b = true) + { + _always_refresh = b; + } + + void setCausal(bool b = true) + { + _causal = b; + } + + void setDrawable(bool b = true) + { + _drawable = b; + } + + void setModified(bool b = true) + { + if (_always_refresh) + return; + _modified = b; + } + + void setDisplayed(bool b = true) + { + _displayed = b; + } + + private: + string _file_name; + bool _always_refresh; + bool _causal; + bool _drawable; + bool _modified; + bool _displayed; + + protected: + Interpreter *_inter; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StyleModule") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StyleModule") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STYLE_MODULE_H__ +#endif // __FREESTYLE_STYLE_MODULE_H__ diff --git a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp index 4b918cd21bc..dc65871ef38 100644 --- a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp @@ -20,58 +20,57 @@ namespace Freestyle { -TextStrokeRenderer::TextStrokeRenderer(const char *iFileName) -:StrokeRenderer() +TextStrokeRenderer::TextStrokeRenderer(const char *iFileName) : StrokeRenderer() { - if (!iFileName) - iFileName = "freestyle.txt"; - // open the stream: - _ofstream.open(iFileName, ios::out); - if (!_ofstream.is_open()) { - cerr << "couldn't open the output file " << iFileName << endl; - } - _ofstream << "%!FREESTYLE" << endl; - _ofstream << "%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl; - // Bounding box - _ofstream << 0 << " "<< 0 << " " << Canvas::getInstance()->width() << " " << Canvas::getInstance()->height() << - endl; - _ofstream << "%u x y z tleft tright r g b ..." << endl; + if (!iFileName) + iFileName = "freestyle.txt"; + // open the stream: + _ofstream.open(iFileName, ios::out); + if (!_ofstream.is_open()) { + cerr << "couldn't open the output file " << iFileName << endl; + } + _ofstream << "%!FREESTYLE" << endl; + _ofstream << "%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl; + // Bounding box + _ofstream << 0 << " " << 0 << " " << Canvas::getInstance()->width() << " " + << Canvas::getInstance()->height() << endl; + _ofstream << "%u x y z tleft tright r g b ..." << endl; } TextStrokeRenderer::~TextStrokeRenderer() { - Close(); + Close(); } void TextStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { - RenderStrokeRepBasic(iStrokeRep); + RenderStrokeRepBasic(iStrokeRep); } void TextStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const { - Stroke *stroke = iStrokeRep->getStroke(); - if (!stroke) { - cerr << "no stroke associated with Rep" << endl; - return; - } + Stroke *stroke = iStrokeRep->getStroke(); + if (!stroke) { + cerr << "no stroke associated with Rep" << endl; + return; + } - StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin(); - StrokeAttribute att; - while (!v.isEnd()) { - att = v->attribute(); - _ofstream << v->u() << " " << v->getProjectedX() << " " << v->getProjectedY() << " " << v->getProjectedZ() << - " " << att.getThicknessL() << " " << att.getThicknessR() << " " << - att.getColorR() << " " << att.getColorG() << " " << att.getColorB() << " "; - ++v; - } - _ofstream << endl; + StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin(); + StrokeAttribute att; + while (!v.isEnd()) { + att = v->attribute(); + _ofstream << v->u() << " " << v->getProjectedX() << " " << v->getProjectedY() << " " + << v->getProjectedZ() << " " << att.getThicknessL() << " " << att.getThicknessR() + << " " << att.getColorR() << " " << att.getColorG() << " " << att.getColorB() << " "; + ++v; + } + _ofstream << endl; } void TextStrokeRenderer::Close() { - if (_ofstream.is_open()) - _ofstream.close(); + if (_ofstream.is_open()) + _ofstream.close(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h index 957ad9c49db..c5af09ef598 100644 --- a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h +++ b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h @@ -48,23 +48,22 @@ namespace Freestyle { /* */ /**********************************/ -class TextStrokeRenderer : public StrokeRenderer -{ -public: - TextStrokeRenderer(const char *iFileName = NULL); - virtual ~TextStrokeRenderer(); +class TextStrokeRenderer : public StrokeRenderer { + public: + TextStrokeRenderer(const char *iFileName = NULL); + virtual ~TextStrokeRenderer(); - /*! Renders a stroke rep */ - virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; - virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; + /*! Renders a stroke rep */ + virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const; + virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const; - /*! Closes the output file */ - void Close(); + /*! Closes the output file */ + void Close(); -protected: - mutable ofstream _ofstream; + protected: + mutable ofstream _ofstream; }; } /* namespace Freestyle */ -#endif // TEXTSTROKERENDERER_H +#endif // TEXTSTROKERENDERER_H diff --git a/source/blender/freestyle/intern/system/BaseIterator.h b/source/blender/freestyle/intern/system/BaseIterator.h index b01fac96267..3826a129a1c 100644 --- a/source/blender/freestyle/intern/system/BaseIterator.h +++ b/source/blender/freestyle/intern/system/BaseIterator.h @@ -25,88 +25,83 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { // use for iterators defintions -template -class Nonconst_traits; - -template -class Const_traits -{ -public: - typedef Element value_type; - typedef const Element& reference; - typedef const Element *pointer; - typedef ptrdiff_t difference_type; - typedef Nonconst_traits Non_const_traits; +template class Nonconst_traits; + +template class Const_traits { + public: + typedef Element value_type; + typedef const Element &reference; + typedef const Element *pointer; + typedef ptrdiff_t difference_type; + typedef Nonconst_traits Non_const_traits; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Const_traits") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Const_traits") #endif }; -template -class Nonconst_traits -{ -public: - typedef Element value_type; - typedef Element& reference; - typedef Element *pointer; - typedef ptrdiff_t difference_type; - typedef Nonconst_traits Non_const_traits; +template class Nonconst_traits { + public: + typedef Element value_type; + typedef Element &reference; + typedef Element *pointer; + typedef ptrdiff_t difference_type; + typedef Nonconst_traits Non_const_traits; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Nonconst_traits") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Nonconst_traits") #endif }; -class InputIteratorTag_Traits -{ -public: - typedef std::input_iterator_tag iterator_category; +class InputIteratorTag_Traits { + public: + typedef std::input_iterator_tag iterator_category; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:InputIteratorTag_Traits") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:InputIteratorTag_Traits") #endif }; -class BidirectionalIteratorTag_Traits -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; +class BidirectionalIteratorTag_Traits { + public: + typedef std::bidirectional_iterator_tag iterator_category; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BidirectionalIteratorTag_Traits") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BidirectionalIteratorTag_Traits") #endif }; -template -class IteratorBase -{ -public: - virtual ~IteratorBase() {} +template class IteratorBase { + public: + virtual ~IteratorBase() + { + } - virtual bool begin() const = 0; - virtual bool end() const = 0; + virtual bool begin() const = 0; + virtual bool end() const = 0; - typedef typename IteratorTagTraits::iterator_category iterator_category; - typedef typename Traits::value_type value_type; - typedef typename Traits::difference_type difference_type; - typedef typename Traits::pointer pointer; - typedef typename Traits::reference reference; + typedef typename IteratorTagTraits::iterator_category iterator_category; + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; -protected: - IteratorBase() {} + protected: + IteratorBase() + { + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IteratorBase") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IteratorBase") #endif }; } /* namespace Freestyle */ -#endif // BASEITERATOR_H +#endif // BASEITERATOR_H diff --git a/source/blender/freestyle/intern/system/BaseObject.h b/source/blender/freestyle/intern/system/BaseObject.h index 01099c7724a..d64c47b2445 100644 --- a/source/blender/freestyle/intern/system/BaseObject.h +++ b/source/blender/freestyle/intern/system/BaseObject.h @@ -24,51 +24,52 @@ */ #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class BaseObject -{ -public: - inline BaseObject() - { - _ref_counter = 0; - } +class BaseObject { + public: + inline BaseObject() + { + _ref_counter = 0; + } - virtual ~BaseObject() {} + virtual ~BaseObject() + { + } - /*! At least makes a release on this. - * The BaseObject::destroy method must be explicitly called at the end of any overloaded destroy - */ - virtual int destroy() - { - return release(); - } + /*! At least makes a release on this. + * The BaseObject::destroy method must be explicitly called at the end of any overloaded destroy + */ + virtual int destroy() + { + return release(); + } - /*! Increments the reference counter */ - inline int addRef() - { - return ++_ref_counter; - } + /*! Increments the reference counter */ + inline int addRef() + { + return ++_ref_counter; + } - /*! Decrements the reference counter */ - inline int release() - { - if (_ref_counter) - _ref_counter--; - return _ref_counter; - } + /*! Decrements the reference counter */ + inline int release() + { + if (_ref_counter) + _ref_counter--; + return _ref_counter; + } -private: - unsigned _ref_counter; + private: + unsigned _ref_counter; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BaseObject") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BaseObject") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_BASE_OBJECT_H__ +#endif // __FREESTYLE_BASE_OBJECT_H__ diff --git a/source/blender/freestyle/intern/system/Cast.h b/source/blender/freestyle/intern/system/Cast.h index f3efcc462bf..8318633c4b5 100644 --- a/source/blender/freestyle/intern/system/Cast.h +++ b/source/blender/freestyle/intern/system/Cast.h @@ -24,17 +24,15 @@ namespace Freestyle { -namespace Cast +namespace Cast { +template U *cast(T *in) { - template - U *cast(T *in) - { - if (!in) - return NULL; - return dynamic_cast(in); - } -} // end of namespace Cast + if (!in) + return NULL; + return dynamic_cast(in); +} +} // end of namespace Cast } /* namespace Freestyle */ -#endif // __FREESTYLE_CAST_H__ +#endif // __FREESTYLE_CAST_H__ diff --git a/source/blender/freestyle/intern/system/Exception.h b/source/blender/freestyle/intern/system/Exception.h index f334ca040ef..0efd136af8f 100644 --- a/source/blender/freestyle/intern/system/Exception.h +++ b/source/blender/freestyle/intern/system/Exception.h @@ -23,45 +23,44 @@ */ #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class Exception -{ -public: - typedef enum { - NO_EXCEPTION, - UNDEFINED, - } exception_type; +class Exception { + public: + typedef enum { + NO_EXCEPTION, + UNDEFINED, + } exception_type; - static int getException() - { - exception_type e = _exception; - _exception = NO_EXCEPTION; - return e; - } + static int getException() + { + exception_type e = _exception; + _exception = NO_EXCEPTION; + return e; + } - static int raiseException(exception_type exception = UNDEFINED) - { - _exception = exception; - return _exception; - } + static int raiseException(exception_type exception = UNDEFINED) + { + _exception = exception; + return _exception; + } - static void reset() - { - _exception = NO_EXCEPTION; - } + static void reset() + { + _exception = NO_EXCEPTION; + } -private: - static exception_type _exception; + private: + static exception_type _exception; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Exception") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Exception") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_EXCEPTION_H__ +#endif // __FREESTYLE_EXCEPTION_H__ diff --git a/source/blender/freestyle/intern/system/FreestyleConfig.h b/source/blender/freestyle/intern/system/FreestyleConfig.h index 9603ad8190d..34db7121eaf 100644 --- a/source/blender/freestyle/intern/system/FreestyleConfig.h +++ b/source/blender/freestyle/intern/system/FreestyleConfig.h @@ -33,15 +33,15 @@ namespace Config { // Directory separators // TODO Use Blender's stuff for such things! #ifdef WIN32 - static const string DIR_SEP("\\"); - static const string PATH_SEP(";"); +static const string DIR_SEP("\\"); +static const string PATH_SEP(";"); #else - static const string DIR_SEP("/"); - static const string PATH_SEP(":"); -#endif // WIN32 +static const string DIR_SEP("/"); +static const string PATH_SEP(":"); +#endif // WIN32 -} // end of namespace Config +} // end of namespace Config } /* namespace Freestyle */ -#endif // __FREESTYLE_CONFIG_H__ +#endif // __FREESTYLE_CONFIG_H__ diff --git a/source/blender/freestyle/intern/system/Id.h b/source/blender/freestyle/intern/system/Id.h index 5e8e9ba82bd..9a83ae27767 100644 --- a/source/blender/freestyle/intern/system/Id.h +++ b/source/blender/freestyle/intern/system/Id.h @@ -23,7 +23,7 @@ */ #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -31,111 +31,110 @@ namespace Freestyle { /*! Class used to tag any object by an id. * It is made of two unsigned integers. */ -class Id -{ -public: - typedef unsigned id_type; - - /*! Default constructor */ - Id() - { - _first = 0; - _second = 0; - } - - /*! Builds an Id from an integer. - * The second number is set to 0. - */ - Id(id_type id) - { - _first = id; - _second = 0; - } - - /*! Builds the Id from the two numbers */ - Id(id_type ifirst, id_type isecond) - { - _first = ifirst; - _second = isecond; - } - - /*! Copy constructor */ - Id(const Id& iBrother) - { - _first = iBrother._first; - _second = iBrother._second; - } - - /*! Operator= */ - Id& operator=(const Id& iBrother) - { - _first = iBrother._first; - _second = iBrother._second; - return *this; - } - - /*! Returns the first Id number */ - id_type getFirst() const - { - return _first; - } - - /*! Returns the second Id number */ - id_type getSecond() const - { - return _second; - } - - /*! Sets the first number constituting the Id */ - void setFirst(id_type first) - { - _first = first; - } - - /*! Sets the second number constituting the Id */ - void setSecond(id_type second) - { - _second = second; - } - - /*! Operator== */ - bool operator==(const Id& id) const - { - return ((_first == id._first) && (_second == id._second)); - } - - /*! Operator!= */ - bool operator!=(const Id& id) const - { - return !((*this) == id); - } - - /*! Operator< */ - bool operator<(const Id& id) const - { - if (_first < id._first) - return true; - if (_first == id._first && _second < id._second) - return true; - return false; - } - -private: - id_type _first; - id_type _second; +class Id { + public: + typedef unsigned id_type; + + /*! Default constructor */ + Id() + { + _first = 0; + _second = 0; + } + + /*! Builds an Id from an integer. + * The second number is set to 0. + */ + Id(id_type id) + { + _first = id; + _second = 0; + } + + /*! Builds the Id from the two numbers */ + Id(id_type ifirst, id_type isecond) + { + _first = ifirst; + _second = isecond; + } + + /*! Copy constructor */ + Id(const Id &iBrother) + { + _first = iBrother._first; + _second = iBrother._second; + } + + /*! Operator= */ + Id &operator=(const Id &iBrother) + { + _first = iBrother._first; + _second = iBrother._second; + return *this; + } + + /*! Returns the first Id number */ + id_type getFirst() const + { + return _first; + } + + /*! Returns the second Id number */ + id_type getSecond() const + { + return _second; + } + + /*! Sets the first number constituting the Id */ + void setFirst(id_type first) + { + _first = first; + } + + /*! Sets the second number constituting the Id */ + void setSecond(id_type second) + { + _second = second; + } + + /*! Operator== */ + bool operator==(const Id &id) const + { + return ((_first == id._first) && (_second == id._second)); + } + + /*! Operator!= */ + bool operator!=(const Id &id) const + { + return !((*this) == id); + } + + /*! Operator< */ + bool operator<(const Id &id) const + { + if (_first < id._first) + return true; + if (_first == id._first && _second < id._second) + return true; + return false; + } + + private: + id_type _first; + id_type _second; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Id") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Id") #endif }; // stream operator -inline std::ostream& operator<<(std::ostream& s, const Id& id) +inline std::ostream &operator<<(std::ostream &s, const Id &id) { - s << "[" << id.getFirst() << ", " << id.getSecond() << "]"; - return s; + s << "[" << id.getFirst() << ", " << id.getSecond() << "]"; + return s; } } /* namespace Freestyle */ -# endif // __FREESTYLE_ID_H__ +#endif // __FREESTYLE_ID_H__ diff --git a/source/blender/freestyle/intern/system/Interpreter.h b/source/blender/freestyle/intern/system/Interpreter.h index 3bc7fa75141..911d03318e5 100644 --- a/source/blender/freestyle/intern/system/Interpreter.h +++ b/source/blender/freestyle/intern/system/Interpreter.h @@ -25,40 +25,41 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; namespace Freestyle { -class Interpreter -{ -public: - Interpreter() - { - _language = "Unknown"; - } +class Interpreter { + public: + Interpreter() + { + _language = "Unknown"; + } - virtual ~Interpreter() {} + virtual ~Interpreter() + { + } - virtual int interpretFile(const string& filename) = 0; + virtual int interpretFile(const string &filename) = 0; - virtual string getLanguage() const - { - return _language; - } + virtual string getLanguage() const + { + return _language; + } - virtual void reset() = 0; + virtual void reset() = 0; -protected: - string _language; + protected: + string _language; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interpreter") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interpreter") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_INTERPRETER_H__ +#endif // __FREESTYLE_INTERPRETER_H__ diff --git a/source/blender/freestyle/intern/system/Iterator.h b/source/blender/freestyle/intern/system/Iterator.h index c38dc09fd2e..75d49521f96 100644 --- a/source/blender/freestyle/intern/system/Iterator.h +++ b/source/blender/freestyle/intern/system/Iterator.h @@ -25,52 +25,53 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; namespace Freestyle { -class Iterator -{ -public: - virtual ~Iterator() {} +class Iterator { + public: + virtual ~Iterator() + { + } - virtual string getExactTypeName() const - { - return "Iterator"; - } + virtual string getExactTypeName() const + { + return "Iterator"; + } - virtual int increment() - { - cerr << "Warning: increment() not implemented" << endl; - return 0; - } + virtual int increment() + { + cerr << "Warning: increment() not implemented" << endl; + return 0; + } - virtual int decrement() - { - cerr << "Warning: decrement() not implemented" << endl; - return 0; - } + virtual int decrement() + { + cerr << "Warning: decrement() not implemented" << endl; + return 0; + } - virtual bool isBegin() const - { - cerr << "Warning: isBegin() not implemented" << endl; - return false; - } + virtual bool isBegin() const + { + cerr << "Warning: isBegin() not implemented" << endl; + return false; + } - virtual bool isEnd() const - { - cerr << "Warning: isEnd() not implemented" << endl; - return false; - } + virtual bool isEnd() const + { + cerr << "Warning: isEnd() not implemented" << endl; + return false; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Iterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Iterator") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_ITERATOR_H__ +#endif // __FREESTYLE_ITERATOR_H__ diff --git a/source/blender/freestyle/intern/system/PointerSequence.h b/source/blender/freestyle/intern/system/PointerSequence.h index b4fc73d6e93..015033beeb4 100644 --- a/source/blender/freestyle/intern/system/PointerSequence.h +++ b/source/blender/freestyle/intern/system/PointerSequence.h @@ -56,40 +56,38 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -template -class PointerSequence : public C -{ - PointerSequence (PointerSequence& other); - PointerSequence& operator=(PointerSequence& other); +template class PointerSequence : public C { + PointerSequence(PointerSequence &other); + PointerSequence &operator=(PointerSequence &other); - static void destroyer(T t) - { - delete t; - } + static void destroyer(T t) + { + delete t; + } -public: - PointerSequence () {}; + public: + PointerSequence(){}; - ~PointerSequence () - { - destroy(); - } + ~PointerSequence() + { + destroy(); + } - void destroy () - { - for_each(this->begin(), this->end(), destroyer); - } + void destroy() + { + for_each(this->begin(), this->end(), destroyer); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PointerSequence") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PointerSequence") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_POINTER_SEQUENCE_H__ +#endif // __FREESTYLE_POINTER_SEQUENCE_H__ diff --git a/source/blender/freestyle/intern/system/Precision.h b/source/blender/freestyle/intern/system/Precision.h index a03730433e5..c6695f207cc 100644 --- a/source/blender/freestyle/intern/system/Precision.h +++ b/source/blender/freestyle/intern/system/Precision.h @@ -27,9 +27,9 @@ namespace Freestyle { typedef double real; #ifndef SWIG - static const real M_EPSILON = 0.00000001; -#endif // SWIG +static const real M_EPSILON = 0.00000001; +#endif // SWIG } /* namespace Freestyle */ -#endif // __FREESTYLE_PRECISION_H__ +#endif // __FREESTYLE_PRECISION_H__ diff --git a/source/blender/freestyle/intern/system/ProgressBar.h b/source/blender/freestyle/intern/system/ProgressBar.h index d3589987202..b3a1f98f15e 100644 --- a/source/blender/freestyle/intern/system/ProgressBar.h +++ b/source/blender/freestyle/intern/system/ProgressBar.h @@ -25,71 +25,72 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; namespace Freestyle { -class ProgressBar -{ -public: - inline ProgressBar() - { - _numtotalsteps = 0; - _progress = 0; - } - - virtual ~ProgressBar() {} - - virtual void reset() - { - _numtotalsteps = 0; - _progress = 0; - } - - virtual void setTotalSteps(unsigned n) - { - _numtotalsteps = n; - } - - virtual void setProgress(unsigned i) - { - _progress = i; - } - - virtual void setLabelText(const string& s) - { - _label = s; - } - - /*! accessors */ - inline unsigned int getTotalSteps() const - { - return _numtotalsteps; - } - - inline unsigned int getProgress() const - { - return _progress; - } - - inline string getLabelText() const - { - return _label; - } - -protected: - unsigned _numtotalsteps; - unsigned _progress; - string _label; +class ProgressBar { + public: + inline ProgressBar() + { + _numtotalsteps = 0; + _progress = 0; + } + + virtual ~ProgressBar() + { + } + + virtual void reset() + { + _numtotalsteps = 0; + _progress = 0; + } + + virtual void setTotalSteps(unsigned n) + { + _numtotalsteps = n; + } + + virtual void setProgress(unsigned i) + { + _progress = i; + } + + virtual void setLabelText(const string &s) + { + _label = s; + } + + /*! accessors */ + inline unsigned int getTotalSteps() const + { + return _numtotalsteps; + } + + inline unsigned int getProgress() const + { + return _progress; + } + + inline string getLabelText() const + { + return _label; + } + + protected: + unsigned _numtotalsteps; + unsigned _progress; + string _label; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ProgressBar") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ProgressBar") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_PROGRESS_BAR_H__ +#endif // __FREESTYLE_PROGRESS_BAR_H__ diff --git a/source/blender/freestyle/intern/system/PseudoNoise.cpp b/source/blender/freestyle/intern/system/PseudoNoise.cpp index 789583591ab..877cdee0814 100644 --- a/source/blender/freestyle/intern/system/PseudoNoise.cpp +++ b/source/blender/freestyle/intern/system/PseudoNoise.cpp @@ -27,92 +27,94 @@ static int modf_to_index(Freestyle::real x, unsigned int range) { - if (isfinite(x)) { - Freestyle::real tmp; - int i = abs((int)(modf(x, &tmp) * range)); - BLI_assert(i >= 0 && i < range); - return i; - } - else { - return 0; - } + if (isfinite(x)) { + Freestyle::real tmp; + int i = abs((int)(modf(x, &tmp) * range)); + BLI_assert(i >= 0 && i < range); + return i; + } + else { + return 0; + } } namespace Freestyle { real PseudoNoise::_values[]; -PseudoNoise::PseudoNoise() {} +PseudoNoise::PseudoNoise() +{ +} void PseudoNoise::init(long seed) { - RandGen::srand48(seed); - for (unsigned int i = 0; i < NB_VALUE_NOISE; i++) - _values[i] = -1.0 + 2.0 * RandGen::drand48(); + RandGen::srand48(seed); + for (unsigned int i = 0; i < NB_VALUE_NOISE; i++) + _values[i] = -1.0 + 2.0 * RandGen::drand48(); } real PseudoNoise::linearNoise(real x) { - real tmp; - int i = modf_to_index(x, NB_VALUE_NOISE); - real x1 = _values[i], x2 = _values[(i + 1) % NB_VALUE_NOISE]; - real t = modf(x * NB_VALUE_NOISE, &tmp); - return x1 * (1 - t) + x2 * t; + real tmp; + int i = modf_to_index(x, NB_VALUE_NOISE); + real x1 = _values[i], x2 = _values[(i + 1) % NB_VALUE_NOISE]; + real t = modf(x * NB_VALUE_NOISE, &tmp); + return x1 * (1 - t) + x2 * t; } static real LanczosWindowed(real t) { - if (fabs(t) > 2) - return 0; - if (fabs(t) < M_EPSILON) - return 1.0; - return sin(M_PI * t) / (M_PI * t) * sin(M_PI * t / 2.0) / (M_PI * t / 2.0); + if (fabs(t) > 2) + return 0; + if (fabs(t) < M_EPSILON) + return 1.0; + return sin(M_PI * t) / (M_PI * t) * sin(M_PI * t / 2.0) / (M_PI * t / 2.0); } real PseudoNoise::smoothNoise(real x) { - real tmp; - int i = modf_to_index(x, NB_VALUE_NOISE); - int h = i - 1; - if (UNLIKELY(h < 0)) { - h = NB_VALUE_NOISE + h; - } - - real x1 = _values[i], x2 = _values[(i + 1) % NB_VALUE_NOISE]; - real x0 = _values[h], x3 = _values[(i + 2) % NB_VALUE_NOISE]; - - real t = modf(x * NB_VALUE_NOISE, &tmp); - real y0 = LanczosWindowed(-1 -t); - real y1 = LanczosWindowed(-t); - real y2 = LanczosWindowed(1 - t); - real y3 = LanczosWindowed(2 - t); + real tmp; + int i = modf_to_index(x, NB_VALUE_NOISE); + int h = i - 1; + if (UNLIKELY(h < 0)) { + h = NB_VALUE_NOISE + h; + } + + real x1 = _values[i], x2 = _values[(i + 1) % NB_VALUE_NOISE]; + real x0 = _values[h], x3 = _values[(i + 2) % NB_VALUE_NOISE]; + + real t = modf(x * NB_VALUE_NOISE, &tmp); + real y0 = LanczosWindowed(-1 - t); + real y1 = LanczosWindowed(-t); + real y2 = LanczosWindowed(1 - t); + real y3 = LanczosWindowed(2 - t); #if 0 - cerr << "x0=" << x0 << " x1=" << x1 << " x2=" << x2 << " x3=" << x3 << endl; - cerr << "y0=" << y0 << " y1=" << y1 << " y2=" << y2 << " y3=" << y3 << " :" << endl; + cerr << "x0=" << x0 << " x1=" << x1 << " x2=" << x2 << " x3=" << x3 << endl; + cerr << "y0=" << y0 << " y1=" << y1 << " y2=" << y2 << " y3=" << y3 << " :" << endl; #endif - return (x0 * y0 + x1 * y1 + x2 * y2 + x3 * y3) / (y0 + y1 + y2 + y3); + return (x0 * y0 + x1 * y1 + x2 * y2 + x3 * y3) / (y0 + y1 + y2 + y3); } real PseudoNoise::turbulenceSmooth(real x, unsigned nbOctave) { - real y = 0; - real k = 1.0; - for (unsigned int i = 0; i < nbOctave; i++) { - y = y + k * smoothNoise(x * k); - k = k / 2.0; - } - return y; + real y = 0; + real k = 1.0; + for (unsigned int i = 0; i < nbOctave; i++) { + y = y + k * smoothNoise(x * k); + k = k / 2.0; + } + return y; } real PseudoNoise::turbulenceLinear(real x, unsigned nbOctave) { - real y = 0; - real k = 1.0; - for (unsigned int i = 0; i < nbOctave; i++) { - y = y + k * linearNoise(x * k); - k = k / 2.0; - } - return y; + real y = 0; + real k = 1.0; + for (unsigned int i = 0; i < nbOctave; i++) { + y = y + k * linearNoise(x * k); + k = k / 2.0; + } + return y; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/system/PseudoNoise.h b/source/blender/freestyle/intern/system/PseudoNoise.h index dbcc2a477a2..53fe54754c8 100644 --- a/source/blender/freestyle/intern/system/PseudoNoise.h +++ b/source/blender/freestyle/intern/system/PseudoNoise.h @@ -25,35 +25,36 @@ #include "Precision.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class PseudoNoise -{ -public: - PseudoNoise(); +class PseudoNoise { + public: + PseudoNoise(); - virtual ~PseudoNoise() {} + virtual ~PseudoNoise() + { + } - real smoothNoise(real x); - real linearNoise(real x); + real smoothNoise(real x); + real linearNoise(real x); - real turbulenceSmooth(real x, unsigned nbOctave = 8); - real turbulenceLinear(real x, unsigned nbOctave = 8); + real turbulenceSmooth(real x, unsigned nbOctave = 8); + real turbulenceLinear(real x, unsigned nbOctave = 8); - static void init(long seed); + static void init(long seed); -protected: - static const unsigned NB_VALUE_NOISE = 512; - static real _values[NB_VALUE_NOISE]; + protected: + static const unsigned NB_VALUE_NOISE = 512; + static real _values[NB_VALUE_NOISE]; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PseudoNoise") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PseudoNoise") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_PSEUDO_NOISE_H__ +#endif // __FREESTYLE_PSEUDO_NOISE_H__ diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h index d829f4f87c4..bcb36d8d6b5 100644 --- a/source/blender/freestyle/intern/system/PythonInterpreter.h +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -51,104 +51,103 @@ extern "C" { namespace Freestyle { -class PythonInterpreter : public Interpreter -{ -public: - PythonInterpreter() - { - _language = "Python"; - _context = 0; - memset(&_freestyle_bmain, 0, sizeof(Main)); - } - - void setContext(bContext *C) - { - _context = C; - } - - int interpretFile(const string& filename) - { - ReportList *reports = CTX_wm_reports(_context); - BKE_reports_clear(reports); - char *fn = const_cast(filename.c_str()); +class PythonInterpreter : public Interpreter { + public: + PythonInterpreter() + { + _language = "Python"; + _context = 0; + memset(&_freestyle_bmain, 0, sizeof(Main)); + } + + void setContext(bContext *C) + { + _context = C; + } + + int interpretFile(const string &filename) + { + ReportList *reports = CTX_wm_reports(_context); + BKE_reports_clear(reports); + char *fn = const_cast(filename.c_str()); #if 0 - bool ok = BPY_execute_filepath(_context, fn, reports); + bool ok = BPY_execute_filepath(_context, fn, reports); #else - bool ok; - Text *text = BKE_text_load(&_freestyle_bmain, fn, G_MAIN->name); - if (text) { - ok = BPY_execute_text(_context, text, reports, false); - BKE_id_delete(&_freestyle_bmain, text); - } - else { - BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn); - ok = false; - } + bool ok; + Text *text = BKE_text_load(&_freestyle_bmain, fn, G_MAIN->name); + if (text) { + ok = BPY_execute_text(_context, text, reports, false); + BKE_id_delete(&_freestyle_bmain, text); + } + else { + BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn); + ok = false; + } #endif - if (ok == false) { - cerr << "\nError executing Python script from PythonInterpreter::interpretFile" << endl; - cerr << "File: " << fn << endl; - cerr << "Errors: " << endl; - BKE_reports_print(reports, RPT_ERROR); - return 1; - } + if (ok == false) { + cerr << "\nError executing Python script from PythonInterpreter::interpretFile" << endl; + cerr << "File: " << fn << endl; + cerr << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } - // cleaning up - BKE_reports_clear(reports); + // cleaning up + BKE_reports_clear(reports); - return 0; - } + return 0; + } - int interpretString(const string& str, const string& name) - { - ReportList *reports = CTX_wm_reports(_context); + int interpretString(const string &str, const string &name) + { + ReportList *reports = CTX_wm_reports(_context); - BKE_reports_clear(reports); + BKE_reports_clear(reports); - if (!BPY_execute_string(_context, NULL, str.c_str())) { - BPy_errors_to_report(reports); - cerr << "\nError executing Python script from PythonInterpreter::interpretString" << endl; - cerr << "Name: " << name << endl; - cerr << "Errors: " << endl; - BKE_reports_print(reports, RPT_ERROR); - return 1; - } + if (!BPY_execute_string(_context, NULL, str.c_str())) { + BPy_errors_to_report(reports); + cerr << "\nError executing Python script from PythonInterpreter::interpretString" << endl; + cerr << "Name: " << name << endl; + cerr << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } - BKE_reports_clear(reports); + BKE_reports_clear(reports); - return 0; - } + return 0; + } - int interpretText(struct Text *text, const string& name) - { - ReportList *reports = CTX_wm_reports(_context); + int interpretText(struct Text *text, const string &name) + { + ReportList *reports = CTX_wm_reports(_context); - BKE_reports_clear(reports); + BKE_reports_clear(reports); - if (!BPY_execute_text(_context, text, reports, false)) { - cerr << "\nError executing Python script from PythonInterpreter::interpretText" << endl; - cerr << "Name: " << name << endl; - cerr << "Errors: " << endl; - BKE_reports_print(reports, RPT_ERROR); - return 1; - } + if (!BPY_execute_text(_context, text, reports, false)) { + cerr << "\nError executing Python script from PythonInterpreter::interpretText" << endl; + cerr << "Name: " << name << endl; + cerr << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } - BKE_reports_clear(reports); + BKE_reports_clear(reports); - return 0; - } + return 0; + } - void reset() - { - // nothing to do - } + void reset() + { + // nothing to do + } -private: - bContext *_context; - Main _freestyle_bmain; + private: + bContext *_context; + Main _freestyle_bmain; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_PYTHON_INTERPRETER_H__ +#endif // __FREESTYLE_PYTHON_INTERPRETER_H__ diff --git a/source/blender/freestyle/intern/system/RandGen.cpp b/source/blender/freestyle/intern/system/RandGen.cpp index 49a9df14f22..77eb9a8c10a 100644 --- a/source/blender/freestyle/intern/system/RandGen.cpp +++ b/source/blender/freestyle/intern/system/RandGen.cpp @@ -28,69 +28,70 @@ namespace Freestyle { // /////////////////////////////////////////////////////////////////////////////// -#define N 16 -#define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1) -#define X0 0x330E -#define X1 0xABCD -#define X2 0x1234 -#define A0 0xE66D -#define A1 0xDEEC -#define A2 0x5 -#define C 0xB +#define N 16 +#define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1) +#define X0 0x330E +#define X1 0xABCD +#define X2 0x1234 +#define A0 0xE66D +#define A1 0xDEEC +#define A2 0x5 +#define C 0xB #if 0 // XXX Unused -#define HI_BIT (1L << (2 * N - 1)) +# define HI_BIT (1L << (2 * N - 1)) #endif -#define LOW(x) ((unsigned)(x) & MASK) +#define LOW(x) ((unsigned)(x)&MASK) #define HIGH(x) LOW((x) >> N) -#define MUL(x, y, z) \ - { \ - long l = (long)(x) * (long)(y); \ - (z)[0] = LOW(l); \ - (z)[1] = HIGH(l); \ - } +#define MUL(x, y, z) \ + { \ + long l = (long)(x) * (long)(y); \ + (z)[0] = LOW(l); \ + (z)[1] = HIGH(l); \ + } -#define CARRY(x, y) ((unsigned long)((long)(x) + (long)(y)) > MASK) -#define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y))) +#define CARRY(x, y) ((unsigned long)((long)(x) + (long)(y)) > MASK) +#define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y))) #define SET3(x, x0, x1, x2) ((x)[0] = (x0), (x)[1] = (x1), (x)[2] = (x2)) -#if 0 // XXX, unused -#define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n)+1]), LOW((y)[(n)+2])) +#if 0 // XXX, unused +# define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n) + 1]), LOW((y)[(n) + 2])) #endif -#define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C) - -#if 0 // XXX, unused -#define REST(v) \ - for (i = 0; i < 3; i++) { \ - xsubi[i] = x[i]; \ - x[i] = temp[i]; \ - } \ - return (v); \ - (void) 0 - -#define NEST(TYPE, f, F) \ - TYPE f(register unsigned short *xsubi) { \ - register int i; \ - register TYPE v; \ - unsigned temp[3]; \ - for (i = 0; i < 3; i++) { \ - temp[i] = x[i]; \ - x[i] = LOW(xsubi[i]); \ - } \ - v = F(); \ - REST(v); \ - } +#define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C) + +#if 0 // XXX, unused +# define REST(v) \ + for (i = 0; i < 3; i++) { \ + xsubi[i] = x[i]; \ + x[i] = temp[i]; \ + } \ + return (v); \ + (void)0 + +# define NEST(TYPE, f, F) \ + TYPE f(register unsigned short *xsubi) \ + { \ + register int i; \ + register TYPE v; \ + unsigned temp[3]; \ + for (i = 0; i < 3; i++) { \ + temp[i] = x[i]; \ + x[i] = LOW(xsubi[i]); \ + } \ + v = F(); \ + REST(v); \ + } #endif static unsigned x[3] = { - X0, - X1, - X2, + X0, + X1, + X2, }; static unsigned a[3] = { - A0, - A1, - A2, + A0, + A1, + A2, }; static unsigned c = C; @@ -101,29 +102,30 @@ static unsigned c = C; real RandGen::drand48() { - static real two16m = 1.0 / (1L << N); - next(); - return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2])); + static real two16m = 1.0 / (1L << N); + next(); + return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2])); } void RandGen::srand48(long seedval) { - SEED(X0, LOW(seedval), HIGH(seedval)); + SEED(X0, LOW(seedval), HIGH(seedval)); } void RandGen::next() { - unsigned p[2], q[2], r[2], carry0, carry1; - - MUL(a[0], x[0], p); - ADDEQU(p[0], c, carry0); - ADDEQU(p[1], carry0, carry1); - MUL(a[0], x[1], q); - ADDEQU(p[1], q[0], carry0); - MUL(a[1], x[0], r); - x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + a[0] * x[2] + a[1] * x[1] + a[2] * x[0]); - x[1] = LOW(p[1] + r[0]); - x[0] = LOW(p[0]); + unsigned p[2], q[2], r[2], carry0, carry1; + + MUL(a[0], x[0], p); + ADDEQU(p[0], c, carry0); + ADDEQU(p[1], carry0, carry1); + MUL(a[0], x[1], q); + ADDEQU(p[1], q[0], carry0); + MUL(a[1], x[0], r); + x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + a[0] * x[2] + a[1] * x[1] + + a[2] * x[0]); + x[1] = LOW(p[1] + r[0]); + x[0] = LOW(p[0]); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/system/RandGen.h b/source/blender/freestyle/intern/system/RandGen.h index de3c834be55..43f36b0a2fd 100644 --- a/source/blender/freestyle/intern/system/RandGen.h +++ b/source/blender/freestyle/intern/system/RandGen.h @@ -27,25 +27,24 @@ #include "../system/Precision.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class RandGen -{ -public: - static real drand48(); - static void srand48(long value); +class RandGen { + public: + static real drand48(); + static void srand48(long value); -private: - static void next(); + private: + static void next(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RandGen") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RandGen") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_RAND_GEN_H__ +#endif // __FREESTYLE_RAND_GEN_H__ diff --git a/source/blender/freestyle/intern/system/RenderMonitor.h b/source/blender/freestyle/intern/system/RenderMonitor.h index 6d8414337c5..8058ab1b7ff 100644 --- a/source/blender/freestyle/intern/system/RenderMonitor.h +++ b/source/blender/freestyle/intern/system/RenderMonitor.h @@ -27,49 +27,50 @@ extern "C" { } #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class RenderMonitor -{ -public: - inline RenderMonitor(Render *re) - { - _re = re; - } +class RenderMonitor { + public: + inline RenderMonitor(Render *re) + { + _re = re; + } - virtual ~RenderMonitor() {} + virtual ~RenderMonitor() + { + } - inline void setInfo(string info) - { - if (_re && !info.empty()) { - _re->i.infostr = info.c_str(); - _re->stats_draw(_re->sdh, &_re->i); - _re->i.infostr = NULL; - } - } + inline void setInfo(string info) + { + if (_re && !info.empty()) { + _re->i.infostr = info.c_str(); + _re->stats_draw(_re->sdh, &_re->i); + _re->i.infostr = NULL; + } + } - inline void progress(float i) - { - if (_re) - _re->progress(_re->prh, i); - } + inline void progress(float i) + { + if (_re) + _re->progress(_re->prh, i); + } - inline bool testBreak() - { - return _re && _re->test_break(_re->tbh); - } + inline bool testBreak() + { + return _re && _re->test_break(_re->tbh); + } -protected: - Render *_re; + protected: + Render *_re; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RenderMonitor") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RenderMonitor") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_RENDER_MONITOR_H__ +#endif // __FREESTYLE_RENDER_MONITOR_H__ diff --git a/source/blender/freestyle/intern/system/StringUtils.cpp b/source/blender/freestyle/intern/system/StringUtils.cpp index e8c3dad5d85..027491a790f 100644 --- a/source/blender/freestyle/intern/system/StringUtils.cpp +++ b/source/blender/freestyle/intern/system/StringUtils.cpp @@ -28,35 +28,33 @@ namespace Freestyle { namespace StringUtils { -void getPathName(const string& path, const string& base, vector& pathnames) +void getPathName(const string &path, const string &base, vector &pathnames) { - string dir; - string res; - char cleaned[FILE_MAX]; - unsigned size = path.size(); + string dir; + string res; + char cleaned[FILE_MAX]; + unsigned size = path.size(); - pathnames.push_back(base); + pathnames.push_back(base); - for (unsigned int pos = 0, sep = path.find(Config::PATH_SEP, pos); - pos < size; - pos = sep + 1, sep = path.find(Config::PATH_SEP, pos)) - { - if (sep == (unsigned)string::npos) - sep = size; + for (unsigned int pos = 0, sep = path.find(Config::PATH_SEP, pos); pos < size; + pos = sep + 1, sep = path.find(Config::PATH_SEP, pos)) { + if (sep == (unsigned)string::npos) + sep = size; - dir = path.substr(pos, sep - pos); + dir = path.substr(pos, sep - pos); - BLI_strncpy(cleaned, dir.c_str(), FILE_MAX); - BLI_cleanup_file(NULL, cleaned); - res = string(cleaned); + BLI_strncpy(cleaned, dir.c_str(), FILE_MAX); + BLI_cleanup_file(NULL, cleaned); + res = string(cleaned); - if (!base.empty()) - res += Config::DIR_SEP + base; + if (!base.empty()) + res += Config::DIR_SEP + base; - pathnames.push_back(res); - } + pathnames.push_back(res); + } } -} // end of namespace StringUtils +} // end of namespace StringUtils } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/system/StringUtils.h b/source/blender/freestyle/intern/system/StringUtils.h index 8329f071a51..575d26597ee 100644 --- a/source/blender/freestyle/intern/system/StringUtils.h +++ b/source/blender/freestyle/intern/system/StringUtils.h @@ -39,19 +39,18 @@ namespace Freestyle { namespace StringUtils { -void getPathName(const string& path, const string& base, vector& pathnames); +void getPathName(const string &path, const string &base, vector &pathnames); // STL related -struct ltstr -{ - bool operator()(const char *s1, const char *s2) const - { - return strcmp(s1, s2) < 0; - } +struct ltstr { + bool operator()(const char *s1, const char *s2) const + { + return strcmp(s1, s2) < 0; + } }; -} // end of namespace StringUtils +} // end of namespace StringUtils } /* namespace Freestyle */ -#endif // __FREESTYLE_STRING_UTILS_H__ +#endif // __FREESTYLE_STRING_UTILS_H__ diff --git a/source/blender/freestyle/intern/system/TimeStamp.h b/source/blender/freestyle/intern/system/TimeStamp.h index adf6083a16f..2fbf83d226d 100644 --- a/source/blender/freestyle/intern/system/TimeStamp.h +++ b/source/blender/freestyle/intern/system/TimeStamp.h @@ -23,51 +23,52 @@ */ #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class TimeStamp -{ -public: - static inline TimeStamp *instance() - { - return &_instance; - } +class TimeStamp { + public: + static inline TimeStamp *instance() + { + return &_instance; + } - inline unsigned getTimeStamp() const - { - return _time_stamp; - } + inline unsigned getTimeStamp() const + { + return _time_stamp; + } - inline void increment() - { - ++_time_stamp; - } + inline void increment() + { + ++_time_stamp; + } - inline void reset() - { - _time_stamp = 1; - } + inline void reset() + { + _time_stamp = 1; + } -protected: - TimeStamp() - { - _time_stamp = 1; - } + protected: + TimeStamp() + { + _time_stamp = 1; + } - TimeStamp(const TimeStamp&) {} + TimeStamp(const TimeStamp &) + { + } -private: - static TimeStamp _instance; - unsigned _time_stamp; + private: + static TimeStamp _instance; + unsigned _time_stamp; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TimeStamp") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TimeStamp") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_TIME_STAMP_H__ +#endif // __FREESTYLE_TIME_STAMP_H__ diff --git a/source/blender/freestyle/intern/system/TimeUtils.h b/source/blender/freestyle/intern/system/TimeUtils.h index 1e3bd05c81d..6d4c56ab15e 100644 --- a/source/blender/freestyle/intern/system/TimeUtils.h +++ b/source/blender/freestyle/intern/system/TimeUtils.h @@ -25,37 +25,40 @@ #include #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class Chronometer -{ -public: - inline Chronometer() {} - inline ~Chronometer() {} +class Chronometer { + public: + inline Chronometer() + { + } + inline ~Chronometer() + { + } - inline clock_t start() - { - _start = clock(); - return _start; - } + inline clock_t start() + { + _start = clock(); + return _start; + } - inline double stop() - { - clock_t stop = clock(); - return (double)(stop - _start) / CLOCKS_PER_SEC; - } + inline double stop() + { + clock_t stop = clock(); + return (double)(stop - _start) / CLOCKS_PER_SEC; + } -private: - clock_t _start; + private: + clock_t _start; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chronometer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chronometer") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_TIME_UTILS_H__ +#endif // __FREESTYLE_TIME_UTILS_H__ diff --git a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp index 37273b0dd1e..6c5cbc71a76 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp @@ -25,91 +25,102 @@ namespace Freestyle { -ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource& source, const real proscenium[4], +ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source, + const real proscenium[4], unsigned numCells) -: GridDensityProvider(source), numCells(numCells) + : GridDensityProvider(source), numCells(numCells) { - initialize (proscenium); + initialize(proscenium); } -ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform, unsigned numCells) -: GridDensityProvider(source), numCells(numCells) +ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + unsigned numCells) + : GridDensityProvider(source), numCells(numCells) { - real proscenium[4]; - calculateQuickProscenium(transform, bbox, proscenium); + real proscenium[4]; + calculateQuickProscenium(transform, bbox, proscenium); - initialize (proscenium); + initialize(proscenium); } -ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource& source, unsigned numCells) -: GridDensityProvider(source), numCells(numCells) +ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source, + unsigned numCells) + : GridDensityProvider(source), numCells(numCells) { - real proscenium[4]; - calculateOptimalProscenium(source, proscenium); + real proscenium[4]; + calculateOptimalProscenium(source, proscenium); - initialize (proscenium); + initialize(proscenium); } -ArbitraryGridDensityProvider::~ArbitraryGridDensityProvider() {} +ArbitraryGridDensityProvider::~ArbitraryGridDensityProvider() +{ +} void ArbitraryGridDensityProvider::initialize(const real proscenium[4]) { - float prosceniumWidth = (proscenium[1] - proscenium[0]); - float prosceniumHeight = (proscenium[3] - proscenium[2]); - real cellArea = prosceniumWidth * prosceniumHeight / numCells; - if (G.debug & G_DEBUG_FREESTYLE) { - cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea << "." << endl; - } - - _cellSize = sqrt(cellArea); - // Now we know how many cells make each side of our grid - _cellsX = ceil(prosceniumWidth / _cellSize); - _cellsY = ceil(prosceniumHeight / _cellSize); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Make sure the grid exceeds the proscenium by a small amount - float safetyZone = 0.1f; - if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { - _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); - } - if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { - _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Find grid origin - _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; - _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; + float prosceniumWidth = (proscenium[1] - proscenium[0]); + float prosceniumHeight = (proscenium[3] - proscenium[2]); + real cellArea = prosceniumWidth * prosceniumHeight / numCells; + if (G.debug & G_DEBUG_FREESTYLE) { + cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea + << "." << endl; + } + + _cellSize = sqrt(cellArea); + // Now we know how many cells make each side of our grid + _cellsX = ceil(prosceniumWidth / _cellSize); + _cellsY = ceil(prosceniumHeight / _cellSize); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Make sure the grid exceeds the proscenium by a small amount + float safetyZone = 0.1f; + if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { + _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); + } + if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { + _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Find grid origin + _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; + _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; } ArbitraryGridDensityProviderFactory::ArbitraryGridDensityProviderFactory(unsigned numCells) -: numCells(numCells) + : numCells(numCells) { } -ArbitraryGridDensityProviderFactory::~ArbitraryGridDensityProviderFactory() {} +ArbitraryGridDensityProviderFactory::~ArbitraryGridDensityProviderFactory() +{ +} -AutoPtr ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, - const real proscenium[4]) +AutoPtr ArbitraryGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const real proscenium[4]) { - return AutoPtr(new ArbitraryGridDensityProvider(source, proscenium, numCells)); + return AutoPtr( + new ArbitraryGridDensityProvider(source, proscenium, numCells)); } -AutoPtr -ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform) +AutoPtr ArbitraryGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const BBox &bbox, const GridHelpers::Transform &transform) { - return AutoPtr(new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); + return AutoPtr( + new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); } -AutoPtr ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr ArbitraryGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source) { - return AutoPtr(new ArbitraryGridDensityProvider(source, numCells)); + return AutoPtr(new ArbitraryGridDensityProvider(source, numCells)); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h index 8b616002279..97aae3d653c 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h @@ -26,41 +26,45 @@ namespace Freestyle { -class ArbitraryGridDensityProvider : public GridDensityProvider -{ - // Disallow copying and assignment - ArbitraryGridDensityProvider(const ArbitraryGridDensityProvider& other); - ArbitraryGridDensityProvider& operator=(const ArbitraryGridDensityProvider& other); +class ArbitraryGridDensityProvider : public GridDensityProvider { + // Disallow copying and assignment + ArbitraryGridDensityProvider(const ArbitraryGridDensityProvider &other); + ArbitraryGridDensityProvider &operator=(const ArbitraryGridDensityProvider &other); -public: - ArbitraryGridDensityProvider(OccluderSource& source, const real proscenium[4], unsigned numCells); - ArbitraryGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform, unsigned numCells); - ArbitraryGridDensityProvider(OccluderSource& source, unsigned numCells); - virtual ~ArbitraryGridDensityProvider(); + public: + ArbitraryGridDensityProvider(OccluderSource &source, + const real proscenium[4], + unsigned numCells); + ArbitraryGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + unsigned numCells); + ArbitraryGridDensityProvider(OccluderSource &source, unsigned numCells); + virtual ~ArbitraryGridDensityProvider(); -protected: - unsigned numCells; + protected: + unsigned numCells; -private: - void initialize (const real proscenium[4]); + private: + void initialize(const real proscenium[4]); }; -class ArbitraryGridDensityProviderFactory : public GridDensityProviderFactory -{ -public: - ArbitraryGridDensityProviderFactory(unsigned numCells); - ~ArbitraryGridDensityProviderFactory(); +class ArbitraryGridDensityProviderFactory : public GridDensityProviderFactory { + public: + ArbitraryGridDensityProviderFactory(unsigned numCells); + ~ArbitraryGridDensityProviderFactory(); - AutoPtr newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - AutoPtr newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform); - AutoPtr newGridDensityProvider(OccluderSource& source); + AutoPtr newGridDensityProvider(OccluderSource &source, + const real proscenium[4]); + AutoPtr newGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform); + AutoPtr newGridDensityProvider(OccluderSource &source); -protected: - unsigned numCells; + protected: + unsigned numCells; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_ARBITRARY_GRID_DENSITY_PROVIDER_H__ +#endif // __FREESTYLE_ARBITRARY_GRID_DENSITY_PROVIDER_H__ diff --git a/source/blender/freestyle/intern/view_map/AutoPtrHelper.h b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h index 2554d303b08..9da109ab2a6 100644 --- a/source/blender/freestyle/intern/view_map/AutoPtrHelper.h +++ b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h @@ -27,28 +27,36 @@ namespace Freestyle { #if __cplusplus > 199711L -template -class AutoPtr : public std::unique_ptr { -public: - AutoPtr() : std::unique_ptr() {} - AutoPtr(T *ptr) : std::unique_ptr(ptr) {} - - /* TODO(sergey): Is there more clear way to do this? */ - template - AutoPtr(AutoPtr& other) : std::unique_ptr(other.get()) { - other.release(); - } +template class AutoPtr : public std::unique_ptr { + public: + AutoPtr() : std::unique_ptr() + { + } + AutoPtr(T *ptr) : std::unique_ptr(ptr) + { + } + + /* TODO(sergey): Is there more clear way to do this? */ + template AutoPtr(AutoPtr &other) : std::unique_ptr(other.get()) + { + other.release(); + } }; #else -template -class AutoPtr : public std::auto_ptr { -public: - AutoPtr() : std::auto_ptr() {} - AutoPtr(T *ptr) : std::auto_ptr(ptr) {} - AutoPtr(std::auto_ptr_ref ref) : std::auto_ptr(ref) {} +template class AutoPtr : public std::auto_ptr { + public: + AutoPtr() : std::auto_ptr() + { + } + AutoPtr(T *ptr) : std::auto_ptr(ptr) + { + } + AutoPtr(std::auto_ptr_ref ref) : std::auto_ptr(ref) + { + } }; #endif -} /* namespace Freestyle */ +} /* namespace Freestyle */ #endif // __FREESTYLE_AUTOPTR_HELPER_H__ diff --git a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp index 8fc3fe810af..1384dc0f78b 100644 --- a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp @@ -25,112 +25,123 @@ namespace Freestyle { -AverageAreaGridDensityProvider::AverageAreaGridDensityProvider(OccluderSource& source, const real proscenium[4], +AverageAreaGridDensityProvider::AverageAreaGridDensityProvider(OccluderSource &source, + const real proscenium[4], real sizeFactor) -: GridDensityProvider(source) + : GridDensityProvider(source) { - initialize (proscenium, sizeFactor); + initialize(proscenium, sizeFactor); } -AverageAreaGridDensityProvider::AverageAreaGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform, real sizeFactor) -: GridDensityProvider(source) +AverageAreaGridDensityProvider::AverageAreaGridDensityProvider( + OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + real sizeFactor) + : GridDensityProvider(source) { - real proscenium[4]; - calculateQuickProscenium(transform, bbox, proscenium); + real proscenium[4]; + calculateQuickProscenium(transform, bbox, proscenium); - initialize(proscenium, sizeFactor); + initialize(proscenium, sizeFactor); } -AverageAreaGridDensityProvider::AverageAreaGridDensityProvider(OccluderSource& source, real sizeFactor) -: GridDensityProvider(source) +AverageAreaGridDensityProvider::AverageAreaGridDensityProvider(OccluderSource &source, + real sizeFactor) + : GridDensityProvider(source) { - real proscenium[4]; - calculateOptimalProscenium(source, proscenium); + real proscenium[4]; + calculateOptimalProscenium(source, proscenium); - initialize(proscenium, sizeFactor); + initialize(proscenium, sizeFactor); } -AverageAreaGridDensityProvider::~AverageAreaGridDensityProvider() {} +AverageAreaGridDensityProvider::~AverageAreaGridDensityProvider() +{ +} void AverageAreaGridDensityProvider::initialize(const real proscenium[4], real sizeFactor) { - float prosceniumWidth = (proscenium[1] - proscenium[0]); - float prosceniumHeight = (proscenium[3] - proscenium[2]); - - real cellArea = 0.0; - unsigned numFaces = 0; - for (source.begin(); source.isValid(); source.next()) { - Polygon3r& poly(source.getGridSpacePolygon()); - Vec3r min, max; - poly.getBBox(min, max); - cellArea += (max[0] - min[0]) * (max[1] - min[1]); - ++numFaces; - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Total area: " << cellArea << ". Number of faces: " << numFaces << "." << endl; - } - cellArea /= numFaces; - cellArea *= sizeFactor; - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Building grid with average area " << cellArea << endl; - } - - _cellSize = sqrt(cellArea); - unsigned maxCells = 931; // * 1.1 = 1024 - if (std::max(prosceniumWidth, prosceniumHeight) / _cellSize > maxCells) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Scene-dependent cell size (" << _cellSize << " square) is too small." << endl; - } - _cellSize = std::max(prosceniumWidth, prosceniumHeight) / maxCells; - } - // Now we know how many cells make each side of our grid - _cellsX = ceil(prosceniumWidth / _cellSize); - _cellsY = ceil(prosceniumHeight / _cellSize); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Make sure the grid exceeds the proscenium by a small amount - float safetyZone = 0.1f; - if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { - _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); - } - if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { - _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Find grid origin - _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; - _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; + float prosceniumWidth = (proscenium[1] - proscenium[0]); + float prosceniumHeight = (proscenium[3] - proscenium[2]); + + real cellArea = 0.0; + unsigned numFaces = 0; + for (source.begin(); source.isValid(); source.next()) { + Polygon3r &poly(source.getGridSpacePolygon()); + Vec3r min, max; + poly.getBBox(min, max); + cellArea += (max[0] - min[0]) * (max[1] - min[1]); + ++numFaces; + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Total area: " << cellArea << ". Number of faces: " << numFaces << "." << endl; + } + cellArea /= numFaces; + cellArea *= sizeFactor; + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Building grid with average area " << cellArea << endl; + } + + _cellSize = sqrt(cellArea); + unsigned maxCells = 931; // * 1.1 = 1024 + if (std::max(prosceniumWidth, prosceniumHeight) / _cellSize > maxCells) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Scene-dependent cell size (" << _cellSize << " square) is too small." << endl; + } + _cellSize = std::max(prosceniumWidth, prosceniumHeight) / maxCells; + } + // Now we know how many cells make each side of our grid + _cellsX = ceil(prosceniumWidth / _cellSize); + _cellsY = ceil(prosceniumHeight / _cellSize); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Make sure the grid exceeds the proscenium by a small amount + float safetyZone = 0.1f; + if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { + _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); + } + if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { + _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Find grid origin + _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; + _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; } AverageAreaGridDensityProviderFactory::AverageAreaGridDensityProviderFactory(real sizeFactor) -: sizeFactor(sizeFactor) + : sizeFactor(sizeFactor) { } -AverageAreaGridDensityProviderFactory::~AverageAreaGridDensityProviderFactory() {} +AverageAreaGridDensityProviderFactory::~AverageAreaGridDensityProviderFactory() +{ +} -AutoPtr -AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) +AutoPtr AverageAreaGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const real proscenium[4]) { - return AutoPtr(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + return AutoPtr( + new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); } -AutoPtr -AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform) +AutoPtr AverageAreaGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const BBox &bbox, const GridHelpers::Transform &transform) { - return AutoPtr(new AverageAreaGridDensityProvider(source, bbox, transform, sizeFactor)); + return AutoPtr( + new AverageAreaGridDensityProvider(source, bbox, transform, sizeFactor)); } -AutoPtr AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr AverageAreaGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source) { - return AutoPtr(new AverageAreaGridDensityProvider(source, sizeFactor)); + return AutoPtr(new AverageAreaGridDensityProvider(source, sizeFactor)); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h index e422ad2ba8d..f530cf35569 100644 --- a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h @@ -26,38 +26,42 @@ namespace Freestyle { -class AverageAreaGridDensityProvider : public GridDensityProvider -{ - // Disallow copying and assignment - AverageAreaGridDensityProvider(const AverageAreaGridDensityProvider& other); - AverageAreaGridDensityProvider& operator=(const AverageAreaGridDensityProvider& other); - -public: - AverageAreaGridDensityProvider(OccluderSource& source, const real proscenium[4], real sizeFactor); - AverageAreaGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform, real sizeFactor); - AverageAreaGridDensityProvider(OccluderSource& source, real sizeFactor); - virtual ~AverageAreaGridDensityProvider(); - -private: - void initialize (const real proscenium[4], real sizeFactor); +class AverageAreaGridDensityProvider : public GridDensityProvider { + // Disallow copying and assignment + AverageAreaGridDensityProvider(const AverageAreaGridDensityProvider &other); + AverageAreaGridDensityProvider &operator=(const AverageAreaGridDensityProvider &other); + + public: + AverageAreaGridDensityProvider(OccluderSource &source, + const real proscenium[4], + real sizeFactor); + AverageAreaGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + real sizeFactor); + AverageAreaGridDensityProvider(OccluderSource &source, real sizeFactor); + virtual ~AverageAreaGridDensityProvider(); + + private: + void initialize(const real proscenium[4], real sizeFactor); }; -class AverageAreaGridDensityProviderFactory : public GridDensityProviderFactory -{ -public: - AverageAreaGridDensityProviderFactory(real sizeFactor); - ~AverageAreaGridDensityProviderFactory(); +class AverageAreaGridDensityProviderFactory : public GridDensityProviderFactory { + public: + AverageAreaGridDensityProviderFactory(real sizeFactor); + ~AverageAreaGridDensityProviderFactory(); - AutoPtr newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - AutoPtr newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform); - AutoPtr newGridDensityProvider(OccluderSource& source); + AutoPtr newGridDensityProvider(OccluderSource &source, + const real proscenium[4]); + AutoPtr newGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform); + AutoPtr newGridDensityProvider(OccluderSource &source); -protected: - real sizeFactor; + protected: + real sizeFactor; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_AVERAGE_AREA_GRID_DENSITY_PROVIDER_H__ +#endif // __FREESTYLE_AVERAGE_AREA_GRID_DENSITY_PROVIDER_H__ diff --git a/source/blender/freestyle/intern/view_map/BoxGrid.cpp b/source/blender/freestyle/intern/view_map/BoxGrid.cpp index 396688fe62c..5a490e3c7cc 100644 --- a/source/blender/freestyle/intern/view_map/BoxGrid.cpp +++ b/source/blender/freestyle/intern/view_map/BoxGrid.cpp @@ -38,199 +38,217 @@ namespace Freestyle { // Cell ///////// -BoxGrid::Cell::Cell() {} +BoxGrid::Cell::Cell() +{ +} -BoxGrid::Cell::~Cell() {} +BoxGrid::Cell::~Cell() +{ +} void BoxGrid::Cell::setDimensions(real x, real y, real sizeX, real sizeY) { - const real epsilon = 1.0e-06; - boundary[0] = x - epsilon; - boundary[1] = x + sizeX + epsilon; - boundary[2] = y - epsilon; - boundary[3] = y + sizeY + epsilon; + const real epsilon = 1.0e-06; + boundary[0] = x - epsilon; + boundary[1] = x + sizeX + epsilon; + boundary[2] = y - epsilon; + boundary[3] = y + sizeY + epsilon; } -bool BoxGrid::Cell::compareOccludersByShallowestPoint(const BoxGrid::OccluderData *a, const BoxGrid::OccluderData *b) +bool BoxGrid::Cell::compareOccludersByShallowestPoint(const BoxGrid::OccluderData *a, + const BoxGrid::OccluderData *b) { - return a->shallowest < b->shallowest; + return a->shallowest < b->shallowest; } void BoxGrid::Cell::indexPolygons() { - // Sort occluders by their shallowest points. - sort(faces.begin(), faces.end(), compareOccludersByShallowestPoint); + // Sort occluders by their shallowest points. + sort(faces.begin(), faces.end(), compareOccludersByShallowestPoint); } // Iterator ////////////////// -BoxGrid::Iterator::Iterator (BoxGrid& grid, Vec3r& center, real /*epsilon*/) -: _target(grid.transform(center)), _foundOccludee(false) +BoxGrid::Iterator::Iterator(BoxGrid &grid, Vec3r ¢er, real /*epsilon*/) + : _target(grid.transform(center)), _foundOccludee(false) { - // Find target cell - _cell = grid.findCell(_target); + // Find target cell + _cell = grid.findCell(_target); #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Searching for occluders of edge centered at " << _target << " in cell [" << - 1_cell->boundary[0] << ", " << _cell->boundary[1] << ", " << _cell->boundary[2] << - ", " << _cell->boundary[3] << "] (" << _cell->faces.size() << " occluders)" << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Searching for occluders of edge centered at " << _target << " in cell [" + << 1_cell->boundary[0] << ", " << _cell->boundary[1] << ", " << _cell->boundary[2] << ", " + << _cell->boundary[3] << "] (" << _cell->faces.size() << " occluders)" << endl; + } #endif - // Set iterator - _current = _cell->faces.begin(); + // Set iterator + _current = _cell->faces.begin(); } -BoxGrid::Iterator::~Iterator() {} +BoxGrid::Iterator::~Iterator() +{ +} // BoxGrid ///////////////// -BoxGrid::BoxGrid(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap, Vec3r& viewpoint, +BoxGrid::BoxGrid(OccluderSource &source, + GridDensityProvider &density, + ViewMap *viewMap, + Vec3r &viewpoint, bool enableQI) -: _viewpoint(viewpoint), _enableQI(enableQI) -{ - // Generate Cell structure - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Generate Cell structure" << endl; - } - assignCells(source, density, viewMap); - - // Fill Cells - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Distribute occluders" << endl; - } - distributePolygons(source); - - // Reorganize Cells - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Reorganize cells" << endl; - } - reorganizeCells(); - - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Ready to use BoxGrid" << endl; - } -} - -BoxGrid::~BoxGrid() {} - -void BoxGrid::assignCells (OccluderSource& /*source*/, GridDensityProvider& density, ViewMap *viewMap) -{ - _cellSize = density.cellSize(); - _cellsX = density.cellsX(); - _cellsY = density.cellsY(); - _cellOrigin[0] = density.cellOrigin(0); - _cellOrigin[1] = density.cellOrigin(1); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Using " << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - cout << "Cell origin: " << _cellOrigin[0] << ", " << _cellOrigin[1] << endl; - } - - // Now allocate the cell table and fill it with default (empty) cells - _cells.resize(_cellsX * _cellsY); - for (cellContainer::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { - (*i) = NULL; - } - - // Identify cells that will be used, and set the dimensions for each - ViewMap::fedges_container& fedges = viewMap->FEdges(); - for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; ++f) { - if ((*f)->isInImage()) { - Vec3r point = transform((*f)->center3d()); - unsigned int i, j; - getCellCoordinates(point, i, j); - if (_cells[i * _cellsY + j] == NULL) { - // This is an uninitialized cell - real x, y, width, height; - - x = _cellOrigin[0] + _cellSize * i; - width = _cellSize; - - y = _cellOrigin[1] + _cellSize * j; - height = _cellSize; - - // Initialize cell - Cell *b = _cells[i * _cellsY + j] = new Cell(); - b->setDimensions(x, y, width, height); - } - } - } -} - -void BoxGrid::distributePolygons(OccluderSource& source) -{ - unsigned long nFaces = 0; - unsigned long nKeptFaces = 0; - - for (source.begin(); source.isValid(); source.next()) { - OccluderData *occluder = NULL; - - try { - if (insertOccluder(source, occluder)) { - _faces.push_back(occluder); - ++nKeptFaces; - } - } - catch (...) { - // If an exception was thrown, _faces.push_back() cannot have succeeded. - // occluder is not owned by anyone, and must be deleted. - // If the exception was thrown before or during new OccluderData(), then - // occluder is NULL, and this delete is harmless. - delete occluder; - throw; - } - ++nFaces; - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Distributed " << nFaces << " occluders. Retained " << nKeptFaces << "." << endl; - } + : _viewpoint(viewpoint), _enableQI(enableQI) +{ + // Generate Cell structure + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Generate Cell structure" << endl; + } + assignCells(source, density, viewMap); + + // Fill Cells + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Distribute occluders" << endl; + } + distributePolygons(source); + + // Reorganize Cells + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Reorganize cells" << endl; + } + reorganizeCells(); + + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Ready to use BoxGrid" << endl; + } +} + +BoxGrid::~BoxGrid() +{ +} + +void BoxGrid::assignCells(OccluderSource & /*source*/, + GridDensityProvider &density, + ViewMap *viewMap) +{ + _cellSize = density.cellSize(); + _cellsX = density.cellsX(); + _cellsY = density.cellsY(); + _cellOrigin[0] = density.cellOrigin(0); + _cellOrigin[1] = density.cellOrigin(1); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Using " << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." + << endl; + cout << "Cell origin: " << _cellOrigin[0] << ", " << _cellOrigin[1] << endl; + } + + // Now allocate the cell table and fill it with default (empty) cells + _cells.resize(_cellsX * _cellsY); + for (cellContainer::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { + (*i) = NULL; + } + + // Identify cells that will be used, and set the dimensions for each + ViewMap::fedges_container &fedges = viewMap->FEdges(); + for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; + ++f) { + if ((*f)->isInImage()) { + Vec3r point = transform((*f)->center3d()); + unsigned int i, j; + getCellCoordinates(point, i, j); + if (_cells[i * _cellsY + j] == NULL) { + // This is an uninitialized cell + real x, y, width, height; + + x = _cellOrigin[0] + _cellSize * i; + width = _cellSize; + + y = _cellOrigin[1] + _cellSize * j; + height = _cellSize; + + // Initialize cell + Cell *b = _cells[i * _cellsY + j] = new Cell(); + b->setDimensions(x, y, width, height); + } + } + } +} + +void BoxGrid::distributePolygons(OccluderSource &source) +{ + unsigned long nFaces = 0; + unsigned long nKeptFaces = 0; + + for (source.begin(); source.isValid(); source.next()) { + OccluderData *occluder = NULL; + + try { + if (insertOccluder(source, occluder)) { + _faces.push_back(occluder); + ++nKeptFaces; + } + } + catch (...) { + // If an exception was thrown, _faces.push_back() cannot have succeeded. + // occluder is not owned by anyone, and must be deleted. + // If the exception was thrown before or during new OccluderData(), then + // occluder is NULL, and this delete is harmless. + delete occluder; + throw; + } + ++nFaces; + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Distributed " << nFaces << " occluders. Retained " << nKeptFaces << "." << endl; + } } void BoxGrid::reorganizeCells() { - // Sort the occluders by shallowest point - for (vector::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { - if (*i != NULL) { - (*i)->indexPolygons(); - } - } + // Sort the occluders by shallowest point + for (vector::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { + if (*i != NULL) { + (*i)->indexPolygons(); + } + } } -void BoxGrid::getCellCoordinates(const Vec3r& point, unsigned& x, unsigned& y) +void BoxGrid::getCellCoordinates(const Vec3r &point, unsigned &x, unsigned &y) { - x = min(_cellsX - 1, (unsigned) floor (max((double) 0.0f, point[0] - _cellOrigin[0]) / _cellSize)); - y = min(_cellsY - 1, (unsigned) floor (max((double) 0.0f, point[1] - _cellOrigin[1]) / _cellSize)); + x = min(_cellsX - 1, (unsigned)floor(max((double)0.0f, point[0] - _cellOrigin[0]) / _cellSize)); + y = min(_cellsY - 1, (unsigned)floor(max((double)0.0f, point[1] - _cellOrigin[1]) / _cellSize)); } -BoxGrid::Cell *BoxGrid::findCell(const Vec3r& point) +BoxGrid::Cell *BoxGrid::findCell(const Vec3r &point) { - unsigned int x, y; - getCellCoordinates(point, x, y); - return _cells[x * _cellsY + y]; + unsigned int x, y; + getCellCoordinates(point, x, y); + return _cells[x * _cellsY + y]; } bool BoxGrid::orthographicProjection() const { - return true; + return true; } -const Vec3r& BoxGrid::viewpoint() const +const Vec3r &BoxGrid::viewpoint() const { - return _viewpoint; + return _viewpoint; } bool BoxGrid::enableQI() const { - return _enableQI; + return _enableQI; } -BoxGrid::Transform::Transform() : GridHelpers::Transform() {} +BoxGrid::Transform::Transform() : GridHelpers::Transform() +{ +} -Vec3r BoxGrid::Transform::operator()(const Vec3r& point) const +Vec3r BoxGrid::Transform::operator()(const Vec3r &point) const { - return Vec3r(point[0], point[1], -point[2]); + return Vec3r(point[0], point[1], -point[2]); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/BoxGrid.h b/source/blender/freestyle/intern/view_map/BoxGrid.h index 9d2a3c7ea4c..83c379102f5 100644 --- a/source/blender/freestyle/intern/view_map/BoxGrid.h +++ b/source/blender/freestyle/intern/view_map/BoxGrid.h @@ -45,380 +45,379 @@ #include "BKE_global.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class BoxGrid -{ -public: - // Helper classes - struct OccluderData - { - explicit OccluderData(OccluderSource& source, Polygon3r& p); - Polygon3r poly; - Polygon3r cameraSpacePolygon; - real shallowest, deepest; - // N.B. We could, of course, store face in poly's userdata member, like the old ViewMapBuilder code does. - // However, code comments make it clear that userdata is deprecated, so we avoid the temptation - // to save 4 or 8 bytes. - WFace *face; +class BoxGrid { + public: + // Helper classes + struct OccluderData { + explicit OccluderData(OccluderSource &source, Polygon3r &p); + Polygon3r poly; + Polygon3r cameraSpacePolygon; + real shallowest, deepest; + // N.B. We could, of course, store face in poly's userdata member, like the old ViewMapBuilder code does. + // However, code comments make it clear that userdata is deprecated, so we avoid the temptation + // to save 4 or 8 bytes. + WFace *face; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid:OccluderData") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid:OccluderData") #endif - }; - -private: - struct Cell - { - // Can't store Cell in a vector without copy and assign - // Cell(const Cell& other); - // Cell& operator=(const Cell& other); - - explicit Cell(); - ~Cell(); - - static bool compareOccludersByShallowestPoint(const OccluderData *a, const OccluderData *b); - - void setDimensions(real x, real y, real sizeX, real sizeY); - void checkAndInsert(OccluderSource& source, Polygon3r& poly, OccluderData*& occluder); - void indexPolygons(); - - real boundary[4]; - //deque faces; - vector faces; - }; - -public: - /* Iterator needs to allow the user to avoid full 3D comparison in two cases: - * - * (1) Where (*current)->deepest < target[2], where the occluder is unambiguously in front of the target point. - * - * (2) Where (*current)->shallowest > target[2], where the occluder is unambiguously in back of the target point. - * - * In addition, when used by OptimizedFindOccludee, Iterator should stop iterating as soon as it has an - * occludee candidate and (*current)->shallowest > candidate[2], because at that point forward no new occluder - * could possibly be a better occludee. - */ - class Iterator - { - public: - // epsilon is not used in this class, but other grids with the same interface may need an epsilon - explicit Iterator(BoxGrid& grid, Vec3r& center, real epsilon = 1.0e-06); - ~Iterator(); - void initBeforeTarget(); - void initAfterTarget(); - void nextOccluder(); - void nextOccludee(); - bool validBeforeTarget(); - bool validAfterTarget(); - WFace *getWFace() const; - Polygon3r *getCameraSpacePolygon(); - void reportDepth(Vec3r origin, Vec3r u, real t); - - private: - bool testOccluder(bool wantOccludee); - void markCurrentOccludeeCandidate(real depth); - - Cell *_cell; - Vec3r _target; - bool _foundOccludee; - real _occludeeDepth; - //deque::iterator _current, _occludeeCandidate; - vector::iterator _current, _occludeeCandidate; + }; + + private: + struct Cell { + // Can't store Cell in a vector without copy and assign + // Cell(const Cell& other); + // Cell& operator=(const Cell& other); + + explicit Cell(); + ~Cell(); + + static bool compareOccludersByShallowestPoint(const OccluderData *a, const OccluderData *b); + + void setDimensions(real x, real y, real sizeX, real sizeY); + void checkAndInsert(OccluderSource &source, Polygon3r &poly, OccluderData *&occluder); + void indexPolygons(); + + real boundary[4]; + //deque faces; + vector faces; + }; + + public: + /* Iterator needs to allow the user to avoid full 3D comparison in two cases: + * + * (1) Where (*current)->deepest < target[2], where the occluder is unambiguously in front of the target point. + * + * (2) Where (*current)->shallowest > target[2], where the occluder is unambiguously in back of the target point. + * + * In addition, when used by OptimizedFindOccludee, Iterator should stop iterating as soon as it has an + * occludee candidate and (*current)->shallowest > candidate[2], because at that point forward no new occluder + * could possibly be a better occludee. + */ + class Iterator { + public: + // epsilon is not used in this class, but other grids with the same interface may need an epsilon + explicit Iterator(BoxGrid &grid, Vec3r ¢er, real epsilon = 1.0e-06); + ~Iterator(); + void initBeforeTarget(); + void initAfterTarget(); + void nextOccluder(); + void nextOccludee(); + bool validBeforeTarget(); + bool validAfterTarget(); + WFace *getWFace() const; + Polygon3r *getCameraSpacePolygon(); + void reportDepth(Vec3r origin, Vec3r u, real t); + + private: + bool testOccluder(bool wantOccludee); + void markCurrentOccludeeCandidate(real depth); + + Cell *_cell; + Vec3r _target; + bool _foundOccludee; + real _occludeeDepth; + //deque::iterator _current, _occludeeCandidate; + vector::iterator _current, _occludeeCandidate; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid:Iterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid:Iterator") #endif - }; - - class Transform : public GridHelpers::Transform - { - public: - explicit Transform(); - explicit Transform(Transform& other); - Vec3r operator()(const Vec3r& point) const; - }; - -private: - // Prevent implicit copies and assignments. - BoxGrid(const BoxGrid& other); - BoxGrid& operator=(const BoxGrid& other); - -public: - explicit BoxGrid(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap, Vec3r& viewpoint, - bool enableQI); - virtual ~BoxGrid(); - - // Generate Cell structure - void assignCells(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap); - // Fill Cells - void distributePolygons(OccluderSource& source); - // Insert one polygon into each matching cell, return true if any cell consumes the polygon - bool insertOccluder(OccluderSource& source, OccluderData*& occluder); - // Sort occluders in each cell - void reorganizeCells(); - - Cell *findCell(const Vec3r& point); - - // Accessors: - bool orthographicProjection() const; - const Vec3r& viewpoint() const; - bool enableQI() const; - Transform transform; - -private: - void getCellCoordinates(const Vec3r& point, unsigned& x, unsigned& y); - - typedef PointerSequence, Cell*> cellContainer; - //typedef PointerSequence, OccluderData*> occluderContainer; - typedef PointerSequence, OccluderData*> occluderContainer; - unsigned _cellsX, _cellsY; - float _cellSize; - float _cellOrigin[2]; - cellContainer _cells; - occluderContainer _faces; - Vec3r _viewpoint; - bool _enableQI; + }; + + class Transform : public GridHelpers::Transform { + public: + explicit Transform(); + explicit Transform(Transform &other); + Vec3r operator()(const Vec3r &point) const; + }; + + private: + // Prevent implicit copies and assignments. + BoxGrid(const BoxGrid &other); + BoxGrid &operator=(const BoxGrid &other); + + public: + explicit BoxGrid(OccluderSource &source, + GridDensityProvider &density, + ViewMap *viewMap, + Vec3r &viewpoint, + bool enableQI); + virtual ~BoxGrid(); + + // Generate Cell structure + void assignCells(OccluderSource &source, GridDensityProvider &density, ViewMap *viewMap); + // Fill Cells + void distributePolygons(OccluderSource &source); + // Insert one polygon into each matching cell, return true if any cell consumes the polygon + bool insertOccluder(OccluderSource &source, OccluderData *&occluder); + // Sort occluders in each cell + void reorganizeCells(); + + Cell *findCell(const Vec3r &point); + + // Accessors: + bool orthographicProjection() const; + const Vec3r &viewpoint() const; + bool enableQI() const; + Transform transform; + + private: + void getCellCoordinates(const Vec3r &point, unsigned &x, unsigned &y); + + typedef PointerSequence, Cell *> cellContainer; + //typedef PointerSequence, OccluderData*> occluderContainer; + typedef PointerSequence, OccluderData *> occluderContainer; + unsigned _cellsX, _cellsY; + float _cellSize; + float _cellOrigin[2]; + cellContainer _cells; + occluderContainer _faces; + Vec3r _viewpoint; + bool _enableQI; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BoxGrid") #endif }; inline void BoxGrid::Iterator::initBeforeTarget() { - _current = _cell->faces.begin(); - while (_current != _cell->faces.end() && !testOccluder(false)) { - ++_current; - } + _current = _cell->faces.begin(); + while (_current != _cell->faces.end() && !testOccluder(false)) { + ++_current; + } } inline void BoxGrid::Iterator::initAfterTarget() { - if (_foundOccludee) { + if (_foundOccludee) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tStarting occludee search from occludeeCandidate at depth " << - _occludeeDepth << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth + << std::endl; + } #endif - _current = _occludeeCandidate; - return; - } + _current = _occludeeCandidate; + return; + } #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tStarting occludee search from current position" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tStarting occludee search from current position" << std::endl; + } #endif - while (_current != _cell->faces.end() && !testOccluder(true)) { - ++_current; - } + while (_current != _cell->faces.end() && !testOccluder(true)) { + ++_current; + } } inline bool BoxGrid::Iterator::testOccluder(bool wantOccludee) { - // End-of-list is not even a valid iterator position - if (_current == _cell->faces.end()) { - // Returning true seems strange, but it will break us out of whatever loop is calling testOccluder, - // and _current = _cell->face.end() will make the calling routine give up. - return true; - } + // End-of-list is not even a valid iterator position + if (_current == _cell->faces.end()) { + // Returning true seems strange, but it will break us out of whatever loop is calling testOccluder, + // and _current = _cell->face.end() will make the calling routine give up. + return true; + } #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tTesting occluder " << (*_current)->poly.getVertices()[0]; - for (unsigned int i = 1; i < (*_current)->poly.getVertices().size(); ++i) { - std::cout << ", " << (*_current)->poly.getVertices()[i]; - } - std::cout << " from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tTesting occluder " << (*_current)->poly.getVertices()[0]; + for (unsigned int i = 1; i < (*_current)->poly.getVertices().size(); ++i) { + std::cout << ", " << (*_current)->poly.getVertices()[i]; + } + std::cout << " from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl; + } #endif - // If we have an occluder candidate and we are unambiguously after it, abort - if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) { + // If we have an occluder candidate and we are unambiguously after it, abort + if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl; + } #endif - _current = _cell->faces.end(); + _current = _cell->faces.end(); - // See note above - return true; - } + // See note above + return true; + } - // Specific continue or stop conditions when searching for each type - if (wantOccludee) { - if ((*_current)->deepest < _target[2]) { + // Specific continue or stop conditions when searching for each type + if (wantOccludee) { + if ((*_current)->deepest < _target[2]) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tSkipping: shallower than target while looking for occludee" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tSkipping: shallower than target while looking for occludee" << std::endl; + } #endif - return false; - } - } - else { - if ((*_current)->shallowest > _target[2]) { + return false; + } + } + else { + if ((*_current)->shallowest > _target[2]) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tStopping: deeper than target while looking for occluder" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tStopping: deeper than target while looking for occluder" << std::endl; + } #endif - return true; - } - } + return true; + } + } - // Depthwise, this is a valid occluder. + // Depthwise, this is a valid occluder. - // Check to see if target is in the 2D bounding box - Vec3r bbMin, bbMax; - (*_current)->poly.getBBox(bbMin, bbMax); - if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] || _target[1] > bbMax[1]) { + // Check to see if target is in the 2D bounding box + Vec3r bbMin, bbMax; + (*_current)->poly.getBBox(bbMin, bbMax); + if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] || + _target[1] > bbMax[1]) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tSkipping: bounding box violation" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tSkipping: bounding box violation" << std::endl; + } #endif - return false; - } + return false; + } - // We've done all the corner cutting we can. - // Let the caller work out whether or not the geometry is correct. - return true; + // We've done all the corner cutting we can. + // Let the caller work out whether or not the geometry is correct. + return true; } inline void BoxGrid::Iterator::reportDepth(Vec3r origin, Vec3r u, real t) { - // The reported depth is the length of a ray in camera space - // We need to convert it into a Z-value in grid space - real depth = -(origin + (u * t))[2]; + // The reported depth is the length of a ray in camera space + // We need to convert it into a Z-value in grid space + real depth = -(origin + (u * t))[2]; #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tReporting depth of occluder/ee: " << depth; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tReporting depth of occluder/ee: " << depth; + } #endif - if (depth > _target[2]) { + if (depth > _target[2]) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << " is deeper than target" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << " is deeper than target" << std::endl; + } #endif - // If the current occluder is the best occludee so far, save it. - if (! _foundOccludee || _occludeeDepth > depth) { - markCurrentOccludeeCandidate(depth); - } - } - else { + // If the current occluder is the best occludee so far, save it. + if (!_foundOccludee || _occludeeDepth > depth) { + markCurrentOccludeeCandidate(depth); + } + } + else { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << std::endl; + } #endif - } + } } inline void BoxGrid::Iterator::nextOccluder() { - if (_current != _cell->faces.end()) { - do { - ++_current; - } while (_current != _cell->faces.end() && ! testOccluder(false)); - } + if (_current != _cell->faces.end()) { + do { + ++_current; + } while (_current != _cell->faces.end() && !testOccluder(false)); + } } inline void BoxGrid::Iterator::nextOccludee() { - if (_current != _cell->faces.end()) { - do { - ++_current; - } while (_current != _cell->faces.end() && ! testOccluder(true)); - } + if (_current != _cell->faces.end()) { + do { + ++_current; + } while (_current != _cell->faces.end() && !testOccluder(true)); + } } inline bool BoxGrid::Iterator::validBeforeTarget() { - return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2]; + return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2]; } inline bool BoxGrid::Iterator::validAfterTarget() { - return _current != _cell->faces.end(); + return _current != _cell->faces.end(); } inline void BoxGrid::Iterator::markCurrentOccludeeCandidate(real depth) { #if BOX_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tFound occludeeCandidate at depth " << depth << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tFound occludeeCandidate at depth " << depth << std::endl; + } #endif - _occludeeCandidate = _current; - _occludeeDepth = depth; - _foundOccludee = true; + _occludeeCandidate = _current; + _occludeeDepth = depth; + _foundOccludee = true; } inline WFace *BoxGrid::Iterator::getWFace() const { - return (*_current)->face; + return (*_current)->face; } inline Polygon3r *BoxGrid::Iterator::getCameraSpacePolygon() { - return &((*_current)->cameraSpacePolygon); + return &((*_current)->cameraSpacePolygon); } -inline BoxGrid::OccluderData::OccluderData(OccluderSource& source, Polygon3r& p) -: poly(p), - cameraSpacePolygon(source.getCameraSpacePolygon()), - face(source.getWFace()) +inline BoxGrid::OccluderData::OccluderData(OccluderSource &source, Polygon3r &p) + : poly(p), cameraSpacePolygon(source.getCameraSpacePolygon()), face(source.getWFace()) { - // Set shallowest and deepest based on bbox - Vec3r min, max; - poly.getBBox(min, max); - shallowest = min[2]; - deepest = max[2]; + // Set shallowest and deepest based on bbox + Vec3r min, max; + poly.getBBox(min, max); + shallowest = min[2]; + deepest = max[2]; } -inline void BoxGrid::Cell::checkAndInsert(OccluderSource& source, Polygon3r& poly, OccluderData*& occluder) +inline void BoxGrid::Cell::checkAndInsert(OccluderSource &source, + Polygon3r &poly, + OccluderData *&occluder) { - if (GridHelpers::insideProscenium (boundary, poly)) { - if (occluder == NULL) { - // Disposal of occluder will be handled in BoxGrid::distributePolygons(), - // or automatically by BoxGrid::_faces; - occluder = new OccluderData(source, poly); - } - faces.push_back(occluder); - } + if (GridHelpers::insideProscenium(boundary, poly)) { + if (occluder == NULL) { + // Disposal of occluder will be handled in BoxGrid::distributePolygons(), + // or automatically by BoxGrid::_faces; + occluder = new OccluderData(source, poly); + } + faces.push_back(occluder); + } } -inline bool BoxGrid::insertOccluder(OccluderSource& source, OccluderData*& occluder) +inline bool BoxGrid::insertOccluder(OccluderSource &source, OccluderData *&occluder) { - Polygon3r& poly(source.getGridSpacePolygon()); - occluder = NULL; - - Vec3r bbMin, bbMax; - poly.getBBox(bbMin, bbMax); - // Check overlapping cells - unsigned startX, startY, endX, endY; - getCellCoordinates(bbMin, startX, startY); - getCellCoordinates(bbMax, endX, endY); - - for (unsigned int i = startX; i <= endX; ++i) { - for (unsigned int j = startY; j <= endY; ++j) { - if (_cells[i * _cellsY + j] != NULL) { - _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder); - } - } - } - - return occluder != NULL; + Polygon3r &poly(source.getGridSpacePolygon()); + occluder = NULL; + + Vec3r bbMin, bbMax; + poly.getBBox(bbMin, bbMax); + // Check overlapping cells + unsigned startX, startY, endX, endY; + getCellCoordinates(bbMin, startX, startY); + getCellCoordinates(bbMax, endX, endY); + + for (unsigned int i = startX; i <= endX; ++i) { + for (unsigned int j = startY; j <= endY; ++j) { + if (_cells[i * _cellsY + j] != NULL) { + _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder); + } + } + } + + return occluder != NULL; } } /* namespace Freestyle */ -#endif // __FREESTYLE_BOX_GRID_H__ +#endif // __FREESTYLE_BOX_GRID_H__ diff --git a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp index 28e4b0251de..214852001b6 100644 --- a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp +++ b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp @@ -27,250 +27,254 @@ namespace Freestyle { -CulledOccluderSource::CulledOccluderSource(const GridHelpers::Transform& t, WingedEdge& we, ViewMap& viewMap, +CulledOccluderSource::CulledOccluderSource(const GridHelpers::Transform &t, + WingedEdge &we, + ViewMap &viewMap, bool extensiveFEdgeSearch) -: OccluderSource(t, we), rejected(0), gridSpaceOccluderProsceniumInitialized(false) + : OccluderSource(t, we), rejected(0), gridSpaceOccluderProsceniumInitialized(false) { - cullViewEdges(viewMap, extensiveFEdgeSearch); + cullViewEdges(viewMap, extensiveFEdgeSearch); - // If we have not found any visible FEdges during our cull, then there is nothing to iterate over. - // Short-circuit everything. - valid = gridSpaceOccluderProsceniumInitialized; + // If we have not found any visible FEdges during our cull, then there is nothing to iterate over. + // Short-circuit everything. + valid = gridSpaceOccluderProsceniumInitialized; - if (valid && ! testCurrent()) { - next(); - } + if (valid && !testCurrent()) { + next(); + } } -CulledOccluderSource::~CulledOccluderSource() {} +CulledOccluderSource::~CulledOccluderSource() +{ +} bool CulledOccluderSource::testCurrent() { - if (valid) { - // The test for gridSpaceOccluderProsceniumInitialized should not be necessary - return gridSpaceOccluderProsceniumInitialized && - GridHelpers::insideProscenium(gridSpaceOccluderProscenium, cachedPolygon); - } - return false; + if (valid) { + // The test for gridSpaceOccluderProsceniumInitialized should not be necessary + return gridSpaceOccluderProsceniumInitialized && + GridHelpers::insideProscenium(gridSpaceOccluderProscenium, cachedPolygon); + } + return false; } bool CulledOccluderSource::next() { - while (OccluderSource::next()) { - if (testCurrent()) { - ++rejected; - return true; - } - } - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "Finished generating occluders. Rejected " << rejected << " faces." << std::endl; - } - return false; + while (OccluderSource::next()) { + if (testCurrent()) { + ++rejected; + return true; + } + } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "Finished generating occluders. Rejected " << rejected << " faces." << std::endl; + } + return false; } void CulledOccluderSource::getOccluderProscenium(real proscenium[4]) { - for (unsigned int i = 0; i < 4; ++i) { - proscenium[i] = gridSpaceOccluderProscenium[i]; - } + for (unsigned int i = 0; i < 4; ++i) { + proscenium[i] = gridSpaceOccluderProscenium[i]; + } } -static inline real distance2D(const Vec3r & point, const real origin[2]) +static inline real distance2D(const Vec3r &point, const real origin[2]) { - return ::hypot((point[0] - origin[0]), (point[1] - origin[1])); + return ::hypot((point[0] - origin[0]), (point[1] - origin[1])); } static inline bool crossesProscenium(real proscenium[4], FEdge *fe) { - Vec2r min(proscenium[0], proscenium[2]); - Vec2r max(proscenium[1], proscenium[3]); - Vec2r A(fe->vertexA()->getProjectedX(), fe->vertexA()->getProjectedY()); - Vec2r B(fe->vertexB()->getProjectedX(), fe->vertexB()->getProjectedY()); + Vec2r min(proscenium[0], proscenium[2]); + Vec2r max(proscenium[1], proscenium[3]); + Vec2r A(fe->vertexA()->getProjectedX(), fe->vertexA()->getProjectedY()); + Vec2r B(fe->vertexB()->getProjectedX(), fe->vertexB()->getProjectedY()); - return GeomUtils::intersect2dSeg2dArea (min, max, A, B); + return GeomUtils::intersect2dSeg2dArea(min, max, A, B); } -static inline bool insideProscenium(real proscenium[4], const Vec3r& point) +static inline bool insideProscenium(real proscenium[4], const Vec3r &point) { - return !(point[0] < proscenium[0] || point[0] > proscenium[1] || - point[1] < proscenium[2] || point[1] > proscenium[3]); + return !(point[0] < proscenium[0] || point[0] > proscenium[1] || point[1] < proscenium[2] || + point[1] > proscenium[3]); } -void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSearch) +void CulledOccluderSource::cullViewEdges(ViewMap &viewMap, bool extensiveFEdgeSearch) { - // Cull view edges by marking them as non-displayable. - // This avoids the complications of trying to delete edges from the ViewMap. - - // Non-displayable view edges will be skipped over during visibility calculation. - - // View edges will be culled according to their position w.r.t. the viewport proscenium (viewport + 5% border, - // or some such). - - // Get proscenium boundary for culling - real viewProscenium[4]; - GridHelpers::getDefaultViewProscenium(viewProscenium); - real prosceniumOrigin[2]; - prosceniumOrigin[0] = (viewProscenium[1] - viewProscenium[0]) / 2.0; - prosceniumOrigin[1] = (viewProscenium[3] - viewProscenium[2]) / 2.0; - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Proscenium culling:" << endl; - cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " << viewProscenium[2] << - ", " << viewProscenium[3] << "]"<< endl; - cout << "Origin: [" << prosceniumOrigin[0] << ", " << prosceniumOrigin[1] << "]"<< endl; - } - - // A separate occluder proscenium will also be maintained, starting out the same as the viewport proscenium, and - // expanding as necessary so that it encompasses the center point of at least one feature edge in each - // retained view edge. - // The occluder proscenium will be used later to cull occluding triangles before they are inserted into the Grid. - // The occluder proscenium starts out the same size as the view proscenium - GridHelpers::getDefaultViewProscenium(occluderProscenium); - - // XXX Freestyle is inconsistent in its use of ViewMap::viewedges_container and vector::iterator. - // Probably all occurences of vector::iterator should be replaced ViewMap::viewedges_container - // throughout the code. - // For each view edge - ViewMap::viewedges_container::iterator ve, veend; - - for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) { - // Overview: - // Search for a visible feature edge - // If none: mark view edge as non-displayable - // Otherwise: - // Find a feature edge with center point inside occluder proscenium. - // If none exists, find the feature edge with center point closest to viewport origin. - // Expand occluder proscenium to enclose center point. - - // For each feature edge, while bestOccluderTarget not found and view edge not visibile - bool bestOccluderTargetFound = false; - FEdge *bestOccluderTarget = NULL; - real bestOccluderDistance = 0.0; - FEdge *festart = (*ve)->fedgeA(); - FEdge *fe = festart; - // All ViewEdges start culled - (*ve)->setIsInImage(false); - - // For simple visibility calculation: mark a feature edge that is known to have a center point inside - // the occluder proscenium. Cull all other feature edges. - do { - // All FEdges start culled - fe->setIsInImage(false); - - // Look for the visible edge that can most easily be included in the occluder proscenium. - if (!bestOccluderTargetFound) { - // If center point is inside occluder proscenium, - if (insideProscenium(occluderProscenium, fe->center2d())) { - // Use this feature edge for visibility deterimination - fe->setIsInImage(true); - expandGridSpaceOccluderProscenium(fe); - // Mark bestOccluderTarget as found - bestOccluderTargetFound = true; - bestOccluderTarget = fe; - } - else { - real d = distance2D(fe->center2d(), prosceniumOrigin); - // If center point is closer to viewport origin than current target - if (bestOccluderTarget == NULL || d < bestOccluderDistance) { - // Then store as bestOccluderTarget - bestOccluderDistance = d; - bestOccluderTarget = fe; - } - } - } - - // If feature edge crosses the view proscenium - if (!(*ve)->isInImage() && crossesProscenium(viewProscenium, fe)) { - // Then the view edge will be included in the image - (*ve)->setIsInImage(true); - } - fe = fe->nextEdge(); - } while (fe != NULL && fe != festart && !(bestOccluderTargetFound && (*ve)->isInImage())); - - // Either we have run out of FEdges, or we already have the one edge we need to determine visibility - // Cull all remaining edges. - while (fe != NULL && fe != festart) { - fe->setIsInImage(false); - fe = fe->nextEdge(); - } - - // If bestOccluderTarget was not found inside the occluder proscenium, - // we need to expand the occluder proscenium to include it. - if ((*ve)->isInImage() && bestOccluderTarget != NULL && ! bestOccluderTargetFound) { - // Expand occluder proscenium to enclose bestOccluderTarget - Vec3r point = bestOccluderTarget->center2d(); - if (point[0] < occluderProscenium[0]) { - occluderProscenium[0] = point[0]; - } - else if (point[0] > occluderProscenium[1]) { - occluderProscenium[1] = point[0]; - } - if (point[1] < occluderProscenium[2]) { - occluderProscenium[2] = point[1]; - } - else if (point[1] > occluderProscenium[3]) { - occluderProscenium[3] = point[1]; - } - // Use bestOccluderTarget for visibility determination - bestOccluderTarget->setIsInImage(true); - } - } - - // We are done calculating the occluder proscenium. - // Expand the occluder proscenium by an epsilon to avoid rounding errors. - const real epsilon = 1.0e-6; - occluderProscenium[0] -= epsilon; - occluderProscenium[1] += epsilon; - occluderProscenium[2] -= epsilon; - occluderProscenium[3] += epsilon; - - // For "Normal" or "Fast" style visibility computation only: - - // For more detailed visibility calculation, make a second pass through the view map, marking all feature edges - // with center points inside the final occluder proscenium. All of these feature edges can be considered during - // visibility calculation. - - // So far we have only found one FEdge per ViewEdge. The "Normal" and "Fast" styles of visibility computation - // want to consider many FEdges for each ViewEdge. - // Here we re-scan the view map to find any usable FEdges that we skipped on the first pass, or that have become - // usable because the occluder proscenium has been expanded since the edge was visited on the first pass. - if (extensiveFEdgeSearch) { - // For each view edge, - for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) { - if (!(*ve)->isInImage()) { - continue; - } - // For each feature edge, - FEdge *festart = (*ve)->fedgeA(); - FEdge *fe = festart; - do { - // If not (already) visible and center point inside occluder proscenium, - if (!fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d())) { - // Use the feature edge for visibility determination - fe->setIsInImage(true); - expandGridSpaceOccluderProscenium(fe); - } - fe = fe->nextEdge(); - } while (fe != NULL && fe != festart); - } - } - - // Up until now, all calculations have been done in camera space. - // However, the occluder source's iteration and the grid that consumes the occluders both work in gridspace, - // so we need a version of the occluder proscenium in gridspace. - // Set the gridspace occlude proscenium + // Cull view edges by marking them as non-displayable. + // This avoids the complications of trying to delete edges from the ViewMap. + + // Non-displayable view edges will be skipped over during visibility calculation. + + // View edges will be culled according to their position w.r.t. the viewport proscenium (viewport + 5% border, + // or some such). + + // Get proscenium boundary for culling + real viewProscenium[4]; + GridHelpers::getDefaultViewProscenium(viewProscenium); + real prosceniumOrigin[2]; + prosceniumOrigin[0] = (viewProscenium[1] - viewProscenium[0]) / 2.0; + prosceniumOrigin[1] = (viewProscenium[3] - viewProscenium[2]) / 2.0; + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Proscenium culling:" << endl; + cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " + << viewProscenium[2] << ", " << viewProscenium[3] << "]" << endl; + cout << "Origin: [" << prosceniumOrigin[0] << ", " << prosceniumOrigin[1] << "]" << endl; + } + + // A separate occluder proscenium will also be maintained, starting out the same as the viewport proscenium, and + // expanding as necessary so that it encompasses the center point of at least one feature edge in each + // retained view edge. + // The occluder proscenium will be used later to cull occluding triangles before they are inserted into the Grid. + // The occluder proscenium starts out the same size as the view proscenium + GridHelpers::getDefaultViewProscenium(occluderProscenium); + + // XXX Freestyle is inconsistent in its use of ViewMap::viewedges_container and vector::iterator. + // Probably all occurences of vector::iterator should be replaced ViewMap::viewedges_container + // throughout the code. + // For each view edge + ViewMap::viewedges_container::iterator ve, veend; + + for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) { + // Overview: + // Search for a visible feature edge + // If none: mark view edge as non-displayable + // Otherwise: + // Find a feature edge with center point inside occluder proscenium. + // If none exists, find the feature edge with center point closest to viewport origin. + // Expand occluder proscenium to enclose center point. + + // For each feature edge, while bestOccluderTarget not found and view edge not visibile + bool bestOccluderTargetFound = false; + FEdge *bestOccluderTarget = NULL; + real bestOccluderDistance = 0.0; + FEdge *festart = (*ve)->fedgeA(); + FEdge *fe = festart; + // All ViewEdges start culled + (*ve)->setIsInImage(false); + + // For simple visibility calculation: mark a feature edge that is known to have a center point inside + // the occluder proscenium. Cull all other feature edges. + do { + // All FEdges start culled + fe->setIsInImage(false); + + // Look for the visible edge that can most easily be included in the occluder proscenium. + if (!bestOccluderTargetFound) { + // If center point is inside occluder proscenium, + if (insideProscenium(occluderProscenium, fe->center2d())) { + // Use this feature edge for visibility deterimination + fe->setIsInImage(true); + expandGridSpaceOccluderProscenium(fe); + // Mark bestOccluderTarget as found + bestOccluderTargetFound = true; + bestOccluderTarget = fe; + } + else { + real d = distance2D(fe->center2d(), prosceniumOrigin); + // If center point is closer to viewport origin than current target + if (bestOccluderTarget == NULL || d < bestOccluderDistance) { + // Then store as bestOccluderTarget + bestOccluderDistance = d; + bestOccluderTarget = fe; + } + } + } + + // If feature edge crosses the view proscenium + if (!(*ve)->isInImage() && crossesProscenium(viewProscenium, fe)) { + // Then the view edge will be included in the image + (*ve)->setIsInImage(true); + } + fe = fe->nextEdge(); + } while (fe != NULL && fe != festart && !(bestOccluderTargetFound && (*ve)->isInImage())); + + // Either we have run out of FEdges, or we already have the one edge we need to determine visibility + // Cull all remaining edges. + while (fe != NULL && fe != festart) { + fe->setIsInImage(false); + fe = fe->nextEdge(); + } + + // If bestOccluderTarget was not found inside the occluder proscenium, + // we need to expand the occluder proscenium to include it. + if ((*ve)->isInImage() && bestOccluderTarget != NULL && !bestOccluderTargetFound) { + // Expand occluder proscenium to enclose bestOccluderTarget + Vec3r point = bestOccluderTarget->center2d(); + if (point[0] < occluderProscenium[0]) { + occluderProscenium[0] = point[0]; + } + else if (point[0] > occluderProscenium[1]) { + occluderProscenium[1] = point[0]; + } + if (point[1] < occluderProscenium[2]) { + occluderProscenium[2] = point[1]; + } + else if (point[1] > occluderProscenium[3]) { + occluderProscenium[3] = point[1]; + } + // Use bestOccluderTarget for visibility determination + bestOccluderTarget->setIsInImage(true); + } + } + + // We are done calculating the occluder proscenium. + // Expand the occluder proscenium by an epsilon to avoid rounding errors. + const real epsilon = 1.0e-6; + occluderProscenium[0] -= epsilon; + occluderProscenium[1] += epsilon; + occluderProscenium[2] -= epsilon; + occluderProscenium[3] += epsilon; + + // For "Normal" or "Fast" style visibility computation only: + + // For more detailed visibility calculation, make a second pass through the view map, marking all feature edges + // with center points inside the final occluder proscenium. All of these feature edges can be considered during + // visibility calculation. + + // So far we have only found one FEdge per ViewEdge. The "Normal" and "Fast" styles of visibility computation + // want to consider many FEdges for each ViewEdge. + // Here we re-scan the view map to find any usable FEdges that we skipped on the first pass, or that have become + // usable because the occluder proscenium has been expanded since the edge was visited on the first pass. + if (extensiveFEdgeSearch) { + // For each view edge, + for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) { + if (!(*ve)->isInImage()) { + continue; + } + // For each feature edge, + FEdge *festart = (*ve)->fedgeA(); + FEdge *fe = festart; + do { + // If not (already) visible and center point inside occluder proscenium, + if (!fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d())) { + // Use the feature edge for visibility determination + fe->setIsInImage(true); + expandGridSpaceOccluderProscenium(fe); + } + fe = fe->nextEdge(); + } while (fe != NULL && fe != festart); + } + } + + // Up until now, all calculations have been done in camera space. + // However, the occluder source's iteration and the grid that consumes the occluders both work in gridspace, + // so we need a version of the occluder proscenium in gridspace. + // Set the gridspace occlude proscenium } void CulledOccluderSource::expandGridSpaceOccluderProscenium(FEdge *fe) { - if (gridSpaceOccluderProsceniumInitialized) { - GridHelpers::expandProscenium(gridSpaceOccluderProscenium, transform(fe->center3d())); - } - else { - const Vec3r& point = transform(fe->center3d()); - gridSpaceOccluderProscenium[0] = gridSpaceOccluderProscenium[1] = point[0]; - gridSpaceOccluderProscenium[2] = gridSpaceOccluderProscenium[3] = point[1]; - gridSpaceOccluderProsceniumInitialized = true; - } + if (gridSpaceOccluderProsceniumInitialized) { + GridHelpers::expandProscenium(gridSpaceOccluderProscenium, transform(fe->center3d())); + } + else { + const Vec3r &point = transform(fe->center3d()); + gridSpaceOccluderProscenium[0] = gridSpaceOccluderProscenium[1] = point[0]; + gridSpaceOccluderProscenium[2] = gridSpaceOccluderProscenium[3] = point[1]; + gridSpaceOccluderProsceniumInitialized = true; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/CulledOccluderSource.h b/source/blender/freestyle/intern/view_map/CulledOccluderSource.h index de782eda64c..3457fb6ca10 100644 --- a/source/blender/freestyle/intern/view_map/CulledOccluderSource.h +++ b/source/blender/freestyle/intern/view_map/CulledOccluderSource.h @@ -27,34 +27,35 @@ namespace Freestyle { -class CulledOccluderSource : public OccluderSource -{ - // Disallow copying and assignment - CulledOccluderSource(const CulledOccluderSource& other); - CulledOccluderSource& operator=(const CulledOccluderSource& other); +class CulledOccluderSource : public OccluderSource { + // Disallow copying and assignment + CulledOccluderSource(const CulledOccluderSource &other); + CulledOccluderSource &operator=(const CulledOccluderSource &other); -public: - CulledOccluderSource(const GridHelpers::Transform& transform, WingedEdge& we, ViewMap& viewMap, - bool extensiveFEdgeSearch = true); - virtual ~CulledOccluderSource(); + public: + CulledOccluderSource(const GridHelpers::Transform &transform, + WingedEdge &we, + ViewMap &viewMap, + bool extensiveFEdgeSearch = true); + virtual ~CulledOccluderSource(); - void cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSearch); + void cullViewEdges(ViewMap &viewMap, bool extensiveFEdgeSearch); - bool next(); + bool next(); - void getOccluderProscenium(real proscenium[4]); + void getOccluderProscenium(real proscenium[4]); -private: - bool testCurrent(); - void expandGridSpaceOccluderProscenium(FEdge *fe); + private: + bool testCurrent(); + void expandGridSpaceOccluderProscenium(FEdge *fe); - real occluderProscenium[4]; - real gridSpaceOccluderProscenium[4]; + real occluderProscenium[4]; + real gridSpaceOccluderProscenium[4]; - unsigned long rejected; - bool gridSpaceOccluderProsceniumInitialized; + unsigned long rejected; + bool gridSpaceOccluderProsceniumInitialized; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_CULLED_OCCLUDER_SOURCE_H__ +#endif // __FREESTYLE_CULLED_OCCLUDER_SOURCE_H__ diff --git a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp index a195db76fe7..bb2b95be84e 100644 --- a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp +++ b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp @@ -30,511 +30,512 @@ namespace Freestyle { -void FEdgeXDetector::processShapes(WingedEdge& we) +void FEdgeXDetector::processShapes(WingedEdge &we) { - bool progressBarDisplay = false; + bool progressBarDisplay = false; #if 0 - Vec3r Min, Max; + Vec3r Min, Max; #endif - vector wshapes = we.getWShapes(); - WXShape *wxs; - - if (_pProgressBar != NULL) { - _pProgressBar->reset(); - _pProgressBar->setLabelText("Detecting feature lines"); - _pProgressBar->setTotalSteps(wshapes.size() * 3); - _pProgressBar->setProgress(0); - progressBarDisplay = true; - } - - for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); it++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - wxs = dynamic_cast(*it); + vector wshapes = we.getWShapes(); + WXShape *wxs; + + if (_pProgressBar != NULL) { + _pProgressBar->reset(); + _pProgressBar->setLabelText("Detecting feature lines"); + _pProgressBar->setTotalSteps(wshapes.size() * 3); + _pProgressBar->setProgress(0); + progressBarDisplay = true; + } + + for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); it++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + wxs = dynamic_cast(*it); #if 0 - wxs->bbox(Min, Max); - _bbox_diagonal = (Max - Min).norm(); + wxs->bbox(Min, Max); + _bbox_diagonal = (Max - Min).norm(); #endif - if (_changes) { - vector& wfaces = wxs->GetFaceList(); - for (vector::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; ++wf) { - WXFace *wxf = dynamic_cast(*wf); - wxf->Clear(); - } - _computeViewIndependent = true; - } - else if (!(wxs)->getComputeViewIndependentFlag()) { - wxs->Reset(); - _computeViewIndependent = false; - } - else { - _computeViewIndependent = true; - } - preProcessShape(wxs); - if (progressBarDisplay) - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - processBorderShape(wxs); - if (_computeMaterialBoundaries) - processMaterialBoundaryShape(wxs); - processCreaseShape(wxs); - if (_computeRidgesAndValleys) - processRidgesAndValleysShape(wxs); - if (_computeSuggestiveContours) - processSuggestiveContourShape(wxs); - processSilhouetteShape(wxs); - processEdgeMarksShape(wxs); - if (progressBarDisplay) - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - - // build smooth edges: - buildSmoothEdges(wxs); - - // Post processing for suggestive contours - if (_computeSuggestiveContours) - postProcessSuggestiveContourShape(wxs); - if (progressBarDisplay) - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - - wxs->setComputeViewIndependentFlag(false); - _computeViewIndependent = false; - _changes = false; - - // reset user data - (*it)->ResetUserData(); - } + if (_changes) { + vector &wfaces = wxs->GetFaceList(); + for (vector::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; + ++wf) { + WXFace *wxf = dynamic_cast(*wf); + wxf->Clear(); + } + _computeViewIndependent = true; + } + else if (!(wxs)->getComputeViewIndependentFlag()) { + wxs->Reset(); + _computeViewIndependent = false; + } + else { + _computeViewIndependent = true; + } + preProcessShape(wxs); + if (progressBarDisplay) + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + processBorderShape(wxs); + if (_computeMaterialBoundaries) + processMaterialBoundaryShape(wxs); + processCreaseShape(wxs); + if (_computeRidgesAndValleys) + processRidgesAndValleysShape(wxs); + if (_computeSuggestiveContours) + processSuggestiveContourShape(wxs); + processSilhouetteShape(wxs); + processEdgeMarksShape(wxs); + if (progressBarDisplay) + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + + // build smooth edges: + buildSmoothEdges(wxs); + + // Post processing for suggestive contours + if (_computeSuggestiveContours) + postProcessSuggestiveContourShape(wxs); + if (progressBarDisplay) + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + + wxs->setComputeViewIndependentFlag(false); + _computeViewIndependent = false; + _changes = false; + + // reset user data + (*it)->ResetUserData(); + } } // GENERAL STUFF //////////////// void FEdgeXDetector::preProcessShape(WXShape *iWShape) { - _meanK1 = 0; - _meanKr = 0; - _minK1 = FLT_MAX; - _maxK1 = -FLT_MAX; - _minKr = FLT_MAX; - _maxKr = -FLT_MAX; - _nPoints = 0; + _meanK1 = 0; + _meanKr = 0; + _minK1 = FLT_MAX; + _maxK1 = -FLT_MAX; + _minKr = FLT_MAX; + _maxKr = -FLT_MAX; + _nPoints = 0; #if 0 - _meanEdgeSize = iWShape->getMeanEdgeSize(); + _meanEdgeSize = iWShape->getMeanEdgeSize(); #else - _meanEdgeSize = iWShape->ComputeMeanEdgeSize(); + _meanEdgeSize = iWShape->ComputeMeanEdgeSize(); #endif - vector& wfaces = iWShape->GetFaceList(); - vector::iterator f, fend; - // view dependant stuff - for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - preProcessFace((WXFace *)(*f)); - } - - if (_computeRidgesAndValleys || _computeSuggestiveContours) { - vector& wvertices = iWShape->getVertexList(); - for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; ++wv) { - // Compute curvatures - WXVertex *wxv = dynamic_cast(*wv); - computeCurvatures(wxv); - } - _meanK1 /= (real)(_nPoints); - _meanKr /= (real)(_nPoints); - } + vector &wfaces = iWShape->GetFaceList(); + vector::iterator f, fend; + // view dependant stuff + for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + preProcessFace((WXFace *)(*f)); + } + + if (_computeRidgesAndValleys || _computeSuggestiveContours) { + vector &wvertices = iWShape->getVertexList(); + for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; + ++wv) { + // Compute curvatures + WXVertex *wxv = dynamic_cast(*wv); + computeCurvatures(wxv); + } + _meanK1 /= (real)(_nPoints); + _meanKr /= (real)(_nPoints); + } } void FEdgeXDetector::preProcessFace(WXFace *iFace) { - Vec3f firstPoint = iFace->GetVertex(0)->GetVertex(); - Vec3f N = iFace->GetNormal(); - - // Compute the dot product between V (=_Viewpoint - firstPoint) and N: - Vec3f V; - if (_orthographicProjection) { - V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - firstPoint.z()); - } - else { - V = Vec3f(_Viewpoint - firstPoint); - } - N.normalize(); - V.normalize(); - iFace->setDotP(N * V); - - // compute the distance between the face center and the viewpoint: - if (_orthographicProjection) { - iFace->setZ(iFace->center().z() - _Viewpoint.z()); - } - else { - Vec3f dist_vec(iFace->center() - _Viewpoint); - iFace->setZ(dist_vec.norm()); - } + Vec3f firstPoint = iFace->GetVertex(0)->GetVertex(); + Vec3f N = iFace->GetNormal(); + + // Compute the dot product between V (=_Viewpoint - firstPoint) and N: + Vec3f V; + if (_orthographicProjection) { + V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - firstPoint.z()); + } + else { + V = Vec3f(_Viewpoint - firstPoint); + } + N.normalize(); + V.normalize(); + iFace->setDotP(N * V); + + // compute the distance between the face center and the viewpoint: + if (_orthographicProjection) { + iFace->setZ(iFace->center().z() - _Viewpoint.z()); + } + else { + Vec3f dist_vec(iFace->center() - _Viewpoint); + iFace->setZ(dist_vec.norm()); + } } void FEdgeXDetector::computeCurvatures(WXVertex *vertex) { - // TODO: for some reason, the 'vertex' may have no associated edges - // (i.e., WVertex::_EdgeList is empty), which causes a crash due to - // a subsequent call of WVertex::_EdgeList.front(). - if (vertex->GetEdges().empty()) { - if (G.debug & G_DEBUG_FREESTYLE) { - printf("Warning: WVertex %d has no associated edges.\n", vertex->GetId()); - } - return; - } - - // CURVATURE LAYER - // store all the curvature datas for each vertex - - //soc unused - real K1, K2 - real cos2theta, sin2theta; - Vec3r e1, n, v; - // one vertex curvature info : - CurvatureInfo *C; - float radius = _sphereRadius * _meanEdgeSize; - - // view independent stuff - if (_computeViewIndependent) { - C = new CurvatureInfo(); - vertex->setCurvatures(C); - OGF::NormalCycle ncycle; - ncycle.begin(); - if (radius > 0) { - OGF::compute_curvature_tensor(vertex, radius, ncycle); - } - else { - OGF::compute_curvature_tensor_one_ring(vertex, ncycle); - } - ncycle.end(); - C->K1 = ncycle.kmin(); - C->K2 = ncycle.kmax(); - C->e1 = ncycle.Kmax(); //ncycle.kmin() * ncycle.Kmax(); - C->e2 = ncycle.Kmin(); //ncycle.kmax() * ncycle.Kmin(); - - real absK1 = fabs(C->K1); - _meanK1 += absK1; - if (absK1 > _maxK1) - _maxK1 = absK1; - if (absK1 < _minK1) - _minK1 = absK1; - } - // view dependant - C = vertex->curvatures(); - if (C == 0) - return; - - // compute radial curvature : - n = C->e1 ^ C->e2; - if (_orthographicProjection) { - v = Vec3r(0.0, 0.0, _Viewpoint.z() - vertex->GetVertex().z()); - } - else { - v = Vec3r(_Viewpoint - vertex->GetVertex()); - } - C->er = v - (v * n) * n; - C->er.normalize(); - e1 = C->e1; - e1.normalize(); - cos2theta = C->er * e1; - cos2theta *= cos2theta; - sin2theta = 1 - cos2theta; - C->Kr = C->K1 * cos2theta + C->K2 * sin2theta; - real absKr = fabs(C->Kr); - _meanKr += absKr; - if (absKr > _maxKr) - _maxKr = absKr; - if (absKr < _minKr) - _minKr = absKr; - - ++_nPoints; + // TODO: for some reason, the 'vertex' may have no associated edges + // (i.e., WVertex::_EdgeList is empty), which causes a crash due to + // a subsequent call of WVertex::_EdgeList.front(). + if (vertex->GetEdges().empty()) { + if (G.debug & G_DEBUG_FREESTYLE) { + printf("Warning: WVertex %d has no associated edges.\n", vertex->GetId()); + } + return; + } + + // CURVATURE LAYER + // store all the curvature datas for each vertex + + //soc unused - real K1, K2 + real cos2theta, sin2theta; + Vec3r e1, n, v; + // one vertex curvature info : + CurvatureInfo *C; + float radius = _sphereRadius * _meanEdgeSize; + + // view independent stuff + if (_computeViewIndependent) { + C = new CurvatureInfo(); + vertex->setCurvatures(C); + OGF::NormalCycle ncycle; + ncycle.begin(); + if (radius > 0) { + OGF::compute_curvature_tensor(vertex, radius, ncycle); + } + else { + OGF::compute_curvature_tensor_one_ring(vertex, ncycle); + } + ncycle.end(); + C->K1 = ncycle.kmin(); + C->K2 = ncycle.kmax(); + C->e1 = ncycle.Kmax(); //ncycle.kmin() * ncycle.Kmax(); + C->e2 = ncycle.Kmin(); //ncycle.kmax() * ncycle.Kmin(); + + real absK1 = fabs(C->K1); + _meanK1 += absK1; + if (absK1 > _maxK1) + _maxK1 = absK1; + if (absK1 < _minK1) + _minK1 = absK1; + } + // view dependant + C = vertex->curvatures(); + if (C == 0) + return; + + // compute radial curvature : + n = C->e1 ^ C->e2; + if (_orthographicProjection) { + v = Vec3r(0.0, 0.0, _Viewpoint.z() - vertex->GetVertex().z()); + } + else { + v = Vec3r(_Viewpoint - vertex->GetVertex()); + } + C->er = v - (v * n) * n; + C->er.normalize(); + e1 = C->e1; + e1.normalize(); + cos2theta = C->er * e1; + cos2theta *= cos2theta; + sin2theta = 1 - cos2theta; + C->Kr = C->K1 * cos2theta + C->K2 * sin2theta; + real absKr = fabs(C->Kr); + _meanKr += absKr; + if (absKr > _maxKr) + _maxKr = absKr; + if (absKr < _minKr) + _minKr = absKr; + + ++_nPoints; } // SILHOUETTE ///////////// void FEdgeXDetector::processSilhouetteShape(WXShape *iWShape) { - // Make a first pass on every polygons in order to compute all their silhouette relative values: - vector& wfaces = iWShape->GetFaceList(); - vector::iterator f, fend; - for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - ProcessSilhouetteFace((WXFace *)(*f)); - } - - // Make a pass on the edges to detect the silhouette edges that are not smooth - vector::iterator we, weend; - vector &wedges = iWShape->getEdgeList(); - for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ProcessSilhouetteEdge((WXEdge *)(*we)); - } + // Make a first pass on every polygons in order to compute all their silhouette relative values: + vector &wfaces = iWShape->GetFaceList(); + vector::iterator f, fend; + for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + ProcessSilhouetteFace((WXFace *)(*f)); + } + + // Make a pass on the edges to detect the silhouette edges that are not smooth + vector::iterator we, weend; + vector &wedges = iWShape->getEdgeList(); + for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ProcessSilhouetteEdge((WXEdge *)(*we)); + } } void FEdgeXDetector::ProcessSilhouetteFace(WXFace *iFace) { - // SILHOUETTE LAYER - Vec3f normal; - // Compute the dot products between View direction and N at each vertex of the face: - Vec3f point; - int closestPointId = 0; - float dist, minDist = FLT_MAX; - int numVertices = iFace->numberOfVertices(); - WXFaceLayer *faceLayer = new WXFaceLayer(iFace, Nature::SILHOUETTE, true); - for (int i = 0; i < numVertices; i++) { - point = iFace->GetVertex(i)->GetVertex(); - normal = iFace->GetVertexNormal(i); - normal.normalize(); - Vec3f V; - if (_orthographicProjection) { - V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - point.z()); - } - else { - V = Vec3f(_Viewpoint - point); - } - V.normalize(); - float d = normal * V; - faceLayer->PushDotP(d); - // Find the point the closest to the viewpoint - if (_orthographicProjection) { - dist = point.z() - _Viewpoint.z(); - } - else { - Vec3f dist_vec(point - _Viewpoint); - dist = dist_vec.norm(); - } - if (dist < minDist) { - minDist = dist; - closestPointId = i; - } - } - // Set the closest point id: - faceLayer->setClosestPointIndex(closestPointId); - // Add this layer to the face: - iFace->AddSmoothLayer(faceLayer); + // SILHOUETTE LAYER + Vec3f normal; + // Compute the dot products between View direction and N at each vertex of the face: + Vec3f point; + int closestPointId = 0; + float dist, minDist = FLT_MAX; + int numVertices = iFace->numberOfVertices(); + WXFaceLayer *faceLayer = new WXFaceLayer(iFace, Nature::SILHOUETTE, true); + for (int i = 0; i < numVertices; i++) { + point = iFace->GetVertex(i)->GetVertex(); + normal = iFace->GetVertexNormal(i); + normal.normalize(); + Vec3f V; + if (_orthographicProjection) { + V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - point.z()); + } + else { + V = Vec3f(_Viewpoint - point); + } + V.normalize(); + float d = normal * V; + faceLayer->PushDotP(d); + // Find the point the closest to the viewpoint + if (_orthographicProjection) { + dist = point.z() - _Viewpoint.z(); + } + else { + Vec3f dist_vec(point - _Viewpoint); + dist = dist_vec.norm(); + } + if (dist < minDist) { + minDist = dist; + closestPointId = i; + } + } + // Set the closest point id: + faceLayer->setClosestPointIndex(closestPointId); + // Add this layer to the face: + iFace->AddSmoothLayer(faceLayer); } void FEdgeXDetector::ProcessSilhouetteEdge(WXEdge *iEdge) { - if (iEdge->nature() & Nature::BORDER) - return; - // SILHOUETTE ? - //------------- - WXFace *fA = (WXFace *)iEdge->GetaOEdge()->GetaFace(); - WXFace *fB = (WXFace *)iEdge->GetaOEdge()->GetbFace(); - - if ((fA->front()) ^ (fB->front())) { // fA->visible XOR fB->visible (true if one is 0 and the other is 1) - // The only edges we want to set as silhouette edges in this way are the ones with 2 different normals - // for 1 vertex for these two faces - //-------------------- - // In reality we only test the normals for 1 of the 2 vertices. - if (fA->GetVertexNormal(iEdge->GetaVertex()) == fB->GetVertexNormal(iEdge->GetaVertex())) - return; - iEdge->AddNature(Nature::SILHOUETTE); - if (fB->front()) - iEdge->setOrder(1); - else - iEdge->setOrder(-1); - } + if (iEdge->nature() & Nature::BORDER) + return; + // SILHOUETTE ? + //------------- + WXFace *fA = (WXFace *)iEdge->GetaOEdge()->GetaFace(); + WXFace *fB = (WXFace *)iEdge->GetaOEdge()->GetbFace(); + + if ((fA->front()) ^ + (fB->front())) { // fA->visible XOR fB->visible (true if one is 0 and the other is 1) + // The only edges we want to set as silhouette edges in this way are the ones with 2 different normals + // for 1 vertex for these two faces + //-------------------- + // In reality we only test the normals for 1 of the 2 vertices. + if (fA->GetVertexNormal(iEdge->GetaVertex()) == fB->GetVertexNormal(iEdge->GetaVertex())) + return; + iEdge->AddNature(Nature::SILHOUETTE); + if (fB->front()) + iEdge->setOrder(1); + else + iEdge->setOrder(-1); + } } // BORDER ///////// void FEdgeXDetector::processBorderShape(WXShape *iWShape) { - if (!_computeViewIndependent) - return; - // Make a pass on the edges to detect the BORDER - vector::iterator we, weend; - vector &wedges = iWShape->getEdgeList(); - for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ProcessBorderEdge((WXEdge *)(*we)); - } + if (!_computeViewIndependent) + return; + // Make a pass on the edges to detect the BORDER + vector::iterator we, weend; + vector &wedges = iWShape->getEdgeList(); + for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ProcessBorderEdge((WXEdge *)(*we)); + } } void FEdgeXDetector::ProcessBorderEdge(WXEdge *iEdge) { - // first check whether it is a border edge: BORDER ? - //--------- - if (iEdge->GetaFace() == 0) { - // it is a border edge - iEdge->AddNature(Nature::BORDER); - } + // first check whether it is a border edge: BORDER ? + //--------- + if (iEdge->GetaFace() == 0) { + // it is a border edge + iEdge->AddNature(Nature::BORDER); + } } - // CREASE ///////// void FEdgeXDetector::processCreaseShape(WXShape *iWShape) { - if (!_computeViewIndependent) - return; - - // Make a pass on the edges to detect the CREASE - vector::iterator we, weend; - vector &wedges = iWShape->getEdgeList(); - for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ProcessCreaseEdge((WXEdge *)(*we)); - } + if (!_computeViewIndependent) + return; + + // Make a pass on the edges to detect the CREASE + vector::iterator we, weend; + vector &wedges = iWShape->getEdgeList(); + for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ProcessCreaseEdge((WXEdge *)(*we)); + } } void FEdgeXDetector::ProcessCreaseEdge(WXEdge *iEdge) { - // CREASE ? - //--------- - if (iEdge->nature() & Nature::BORDER) - return; - WXFace *fA = (WXFace *)iEdge->GetaOEdge()->GetaFace(); - WXFace *fB = (WXFace *)iEdge->GetaOEdge()->GetbFace(); - - WVertex *aVertex = iEdge->GetaVertex(); - if ((fA->GetVertexNormal(aVertex) * fB->GetVertexNormal(aVertex)) <= _creaseAngle) - iEdge->AddNature(Nature::CREASE); + // CREASE ? + //--------- + if (iEdge->nature() & Nature::BORDER) + return; + WXFace *fA = (WXFace *)iEdge->GetaOEdge()->GetaFace(); + WXFace *fB = (WXFace *)iEdge->GetaOEdge()->GetbFace(); + + WVertex *aVertex = iEdge->GetaVertex(); + if ((fA->GetVertexNormal(aVertex) * fB->GetVertexNormal(aVertex)) <= _creaseAngle) + iEdge->AddNature(Nature::CREASE); } // RIDGES AND VALLEYS ///////////////////// void FEdgeXDetector::processRidgesAndValleysShape(WXShape *iWShape) { - // Don't forget to add the built layer to the face at the end of the ProcessFace: - //iFace->AddSmoothLayer(faceLayer); - - if (!_computeViewIndependent) - return; - - // Here the curvatures must already have been computed - vector& wfaces = iWShape->GetFaceList(); - vector::iterator f, fend; - for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - ProcessRidgeFace((WXFace *)(*f)); - } + // Don't forget to add the built layer to the face at the end of the ProcessFace: + //iFace->AddSmoothLayer(faceLayer); + + if (!_computeViewIndependent) + return; + + // Here the curvatures must already have been computed + vector &wfaces = iWShape->GetFaceList(); + vector::iterator f, fend; + for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + ProcessRidgeFace((WXFace *)(*f)); + } } - // RIDGES ///////// void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) { - WXFaceLayer *flayer = new WXFaceLayer(iFace, Nature::RIDGE | Nature::VALLEY, false); - iFace->AddSmoothLayer(flayer); - - unsigned int numVertices = iFace->numberOfVertices(); - for (unsigned int i = 0; i < numVertices; ++i) { - WVertex *wv = iFace->GetVertex(i); - WXVertex *wxv = dynamic_cast(wv); - flayer->PushDotP(wxv->curvatures()->K1); - } - -#if 0 // XXX fabs(flayer->dotP(i)) < threshold cannot be true - real threshold = 0; - //real threshold = _maxK1 - (_maxK1 - _meanK1) / 20.0; - - if (flayer->nPosDotP() != numVertices) { - if ((fabs(flayer->dotP(0)) < threshold) && (fabs(flayer->dotP(1)) < threshold) && - (fabs(flayer->dotP(2)) < threshold)) - { - flayer->ReplaceDotP(0, 0); - flayer->ReplaceDotP(1, 0); - flayer->ReplaceDotP(2, 0); - } - } + WXFaceLayer *flayer = new WXFaceLayer(iFace, Nature::RIDGE | Nature::VALLEY, false); + iFace->AddSmoothLayer(flayer); + + unsigned int numVertices = iFace->numberOfVertices(); + for (unsigned int i = 0; i < numVertices; ++i) { + WVertex *wv = iFace->GetVertex(i); + WXVertex *wxv = dynamic_cast(wv); + flayer->PushDotP(wxv->curvatures()->K1); + } + +#if 0 // XXX fabs(flayer->dotP(i)) < threshold cannot be true + real threshold = 0; + //real threshold = _maxK1 - (_maxK1 - _meanK1) / 20.0; + + if (flayer->nPosDotP() != numVertices) { + if ((fabs(flayer->dotP(0)) < threshold) && (fabs(flayer->dotP(1)) < threshold) && + (fabs(flayer->dotP(2)) < threshold)) + { + flayer->ReplaceDotP(0, 0); + flayer->ReplaceDotP(1, 0); + flayer->ReplaceDotP(2, 0); + } + } #endif } #if 0 void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) { - // RIDGE LAYER - // Compute the RidgeFunction, that is the derivative of the ppal curvature along e1 at each vertex of the face - WVertex *v; - Vec3r v1v2; - real t; - vector SmoothLayers; - WXFaceLayer *faceLayer; - Face_Curvature_Info *layer_info; - real K1_a(0), K1_b(0); - Vec3r Inter_a, Inter_b; - - // find the ridge layer of the face - iFace->retrieveSmoothLayers(Nature::RIDGE, SmoothLayers); - if ( SmoothLayers.size()!=1 ) - return; - faceLayer = SmoothLayers[0]; - // retrieve the curvature info of this layer - layer_info = (Face_Curvature_Info *)faceLayer->userdata; - - int numVertices = iFace->numberOfVertices(); - for (int i = 0; i < numVertices; i++) { - v = iFace->GetVertex(i); - // vec_curvature_info[i] contains the curvature info of this vertex - Vec3r e2 = layer_info->vec_curvature_info[i]->K2*layer_info->vec_curvature_info[i]->e2; - Vec3r e1 = layer_info->vec_curvature_info[i]->K1*layer_info->vec_curvature_info[i]->e1; - e2.normalize(); - - WVertex::face_iterator fit = v->faces_begin(); - WVertex::face_iterator fitend = v->faces_end(); - for (; fit != fitend; ++fit) { - WXFace *wxf = dynamic_cast(*fit); - WOEdge *oppositeEdge; - if (!(wxf->getOppositeEdge(v, oppositeEdge))) - continue; - v1v2 = oppositeEdge->GetbVertex()->GetVertex() - oppositeEdge->GetaVertex()->GetVertex(); - GeomUtils::intersection_test res; - res = GeomUtils::intersectRayPlane(oppositeEdge->GetaVertex()->GetVertex(), v1v2, e2, -(v->GetVertex()*e2), - t, 1.0e-06); - if ((res == GeomUtils::DO_INTERSECT) && (t >= 0.0) && (t <= 1.0)) { - vector second_ridge_layer; - wxf->retrieveSmoothLayers(Nature::RIDGE, second_ridge_layer); - if (second_ridge_layer.size() != 1) - continue; - Face_Curvature_Info *second_layer_info = (Face_Curvature_Info*)second_ridge_layer[0]->userdata; - - unsigned index1 = wxf->GetIndex(oppositeEdge->GetaVertex()); - unsigned index2 = wxf->GetIndex(oppositeEdge->GetbVertex()); - real K1_1 = second_layer_info->vec_curvature_info[index1]->K1; - real K1_2 = second_layer_info->vec_curvature_info[index2]->K1; - real K1 = (1.0 - t) * K1_1 + t * K1_2; - Vec3r inter((1.0 - t) * oppositeEdge->GetaVertex()->GetVertex() + - t * oppositeEdge->GetbVertex()->GetVertex()); - Vec3r vtmp(inter - v->GetVertex()); - // is it K1_a or K1_b ? - if (vtmp * e1 > 0) { - K1_b = K1; - Inter_b = inter; - } - else { - K1_a = K1; - Inter_a = inter; - } - } - } - // Once we have K1 along the ppal direction compute the derivative : K1b - K1a put it in DotP - //real d = fabs(K1_b) - fabs(K1_a); - real d = 0; - real threshold = _meanK1 + (_maxK1 - _meanK1) / 7.0; - //real threshold = _meanK1; - //if ((fabs(K1_b) > threshold) || ((fabs(K1_a) > threshold))) - d = (K1_b) - (K1_a) / (Inter_b - Inter_a).norm(); - faceLayer->PushDotP(d); - //faceLayer->PushDotP(layer_info->vec_curvature_info[i]->K1); - } - - // Make the values relevant by checking whether all principal directions have the "same" direction: - Vec3r e0((layer_info->vec_curvature_info[0]->K1 * layer_info->vec_curvature_info[0]->e1)); - e0.normalize(); - Vec3r e1((layer_info->vec_curvature_info[1]->K1 * layer_info->vec_curvature_info[1]->e1)); - e1.normalize(); - Vec3r e2((layer_info->vec_curvature_info[2]->K1 * layer_info->vec_curvature_info[2]->e1)); - e2.normalize(); - if (e0 * e1 < 0) - // invert dotP[1] - faceLayer->ReplaceDotP(1, -faceLayer->dotP(1)); - if (e0 * e2 < 0) - // invert dotP[2] - faceLayer->ReplaceDotP(2, -faceLayer->dotP(2)); - -#if 0 // remove the weakest values; - real minDiff = (_maxK1 - _minK1) / 10.0; - real minDiff = _meanK1; - if ((faceLayer->dotP(0) < minDiff) && (faceLayer->dotP(1) < minDiff) && (faceLayer->dotP(2) < minDiff)) { - faceLayer->ReplaceDotP(0, 0); - faceLayer->ReplaceDotP(1, 0); - faceLayer->ReplaceDotP(2, 0); - } -#endif + // RIDGE LAYER + // Compute the RidgeFunction, that is the derivative of the ppal curvature along e1 at each vertex of the face + WVertex *v; + Vec3r v1v2; + real t; + vector SmoothLayers; + WXFaceLayer *faceLayer; + Face_Curvature_Info *layer_info; + real K1_a(0), K1_b(0); + Vec3r Inter_a, Inter_b; + + // find the ridge layer of the face + iFace->retrieveSmoothLayers(Nature::RIDGE, SmoothLayers); + if ( SmoothLayers.size()!=1 ) + return; + faceLayer = SmoothLayers[0]; + // retrieve the curvature info of this layer + layer_info = (Face_Curvature_Info *)faceLayer->userdata; + + int numVertices = iFace->numberOfVertices(); + for (int i = 0; i < numVertices; i++) { + v = iFace->GetVertex(i); + // vec_curvature_info[i] contains the curvature info of this vertex + Vec3r e2 = layer_info->vec_curvature_info[i]->K2*layer_info->vec_curvature_info[i]->e2; + Vec3r e1 = layer_info->vec_curvature_info[i]->K1*layer_info->vec_curvature_info[i]->e1; + e2.normalize(); + + WVertex::face_iterator fit = v->faces_begin(); + WVertex::face_iterator fitend = v->faces_end(); + for (; fit != fitend; ++fit) { + WXFace *wxf = dynamic_cast(*fit); + WOEdge *oppositeEdge; + if (!(wxf->getOppositeEdge(v, oppositeEdge))) + continue; + v1v2 = oppositeEdge->GetbVertex()->GetVertex() - oppositeEdge->GetaVertex()->GetVertex(); + GeomUtils::intersection_test res; + res = GeomUtils::intersectRayPlane(oppositeEdge->GetaVertex()->GetVertex(), v1v2, e2, -(v->GetVertex()*e2), + t, 1.0e-06); + if ((res == GeomUtils::DO_INTERSECT) && (t >= 0.0) && (t <= 1.0)) { + vector second_ridge_layer; + wxf->retrieveSmoothLayers(Nature::RIDGE, second_ridge_layer); + if (second_ridge_layer.size() != 1) + continue; + Face_Curvature_Info *second_layer_info = (Face_Curvature_Info*)second_ridge_layer[0]->userdata; + + unsigned index1 = wxf->GetIndex(oppositeEdge->GetaVertex()); + unsigned index2 = wxf->GetIndex(oppositeEdge->GetbVertex()); + real K1_1 = second_layer_info->vec_curvature_info[index1]->K1; + real K1_2 = second_layer_info->vec_curvature_info[index2]->K1; + real K1 = (1.0 - t) * K1_1 + t * K1_2; + Vec3r inter((1.0 - t) * oppositeEdge->GetaVertex()->GetVertex() + + t * oppositeEdge->GetbVertex()->GetVertex()); + Vec3r vtmp(inter - v->GetVertex()); + // is it K1_a or K1_b ? + if (vtmp * e1 > 0) { + K1_b = K1; + Inter_b = inter; + } + else { + K1_a = K1; + Inter_a = inter; + } + } + } + // Once we have K1 along the ppal direction compute the derivative : K1b - K1a put it in DotP + //real d = fabs(K1_b) - fabs(K1_a); + real d = 0; + real threshold = _meanK1 + (_maxK1 - _meanK1) / 7.0; + //real threshold = _meanK1; + //if ((fabs(K1_b) > threshold) || ((fabs(K1_a) > threshold))) + d = (K1_b) - (K1_a) / (Inter_b - Inter_a).norm(); + faceLayer->PushDotP(d); + //faceLayer->PushDotP(layer_info->vec_curvature_info[i]->K1); + } + + // Make the values relevant by checking whether all principal directions have the "same" direction: + Vec3r e0((layer_info->vec_curvature_info[0]->K1 * layer_info->vec_curvature_info[0]->e1)); + e0.normalize(); + Vec3r e1((layer_info->vec_curvature_info[1]->K1 * layer_info->vec_curvature_info[1]->e1)); + e1.normalize(); + Vec3r e2((layer_info->vec_curvature_info[2]->K1 * layer_info->vec_curvature_info[2]->e1)); + e2.normalize(); + if (e0 * e1 < 0) + // invert dotP[1] + faceLayer->ReplaceDotP(1, -faceLayer->dotP(1)); + if (e0 * e2 < 0) + // invert dotP[2] + faceLayer->ReplaceDotP(2, -faceLayer->dotP(2)); + +# if 0 // remove the weakest values; + real minDiff = (_maxK1 - _minK1) / 10.0; + real minDiff = _meanK1; + if ((faceLayer->dotP(0) < minDiff) && (faceLayer->dotP(1) < minDiff) && (faceLayer->dotP(2) < minDiff)) { + faceLayer->ReplaceDotP(0, 0); + faceLayer->ReplaceDotP(1, 0); + faceLayer->ReplaceDotP(2, 0); + } +# endif } #endif @@ -543,221 +544,226 @@ void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) void FEdgeXDetector::processSuggestiveContourShape(WXShape *iWShape) { - // Here the curvatures must already have been computed - vector& wfaces = iWShape->GetFaceList(); - vector::iterator f, fend; - for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - ProcessSuggestiveContourFace((WXFace *)(*f)); - } + // Here the curvatures must already have been computed + vector &wfaces = iWShape->GetFaceList(); + vector::iterator f, fend; + for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + ProcessSuggestiveContourFace((WXFace *)(*f)); + } } void FEdgeXDetector::ProcessSuggestiveContourFace(WXFace *iFace) { - WXFaceLayer *faceLayer = new WXFaceLayer(iFace, Nature::SUGGESTIVE_CONTOUR, true); - iFace->AddSmoothLayer(faceLayer); - - unsigned int numVertices = iFace->numberOfVertices(); - for (unsigned int i = 0; i < numVertices; ++i) { - WVertex *wv = iFace->GetVertex(i); - WXVertex *wxv = dynamic_cast(wv); - faceLayer->PushDotP(wxv->curvatures()->Kr); - } - -#if 0 // FIXME: find a more clever way to compute the threshold - real threshold = _meanKr; - if (faceLayer->nPosDotP()!=numVertices) { - if ((fabs(faceLayer->dotP(0)) < threshold) && (fabs(faceLayer->dotP(1)) < threshold) && - (fabs(faceLayer->dotP(2)) < threshold)) - { - faceLayer->ReplaceDotP(0, 0); - faceLayer->ReplaceDotP(1, 0); - faceLayer->ReplaceDotP(2, 0); - } - } + WXFaceLayer *faceLayer = new WXFaceLayer(iFace, Nature::SUGGESTIVE_CONTOUR, true); + iFace->AddSmoothLayer(faceLayer); + + unsigned int numVertices = iFace->numberOfVertices(); + for (unsigned int i = 0; i < numVertices; ++i) { + WVertex *wv = iFace->GetVertex(i); + WXVertex *wxv = dynamic_cast(wv); + faceLayer->PushDotP(wxv->curvatures()->Kr); + } + +#if 0 // FIXME: find a more clever way to compute the threshold + real threshold = _meanKr; + if (faceLayer->nPosDotP()!=numVertices) { + if ((fabs(faceLayer->dotP(0)) < threshold) && (fabs(faceLayer->dotP(1)) < threshold) && + (fabs(faceLayer->dotP(2)) < threshold)) + { + faceLayer->ReplaceDotP(0, 0); + faceLayer->ReplaceDotP(1, 0); + faceLayer->ReplaceDotP(2, 0); + } + } #endif } void FEdgeXDetector::postProcessSuggestiveContourShape(WXShape *iShape) { - vector& wfaces = iShape->GetFaceList(); - vector::iterator f, fend; - for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - postProcessSuggestiveContourFace((WXFace *)(*f)); - } + vector &wfaces = iShape->GetFaceList(); + vector::iterator f, fend; + for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + postProcessSuggestiveContourFace((WXFace *)(*f)); + } } void FEdgeXDetector::postProcessSuggestiveContourFace(WXFace *iFace) { - // Compute the derivative of the radial curvature in the radial direction, at the two extremities - // of the smooth edge. - // If the derivative is smaller than a given threshold _kr_derivative_epsilon, discard the edge. - - // Find the suggestive contour layer of the face (zero or one edge). - vector sc_layers; - iFace->retrieveSmoothEdgesLayers(Nature::SUGGESTIVE_CONTOUR, sc_layers); - if (sc_layers.empty()) - return; - - WXFaceLayer *sc_layer; - sc_layer = sc_layers[0]; - - // Compute the derivative value at each vertex of the face, and add it in a vector. - vector kr_derivatives; - - unsigned vertices_nb = iFace->numberOfVertices(); - WXVertex *v, *opposite_vertex_a, *opposite_vertex_b; - WXFace *wxf; - WOEdge *opposite_edge; - Vec3r normal_vec, radial_normal_vec, er_vec, v_vec, inter, inter1, inter2, tmp_vec; - GeomUtils::intersection_test res; - real kr(0), kr1(0), kr2(0), t; - - for (unsigned int i = 0; i < vertices_nb; ++i) { - v = (WXVertex *)(iFace->GetVertex(i)); - - // v is a singular vertex, skip it. - if (v->isBoundary()) { - kr_derivatives.push_back(0); - continue; - } - - v_vec = v->GetVertex(); - er_vec = v->curvatures()->er; - - // For each vertex, iterate on its adjacent faces. - for (WVertex::face_iterator fit = v->faces_begin(), fitend = v->faces_end(); fit != fitend; ++fit) { - wxf = dynamic_cast(*fit); - if (!wxf->getOppositeEdge(v, opposite_edge)) - continue; - - opposite_vertex_a = (WXVertex *)opposite_edge->GetaVertex(); - opposite_vertex_b = (WXVertex *)opposite_edge->GetbVertex(); - normal_vec = wxf->GetVertexNormal(v); // FIXME: what about e1 ^ e2 ? - radial_normal_vec = er_vec ^ normal_vec; - - // Test whether the radial plan intersects with the edge at the opposite of v. - res = GeomUtils::intersectRayPlane(opposite_vertex_a->GetVertex(), opposite_edge->GetVec(), - radial_normal_vec, -(v_vec * radial_normal_vec), - t, 1.0e-06); - - // If there is an intersection, compute the value of the derivative ath that point. - if ((res == GeomUtils::DO_INTERSECT) && (t >= 0) && (t <= 1)) { - kr = t * opposite_vertex_a->curvatures()->Kr + (1 - t) * opposite_vertex_b->curvatures()->Kr; - inter = opposite_vertex_a->GetVertex() + t * opposite_edge->GetVec(); - tmp_vec = inter - v->GetVertex(); - // Is it kr1 or kr2? - if (tmp_vec * er_vec > 0) { - kr2 = kr; - inter2 = inter; - } - else { - kr1 = kr; - inter1 = inter; - } - } - } - - // Now we have kr1 and kr2 along the radial direction, for one vertex of iFace. - // We have to compute the derivative of kr for that vertex, equal to: - // (kr2 - kr1) / dist(inter1, inter2). - // Then we add it to the vector of derivatives. - v->curvatures()->dKr = (kr2 - kr1) / (inter2 - inter1).norm(); - kr_derivatives.push_back(v->curvatures()->dKr); - } - - // At that point, we have the derivatives for each vertex of iFace. - // All we have to do now is to use linear interpolation to compute the values at the extremities of the smooth edge. - WXSmoothEdge *sc_edge = sc_layer->getSmoothEdge(); - WOEdge *sc_oedge = sc_edge->woea(); - t = sc_edge->ta(); - if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] + - (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < _kr_derivative_epsilon) - { - sc_layer->removeSmoothEdge(); - return; - } - sc_oedge = sc_edge->woeb(); - t = sc_edge->tb(); - if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] + - (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < _kr_derivative_epsilon) - { - sc_layer->removeSmoothEdge(); - } + // Compute the derivative of the radial curvature in the radial direction, at the two extremities + // of the smooth edge. + // If the derivative is smaller than a given threshold _kr_derivative_epsilon, discard the edge. + + // Find the suggestive contour layer of the face (zero or one edge). + vector sc_layers; + iFace->retrieveSmoothEdgesLayers(Nature::SUGGESTIVE_CONTOUR, sc_layers); + if (sc_layers.empty()) + return; + + WXFaceLayer *sc_layer; + sc_layer = sc_layers[0]; + + // Compute the derivative value at each vertex of the face, and add it in a vector. + vector kr_derivatives; + + unsigned vertices_nb = iFace->numberOfVertices(); + WXVertex *v, *opposite_vertex_a, *opposite_vertex_b; + WXFace *wxf; + WOEdge *opposite_edge; + Vec3r normal_vec, radial_normal_vec, er_vec, v_vec, inter, inter1, inter2, tmp_vec; + GeomUtils::intersection_test res; + real kr(0), kr1(0), kr2(0), t; + + for (unsigned int i = 0; i < vertices_nb; ++i) { + v = (WXVertex *)(iFace->GetVertex(i)); + + // v is a singular vertex, skip it. + if (v->isBoundary()) { + kr_derivatives.push_back(0); + continue; + } + + v_vec = v->GetVertex(); + er_vec = v->curvatures()->er; + + // For each vertex, iterate on its adjacent faces. + for (WVertex::face_iterator fit = v->faces_begin(), fitend = v->faces_end(); fit != fitend; + ++fit) { + wxf = dynamic_cast(*fit); + if (!wxf->getOppositeEdge(v, opposite_edge)) + continue; + + opposite_vertex_a = (WXVertex *)opposite_edge->GetaVertex(); + opposite_vertex_b = (WXVertex *)opposite_edge->GetbVertex(); + normal_vec = wxf->GetVertexNormal(v); // FIXME: what about e1 ^ e2 ? + radial_normal_vec = er_vec ^ normal_vec; + + // Test whether the radial plan intersects with the edge at the opposite of v. + res = GeomUtils::intersectRayPlane(opposite_vertex_a->GetVertex(), + opposite_edge->GetVec(), + radial_normal_vec, + -(v_vec * radial_normal_vec), + t, + 1.0e-06); + + // If there is an intersection, compute the value of the derivative ath that point. + if ((res == GeomUtils::DO_INTERSECT) && (t >= 0) && (t <= 1)) { + kr = t * opposite_vertex_a->curvatures()->Kr + + (1 - t) * opposite_vertex_b->curvatures()->Kr; + inter = opposite_vertex_a->GetVertex() + t * opposite_edge->GetVec(); + tmp_vec = inter - v->GetVertex(); + // Is it kr1 or kr2? + if (tmp_vec * er_vec > 0) { + kr2 = kr; + inter2 = inter; + } + else { + kr1 = kr; + inter1 = inter; + } + } + } + + // Now we have kr1 and kr2 along the radial direction, for one vertex of iFace. + // We have to compute the derivative of kr for that vertex, equal to: + // (kr2 - kr1) / dist(inter1, inter2). + // Then we add it to the vector of derivatives. + v->curvatures()->dKr = (kr2 - kr1) / (inter2 - inter1).norm(); + kr_derivatives.push_back(v->curvatures()->dKr); + } + + // At that point, we have the derivatives for each vertex of iFace. + // All we have to do now is to use linear interpolation to compute the values at the extremities of the smooth edge. + WXSmoothEdge *sc_edge = sc_layer->getSmoothEdge(); + WOEdge *sc_oedge = sc_edge->woea(); + t = sc_edge->ta(); + if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] + + (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < + _kr_derivative_epsilon) { + sc_layer->removeSmoothEdge(); + return; + } + sc_oedge = sc_edge->woeb(); + t = sc_edge->tb(); + if (t * kr_derivatives[iFace->GetIndex(sc_oedge->GetaVertex())] + + (1 - t) * kr_derivatives[iFace->GetIndex(sc_oedge->GetbVertex())] < + _kr_derivative_epsilon) { + sc_layer->removeSmoothEdge(); + } } // MATERIAL_BOUNDARY //////////////////// void FEdgeXDetector::processMaterialBoundaryShape(WXShape *iWShape) { - if (!_computeViewIndependent) - return; - // Make a pass on the edges to detect material boundaries - vector::iterator we, weend; - vector &wedges = iWShape->getEdgeList(); - for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ProcessMaterialBoundaryEdge((WXEdge *)(*we)); - } + if (!_computeViewIndependent) + return; + // Make a pass on the edges to detect material boundaries + vector::iterator we, weend; + vector &wedges = iWShape->getEdgeList(); + for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ProcessMaterialBoundaryEdge((WXEdge *)(*we)); + } } void FEdgeXDetector::ProcessMaterialBoundaryEdge(WXEdge *iEdge) { - // check whether the edge is a material boundary? - WFace *aFace = iEdge->GetaFace(); - WFace *bFace = iEdge->GetbFace(); - if (aFace && bFace && aFace->frs_materialIndex() != bFace->frs_materialIndex()) { - iEdge->AddNature(Nature::MATERIAL_BOUNDARY); - } + // check whether the edge is a material boundary? + WFace *aFace = iEdge->GetaFace(); + WFace *bFace = iEdge->GetbFace(); + if (aFace && bFace && aFace->frs_materialIndex() != bFace->frs_materialIndex()) { + iEdge->AddNature(Nature::MATERIAL_BOUNDARY); + } } // EDGE MARKS ///////////// void FEdgeXDetector::processEdgeMarksShape(WXShape *iShape) { - // Make a pass on the edges to detect material boundaries - vector::iterator we, weend; - vector &wedges = iShape->getEdgeList(); - for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ProcessEdgeMarks((WXEdge *)(*we)); - } + // Make a pass on the edges to detect material boundaries + vector::iterator we, weend; + vector &wedges = iShape->getEdgeList(); + for (we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ProcessEdgeMarks((WXEdge *)(*we)); + } } void FEdgeXDetector::ProcessEdgeMarks(WXEdge *iEdge) { - if (iEdge->GetMark()) { - iEdge->AddNature(Nature::EDGE_MARK); - } + if (iEdge->GetMark()) { + iEdge->AddNature(Nature::EDGE_MARK); + } } // Build Smooth edges ///////////////////// void FEdgeXDetector::buildSmoothEdges(WXShape *iShape) { - bool hasSmoothEdges = false; - - // Make a last pass to build smooth edges from the previous stored values: - //-------------------------------------------------------------------------- - vector& wfaces = iShape->GetFaceList(); - for (vector::iterator f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { - vector& faceLayers = ((WXFace *)(*f))->getSmoothLayers(); - for (vector::iterator wxfl = faceLayers.begin(), wxflend = faceLayers.end(); - wxfl != wxflend; - ++wxfl) - { - if ((*wxfl)->BuildSmoothEdge()) - hasSmoothEdges = true; - } - } - - if (hasSmoothEdges && !_computeRidgesAndValleys && !_computeSuggestiveContours) { - vector& wvertices = iShape->getVertexList(); - for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; ++wv) { - // Compute curvatures - WXVertex *wxv = dynamic_cast(*wv); - computeCurvatures(wxv); - } - _meanK1 /= (real)(_nPoints); - _meanKr /= (real)(_nPoints); - } + bool hasSmoothEdges = false; + + // Make a last pass to build smooth edges from the previous stored values: + //-------------------------------------------------------------------------- + vector &wfaces = iShape->GetFaceList(); + for (vector::iterator f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { + vector &faceLayers = ((WXFace *)(*f))->getSmoothLayers(); + for (vector::iterator wxfl = faceLayers.begin(), wxflend = faceLayers.end(); + wxfl != wxflend; + ++wxfl) { + if ((*wxfl)->BuildSmoothEdge()) + hasSmoothEdges = true; + } + } + + if (hasSmoothEdges && !_computeRidgesAndValleys && !_computeSuggestiveContours) { + vector &wvertices = iShape->getVertexList(); + for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; + ++wv) { + // Compute curvatures + WXVertex *wxv = dynamic_cast(*wv); + computeCurvatures(wxv); + } + _meanK1 /= (real)(_nPoints); + _meanKr /= (real)(_nPoints); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/FEdgeXDetector.h b/source/blender/freestyle/intern/view_map/FEdgeXDetector.h index 9143a2b507d..61e0c9267a1 100644 --- a/source/blender/freestyle/intern/view_map/FEdgeXDetector.h +++ b/source/blender/freestyle/intern/view_map/FEdgeXDetector.h @@ -36,7 +36,7 @@ #include "BLI_math.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -44,203 +44,204 @@ namespace Freestyle { using namespace Geometry; /*! This class takes as input a WXEdge structure and fills it */ -class FEdgeXDetector -{ -public: - FEdgeXDetector() - { - _pProgressBar = NULL; - _pRenderMonitor = NULL; - _computeViewIndependent = true; +class FEdgeXDetector { + public: + FEdgeXDetector() + { + _pProgressBar = NULL; + _pRenderMonitor = NULL; + _computeViewIndependent = true; #if 0 - _bbox_diagonal = 1.0; + _bbox_diagonal = 1.0; #endif - _meanEdgeSize = 0; - _computeRidgesAndValleys = true; - _computeSuggestiveContours = true; - _computeMaterialBoundaries = true; - _sphereRadius = 1.0; - _orthographicProjection = false; - _faceSmoothness = false; - _changes = false; - _kr_derivative_epsilon = 0.0; - _creaseAngle = 0.7; // angle of 134.43 degrees - } - - virtual ~FEdgeXDetector() {} - - /*! Process shapes from a WingedEdge containing a list of WShapes */ - virtual void processShapes(WingedEdge&); - - // GENERAL STUFF - virtual void preProcessShape(WXShape *iShape); - virtual void preProcessFace(WXFace *iFace); - virtual void computeCurvatures(WXVertex *iVertex); - - // SILHOUETTE - virtual void processSilhouetteShape(WXShape *iShape); - virtual void ProcessSilhouetteFace(WXFace *iFace); - virtual void ProcessSilhouetteEdge(WXEdge *iEdge); - - // CREASE - virtual void processCreaseShape(WXShape *iShape); - virtual void ProcessCreaseEdge(WXEdge *iEdge); - - /*! Sets the minimum angle for detecting crease edges - * \param angle: - * The angular threshold in degrees (between 0 and 180) for detecting crease edges. An edge is considered - * a crease edge if the angle between two faces sharing the edge is smaller than the given threshold. - */ - // XXX angle should be in radian... - inline void setCreaseAngle(float angle) - { - if (angle < 0.0) - angle = 0.0; - else if (angle > 180.0) - angle = 180.0; - angle = cos(M_PI * (180.0 - angle) / 180.0); - if (angle != _creaseAngle) { - _creaseAngle = angle; - _changes = true; - } - } - - // BORDER - virtual void processBorderShape(WXShape *iShape); - virtual void ProcessBorderEdge(WXEdge *iEdge); - - // RIDGES AND VALLEYS - virtual void processRidgesAndValleysShape(WXShape *iShape); - virtual void ProcessRidgeFace(WXFace *iFace); - - // SUGGESTIVE CONTOURS - virtual void processSuggestiveContourShape(WXShape *iShape); - virtual void ProcessSuggestiveContourFace(WXFace *iFace); - virtual void postProcessSuggestiveContourShape(WXShape *iShape); - virtual void postProcessSuggestiveContourFace(WXFace *iFace); - /*! Sets the minimal derivative of the radial curvature for suggestive contours - * \param dkr: - * The minimal derivative of the radial curvature - */ - inline void setSuggestiveContourKrDerivativeEpsilon(float dkr) - { - if (dkr != _kr_derivative_epsilon) { - _kr_derivative_epsilon = dkr; - _changes = true; - } - } - - // MATERIAL BOUNDARY - virtual void processMaterialBoundaryShape(WXShape *iWShape); - virtual void ProcessMaterialBoundaryEdge(WXEdge *iEdge); - - // EDGE MARKS - virtual void processEdgeMarksShape(WXShape *iShape); - virtual void ProcessEdgeMarks(WXEdge *iEdge); - - // EVERYBODY - virtual void buildSmoothEdges(WXShape *iShape); - - /*! Sets the current viewpoint */ - inline void setViewpoint(const Vec3f& ivp) - { - _Viewpoint = ivp; - } - - inline void enableOrthographicProjection(bool b) - { - _orthographicProjection = b; - } - - inline void enableRidgesAndValleysFlag(bool b) - { - _computeRidgesAndValleys = b; - } - - inline void enableSuggestiveContours(bool b) - { - _computeSuggestiveContours = b; - } - - inline void enableMaterialBoundaries(bool b) - { - _computeMaterialBoundaries = b; - } - - inline void enableFaceSmoothness(bool b) - { - if (b != _faceSmoothness) { - _faceSmoothness = b; - _changes = true; - } - } - - inline void enableFaceMarks(bool b) - { - if (b != _faceMarks) { - _faceMarks = b; - _changes = true; - } - } - - /*! Sets the radius of the geodesic sphere around each vertex (for the curvature computation) - * \param r: - * The radius of the sphere expressed as a ratio of the mean edge size - */ - inline void setSphereRadius(float r) - { - if (r != _sphereRadius) { - _sphereRadius = r; - _changes = true; - } - } - - inline void setProgressBar(ProgressBar *iProgressBar) - { - _pProgressBar = iProgressBar; - } - - inline void setRenderMonitor(RenderMonitor *iRenderMonitor) - { - _pRenderMonitor = iRenderMonitor; - } - -protected: - Vec3f _Viewpoint; + _meanEdgeSize = 0; + _computeRidgesAndValleys = true; + _computeSuggestiveContours = true; + _computeMaterialBoundaries = true; + _sphereRadius = 1.0; + _orthographicProjection = false; + _faceSmoothness = false; + _changes = false; + _kr_derivative_epsilon = 0.0; + _creaseAngle = 0.7; // angle of 134.43 degrees + } + + virtual ~FEdgeXDetector() + { + } + + /*! Process shapes from a WingedEdge containing a list of WShapes */ + virtual void processShapes(WingedEdge &); + + // GENERAL STUFF + virtual void preProcessShape(WXShape *iShape); + virtual void preProcessFace(WXFace *iFace); + virtual void computeCurvatures(WXVertex *iVertex); + + // SILHOUETTE + virtual void processSilhouetteShape(WXShape *iShape); + virtual void ProcessSilhouetteFace(WXFace *iFace); + virtual void ProcessSilhouetteEdge(WXEdge *iEdge); + + // CREASE + virtual void processCreaseShape(WXShape *iShape); + virtual void ProcessCreaseEdge(WXEdge *iEdge); + + /*! Sets the minimum angle for detecting crease edges + * \param angle: + * The angular threshold in degrees (between 0 and 180) for detecting crease edges. An edge is considered + * a crease edge if the angle between two faces sharing the edge is smaller than the given threshold. + */ + // XXX angle should be in radian... + inline void setCreaseAngle(float angle) + { + if (angle < 0.0) + angle = 0.0; + else if (angle > 180.0) + angle = 180.0; + angle = cos(M_PI * (180.0 - angle) / 180.0); + if (angle != _creaseAngle) { + _creaseAngle = angle; + _changes = true; + } + } + + // BORDER + virtual void processBorderShape(WXShape *iShape); + virtual void ProcessBorderEdge(WXEdge *iEdge); + + // RIDGES AND VALLEYS + virtual void processRidgesAndValleysShape(WXShape *iShape); + virtual void ProcessRidgeFace(WXFace *iFace); + + // SUGGESTIVE CONTOURS + virtual void processSuggestiveContourShape(WXShape *iShape); + virtual void ProcessSuggestiveContourFace(WXFace *iFace); + virtual void postProcessSuggestiveContourShape(WXShape *iShape); + virtual void postProcessSuggestiveContourFace(WXFace *iFace); + /*! Sets the minimal derivative of the radial curvature for suggestive contours + * \param dkr: + * The minimal derivative of the radial curvature + */ + inline void setSuggestiveContourKrDerivativeEpsilon(float dkr) + { + if (dkr != _kr_derivative_epsilon) { + _kr_derivative_epsilon = dkr; + _changes = true; + } + } + + // MATERIAL BOUNDARY + virtual void processMaterialBoundaryShape(WXShape *iWShape); + virtual void ProcessMaterialBoundaryEdge(WXEdge *iEdge); + + // EDGE MARKS + virtual void processEdgeMarksShape(WXShape *iShape); + virtual void ProcessEdgeMarks(WXEdge *iEdge); + + // EVERYBODY + virtual void buildSmoothEdges(WXShape *iShape); + + /*! Sets the current viewpoint */ + inline void setViewpoint(const Vec3f &ivp) + { + _Viewpoint = ivp; + } + + inline void enableOrthographicProjection(bool b) + { + _orthographicProjection = b; + } + + inline void enableRidgesAndValleysFlag(bool b) + { + _computeRidgesAndValleys = b; + } + + inline void enableSuggestiveContours(bool b) + { + _computeSuggestiveContours = b; + } + + inline void enableMaterialBoundaries(bool b) + { + _computeMaterialBoundaries = b; + } + + inline void enableFaceSmoothness(bool b) + { + if (b != _faceSmoothness) { + _faceSmoothness = b; + _changes = true; + } + } + + inline void enableFaceMarks(bool b) + { + if (b != _faceMarks) { + _faceMarks = b; + _changes = true; + } + } + + /*! Sets the radius of the geodesic sphere around each vertex (for the curvature computation) + * \param r: + * The radius of the sphere expressed as a ratio of the mean edge size + */ + inline void setSphereRadius(float r) + { + if (r != _sphereRadius) { + _sphereRadius = r; + _changes = true; + } + } + + inline void setProgressBar(ProgressBar *iProgressBar) + { + _pProgressBar = iProgressBar; + } + + inline void setRenderMonitor(RenderMonitor *iRenderMonitor) + { + _pRenderMonitor = iRenderMonitor; + } + + protected: + Vec3f _Viewpoint; #if 0 - real _bbox_diagonal; // diagonal of the current processed shape bbox + real _bbox_diagonal; // diagonal of the current processed shape bbox #endif - //oldtmp values - bool _computeViewIndependent; - real _meanK1; - real _meanKr; - real _minK1; - real _minKr; - real _maxK1; - real _maxKr; - unsigned _nPoints; - real _meanEdgeSize; - bool _orthographicProjection; - - bool _computeRidgesAndValleys; - bool _computeSuggestiveContours; - bool _computeMaterialBoundaries; - bool _faceSmoothness; - bool _faceMarks; - float _sphereRadius; // expressed as a ratio of the mean edge size - float _creaseAngle; // [-1, 1] compared with the inner product of face normals - bool _changes; - - float _kr_derivative_epsilon; - - ProgressBar *_pProgressBar; - RenderMonitor *_pRenderMonitor; + //oldtmp values + bool _computeViewIndependent; + real _meanK1; + real _meanKr; + real _minK1; + real _minKr; + real _maxK1; + real _maxKr; + unsigned _nPoints; + real _meanEdgeSize; + bool _orthographicProjection; + + bool _computeRidgesAndValleys; + bool _computeSuggestiveContours; + bool _computeMaterialBoundaries; + bool _faceSmoothness; + bool _faceMarks; + float _sphereRadius; // expressed as a ratio of the mean edge size + float _creaseAngle; // [-1, 1] compared with the inner product of face normals + bool _changes; + + float _kr_derivative_epsilon; + + ProgressBar *_pProgressBar; + RenderMonitor *_pRenderMonitor; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeXDetector") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeXDetector") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_FEDGE_X_DETECTOR_H__ +#endif // __FREESTYLE_FEDGE_X_DETECTOR_H__ diff --git a/source/blender/freestyle/intern/view_map/Functions0D.cpp b/source/blender/freestyle/intern/view_map/Functions0D.cpp index aca8fce2983..5b04b66eeeb 100644 --- a/source/blender/freestyle/intern/view_map/Functions0D.cpp +++ b/source/blender/freestyle/intern/view_map/Functions0D.cpp @@ -31,336 +31,338 @@ namespace Freestyle { namespace Functions0D { // Internal function -FEdge *getFEdge(Interface0D& it1, Interface0D& it2) +FEdge *getFEdge(Interface0D &it1, Interface0D &it2) { - return it1.getFEdge(it2); + return it1.getFEdge(it2); } -void getFEdges(Interface0DIterator& it, FEdge *&fe1, FEdge *&fe2) +void getFEdges(Interface0DIterator &it, FEdge *&fe1, FEdge *&fe2) { - // count number of vertices - Interface0DIterator prev = it, next = it; - ++next; - int count = 1; - if (!it.isBegin() && !next.isEnd()) { - count = 3; - } - if (count < 3) { - // if we only have 2 vertices - FEdge *fe = 0; - Interface0DIterator tmp = it; - if (it.isBegin()) { - ++tmp; - fe = it->getFEdge(*tmp); - } - else { - --tmp; - fe = it->getFEdge(*tmp); - } - fe1 = fe; - fe2 = NULL; - } - else { - // we have more than 2 vertices - bool begin = false, last = false; - Interface0DIterator previous = it; - if (!previous.isBegin()) - --previous; - else - begin = true; - Interface0DIterator next = it; - ++next; - if (next.isEnd()) - last = true; - if (begin) { - fe1 = it->getFEdge(*next); - fe2 = NULL; - } - else if (last) { - fe1 = previous->getFEdge(*it); - fe2 = NULL; - } - else { - fe1 = previous->getFEdge(*it); - fe2 = it->getFEdge(*next); - } - } + // count number of vertices + Interface0DIterator prev = it, next = it; + ++next; + int count = 1; + if (!it.isBegin() && !next.isEnd()) { + count = 3; + } + if (count < 3) { + // if we only have 2 vertices + FEdge *fe = 0; + Interface0DIterator tmp = it; + if (it.isBegin()) { + ++tmp; + fe = it->getFEdge(*tmp); + } + else { + --tmp; + fe = it->getFEdge(*tmp); + } + fe1 = fe; + fe2 = NULL; + } + else { + // we have more than 2 vertices + bool begin = false, last = false; + Interface0DIterator previous = it; + if (!previous.isBegin()) + --previous; + else + begin = true; + Interface0DIterator next = it; + ++next; + if (next.isEnd()) + last = true; + if (begin) { + fe1 = it->getFEdge(*next); + fe2 = NULL; + } + else if (last) { + fe1 = previous->getFEdge(*it); + fe2 = NULL; + } + else { + fe1 = previous->getFEdge(*it); + fe2 = it->getFEdge(*next); + } + } } void getViewEdges(Interface0DIterator &it, ViewEdge *&ve1, ViewEdge *&ve2) { - FEdge *fe1, *fe2; - getFEdges(it, fe1, fe2); - ve1 = fe1->viewedge(); - if (fe2 != NULL) { - ve2 = fe2->viewedge(); - if (ve2 == ve1) - ve2 = NULL; - } - else { - ve2 = NULL; - } + FEdge *fe1, *fe2; + getFEdges(it, fe1, fe2); + ve1 = fe1->viewedge(); + if (fe2 != NULL) { + ve2 = fe2->viewedge(); + if (ve2 == ve1) + ve2 = NULL; + } + else { + ve2 = NULL; + } } -ViewShape *getShapeF0D(Interface0DIterator& it) +ViewShape *getShapeF0D(Interface0DIterator &it) { - ViewEdge *ve1, *ve2; - getViewEdges(it, ve1, ve2); - return ve1->viewShape(); + ViewEdge *ve1, *ve2; + getViewEdges(it, ve1, ve2); + return ve1->viewShape(); } -void getOccludersF0D(Interface0DIterator& it, set& oOccluders) +void getOccludersF0D(Interface0DIterator &it, set &oOccluders) { - ViewEdge *ve1, *ve2; - getViewEdges(it, ve1, ve2); - occluder_container::const_iterator oit = ve1->occluders_begin(); - occluder_container::const_iterator oitend = ve1->occluders_end(); - - for (; oit != oitend; ++oit) - oOccluders.insert((*oit)); - - if (ve2 != NULL) { - oit = ve2->occluders_begin(); - oitend = ve2->occluders_end(); - for (; oit != oitend; ++oit) - oOccluders.insert((*oit)); - } + ViewEdge *ve1, *ve2; + getViewEdges(it, ve1, ve2); + occluder_container::const_iterator oit = ve1->occluders_begin(); + occluder_container::const_iterator oitend = ve1->occluders_end(); + + for (; oit != oitend; ++oit) + oOccluders.insert((*oit)); + + if (ve2 != NULL) { + oit = ve2->occluders_begin(); + oitend = ve2->occluders_end(); + for (; oit != oitend; ++oit) + oOccluders.insert((*oit)); + } } -ViewShape *getOccludeeF0D(Interface0DIterator& it) +ViewShape *getOccludeeF0D(Interface0DIterator &it) { - ViewEdge *ve1, *ve2; - getViewEdges(it, ve1, ve2); - ViewShape *aShape = ve1->aShape(); - return aShape; + ViewEdge *ve1, *ve2; + getViewEdges(it, ve1, ve2); + ViewShape *aShape = ve1->aShape(); + return aShape; } // -int VertexOrientation2DF0D::operator()(Interface0DIterator& iter) +int VertexOrientation2DF0D::operator()(Interface0DIterator &iter) { - Vec2f A, C; - Vec2f B(iter->getProjectedX(), iter->getProjectedY()); - if (iter.isBegin()) { - A = Vec2f(iter->getProjectedX(), iter->getProjectedY()); - } - else { - Interface0DIterator previous = iter; - --previous ; - A = Vec2f(previous->getProjectedX(), previous->getProjectedY()); - } - Interface0DIterator next = iter; - ++next; - if (next.isEnd()) - C = Vec2f(iter->getProjectedX(), iter->getProjectedY()); - else - C = Vec2f(next->getProjectedX(), next->getProjectedY()); - - Vec2f AB(B - A); - if (AB.norm() != 0) - AB.normalize(); - Vec2f BC(C - B); - if (BC.norm() != 0) - BC.normalize(); - result = AB + BC; - if (result.norm() != 0) - result.normalize(); - return 0; + Vec2f A, C; + Vec2f B(iter->getProjectedX(), iter->getProjectedY()); + if (iter.isBegin()) { + A = Vec2f(iter->getProjectedX(), iter->getProjectedY()); + } + else { + Interface0DIterator previous = iter; + --previous; + A = Vec2f(previous->getProjectedX(), previous->getProjectedY()); + } + Interface0DIterator next = iter; + ++next; + if (next.isEnd()) + C = Vec2f(iter->getProjectedX(), iter->getProjectedY()); + else + C = Vec2f(next->getProjectedX(), next->getProjectedY()); + + Vec2f AB(B - A); + if (AB.norm() != 0) + AB.normalize(); + Vec2f BC(C - B); + if (BC.norm() != 0) + BC.normalize(); + result = AB + BC; + if (result.norm() != 0) + result.normalize(); + return 0; } -int VertexOrientation3DF0D::operator()(Interface0DIterator& iter) +int VertexOrientation3DF0D::operator()(Interface0DIterator &iter) { - Vec3r A, C; - Vec3r B(iter->getX(), iter->getY(), iter->getZ()); - if (iter.isBegin()) { - A = Vec3r(iter->getX(), iter->getY(), iter->getZ()); - } - else { - Interface0DIterator previous = iter; - --previous ; - A = Vec3r(previous->getX(), previous->getY(), previous->getZ()); - } - Interface0DIterator next = iter; - ++next ; - if (next.isEnd()) - C = Vec3r(iter->getX(), iter->getY(), iter->getZ()); - else - C = Vec3r(next->getX(), next->getY(), next->getZ()); - - Vec3r AB(B - A); - if (AB.norm() != 0) - AB.normalize(); - Vec3r BC(C - B); - if (BC.norm() != 0) - BC.normalize(); - result = AB + BC; - if (result.norm() != 0) - result.normalize(); - return 0; + Vec3r A, C; + Vec3r B(iter->getX(), iter->getY(), iter->getZ()); + if (iter.isBegin()) { + A = Vec3r(iter->getX(), iter->getY(), iter->getZ()); + } + else { + Interface0DIterator previous = iter; + --previous; + A = Vec3r(previous->getX(), previous->getY(), previous->getZ()); + } + Interface0DIterator next = iter; + ++next; + if (next.isEnd()) + C = Vec3r(iter->getX(), iter->getY(), iter->getZ()); + else + C = Vec3r(next->getX(), next->getY(), next->getZ()); + + Vec3r AB(B - A); + if (AB.norm() != 0) + AB.normalize(); + Vec3r BC(C - B); + if (BC.norm() != 0) + BC.normalize(); + result = AB + BC; + if (result.norm() != 0) + result.normalize(); + return 0; } -int Curvature2DAngleF0D::operator()(Interface0DIterator& iter) +int Curvature2DAngleF0D::operator()(Interface0DIterator &iter) { - Interface0DIterator tmp1 = iter, tmp2 = iter; - ++tmp2; - unsigned count = 1; - while ((!tmp1.isBegin()) && (count < 3)) { - --tmp1; - ++count; - } - while ((!tmp2.isEnd()) && (count < 3)) { - ++tmp2; - ++count; - } - if (count < 3) { - // if we only have 2 vertices - result = 0; - return 0; - } - - Interface0DIterator v = iter; - if (iter.isBegin()) - ++v; - Interface0DIterator next = v; - ++next; - if (next.isEnd()) { - next = v; - --v; - } - Interface0DIterator prev = v; - --prev; - - Vec2r A(prev->getProjectedX(), prev->getProjectedY()); - Vec2r B(v->getProjectedX(), v->getProjectedY()); - Vec2r C(next->getProjectedX(), next->getProjectedY()); - Vec2r AB(B - A); - Vec2r BC(C - B); - Vec2r N1(-AB[1], AB[0]); - if (N1.norm() != 0) - N1.normalize(); - Vec2r N2(-BC[1], BC[0]); - if (N2.norm() != 0) - N2.normalize(); - if ((N1.norm() == 0) && (N2.norm() == 0)) { - Exception::raiseException(); - result = 0; - return -1; - } - double cosin = N1 * N2; - if (cosin > 1) - cosin = 1; - if (cosin < -1) - cosin = -1; - result = acos(cosin); - return 0; + Interface0DIterator tmp1 = iter, tmp2 = iter; + ++tmp2; + unsigned count = 1; + while ((!tmp1.isBegin()) && (count < 3)) { + --tmp1; + ++count; + } + while ((!tmp2.isEnd()) && (count < 3)) { + ++tmp2; + ++count; + } + if (count < 3) { + // if we only have 2 vertices + result = 0; + return 0; + } + + Interface0DIterator v = iter; + if (iter.isBegin()) + ++v; + Interface0DIterator next = v; + ++next; + if (next.isEnd()) { + next = v; + --v; + } + Interface0DIterator prev = v; + --prev; + + Vec2r A(prev->getProjectedX(), prev->getProjectedY()); + Vec2r B(v->getProjectedX(), v->getProjectedY()); + Vec2r C(next->getProjectedX(), next->getProjectedY()); + Vec2r AB(B - A); + Vec2r BC(C - B); + Vec2r N1(-AB[1], AB[0]); + if (N1.norm() != 0) + N1.normalize(); + Vec2r N2(-BC[1], BC[0]); + if (N2.norm() != 0) + N2.normalize(); + if ((N1.norm() == 0) && (N2.norm() == 0)) { + Exception::raiseException(); + result = 0; + return -1; + } + double cosin = N1 * N2; + if (cosin > 1) + cosin = 1; + if (cosin < -1) + cosin = -1; + result = acos(cosin); + return 0; } -int ZDiscontinuityF0D::operator()(Interface0DIterator& iter) +int ZDiscontinuityF0D::operator()(Interface0DIterator &iter) { - FEdge *fe1, *fe2; - getFEdges(iter, fe1, fe2); - result = fe1->z_discontinuity(); - if (fe2 != NULL) { - result += fe2->z_discontinuity(); - result /= 2.0f; - } - return 0; + FEdge *fe1, *fe2; + getFEdges(iter, fe1, fe2); + result = fe1->z_discontinuity(); + if (fe2 != NULL) { + result += fe2->z_discontinuity(); + result /= 2.0f; + } + return 0; } -int Normal2DF0D::operator()(Interface0DIterator& iter) +int Normal2DF0D::operator()(Interface0DIterator &iter) { - FEdge *fe1, *fe2; - getFEdges(iter, fe1, fe2); - Vec3f e1(fe1->orientation2d()); - Vec2f n1(e1[1], -e1[0]); - Vec2f n(n1); - if (fe2 != NULL) { - Vec3f e2(fe2->orientation2d()); - Vec2f n2(e2[1], -e2[0]); - n += n2; - } - n.normalize(); - result = n; - return 0; + FEdge *fe1, *fe2; + getFEdges(iter, fe1, fe2); + Vec3f e1(fe1->orientation2d()); + Vec2f n1(e1[1], -e1[0]); + Vec2f n(n1); + if (fe2 != NULL) { + Vec3f e2(fe2->orientation2d()); + Vec2f n2(e2[1], -e2[0]); + n += n2; + } + n.normalize(); + result = n; + return 0; } -int MaterialF0D::operator()(Interface0DIterator& iter) +int MaterialF0D::operator()(Interface0DIterator &iter) { - FEdge *fe1, *fe2; - getFEdges(iter, fe1, fe2); - if (fe1 == NULL) - return -1; - if (fe1->isSmooth()) - result = ((FEdgeSmooth *)fe1)->frs_material(); - else - result = ((FEdgeSharp *)fe1)->bFrsMaterial(); + FEdge *fe1, *fe2; + getFEdges(iter, fe1, fe2); + if (fe1 == NULL) + return -1; + if (fe1->isSmooth()) + result = ((FEdgeSmooth *)fe1)->frs_material(); + else + result = ((FEdgeSharp *)fe1)->bFrsMaterial(); #if 0 - const SShape *sshape = getShapeF0D(iter); - return sshape->material(); + const SShape *sshape = getShapeF0D(iter); + return sshape->material(); #endif - return 0; + return 0; } -int ShapeIdF0D::operator()(Interface0DIterator& iter) +int ShapeIdF0D::operator()(Interface0DIterator &iter) { - ViewShape *vshape = getShapeF0D(iter); - result = vshape->getId(); - return 0; + ViewShape *vshape = getShapeF0D(iter); + result = vshape->getId(); + return 0; } -int QuantitativeInvisibilityF0D::operator()(Interface0DIterator& iter) +int QuantitativeInvisibilityF0D::operator()(Interface0DIterator &iter) { - ViewEdge *ve1, *ve2; - getViewEdges(iter, ve1, ve2); - unsigned int qi1, qi2; - qi1 = ve1->qi(); - if (ve2 != NULL) { - qi2 = ve2->qi(); - if (qi2 != qi1) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "QuantitativeInvisibilityF0D: ambiguous evaluation for point " << iter->getId() << endl; - } - } - } - result = qi1; - return 0; + ViewEdge *ve1, *ve2; + getViewEdges(iter, ve1, ve2); + unsigned int qi1, qi2; + qi1 = ve1->qi(); + if (ve2 != NULL) { + qi2 = ve2->qi(); + if (qi2 != qi1) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "QuantitativeInvisibilityF0D: ambiguous evaluation for point " << iter->getId() + << endl; + } + } + } + result = qi1; + return 0; } -int CurveNatureF0D::operator()(Interface0DIterator& iter) +int CurveNatureF0D::operator()(Interface0DIterator &iter) { - Nature::EdgeNature nat = 0; - ViewEdge *ve1, *ve2; - getViewEdges(iter, ve1, ve2); - nat |= ve1->getNature(); - if (ve2 != NULL) - nat |= ve2->getNature(); - result = nat; - return 0; + Nature::EdgeNature nat = 0; + ViewEdge *ve1, *ve2; + getViewEdges(iter, ve1, ve2); + nat |= ve1->getNature(); + if (ve2 != NULL) + nat |= ve2->getNature(); + result = nat; + return 0; } -int GetOccludersF0D::operator()(Interface0DIterator& iter) +int GetOccludersF0D::operator()(Interface0DIterator &iter) { - set occluders; - getOccludersF0D(iter, occluders); - result.clear(); - //vsOccluders.insert(vsOccluders.begin(), occluders.begin(), occluders.end()); - for (set::iterator it = occluders.begin(), itend = occluders.end(); it != itend; ++it) { - result.push_back((*it)); - } - return 0; + set occluders; + getOccludersF0D(iter, occluders); + result.clear(); + //vsOccluders.insert(vsOccluders.begin(), occluders.begin(), occluders.end()); + for (set::iterator it = occluders.begin(), itend = occluders.end(); it != itend; + ++it) { + result.push_back((*it)); + } + return 0; } -int GetShapeF0D::operator()(Interface0DIterator& iter) +int GetShapeF0D::operator()(Interface0DIterator &iter) { - result = getShapeF0D(iter); - return 0; + result = getShapeF0D(iter); + return 0; } -int GetOccludeeF0D::operator()(Interface0DIterator& iter) +int GetOccludeeF0D::operator()(Interface0DIterator &iter) { - result = getOccludeeF0D(iter); - return 0; + result = getOccludeeF0D(iter); + return 0; } -} // end of namespace Functions0D +} // end of namespace Functions0D } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Functions0D.h b/source/blender/freestyle/intern/view_map/Functions0D.h index 108a124fe78..ecf94b29d60 100644 --- a/source/blender/freestyle/intern/view_map/Functions0D.h +++ b/source/blender/freestyle/intern/view_map/Functions0D.h @@ -37,7 +37,7 @@ #include "../system/Precision.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -70,44 +70,44 @@ using namespace Geometry; * - UnaryFunction0DViewShape * - UnaryFunction0DVoid */ -template -class UnaryFunction0D -{ -public: - T result; - void *py_uf0D; - - /*! The type of the value returned by the functor. */ - typedef T ReturnedValueType; - - /*! Default constructor. */ - UnaryFunction0D() - { - py_uf0D = NULL; - } - - /*! Destructor; */ - virtual ~UnaryFunction0D() {} - - /*! Returns the string "UnaryFunction0D" */ - virtual string getName() const - { - return "UnaryFunction0D"; - } - - /*! The operator (). - * \param iter: - * An Interface0DIterator pointing onto the point at which we wish to evaluate the function. - * \return the result of the function of type T. - */ - /* FIXME move the implementation to Functions0D.cpp */ - virtual int operator()(Interface0DIterator& iter) - { - return Director_BPy_UnaryFunction0D___call__(this, py_uf0D, iter); - } +template class UnaryFunction0D { + public: + T result; + void *py_uf0D; + + /*! The type of the value returned by the functor. */ + typedef T ReturnedValueType; + + /*! Default constructor. */ + UnaryFunction0D() + { + py_uf0D = NULL; + } + + /*! Destructor; */ + virtual ~UnaryFunction0D() + { + } + + /*! Returns the string "UnaryFunction0D" */ + virtual string getName() const + { + return "UnaryFunction0D"; + } + + /*! The operator (). + * \param iter: + * An Interface0DIterator pointing onto the point at which we wish to evaluate the function. + * \return the result of the function of type T. + */ + /* FIXME move the implementation to Functions0D.cpp */ + virtual int operator()(Interface0DIterator &iter) + { + return Director_BPy_UnaryFunction0D___call__(this, py_uf0D, iter); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction0D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction0D") #endif }; @@ -129,7 +129,7 @@ public: %template(UnaryFunction0DId) UnaryFunction0D; %template(UnaryFunction0DViewShape) UnaryFunction0D; %template(UnaryFunction0DVectorViewShape) UnaryFunction0D >; -#endif // SWIG +#endif // SWIG // // Functions definitions @@ -141,205 +141,194 @@ namespace Functions0D { // GetXF0D /*! Returns the X 3D coordinate of an Interface0D. */ -class GetXF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetXF0D" */ - string getName() const - { - return "GetXF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getX(); - return 0; - } +class GetXF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetXF0D" */ + string getName() const + { + return "GetXF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getX(); + return 0; + } }; // GetYF0D /*! Returns the Y 3D coordinate of an Interface0D. */ -class GetYF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetYF0D" */ - string getName() const - { - return "GetYF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getY(); - return 0; - } +class GetYF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetYF0D" */ + string getName() const + { + return "GetYF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getY(); + return 0; + } }; // GetZF0D /*! Returns the Z 3D coordinate of an Interface0D. */ -class GetZF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetZF0D" */ - string getName() const - { - return "GetZF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getZ(); - return 0; - } +class GetZF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetZF0D" */ + string getName() const + { + return "GetZF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getZ(); + return 0; + } }; // GetProjectedXF0D /*! Returns the X 3D projected coordinate of an Interface0D. */ -class GetProjectedXF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetProjectedXF0D" */ - string getName() const - { - return "GetProjectedXF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getProjectedX(); - return 0; - } +class GetProjectedXF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetProjectedXF0D" */ + string getName() const + { + return "GetProjectedXF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getProjectedX(); + return 0; + } }; // GetProjectedYF0D /*! Returns the Y projected 3D coordinate of an Interface0D. */ -class GetProjectedYF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetProjectedYF0D" */ - string getName() const - { - return "GetProjectedYF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getProjectedY(); - return 0; - } +class GetProjectedYF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetProjectedYF0D" */ + string getName() const + { + return "GetProjectedYF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getProjectedY(); + return 0; + } }; // GetProjectedZF0D /*! Returns the Z projected 3D coordinate of an Interface0D. */ -class GetProjectedZF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetProjectedZF0D" */ - string getName() const - { - return "GetProjectedZF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter->getProjectedZ(); - return 0; - } +class GetProjectedZF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetProjectedZF0D" */ + string getName() const + { + return "GetProjectedZF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter->getProjectedZ(); + return 0; + } }; // GetCurvilinearAbscissaF0D /*! Returns the curvilinear abscissa of an Interface0D in the context of its 1D element. */ -class GetCurvilinearAbscissaF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetCurvilinearAbscissaF0D" */ - string getName() const - { - return "GetCurvilinearAbscissaF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter.t(); - return 0; - } +class GetCurvilinearAbscissaF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetCurvilinearAbscissaF0D" */ + string getName() const + { + return "GetCurvilinearAbscissaF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter.t(); + return 0; + } }; // GetParameterF0D /*! Returns the parameter of an Interface0D in the context of its 1D element. */ -class GetParameterF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "GetCurvilinearAbscissaF0D" */ - string getName() const - { - return "GetParameterF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter) - { - result = iter.u(); - return 0; - } +class GetParameterF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetCurvilinearAbscissaF0D" */ + string getName() const + { + return "GetParameterF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter) + { + result = iter.u(); + return 0; + } }; // VertexOrientation2DF0D /*! Returns a Vec2r giving the 2D oriented tangent to the 1D element to which the Interface0DIterator& belongs to and * evaluated at the Interface0D pointed by this Interface0DIterator&. */ -class VertexOrientation2DF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "VertexOrientation2DF0D" */ - string getName() const - { - return "VertexOrientation2DF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class VertexOrientation2DF0D : public UnaryFunction0D { + public: + /*! Returns the string "VertexOrientation2DF0D" */ + string getName() const + { + return "VertexOrientation2DF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // VertexOrientation3DF0D /*! Returns a Vec3r giving the 3D oriented tangent to the 1D element to which the Interface0DIterator& belongs to and * evaluated at the Interface0D pointed by this Interface0DIterator&. */ -class VertexOrientation3DF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "VertexOrientation3DF0D" */ - string getName() const - { - return "VertexOrientation3DF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class VertexOrientation3DF0D : public UnaryFunction0D { + public: + /*! Returns the string "VertexOrientation3DF0D" */ + string getName() const + { + return "VertexOrientation3DF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // Curvature2DAngleF0D /*! Returns a real giving the 2D curvature (as an angle) of the 1D element to which the Interface0DIterator& * belongs to and evaluated at the Interface0D pointed by this Interface0DIterator&. */ -class Curvature2DAngleF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "Curvature2DAngleF0D" */ - string getName() const - { - return "Curvature2DAngleF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class Curvature2DAngleF0D : public UnaryFunction0D { + public: + /*! Returns the string "Curvature2DAngleF0D" */ + string getName() const + { + return "Curvature2DAngleF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // ZDiscontinuity @@ -347,34 +336,32 @@ public: * This distance is evaluated in the camera space and normalized between 0 and 1. Therefore, if no object is occluded * by the shape to which the Interface0D belongs to, 1 is returned. */ -class ZDiscontinuityF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "ZDiscontinuityF0D" */ - string getName() const - { - return "ZDiscontinuityF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class ZDiscontinuityF0D : public UnaryFunction0D { + public: + /*! Returns the string "ZDiscontinuityF0D" */ + string getName() const + { + return "ZDiscontinuityF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // Normal2DF0D /*! Returns a Vec2f giving the normalized 2D normal to the 1D element to which the Interface0DIterator& belongs to and * evaluated at the Interface0D pointed by this Interface0DIterator&. */ -class Normal2DF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "Normal2DF0D" */ - string getName() const - { - return "Normal2DF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class Normal2DF0D : public UnaryFunction0D { + public: + /*! Returns the string "Normal2DF0D" */ + string getName() const + { + return "Normal2DF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // MaterialF0D @@ -386,17 +373,16 @@ public: * However, there still can be problematic cases, and the user willing to deal with this cases in a specific way * should implement its own getMaterial functor. */ -class MaterialF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "MaterialF0D" */ - string getName() const - { - return "MaterialF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class MaterialF0D : public UnaryFunction0D { + public: + /*! Returns the string "MaterialF0D" */ + string getName() const + { + return "MaterialF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // ShapeIdF0D @@ -407,17 +393,16 @@ public: * However, there still can be problematic cases, and the user willing to deal with this cases in a specific way * should implement its own getShapeIdF0D functor. */ -class ShapeIdF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "ShapeIdF0D" */ - string getName() const - { - return "ShapeIdF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class ShapeIdF0D : public UnaryFunction0D { + public: + /*! Returns the string "ShapeIdF0D" */ + string getName() const + { + return "ShapeIdF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // QiF0D @@ -428,102 +413,96 @@ public: * However, there still can be problematic cases, and the user willing to deal with this cases in a specific way * should implement its own getQIF0D functor. */ -class QuantitativeInvisibilityF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "QuantitativeInvisibilityF0D" */ - string getName() const - { - return "QuantitativeInvisibilityF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class QuantitativeInvisibilityF0D : public UnaryFunction0D { + public: + /*! Returns the string "QuantitativeInvisibilityF0D" */ + string getName() const + { + return "QuantitativeInvisibilityF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // CurveNatureF0D /*! Returns the Nature::EdgeNature of the 1D element the Interface0DIterator& belongs to. */ -class CurveNatureF0D : public UnaryFunction0D -{ -public: - /*! Returns the string "QuantitativeInvisibilityF0D" */ - string getName() const - { - return "CurveNatureF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class CurveNatureF0D : public UnaryFunction0D { + public: + /*! Returns the string "QuantitativeInvisibilityF0D" */ + string getName() const + { + return "CurveNatureF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // GetShapeF0D /*! Returns the ViewShape* containing the Interface0D */ -class GetShapeF0D : public UnaryFunction0D< ViewShape*> -{ -public: - /*! Returns the string "GetShapeF0D" */ - string getName() const - { - return "GetShapeF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class GetShapeF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetShapeF0D" */ + string getName() const + { + return "GetShapeF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // GetOccludersF0D /*! Returns a vector containing the ViewShape* occluding the Interface0D */ -class GetOccludersF0D : public UnaryFunction0D< std::vector > -{ -public: - /*! Returns the string "GetOccludersF0D" */ - string getName() const - { - return "GetOccludersF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class GetOccludersF0D : public UnaryFunction0D> { + public: + /*! Returns the string "GetOccludersF0D" */ + string getName() const + { + return "GetOccludersF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; // GetOccludeeF0D /*! Returns the ViewShape* "occluded" by the Interface0D */ -class GetOccludeeF0D: public UnaryFunction0D< ViewShape*> -{ -public: - /*! Returns the string "GetOccludeeF0D" */ - string getName() const - { - return "GetOccludeeF0D"; - } - - /*! the () operator. */ - int operator()(Interface0DIterator& iter); +class GetOccludeeF0D : public UnaryFunction0D { + public: + /*! Returns the string "GetOccludeeF0D" */ + string getName() const + { + return "GetOccludeeF0D"; + } + + /*! the () operator. */ + int operator()(Interface0DIterator &iter); }; - /////////////////////////// Internal //////////////////////////// // getFEdge -FEdge *getFEdge(Interface0D& it1, Interface0D& it2); +FEdge *getFEdge(Interface0D &it1, Interface0D &it2); // getFEdges -void getFEdges(Interface0DIterator& it, FEdge *&fe1, FEdge *&fe2); +void getFEdges(Interface0DIterator &it, FEdge *&fe1, FEdge *&fe2); // getViewEdges -void getViewEdges(Interface0DIterator& it, ViewEdge *&ve1, ViewEdge *&ve2); +void getViewEdges(Interface0DIterator &it, ViewEdge *&ve1, ViewEdge *&ve2); // getShapeF0D -ViewShape *getShapeF0D(Interface0DIterator& it); +ViewShape *getShapeF0D(Interface0DIterator &it); // getOccludersF0D -void getOccludersF0D(Interface0DIterator& it, std::set& oOccluders); +void getOccludersF0D(Interface0DIterator &it, std::set &oOccluders); // getOccludeeF0D -ViewShape *getOccludeeF0D(Interface0DIterator& it); +ViewShape *getOccludeeF0D(Interface0DIterator &it); -} // end of namespace Functions0D +} // end of namespace Functions0D } /* namespace Freestyle */ -#endif // __FREESTYLE_FUNCTIONS_0D_H__ +#endif // __FREESTYLE_FUNCTIONS_0D_H__ diff --git a/source/blender/freestyle/intern/view_map/Functions1D.cpp b/source/blender/freestyle/intern/view_map/Functions1D.cpp index 31f3b65a2b7..0c0ab9fd631 100644 --- a/source/blender/freestyle/intern/view_map/Functions1D.cpp +++ b/source/blender/freestyle/intern/view_map/Functions1D.cpp @@ -27,237 +27,239 @@ namespace Freestyle { namespace Functions1D { -int GetXF1D::operator()(Interface1D& inter) +int GetXF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int GetYF1D::operator()(Interface1D& inter) +int GetYF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int GetZF1D::operator()(Interface1D& inter) +int GetZF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int GetProjectedXF1D::operator()(Interface1D& inter) +int GetProjectedXF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int GetProjectedYF1D::operator()(Interface1D& inter) +int GetProjectedYF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int GetProjectedZF1D::operator()(Interface1D& inter) +int GetProjectedZF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int Orientation2DF1D::operator()(Interface1D& inter) +int Orientation2DF1D::operator()(Interface1D &inter) { - FEdge *fe = dynamic_cast(&inter); - if (fe) { - Vec3r res = fe->orientation2d(); - result = Vec2f(res[0], res[1]); - } - else { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - } - return 0; + FEdge *fe = dynamic_cast(&inter); + if (fe) { + Vec3r res = fe->orientation2d(); + result = Vec2f(res[0], res[1]); + } + else { + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + } + return 0; } -int Orientation3DF1D::operator()(Interface1D& inter) +int Orientation3DF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int ZDiscontinuityF1D::operator()(Interface1D& inter) +int ZDiscontinuityF1D::operator()(Interface1D &inter) { - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int QuantitativeInvisibilityF1D::operator()(Interface1D& inter) +int QuantitativeInvisibilityF1D::operator()(Interface1D &inter) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - result = ve->qi(); - return 0; - } - FEdge *fe = dynamic_cast(&inter); - if (fe) { - result = fe->qi(); - return 0; - } - result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + result = ve->qi(); + return 0; + } + FEdge *fe = dynamic_cast(&inter); + if (fe) { + result = fe->qi(); + return 0; + } + result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; } -int CurveNatureF1D::operator()(Interface1D& inter) +int CurveNatureF1D::operator()(Interface1D &inter) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - result = ve->getNature(); - } - else { - // we return a nature that contains every natures of the viewedges spanned by the chain. - Nature::EdgeNature nat = Nature::NO_FEATURE; - Interface0DIterator it = inter.verticesBegin(); - while (!it.isEnd()) { - nat |= _func(it); - ++it; - } - result = nat; - } - return 0; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + result = ve->getNature(); + } + else { + // we return a nature that contains every natures of the viewedges spanned by the chain. + Nature::EdgeNature nat = Nature::NO_FEATURE; + Interface0DIterator it = inter.verticesBegin(); + while (!it.isEnd()) { + nat |= _func(it); + ++it; + } + result = nat; + } + return 0; } -int TimeStampF1D::operator()(Interface1D& inter) +int TimeStampF1D::operator()(Interface1D &inter) { - TimeStamp *timestamp = TimeStamp::instance(); - inter.setTimeStamp(timestamp->getTimeStamp()); - return 0; + TimeStamp *timestamp = TimeStamp::instance(); + inter.setTimeStamp(timestamp->getTimeStamp()); + return 0; } -int ChainingTimeStampF1D::operator()(Interface1D& inter) +int ChainingTimeStampF1D::operator()(Interface1D &inter) { - TimeStamp *timestamp = TimeStamp::instance(); - ViewEdge *ve = dynamic_cast(&inter); - if (ve) - ve->setChainingTimeStamp(timestamp->getTimeStamp()); - return 0; + TimeStamp *timestamp = TimeStamp::instance(); + ViewEdge *ve = dynamic_cast(&inter); + if (ve) + ve->setChainingTimeStamp(timestamp->getTimeStamp()); + return 0; } -int IncrementChainingTimeStampF1D::operator()(Interface1D& inter) +int IncrementChainingTimeStampF1D::operator()(Interface1D &inter) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) - ve->setChainingTimeStamp(ve->getChainingTimeStamp() + 1); - return 0; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) + ve->setChainingTimeStamp(ve->getChainingTimeStamp() + 1); + return 0; } -int GetShapeF1D::operator()(Interface1D& inter) +int GetShapeF1D::operator()(Interface1D &inter) { - vector shapesVector; - set shapesSet; - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - shapesVector.push_back(ve->viewShape()); - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) - shapesSet.insert(Functions0D::getShapeF0D(it)); - shapesVector.insert::iterator>(shapesVector.begin(), shapesSet.begin(), shapesSet.end()); - } - result = shapesVector; - return 0; + vector shapesVector; + set shapesSet; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + shapesVector.push_back(ve->viewShape()); + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) + shapesSet.insert(Functions0D::getShapeF0D(it)); + shapesVector.insert::iterator>( + shapesVector.begin(), shapesSet.begin(), shapesSet.end()); + } + result = shapesVector; + return 0; } -int GetOccludersF1D::operator()(Interface1D& inter) +int GetOccludersF1D::operator()(Interface1D &inter) { - vector shapesVector; - set shapesSet; - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - result = ve->occluders(); - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) { - Functions0D::getOccludersF0D(it, shapesSet); - } - shapesVector.insert(shapesVector.begin(), shapesSet.begin(), shapesSet.end()); - result = shapesVector; - } - return 0; + vector shapesVector; + set shapesSet; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + result = ve->occluders(); + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) { + Functions0D::getOccludersF0D(it, shapesSet); + } + shapesVector.insert(shapesVector.begin(), shapesSet.begin(), shapesSet.end()); + result = shapesVector; + } + return 0; } -int GetOccludeeF1D::operator()(Interface1D& inter) +int GetOccludeeF1D::operator()(Interface1D &inter) { - vector shapesVector; - set shapesSet; - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - ViewShape *aShape = ve->aShape(); - if (aShape) { - shapesVector.push_back(aShape); - } - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) { - shapesSet.insert(Functions0D::getOccludeeF0D(it)); - } - shapesVector.insert::iterator>(shapesVector.begin(), shapesSet.begin(), shapesSet.end()); - } - result = shapesVector; - return 0; + vector shapesVector; + set shapesSet; + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + ViewShape *aShape = ve->aShape(); + if (aShape) { + shapesVector.push_back(aShape); + } + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) { + shapesSet.insert(Functions0D::getOccludeeF0D(it)); + } + shapesVector.insert::iterator>( + shapesVector.begin(), shapesSet.begin(), shapesSet.end()); + } + result = shapesVector; + return 0; } // Internal //////////// -void getOccludeeF1D(Interface1D& inter, set& oShapes) +void getOccludeeF1D(Interface1D &inter, set &oShapes) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - ViewShape *aShape = ve->aShape(); - if (aShape == 0) { - oShapes.insert((ViewShape*)0); - return; - } - oShapes.insert(aShape); - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) - oShapes.insert(Functions0D::getOccludeeF0D(it)); - } + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + ViewShape *aShape = ve->aShape(); + if (aShape == 0) { + oShapes.insert((ViewShape *)0); + return; + } + oShapes.insert(aShape); + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) + oShapes.insert(Functions0D::getOccludeeF0D(it)); + } } -void getOccludersF1D(Interface1D& inter, set& oShapes) +void getOccludersF1D(Interface1D &inter, set &oShapes) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - vector& occluders = ve->occluders(); - oShapes.insert::iterator>(occluders.begin(), occluders.end()); - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) { - set shapes; - Functions0D::getOccludersF0D(it, shapes); - for (set::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) - oShapes.insert(*s); - } - } + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + vector &occluders = ve->occluders(); + oShapes.insert::iterator>(occluders.begin(), occluders.end()); + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) { + set shapes; + Functions0D::getOccludersF0D(it, shapes); + for (set::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) + oShapes.insert(*s); + } + } } -void getShapeF1D(Interface1D& inter, set& oShapes) +void getShapeF1D(Interface1D &inter, set &oShapes) { - ViewEdge *ve = dynamic_cast(&inter); - if (ve) { - oShapes.insert(ve->viewShape()); - } - else { - Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); - for (; it != itend; ++it) - oShapes.insert(Functions0D::getShapeF0D(it)); - } + ViewEdge *ve = dynamic_cast(&inter); + if (ve) { + oShapes.insert(ve->viewShape()); + } + else { + Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd(); + for (; it != itend; ++it) + oShapes.insert(Functions0D::getShapeF0D(it)); + } } -} // end of namespace Functions1D +} // end of namespace Functions1D } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Functions1D.h b/source/blender/freestyle/intern/view_map/Functions1D.h index 9101e380a40..581ab9c459a 100644 --- a/source/blender/freestyle/intern/view_map/Functions1D.h +++ b/source/blender/freestyle/intern/view_map/Functions1D.h @@ -33,7 +33,7 @@ #include "../python/Director.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -57,121 +57,120 @@ namespace Freestyle { * - UnaryFunction1DVectorViewShape * - UnaryFunction1DVoid */ -template -class UnaryFunction1D -{ -public: - T result; - void *py_uf1D; - - /*! The type of the value returned by the functor. */ - typedef T ReturnedValueType; - - /*! Default constructor */ - UnaryFunction1D() - { - _integration = MEAN; - } - - /*! Builds a UnaryFunction1D from an integration type. - * \param iType: - * In case the result for the Interface1D would be obtained by evaluating a 0D function over the different - * Interface0D of the Interface1D, \a iType tells which integration method to use. - * The default integration method is the MEAN. - */ - UnaryFunction1D(IntegrationType iType) - { - _integration = iType; - } - - /*! destructor. */ - virtual ~UnaryFunction1D() {} - - /*! returns the string "UnaryFunction1D". */ - virtual string getName() const - { - return "UnaryFunction1D"; - } - - /*! The operator (). - * \param inter: - * The Interface1D on which we wish to evaluate the function. - * \return the result of the function of type T. - */ - /* FIXME move the implementation to Functions1D.cpp */ - virtual int operator()(Interface1D& inter) - { - return Director_BPy_UnaryFunction1D___call__(this, py_uf1D, inter); - } - - /*! Sets the integration method */ - void setIntegrationType(IntegrationType integration) - { - _integration = integration; - } - - /*! Returns the integration method. */ - IntegrationType getIntegrationType() const - { - return _integration; - } - -protected: - IntegrationType _integration; +template class UnaryFunction1D { + public: + T result; + void *py_uf1D; + + /*! The type of the value returned by the functor. */ + typedef T ReturnedValueType; + + /*! Default constructor */ + UnaryFunction1D() + { + _integration = MEAN; + } + + /*! Builds a UnaryFunction1D from an integration type. + * \param iType: + * In case the result for the Interface1D would be obtained by evaluating a 0D function over the different + * Interface0D of the Interface1D, \a iType tells which integration method to use. + * The default integration method is the MEAN. + */ + UnaryFunction1D(IntegrationType iType) + { + _integration = iType; + } + + /*! destructor. */ + virtual ~UnaryFunction1D() + { + } + + /*! returns the string "UnaryFunction1D". */ + virtual string getName() const + { + return "UnaryFunction1D"; + } + + /*! The operator (). + * \param inter: + * The Interface1D on which we wish to evaluate the function. + * \return the result of the function of type T. + */ + /* FIXME move the implementation to Functions1D.cpp */ + virtual int operator()(Interface1D &inter) + { + return Director_BPy_UnaryFunction1D___call__(this, py_uf1D, inter); + } + + /*! Sets the integration method */ + void setIntegrationType(IntegrationType integration) + { + _integration = integration; + } + + /*! Returns the integration method. */ + IntegrationType getIntegrationType() const + { + return _integration; + } + + protected: + IntegrationType _integration; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction1D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction1D") #endif }; +class UnaryFunction1D_void { + public: + void *py_uf1D; -class UnaryFunction1D_void -{ -public: - void *py_uf1D; + UnaryFunction1D_void() + { + _integration = MEAN; + } - UnaryFunction1D_void() - { - _integration = MEAN; - } + UnaryFunction1D_void(IntegrationType iType) + { + _integration = iType; + } - UnaryFunction1D_void(IntegrationType iType) - { - _integration = iType; - } + virtual ~UnaryFunction1D_void() + { + } - virtual ~UnaryFunction1D_void() {} + virtual string getName() const + { + return "UnaryFunction1D_void"; + } - virtual string getName() const - { - return "UnaryFunction1D_void"; - } + /* FIXME move the implementation to Functions1D.cpp */ + int operator()(Interface1D &inter) + { + return Director_BPy_UnaryFunction1D___call__(this, py_uf1D, inter); + } - /* FIXME move the implementation to Functions1D.cpp */ - int operator()(Interface1D& inter) - { - return Director_BPy_UnaryFunction1D___call__(this, py_uf1D, inter); - } + void setIntegrationType(IntegrationType integration) + { + _integration = integration; + } - void setIntegrationType(IntegrationType integration) - { - _integration = integration; - } + IntegrationType getIntegrationType() const + { + return _integration; + } - IntegrationType getIntegrationType() const - { - return _integration; - } - -protected: - IntegrationType _integration; + protected: + IntegrationType _integration; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction1D_void") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction1D_void") #endif }; - // // Functions definitions // @@ -181,194 +180,202 @@ namespace Functions1D { // GetXF1D /*! Returns the X 3D coordinate of an Interface1D. */ -class GetXF1D : public UnaryFunction1D -{ -private: - Functions0D::GetXF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetXF1D(IntegrationType iType) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetXF1D" */ - string getName() const - { - return "GetXF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetXF1D : public UnaryFunction1D { + private: + Functions0D::GetXF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetXF1D(IntegrationType iType) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetXF1D" */ + string getName() const + { + return "GetXF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetYF1D /*! Returns the Y 3D coordinate of an Interface1D. */ -class GetYF1D : public UnaryFunction1D -{ -private: -Functions0D::GetYF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetYF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetYF1D" */ - string getName() const - { - return "GetYF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetYF1D : public UnaryFunction1D { + private: + Functions0D::GetYF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetYF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetYF1D" */ + string getName() const + { + return "GetYF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetZF1D /*! Returns the Z 3D coordinate of an Interface1D. */ -class GetZF1D : public UnaryFunction1D -{ -private: - Functions0D::GetZF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetZF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetZF1D" */ - string getName() const - { - return "GetZF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetZF1D : public UnaryFunction1D { + private: + Functions0D::GetZF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetZF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetZF1D" */ + string getName() const + { + return "GetZF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetProjectedXF1D /*! Returns the projected X 3D coordinate of an Interface1D. */ -class GetProjectedXF1D : public UnaryFunction1D -{ -private: - Functions0D::GetProjectedXF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetProjectedXF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetProjectedXF1D" */ - string getName() const - { - return "GetProjectedXF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetProjectedXF1D : public UnaryFunction1D { + private: + Functions0D::GetProjectedXF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetProjectedXF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetProjectedXF1D" */ + string getName() const + { + return "GetProjectedXF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetProjectedYF1D /*! Returns the projected Y 3D coordinate of an Interface1D. */ -class GetProjectedYF1D : public UnaryFunction1D -{ -private: - Functions0D::GetProjectedYF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetProjectedYF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetProjectedYF1D" */ - string getName() const - { - return "GetProjectedYF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetProjectedYF1D : public UnaryFunction1D { + private: + Functions0D::GetProjectedYF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetProjectedYF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetProjectedYF1D" */ + string getName() const + { + return "GetProjectedYF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetProjectedZF1D /*! Returns the projected Z 3D coordinate of an Interface1D. */ -class GetProjectedZF1D : public UnaryFunction1D -{ -private: - Functions0D::GetProjectedZF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - GetProjectedZF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "GetProjectedZF1D" */ - string getName() const - { - return "GetProjectedZF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetProjectedZF1D : public UnaryFunction1D { + private: + Functions0D::GetProjectedZF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + GetProjectedZF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "GetProjectedZF1D" */ + string getName() const + { + return "GetProjectedZF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // Orientation2DF1D /*! Returns the 2D orientation as a Vec2f*/ -class Orientation2DF1D : public UnaryFunction1D -{ -private: - Functions0D::VertexOrientation2DF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - Orientation2DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "Orientation2DF1D" */ - string getName() const - { - return "Orientation2DF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class Orientation2DF1D : public UnaryFunction1D { + private: + Functions0D::VertexOrientation2DF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + Orientation2DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "Orientation2DF1D" */ + string getName() const + { + return "Orientation2DF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // Orientation3DF1D /*! Returns the 3D orientation as a Vec3f. */ -class Orientation3DF1D : public UnaryFunction1D -{ -private: - Functions0D::VertexOrientation3DF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - Orientation3DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "Orientation3DF1D" */ - string getName() const - { - return "Orientation3DF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class Orientation3DF1D : public UnaryFunction1D { + private: + Functions0D::VertexOrientation3DF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + Orientation3DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "Orientation3DF1D" */ + string getName() const + { + return "Orientation3DF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // ZDiscontinuityF1D @@ -376,26 +383,27 @@ public: * This distance is evaluated in the camera space and normalized between 0 and 1. Therefore, if no object is occluded * by the shape to which the Interface1D belongs to, 1 is returned. */ -class ZDiscontinuityF1D : public UnaryFunction1D -{ -private: - Functions0D::ZDiscontinuityF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - ZDiscontinuityF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "ZDiscontinuityF1D" */ - string getName() const - { - return "ZDiscontinuityF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class ZDiscontinuityF1D : public UnaryFunction1D { + private: + Functions0D::ZDiscontinuityF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + ZDiscontinuityF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "ZDiscontinuityF1D" */ + string getName() const + { + return "ZDiscontinuityF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // QuantitativeInvisibilityF1D @@ -404,26 +412,27 @@ public: * results of a chaining (chain, stroke), then it might be made of several 1D elements of different * Quantitative Invisibilities. */ -class QuantitativeInvisibilityF1D : public UnaryFunction1D -{ -private: - Functions0D::QuantitativeInvisibilityF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - QuantitativeInvisibilityF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "QuantitativeInvisibilityF1D" */ - string getName() const - { - return "QuantitativeInvisibilityF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class QuantitativeInvisibilityF1D : public UnaryFunction1D { + private: + Functions0D::QuantitativeInvisibilityF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + QuantitativeInvisibilityF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "QuantitativeInvisibilityF1D" */ + string getName() const + { + return "QuantitativeInvisibilityF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // CurveNatureF1D @@ -432,198 +441,200 @@ public: * Indeed, the Interface1D might result from the gathering of several 1D elements, each one being of a different * nature. An integration method, such as the MEAN, might give, in this case, irrelevant results. */ -class CurveNatureF1D : public UnaryFunction1D -{ -private: - Functions0D::CurveNatureF0D _func; - -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - CurveNatureF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "CurveNatureF1D" */ - string getName() const - { - return "CurveNatureF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class CurveNatureF1D : public UnaryFunction1D { + private: + Functions0D::CurveNatureF0D _func; + + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + CurveNatureF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "CurveNatureF1D" */ + string getName() const + { + return "CurveNatureF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // TimeStampF1D /*! Returns the time stamp of the Interface1D. */ -class TimeStampF1D : public UnaryFunction1D_void -{ -public: - /*! Returns the string "TimeStampF1D" */ - string getName() const - { - return "TimeStampF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class TimeStampF1D : public UnaryFunction1D_void { + public: + /*! Returns the string "TimeStampF1D" */ + string getName() const + { + return "TimeStampF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // IncrementChainingTimeStampF1D /*! Increments the chaining time stamp of the Interface1D. */ -class IncrementChainingTimeStampF1D : public UnaryFunction1D_void -{ -public: - /*! Returns the string "IncrementChainingTimeStampF1D" */ - string getName() const - { - return "IncrementChainingTimeStampF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class IncrementChainingTimeStampF1D : public UnaryFunction1D_void { + public: + /*! Returns the string "IncrementChainingTimeStampF1D" */ + string getName() const + { + return "IncrementChainingTimeStampF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // ChainingTimeStampF1D /*! Sets the chaining time stamp of the Interface1D. */ -class ChainingTimeStampF1D : public UnaryFunction1D_void -{ -public: - /*! Returns the string "ChainingTimeStampF1D" */ - string getName() const - { - return "ChainingTimeStampF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class ChainingTimeStampF1D : public UnaryFunction1D_void { + public: + /*! Returns the string "ChainingTimeStampF1D" */ + string getName() const + { + return "ChainingTimeStampF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; - // Curvature2DAngleF1D /*! Returns the 2D curvature as an angle for an Interface1D. */ -class Curvature2DAngleF1D : public UnaryFunction1D -{ -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - Curvature2DAngleF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "Curvature2DAngleF1D" */ - string getName() const - { - return "Curvature2DAngleF1D"; - } - - /*! the () operator.*/ - int operator()(Interface1D& inter) - { - result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; - } - -private: - Functions0D::Curvature2DAngleF0D _fun; +class Curvature2DAngleF1D : public UnaryFunction1D { + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + Curvature2DAngleF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "Curvature2DAngleF1D" */ + string getName() const + { + return "Curvature2DAngleF1D"; + } + + /*! the () operator.*/ + int operator()(Interface1D &inter) + { + result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; + } + + private: + Functions0D::Curvature2DAngleF0D _fun; }; // Normal2DF1D /*! Returns the 2D normal for an interface 1D. */ -class Normal2DF1D : public UnaryFunction1D -{ -public: - /*! Builds the functor. - * \param iType: - * The integration method used to compute a single value from a set of values. - */ - Normal2DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) {} - - /*! Returns the string "Normal2DF1D" */ - string getName() const - { - return "Normal2DF1D"; - } - - /*! the () operator.*/ - int operator()(Interface1D& inter) - { - result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); - return 0; - } - -private: - Functions0D::Normal2DF0D _fun; +class Normal2DF1D : public UnaryFunction1D { + public: + /*! Builds the functor. + * \param iType: + * The integration method used to compute a single value from a set of values. + */ + Normal2DF1D(IntegrationType iType = MEAN) : UnaryFunction1D(iType) + { + } + + /*! Returns the string "Normal2DF1D" */ + string getName() const + { + return "Normal2DF1D"; + } + + /*! the () operator.*/ + int operator()(Interface1D &inter) + { + result = integrate(_fun, inter.verticesBegin(), inter.verticesEnd(), _integration); + return 0; + } + + private: + Functions0D::Normal2DF0D _fun; }; // GetShapeF1D /*! Returns list of shapes covered by this Interface1D. */ -class GetShapeF1D : public UnaryFunction1D > -{ -public: - /*! Builds the functor. */ - GetShapeF1D() : UnaryFunction1D >() {} - - /*! Returns the string "GetShapeF1D" */ - string getName() const - { - return "GetShapeF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetShapeF1D : public UnaryFunction1D> { + public: + /*! Builds the functor. */ + GetShapeF1D() : UnaryFunction1D>() + { + } + + /*! Returns the string "GetShapeF1D" */ + string getName() const + { + return "GetShapeF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetOccludersF1D /*! Returns list of occluding shapes covered by this Interface1D. */ -class GetOccludersF1D : public UnaryFunction1D > -{ -public: - /*! Builds the functor. */ - GetOccludersF1D() : UnaryFunction1D >() {} - - /*! Returns the string "GetOccludersF1D" */ - string getName() const - { - return "GetOccludersF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetOccludersF1D : public UnaryFunction1D> { + public: + /*! Builds the functor. */ + GetOccludersF1D() : UnaryFunction1D>() + { + } + + /*! Returns the string "GetOccludersF1D" */ + string getName() const + { + return "GetOccludersF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // GetOccludeeF1D /*! Returns list of occluded shapes covered by this Interface1D. */ -class GetOccludeeF1D : public UnaryFunction1D > -{ -public: - /*! Builds the functor. */ - GetOccludeeF1D() : UnaryFunction1D >() {} - - /*! Returns the string "GetOccludeeF1D" */ - string getName() const - { - return "GetOccludeeF1D"; - } - - /*! the () operator. */ - int operator()(Interface1D& inter); +class GetOccludeeF1D : public UnaryFunction1D> { + public: + /*! Builds the functor. */ + GetOccludeeF1D() : UnaryFunction1D>() + { + } + + /*! Returns the string "GetOccludeeF1D" */ + string getName() const + { + return "GetOccludeeF1D"; + } + + /*! the () operator. */ + int operator()(Interface1D &inter); }; // internal //////////// // getOccludeeF1D -void getOccludeeF1D(Interface1D& inter, set& oShapes); +void getOccludeeF1D(Interface1D &inter, set &oShapes); // getOccludersF1D -void getOccludersF1D(Interface1D& inter, set& oShapes); +void getOccludersF1D(Interface1D &inter, set &oShapes); // getShapeF1D -void getShapeF1D(Interface1D& inter, set& oShapes); +void getShapeF1D(Interface1D &inter, set &oShapes); -} // end of namespace Functions1D +} // end of namespace Functions1D } /* namespace Freestyle */ -#endif // __FREESTYLE_FUNCTIONS_1D_H__ +#endif // __FREESTYLE_FUNCTIONS_1D_H__ diff --git a/source/blender/freestyle/intern/view_map/GridDensityProvider.h b/source/blender/freestyle/intern/view_map/GridDensityProvider.h index a01569b958a..dacdb345c86 100644 --- a/source/blender/freestyle/intern/view_map/GridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/GridDensityProvider.h @@ -34,129 +34,137 @@ #include "BKE_global.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class GridDensityProvider -{ - // Disallow copying and assignment - GridDensityProvider(const GridDensityProvider& other); - GridDensityProvider& operator=(const GridDensityProvider& other); - -public: - GridDensityProvider(OccluderSource& source) : source(source) {} - - virtual ~GridDensityProvider() {}; - - float cellSize() - { - return _cellSize; - } - - unsigned cellsX() - { - return _cellsX; - } - - unsigned cellsY() - { - return _cellsY; - } - - float cellOrigin(int index) - { - if (index < 2) { - return _cellOrigin[index]; - } - else { - throw new out_of_range("GridDensityProvider::cellOrigin can take only indexes of 0 or 1."); - } - } - - static void calculateOptimalProscenium(OccluderSource& source, real proscenium[4]) - { - source.begin(); - if (source.isValid()) { - const Vec3r& initialPoint = source.getGridSpacePolygon().getVertices()[0]; - proscenium[0] = proscenium[1] = initialPoint[0]; - proscenium[2] = proscenium[3] = initialPoint[1]; - while (source.isValid()) { - GridHelpers::expandProscenium (proscenium, source.getGridSpacePolygon()); - source.next(); - } - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] << - ", " << proscenium[3] << ")" << endl; - } - } - - static void calculateQuickProscenium(const GridHelpers::Transform& transform, const BBox& bbox, - real proscenium[4]) - { - // Transform the coordinates of the 8 corners of the 3D bounding box - real xm = bbox.getMin()[0], xM = bbox.getMax()[0]; - real ym = bbox.getMin()[1], yM = bbox.getMax()[1]; - real zm = bbox.getMin()[2], zM = bbox.getMax()[2]; - Vec3r p1 = transform(Vec3r(xm, ym, zm)); - Vec3r p2 = transform(Vec3r(xm, ym, zM)); - Vec3r p3 = transform(Vec3r(xm, yM, zm)); - Vec3r p4 = transform(Vec3r(xm, yM, zM)); - Vec3r p5 = transform(Vec3r(xM, ym, zm)); - Vec3r p6 = transform(Vec3r(xM, ym, zM)); - Vec3r p7 = transform(Vec3r(xM, yM, zm)); - Vec3r p8 = transform(Vec3r(xM, yM, zM)); - // Determine the proscenium face according to the min and max values of the transformed x and y coordinates - proscenium[0] = std::min(std::min(std::min(p1.x(), p2.x()), std::min(p3.x(), p4.x())), - std::min(std::min(p5.x(), p6.x()), std::min(p7.x(), p8.x()))); - proscenium[1] = std::max(std::max(std::max(p1.x(), p2.x()), std::max(p3.x(), p4.x())), - std::max(std::max(p5.x(), p6.x()), std::max(p7.x(), p8.x()))); - proscenium[2] = std::min(std::min(std::min(p1.y(), p2.y()), std::min(p3.y(), p4.y())), - std::min(std::min(p5.y(), p6.y()), std::min(p7.y(), p8.y()))); - proscenium[3] = std::max(std::max(std::max(p1.y(), p2.y()), std::max(p3.y(), p4.y())), - std::max(std::max(p5.y(), p6.y()), std::max(p7.y(), p8.y()))); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Proscenium: " << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] << ", " << - proscenium[3] << endl; - } - } - -protected: - OccluderSource& source; - unsigned _cellsX, _cellsY; - float _cellSize; - float _cellOrigin[2]; +class GridDensityProvider { + // Disallow copying and assignment + GridDensityProvider(const GridDensityProvider &other); + GridDensityProvider &operator=(const GridDensityProvider &other); + + public: + GridDensityProvider(OccluderSource &source) : source(source) + { + } + + virtual ~GridDensityProvider(){}; + + float cellSize() + { + return _cellSize; + } + + unsigned cellsX() + { + return _cellsX; + } + + unsigned cellsY() + { + return _cellsY; + } + + float cellOrigin(int index) + { + if (index < 2) { + return _cellOrigin[index]; + } + else { + throw new out_of_range("GridDensityProvider::cellOrigin can take only indexes of 0 or 1."); + } + } + + static void calculateOptimalProscenium(OccluderSource &source, real proscenium[4]) + { + source.begin(); + if (source.isValid()) { + const Vec3r &initialPoint = source.getGridSpacePolygon().getVertices()[0]; + proscenium[0] = proscenium[1] = initialPoint[0]; + proscenium[2] = proscenium[3] = initialPoint[1]; + while (source.isValid()) { + GridHelpers::expandProscenium(proscenium, source.getGridSpacePolygon()); + source.next(); + } + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] + << ", " << proscenium[3] << ")" << endl; + } + } + + static void calculateQuickProscenium(const GridHelpers::Transform &transform, + const BBox &bbox, + real proscenium[4]) + { + // Transform the coordinates of the 8 corners of the 3D bounding box + real xm = bbox.getMin()[0], xM = bbox.getMax()[0]; + real ym = bbox.getMin()[1], yM = bbox.getMax()[1]; + real zm = bbox.getMin()[2], zM = bbox.getMax()[2]; + Vec3r p1 = transform(Vec3r(xm, ym, zm)); + Vec3r p2 = transform(Vec3r(xm, ym, zM)); + Vec3r p3 = transform(Vec3r(xm, yM, zm)); + Vec3r p4 = transform(Vec3r(xm, yM, zM)); + Vec3r p5 = transform(Vec3r(xM, ym, zm)); + Vec3r p6 = transform(Vec3r(xM, ym, zM)); + Vec3r p7 = transform(Vec3r(xM, yM, zm)); + Vec3r p8 = transform(Vec3r(xM, yM, zM)); + // Determine the proscenium face according to the min and max values of the transformed x and y coordinates + proscenium[0] = std::min(std::min(std::min(p1.x(), p2.x()), std::min(p3.x(), p4.x())), + std::min(std::min(p5.x(), p6.x()), std::min(p7.x(), p8.x()))); + proscenium[1] = std::max(std::max(std::max(p1.x(), p2.x()), std::max(p3.x(), p4.x())), + std::max(std::max(p5.x(), p6.x()), std::max(p7.x(), p8.x()))); + proscenium[2] = std::min(std::min(std::min(p1.y(), p2.y()), std::min(p3.y(), p4.y())), + std::min(std::min(p5.y(), p6.y()), std::min(p7.y(), p8.y()))); + proscenium[3] = std::max(std::max(std::max(p1.y(), p2.y()), std::max(p3.y(), p4.y())), + std::max(std::max(p5.y(), p6.y()), std::max(p7.y(), p8.y()))); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Proscenium: " << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] + << ", " << proscenium[3] << endl; + } + } + + protected: + OccluderSource &source; + unsigned _cellsX, _cellsY; + float _cellSize; + float _cellOrigin[2]; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProvider") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProvider") #endif }; -class GridDensityProviderFactory -{ - // Disallow copying and assignment - GridDensityProviderFactory(const GridDensityProviderFactory& other); - GridDensityProviderFactory& operator=(const GridDensityProviderFactory& other); +class GridDensityProviderFactory { + // Disallow copying and assignment + GridDensityProviderFactory(const GridDensityProviderFactory &other); + GridDensityProviderFactory &operator=(const GridDensityProviderFactory &other); -public: - GridDensityProviderFactory() {} + public: + GridDensityProviderFactory() + { + } - virtual AutoPtr newGridDensityProvider(OccluderSource& source, const real proscenium[4]) = 0; + virtual AutoPtr newGridDensityProvider(OccluderSource &source, + const real proscenium[4]) = 0; - virtual AutoPtr newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform) = 0; + virtual AutoPtr newGridDensityProvider( + OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform) = 0; - virtual AutoPtr newGridDensityProvider(OccluderSource& source) = 0; + virtual AutoPtr newGridDensityProvider(OccluderSource &source) = 0; - virtual ~GridDensityProviderFactory () {} + virtual ~GridDensityProviderFactory() + { + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProviderFactory") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProviderFactory") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_GRID_DENSITY_PROVIDER_H__ +#endif // __FREESTYLE_GRID_DENSITY_PROVIDER_H__ diff --git a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp index 676ce8046ad..55bc02b8358 100644 --- a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp +++ b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp @@ -23,53 +23,61 @@ namespace Freestyle { -HeuristicGridDensityProviderFactory::HeuristicGridDensityProviderFactory(real sizeFactor, unsigned numFaces) -: sizeFactor(sizeFactor), numFaces(numFaces) +HeuristicGridDensityProviderFactory::HeuristicGridDensityProviderFactory(real sizeFactor, + unsigned numFaces) + : sizeFactor(sizeFactor), numFaces(numFaces) { } -HeuristicGridDensityProviderFactory::~HeuristicGridDensityProviderFactory() {} +HeuristicGridDensityProviderFactory::~HeuristicGridDensityProviderFactory() +{ +} -AutoPtr -HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) +AutoPtr HeuristicGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const real proscenium[4]) { - AutoPtr avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); - AutoPtr p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); - if (avg->cellSize() > p23->cellSize()) { - return (AutoPtr) p23; - } - else { - return (AutoPtr) avg; - } + AutoPtr avg( + new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + AutoPtr p23( + new Pow23GridDensityProvider(source, proscenium, numFaces)); + if (avg->cellSize() > p23->cellSize()) { + return (AutoPtr)p23; + } + else { + return (AutoPtr)avg; + } } -AutoPtr -HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform) +AutoPtr HeuristicGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const BBox &bbox, const GridHelpers::Transform &transform) { - AutoPtr avg(new AverageAreaGridDensityProvider(source, bbox, - transform, sizeFactor)); - AutoPtr p23(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); - if (avg->cellSize() > p23->cellSize()) { - return (AutoPtr) p23; - } - else { - return (AutoPtr) avg; - } + AutoPtr avg( + new AverageAreaGridDensityProvider(source, bbox, transform, sizeFactor)); + AutoPtr p23( + new Pow23GridDensityProvider(source, bbox, transform, numFaces)); + if (avg->cellSize() > p23->cellSize()) { + return (AutoPtr)p23; + } + else { + return (AutoPtr)avg; + } } -AutoPtr HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr HeuristicGridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source) { - real proscenium[4]; - GridDensityProvider::calculateOptimalProscenium(source, proscenium); - AutoPtr avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); - AutoPtr p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); - if (avg->cellSize() > p23->cellSize()) { - return (AutoPtr) p23; - } - else { - return (AutoPtr) avg; - } + real proscenium[4]; + GridDensityProvider::calculateOptimalProscenium(source, proscenium); + AutoPtr avg( + new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + AutoPtr p23( + new Pow23GridDensityProvider(source, proscenium, numFaces)); + if (avg->cellSize() > p23->cellSize()) { + return (AutoPtr)p23; + } + else { + return (AutoPtr)avg; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h index 87f602945f1..b32a284cb61 100644 --- a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h +++ b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h @@ -30,22 +30,23 @@ namespace Freestyle { -class HeuristicGridDensityProviderFactory : public GridDensityProviderFactory -{ -public: - HeuristicGridDensityProviderFactory(real sizeFactor, unsigned numFaces); - ~HeuristicGridDensityProviderFactory(); - - AutoPtr newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - AutoPtr newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform); - AutoPtr newGridDensityProvider(OccluderSource& source); - -protected: - real sizeFactor; - unsigned numFaces; +class HeuristicGridDensityProviderFactory : public GridDensityProviderFactory { + public: + HeuristicGridDensityProviderFactory(real sizeFactor, unsigned numFaces); + ~HeuristicGridDensityProviderFactory(); + + AutoPtr newGridDensityProvider(OccluderSource &source, + const real proscenium[4]); + AutoPtr newGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform); + AutoPtr newGridDensityProvider(OccluderSource &source); + + protected: + real sizeFactor; + unsigned numFaces; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_HEURISTIC_GRID_DENSITY_PROVIDER_FACTORY_H__ +#endif // __FREESTYLE_HEURISTIC_GRID_DENSITY_PROVIDER_FACTORY_H__ diff --git a/source/blender/freestyle/intern/view_map/Interface0D.cpp b/source/blender/freestyle/intern/view_map/Interface0D.cpp index 17331bb613f..fc5a797cc87 100644 --- a/source/blender/freestyle/intern/view_map/Interface0D.cpp +++ b/source/blender/freestyle/intern/view_map/Interface0D.cpp @@ -28,92 +28,92 @@ namespace Freestyle { real Interface0D::getX() const { - PyErr_SetString(PyExc_TypeError, "method getX() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getX() not properly overridden"); + return 0; } real Interface0D::getY() const { - PyErr_SetString(PyExc_TypeError, "method getY() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getY() not properly overridden"); + return 0; } real Interface0D::getZ() const { - PyErr_SetString(PyExc_TypeError, "method getZ() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getZ() not properly overridden"); + return 0; } Geometry::Vec3r Interface0D::getPoint3D() const { - PyErr_SetString(PyExc_TypeError, "method getPoint3D() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getPoint3D() not properly overridden"); + return 0; } real Interface0D::getProjectedX() const { - PyErr_SetString(PyExc_TypeError, "method getProjectedX() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getProjectedX() not properly overridden"); + return 0; } real Interface0D::getProjectedY() const { - PyErr_SetString(PyExc_TypeError, "method getProjectedY() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getProjectedY() not properly overridden"); + return 0; } real Interface0D::getProjectedZ() const { - PyErr_SetString(PyExc_TypeError, "method getProjectedZ() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getProjectedZ() not properly overridden"); + return 0; } Geometry::Vec2r Interface0D::getPoint2D() const { - PyErr_SetString(PyExc_TypeError, "method getPoint2D() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getPoint2D() not properly overridden"); + return 0; } -FEdge *Interface0D::getFEdge(Interface0D&) +FEdge *Interface0D::getFEdge(Interface0D &) { - PyErr_SetString(PyExc_TypeError, "method getFEdge() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getFEdge() not properly overridden"); + return 0; } Id Interface0D::getId() const { - PyErr_SetString(PyExc_TypeError, "method getId() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getId() not properly overridden"); + return 0; } Nature::VertexNature Interface0D::getNature() const { - PyErr_SetString(PyExc_TypeError, "method getNature() not properly overridden"); - return Nature::POINT; + PyErr_SetString(PyExc_TypeError, "method getNature() not properly overridden"); + return Nature::POINT; } SVertex *Interface0D::castToSVertex() { - PyErr_SetString(PyExc_TypeError, "method castToSVertex() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method castToSVertex() not properly overridden"); + return 0; } ViewVertex *Interface0D::castToViewVertex() { - PyErr_SetString(PyExc_TypeError, "method castToViewVertex() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method castToViewVertex() not properly overridden"); + return 0; } NonTVertex *Interface0D::castToNonTVertex() { - PyErr_SetString(PyExc_TypeError, "method castToNonTVertex() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method castToNonTVertex() not properly overridden"); + return 0; } TVertex *Interface0D::castToTVertex() { - PyErr_SetString(PyExc_TypeError, "method castToTVertex() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method castToTVertex() not properly overridden"); + return 0; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Interface0D.h b/source/blender/freestyle/intern/view_map/Interface0D.h index 88214bb80a1..bab996d9308 100644 --- a/source/blender/freestyle/intern/view_map/Interface0D.h +++ b/source/blender/freestyle/intern/view_map/Interface0D.h @@ -34,7 +34,7 @@ #include "../winged_edge/Nature.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -53,121 +53,121 @@ class NonTVertex; class TVertex; /*! Base class for any 0D element. */ -class Interface0D -{ -public: - /*! Default constructor */ - Interface0D() {} +class Interface0D { + public: + /*! Default constructor */ + Interface0D() + { + } - /*! Destructor */ - virtual ~Interface0D() {}; + /*! Destructor */ + virtual ~Interface0D(){}; - /*! Returns the string "Interface0D". */ - virtual string getExactTypeName() const - { - return "Interface0D"; - } + /*! Returns the string "Interface0D". */ + virtual string getExactTypeName() const + { + return "Interface0D"; + } - // Data access methods + // Data access methods - /*! Returns the 3D x coordinate of the point. */ - virtual real getX() const; + /*! Returns the 3D x coordinate of the point. */ + virtual real getX() const; - /*! Returns the 3D y coordinate of the point. */ - virtual real getY() const; + /*! Returns the 3D y coordinate of the point. */ + virtual real getY() const; - /*! Returns the 3D z coordinate of the point. */ - virtual real getZ() const; + /*! Returns the 3D z coordinate of the point. */ + virtual real getZ() const; - /*! Returns the 3D point. */ - virtual Geometry::Vec3r getPoint3D() const; + /*! Returns the 3D point. */ + virtual Geometry::Vec3r getPoint3D() const; - /*! Returns the 2D x coordinate of the point. */ - virtual real getProjectedX() const; + /*! Returns the 2D x coordinate of the point. */ + virtual real getProjectedX() const; - /*! Returns the 2D y coordinate of the point. */ - virtual real getProjectedY() const; + /*! Returns the 2D y coordinate of the point. */ + virtual real getProjectedY() const; - /*! Returns the 2D z coordinate of the point. */ - virtual real getProjectedZ() const; + /*! Returns the 2D z coordinate of the point. */ + virtual real getProjectedZ() const; - /*! Returns the 2D point. */ - virtual Geometry::Vec2r getPoint2D() const; + /*! Returns the 2D point. */ + virtual Geometry::Vec2r getPoint2D() const; - /*! Returns the FEdge that lies between this Interface0D and the Interface0D given as argument. */ - virtual FEdge *getFEdge(Interface0D&); + /*! Returns the FEdge that lies between this Interface0D and the Interface0D given as argument. */ + virtual FEdge *getFEdge(Interface0D &); - /*! Returns the Id of the point. */ - virtual Id getId() const; + /*! Returns the Id of the point. */ + virtual Id getId() const; - /*! Returns the nature of the point. */ - virtual Nature::VertexNature getNature() const; + /*! Returns the nature of the point. */ + virtual Nature::VertexNature getNature() const; - /*! Cast the Interface0D in SVertex if it can be. */ - virtual SVertex *castToSVertex(); + /*! Cast the Interface0D in SVertex if it can be. */ + virtual SVertex *castToSVertex(); - /*! Cast the Interface0D in ViewVertex if it can be. */ - virtual ViewVertex *castToViewVertex(); + /*! Cast the Interface0D in ViewVertex if it can be. */ + virtual ViewVertex *castToViewVertex(); - /*! Cast the Interface0D in NonTVertex if it can be. */ - virtual NonTVertex *castToNonTVertex(); + /*! Cast the Interface0D in NonTVertex if it can be. */ + virtual NonTVertex *castToNonTVertex(); - /*! Cast the Interface0D in TVertex if it can be. */ - virtual TVertex *castToTVertex(); + /*! Cast the Interface0D in TVertex if it can be. */ + virtual TVertex *castToTVertex(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface0D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface0D") #endif }; - // // Interface0DIteratorNested // ////////////////////////////////////////////////// -class Interface0DIteratorNested : public Iterator -{ -public: - virtual ~Interface0DIteratorNested() {} +class Interface0DIteratorNested : public Iterator { + public: + virtual ~Interface0DIteratorNested() + { + } - virtual string getExactTypeName() const - { - return "Interface0DIteratorNested"; - } + virtual string getExactTypeName() const + { + return "Interface0DIteratorNested"; + } - virtual Interface0D& operator*() = 0; + virtual Interface0D &operator*() = 0; - virtual Interface0D *operator->() - { - return &(operator*()); - } + virtual Interface0D *operator->() + { + return &(operator*()); + } - virtual int increment() = 0; + virtual int increment() = 0; - virtual int decrement() = 0; + virtual int decrement() = 0; - virtual bool isBegin() const = 0; + virtual bool isBegin() const = 0; - virtual bool isEnd() const = 0; + virtual bool isEnd() const = 0; - virtual bool operator==(const Interface0DIteratorNested& it) const = 0; + virtual bool operator==(const Interface0DIteratorNested &it) const = 0; - virtual bool operator!=(const Interface0DIteratorNested& it) const - { - return !(*this == it); - } + virtual bool operator!=(const Interface0DIteratorNested &it) const + { + return !(*this == it); + } - /*! Returns the curvilinear abscissa */ - virtual float t() const = 0; + /*! Returns the curvilinear abscissa */ + virtual float t() const = 0; - /*! Returns the point parameter 0copy(); - } - - /*! Destructor */ - virtual ~Interface0DIterator() - { - if (_iterator) - delete _iterator; - } - - /*! Operator = - * \attention In the scripting language, you must call \code it2 = Interface0DIterator(it1) \endcode instead of - * \code it2 = it1 \endcode where \a it1 and \a it2 are 2 Interface0DIterator. - * Otherwise, incrementing \a it1 will also increment \a it2. - */ - Interface0DIterator& operator=(const Interface0DIterator& it) - { - if (_iterator) - delete _iterator; - _iterator = it._iterator->copy(); - return *this; - } - - /*! Returns the string "Interface0DIterator". */ - virtual string getExactTypeName() const - { - if (!_iterator) - return "Interface0DIterator"; - return _iterator->getExactTypeName() + "Proxy"; - } - - // FIXME test it != 0 (exceptions ?) - - /*! Returns a reference to the pointed Interface0D. - * In the scripting language, you must call "getObject()" instead using this operator. - */ - Interface0D& operator*() - { - return _iterator->operator*(); - } - - /*! Returns a pointer to the pointed Interface0D. - * Can't be called in the scripting language. - */ - Interface0D *operator->() - { - return &(operator*()); - } - - /*! Increments. In the scripting language, call "increment()". */ - Interface0DIterator& operator++() - { - _iterator->increment(); - return *this; - } - - /*! Increments. In the scripting language, call "increment()". */ - Interface0DIterator operator++(int) - { - Interface0DIterator ret(*this); - _iterator->increment(); - return ret; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - Interface0DIterator& operator--() - { - _iterator->decrement(); - return *this; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - Interface0DIterator operator--(int) - { - Interface0DIterator ret(*this); - _iterator->decrement(); - return ret; - } - - /*! Increments. */ - virtual int increment() - { - return _iterator->increment(); - } - - /*! Decrements. */ - virtual int decrement() - { - return _iterator->decrement(); - } - - /*! Returns true if the pointed Interface0D is the first of the 1D element containing the points over which - * we're iterating. - */ - virtual bool isBegin() const - { - return _iterator->isBegin(); - } - - /*! Returns true if the pointed Interface0D is after the after the last point of the 1D element we're - * iterating from. */ - virtual bool isEnd() const - { - return _iterator->isEnd(); - } - - /*! Returns true when the iterator is pointing to the final valid element. */ - virtual bool atLast() const - { - if (_iterator->isEnd()) - return false; - - _iterator->increment(); - bool result = _iterator->isEnd(); - _iterator->decrement(); - return result; - } - - /*! operator == . */ - bool operator==(const Interface0DIterator& it) const - { - return _iterator->operator==(*(it._iterator)); - } - - /*! operator != . */ - bool operator!=(const Interface0DIterator& it) const - { - return !(*this == it); - } - - /*! Returns the curvilinear abscissa. */ - inline float t() const - { - return _iterator->t(); - } - - /*! Returns the point parameter in the curve 0<=u<=1. */ - inline float u() const - { - return _iterator->u(); - } - -protected: - Interface0DIteratorNested *_iterator; +class Interface0DIterator : public Iterator { + public: + Interface0DIterator(Interface0DIteratorNested *it = NULL) + { + _iterator = it; + } + + /*! Copy constructor */ + Interface0DIterator(const Interface0DIterator &it) + { + _iterator = it._iterator->copy(); + } + + /*! Destructor */ + virtual ~Interface0DIterator() + { + if (_iterator) + delete _iterator; + } + + /*! Operator = + * \attention In the scripting language, you must call \code it2 = Interface0DIterator(it1) \endcode instead of + * \code it2 = it1 \endcode where \a it1 and \a it2 are 2 Interface0DIterator. + * Otherwise, incrementing \a it1 will also increment \a it2. + */ + Interface0DIterator &operator=(const Interface0DIterator &it) + { + if (_iterator) + delete _iterator; + _iterator = it._iterator->copy(); + return *this; + } + + /*! Returns the string "Interface0DIterator". */ + virtual string getExactTypeName() const + { + if (!_iterator) + return "Interface0DIterator"; + return _iterator->getExactTypeName() + "Proxy"; + } + + // FIXME test it != 0 (exceptions ?) + + /*! Returns a reference to the pointed Interface0D. + * In the scripting language, you must call "getObject()" instead using this operator. + */ + Interface0D &operator*() + { + return _iterator->operator*(); + } + + /*! Returns a pointer to the pointed Interface0D. + * Can't be called in the scripting language. + */ + Interface0D *operator->() + { + return &(operator*()); + } + + /*! Increments. In the scripting language, call "increment()". */ + Interface0DIterator &operator++() + { + _iterator->increment(); + return *this; + } + + /*! Increments. In the scripting language, call "increment()". */ + Interface0DIterator operator++(int) + { + Interface0DIterator ret(*this); + _iterator->increment(); + return ret; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + Interface0DIterator &operator--() + { + _iterator->decrement(); + return *this; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + Interface0DIterator operator--(int) + { + Interface0DIterator ret(*this); + _iterator->decrement(); + return ret; + } + + /*! Increments. */ + virtual int increment() + { + return _iterator->increment(); + } + + /*! Decrements. */ + virtual int decrement() + { + return _iterator->decrement(); + } + + /*! Returns true if the pointed Interface0D is the first of the 1D element containing the points over which + * we're iterating. + */ + virtual bool isBegin() const + { + return _iterator->isBegin(); + } + + /*! Returns true if the pointed Interface0D is after the after the last point of the 1D element we're + * iterating from. */ + virtual bool isEnd() const + { + return _iterator->isEnd(); + } + + /*! Returns true when the iterator is pointing to the final valid element. */ + virtual bool atLast() const + { + if (_iterator->isEnd()) + return false; + + _iterator->increment(); + bool result = _iterator->isEnd(); + _iterator->decrement(); + return result; + } + + /*! operator == . */ + bool operator==(const Interface0DIterator &it) const + { + return _iterator->operator==(*(it._iterator)); + } + + /*! operator != . */ + bool operator!=(const Interface0DIterator &it) const + { + return !(*this == it); + } + + /*! Returns the curvilinear abscissa. */ + inline float t() const + { + return _iterator->t(); + } + + /*! Returns the point parameter in the curve 0<=u<=1. */ + inline float u() const + { + return _iterator->u(); + } + + protected: + Interface0DIteratorNested *_iterator; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_INTERFACE_0D_H__ +#endif // __FREESTYLE_INTERFACE_0D_H__ diff --git a/source/blender/freestyle/intern/view_map/Interface1D.cpp b/source/blender/freestyle/intern/view_map/Interface1D.cpp index 4f3c46bbf01..ef219365831 100644 --- a/source/blender/freestyle/intern/view_map/Interface1D.cpp +++ b/source/blender/freestyle/intern/view_map/Interface1D.cpp @@ -28,44 +28,44 @@ namespace Freestyle { Interface0DIterator Interface1D::verticesBegin() { - PyErr_SetString(PyExc_TypeError, "method verticesBegin() not properly overridden"); - return Interface0DIterator(); + PyErr_SetString(PyExc_TypeError, "method verticesBegin() not properly overridden"); + return Interface0DIterator(); } Interface0DIterator Interface1D::verticesEnd() { - PyErr_SetString(PyExc_TypeError, "method verticesEnd() not properly overridden"); - return Interface0DIterator(); + PyErr_SetString(PyExc_TypeError, "method verticesEnd() not properly overridden"); + return Interface0DIterator(); } Interface0DIterator Interface1D::pointsBegin(float /*t*/) { - PyErr_SetString(PyExc_TypeError, "method pointsBegin() not properly overridden"); - return Interface0DIterator(); + PyErr_SetString(PyExc_TypeError, "method pointsBegin() not properly overridden"); + return Interface0DIterator(); } Interface0DIterator Interface1D::pointsEnd(float /*t*/) { - PyErr_SetString(PyExc_TypeError, "method pointsEnd() not properly overridden"); - return Interface0DIterator(); + PyErr_SetString(PyExc_TypeError, "method pointsEnd() not properly overridden"); + return Interface0DIterator(); } real Interface1D::getLength2D() const { - PyErr_SetString(PyExc_TypeError, "method getLength2D() not properly overridden"); - return 0; + PyErr_SetString(PyExc_TypeError, "method getLength2D() not properly overridden"); + return 0; } Id Interface1D::getId() const { - PyErr_SetString(PyExc_TypeError, "method getId() not properly overridden"); - return Id(0, 0); + PyErr_SetString(PyExc_TypeError, "method getId() not properly overridden"); + return Id(0, 0); } Nature::EdgeNature Interface1D::getNature() const { - PyErr_SetString(PyExc_TypeError, "method getNature() not properly overridden"); - return Nature::NO_FEATURE; + PyErr_SetString(PyExc_TypeError, "method getNature() not properly overridden"); + return Nature::NO_FEATURE; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Interface1D.h b/source/blender/freestyle/intern/view_map/Interface1D.h index de190f22e2d..e56a58096f8 100644 --- a/source/blender/freestyle/intern/view_map/Interface1D.h +++ b/source/blender/freestyle/intern/view_map/Interface1D.h @@ -34,7 +34,7 @@ #include "../winged_edge/Nature.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -46,11 +46,11 @@ namespace Freestyle { * from each 0D element of a 1D element. */ typedef enum { - MEAN, /*!< The value computed for the 1D element is the mean of the values obtained for the 0D elements.*/ - MIN, /*!< The value computed for the 1D element is the minimum of the values obtained for the 0D elements.*/ - MAX, /*!< The value computed for the 1D element is the maximum of the values obtained for the 0D elements.*/ - FIRST, /*!< The value computed for the 1D element is the first of the values obtained for the 0D elements.*/ - LAST, /*!< The value computed for the 1D element is the last of the values obtained for the 0D elements.*/ + MEAN, /*!< The value computed for the 1D element is the mean of the values obtained for the 0D elements.*/ + MIN, /*!< The value computed for the 1D element is the minimum of the values obtained for the 0D elements.*/ + MAX, /*!< The value computed for the 1D element is the maximum of the values obtained for the 0D elements.*/ + FIRST, /*!< The value computed for the 1D element is the first of the values obtained for the 0D elements.*/ + LAST, /*!< The value computed for the 1D element is the last of the values obtained for the 0D elements.*/ } IntegrationType; /*! Returns a single value from a set of values evaluated at each 0D element of this 1D element. @@ -65,54 +65,56 @@ typedef enum { * The integration method used to compute a single value from a set of values. * \return the single value obtained for the 1D element. */ -template -T integrate(UnaryFunction0D& fun, Interface0DIterator it, Interface0DIterator it_end, +template +T integrate(UnaryFunction0D &fun, + Interface0DIterator it, + Interface0DIterator it_end, IntegrationType integration_type = MEAN) { - T res; - unsigned size; - switch (integration_type) { - case MIN: - fun(it); - res = fun.result; - ++it; - for (; !it.isEnd(); ++it) { - fun(it); - if (fun.result < res) - res = fun.result; - } - break; - case MAX: - fun(it); - res = fun.result; - ++it; - for (; !it.isEnd(); ++it) { - fun(it); - if (fun.result > res) - res = fun.result; - } - break; - case FIRST: - fun(it); - res = fun.result; - break; - case LAST: - fun(--it_end); - res = fun.result; - break; - case MEAN: - default: - fun(it); - res = fun.result; - ++it; - for (size = 1; !it.isEnd(); ++it, ++size) { - fun(it); - res += fun.result; - } - res /= (size ? size : 1); - break; - } - return res; + T res; + unsigned size; + switch (integration_type) { + case MIN: + fun(it); + res = fun.result; + ++it; + for (; !it.isEnd(); ++it) { + fun(it); + if (fun.result < res) + res = fun.result; + } + break; + case MAX: + fun(it); + res = fun.result; + ++it; + for (; !it.isEnd(); ++it) { + fun(it); + if (fun.result > res) + res = fun.result; + } + break; + case FIRST: + fun(it); + res = fun.result; + break; + case LAST: + fun(--it_end); + res = fun.result; + break; + case MEAN: + default: + fun(it); + res = fun.result; + ++it; + for (size = 1; !it.isEnd(); ++it, ++size) { + fun(it); + res += fun.result; + } + res /= (size ? size : 1); + break; + } + return res; } // @@ -121,80 +123,79 @@ T integrate(UnaryFunction0D& fun, Interface0DIterator it, Interface0DIterator ////////////////////////////////////////////////// /*! Base class for any 1D element. */ -class Interface1D -{ -public: - /*! Default constructor */ - Interface1D() - { - _timeStamp = 0; - } - - /*! Destructor */ - virtual ~Interface1D() {}; - - /*! Returns the string "Interface1D". */ - virtual string getExactTypeName() const - { - return "Interface1D"; - } - - // Iterator access - - /*! Returns an iterator over the Interface1D vertices, pointing to the first vertex. */ - virtual Interface0DIterator verticesBegin(); - - /*! Returns an iterator over the Interface1D vertices, pointing after the last vertex. */ - virtual Interface0DIterator verticesEnd(); - - /*! Returns an iterator over the Interface1D points, pointing to the first point. The difference with - * verticesBegin() is that here we can iterate over points of the 1D element at a any given sampling. - * Indeed, for each iteration, a virtual point is created. - * \param t: - * The sampling with which we want to iterate over points of this 1D element. - */ - virtual Interface0DIterator pointsBegin(float t = 0.0f); - - /*! Returns an iterator over the Interface1D points, pointing after the last point. The difference with - * verticesEnd() is that here we can iterate over points of the 1D element at a any given sampling. - * Indeed, for each iteration, a virtual point is created. - * \param t: - * The sampling with which we want to iterate over points of this 1D element. - */ - virtual Interface0DIterator pointsEnd(float t = 0.0f); - - // Data access methods - - /*! Returns the 2D length of the 1D element. */ - virtual real getLength2D() const; - - /*! Returns the Id of the 1D element. */ - virtual Id getId() const; - - // FIXME: ce truc n'a rien a faire la...(c une requete complexe qui doit etre ds les Function1D) - /*! Returns the nature of the 1D element. */ - virtual Nature::EdgeNature getNature() const; - - /*! Returns the time stamp of the 1D element. Mainly used for selection. */ - virtual unsigned getTimeStamp() const - { - return _timeStamp; - } - - /*! Sets the time stamp for the 1D element. */ - inline void setTimeStamp(unsigned iTimeStamp) - { - _timeStamp = iTimeStamp; - } - -protected: - unsigned _timeStamp; +class Interface1D { + public: + /*! Default constructor */ + Interface1D() + { + _timeStamp = 0; + } + + /*! Destructor */ + virtual ~Interface1D(){}; + + /*! Returns the string "Interface1D". */ + virtual string getExactTypeName() const + { + return "Interface1D"; + } + + // Iterator access + + /*! Returns an iterator over the Interface1D vertices, pointing to the first vertex. */ + virtual Interface0DIterator verticesBegin(); + + /*! Returns an iterator over the Interface1D vertices, pointing after the last vertex. */ + virtual Interface0DIterator verticesEnd(); + + /*! Returns an iterator over the Interface1D points, pointing to the first point. The difference with + * verticesBegin() is that here we can iterate over points of the 1D element at a any given sampling. + * Indeed, for each iteration, a virtual point is created. + * \param t: + * The sampling with which we want to iterate over points of this 1D element. + */ + virtual Interface0DIterator pointsBegin(float t = 0.0f); + + /*! Returns an iterator over the Interface1D points, pointing after the last point. The difference with + * verticesEnd() is that here we can iterate over points of the 1D element at a any given sampling. + * Indeed, for each iteration, a virtual point is created. + * \param t: + * The sampling with which we want to iterate over points of this 1D element. + */ + virtual Interface0DIterator pointsEnd(float t = 0.0f); + + // Data access methods + + /*! Returns the 2D length of the 1D element. */ + virtual real getLength2D() const; + + /*! Returns the Id of the 1D element. */ + virtual Id getId() const; + + // FIXME: ce truc n'a rien a faire la...(c une requete complexe qui doit etre ds les Function1D) + /*! Returns the nature of the 1D element. */ + virtual Nature::EdgeNature getNature() const; + + /*! Returns the time stamp of the 1D element. Mainly used for selection. */ + virtual unsigned getTimeStamp() const + { + return _timeStamp; + } + + /*! Sets the time stamp for the 1D element. */ + inline void setTimeStamp(unsigned iTimeStamp) + { + _timeStamp = iTimeStamp; + } + + protected: + unsigned _timeStamp; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface1D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface1D") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_INTERFACE_1D_H__ +#endif // __FREESTYLE_INTERFACE_1D_H__ diff --git a/source/blender/freestyle/intern/view_map/OccluderSource.cpp b/source/blender/freestyle/intern/view_map/OccluderSource.cpp index 90393825d28..7132e0172ae 100644 --- a/source/blender/freestyle/intern/view_map/OccluderSource.cpp +++ b/source/blender/freestyle/intern/view_map/OccluderSource.cpp @@ -27,116 +27,119 @@ namespace Freestyle { -OccluderSource::OccluderSource(const GridHelpers::Transform& t, WingedEdge& we) -: wingedEdge(we), valid(false), transform(t) +OccluderSource::OccluderSource(const GridHelpers::Transform &t, WingedEdge &we) + : wingedEdge(we), valid(false), transform(t) { - begin(); + begin(); } -OccluderSource::~OccluderSource() {} +OccluderSource::~OccluderSource() +{ +} void OccluderSource::buildCachedPolygon() { - vector vertices(GridHelpers::enumerateVertices((*currentFace)->getEdgeList())); - // This doesn't work, because our functor's polymorphism won't survive the copy: - // std::transform(vertices.begin(), vertices.end(), vertices.begin(), transform); - // so we have to do: - for (vector::iterator i = vertices.begin(); i != vertices.end(); ++i) { - (*i) = transform(*i); - } - cachedPolygon = Polygon3r(vertices, transform((*currentFace)->GetNormal())); + vector vertices(GridHelpers::enumerateVertices((*currentFace)->getEdgeList())); + // This doesn't work, because our functor's polymorphism won't survive the copy: + // std::transform(vertices.begin(), vertices.end(), vertices.begin(), transform); + // so we have to do: + for (vector::iterator i = vertices.begin(); i != vertices.end(); ++i) { + (*i) = transform(*i); + } + cachedPolygon = Polygon3r(vertices, transform((*currentFace)->GetNormal())); } void OccluderSource::begin() { - vector& wshapes = wingedEdge.getWShapes(); - currentShape = wshapes.begin(); - shapesEnd = wshapes.end(); - valid = false; - if (currentShape != shapesEnd) { - vector& wFaces = (*currentShape)->GetFaceList(); - currentFace = wFaces.begin(); - facesEnd = wFaces.end(); - - if (currentFace != facesEnd) { - buildCachedPolygon(); - valid = true; - } - } + vector &wshapes = wingedEdge.getWShapes(); + currentShape = wshapes.begin(); + shapesEnd = wshapes.end(); + valid = false; + if (currentShape != shapesEnd) { + vector &wFaces = (*currentShape)->GetFaceList(); + currentFace = wFaces.begin(); + facesEnd = wFaces.end(); + + if (currentFace != facesEnd) { + buildCachedPolygon(); + valid = true; + } + } } bool OccluderSource::next() { - if (valid) { - ++currentFace; - while (currentFace == facesEnd) { - ++currentShape; - if (currentShape == shapesEnd) { - valid = false; - return false; - } - else { - vector& wFaces = (*currentShape)->GetFaceList(); - currentFace = wFaces.begin(); - facesEnd = wFaces.end(); - } - } - buildCachedPolygon(); - return true; - } - return false; + if (valid) { + ++currentFace; + while (currentFace == facesEnd) { + ++currentShape; + if (currentShape == shapesEnd) { + valid = false; + return false; + } + else { + vector &wFaces = (*currentShape)->GetFaceList(); + currentFace = wFaces.begin(); + facesEnd = wFaces.end(); + } + } + buildCachedPolygon(); + return true; + } + return false; } bool OccluderSource::isValid() { - // Or: - // return currentShapes != shapesEnd && currentFace != facesEnd; - return valid; + // Or: + // return currentShapes != shapesEnd && currentFace != facesEnd; + return valid; } WFace *OccluderSource::getWFace() { - return valid ? *currentFace : NULL; + return valid ? *currentFace : NULL; } Polygon3r OccluderSource::getCameraSpacePolygon() { - return Polygon3r(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()), (*currentFace)->GetNormal()); + return Polygon3r(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()), + (*currentFace)->GetNormal()); } -Polygon3r& OccluderSource::getGridSpacePolygon() +Polygon3r &OccluderSource::getGridSpacePolygon() { - return cachedPolygon; + return cachedPolygon; } void OccluderSource::getOccluderProscenium(real proscenium[4]) { - begin(); - const Vec3r& initialPoint = cachedPolygon.getVertices()[0]; - proscenium[0] = proscenium[1] = initialPoint[0]; - proscenium[2] = proscenium[3] = initialPoint[1]; - while (isValid()) { - GridHelpers::expandProscenium (proscenium, cachedPolygon); - next(); - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] << ", " << - proscenium[3] << ")" << endl; - } + begin(); + const Vec3r &initialPoint = cachedPolygon.getVertices()[0]; + proscenium[0] = proscenium[1] = initialPoint[0]; + proscenium[2] = proscenium[3] = initialPoint[1]; + while (isValid()) { + GridHelpers::expandProscenium(proscenium, cachedPolygon); + next(); + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2] + << ", " << proscenium[3] << ")" << endl; + } } real OccluderSource::averageOccluderArea() { - real area = 0.0; - unsigned numFaces = 0; - for (begin(); isValid(); next()) { - Vec3r min, max; - cachedPolygon.getBBox(min, max); - area += (max[0] - min[0]) * (max[1] - min[1]); - ++numFaces; - } - area /= numFaces; - return area; + real area = 0.0; + unsigned numFaces = 0; + for (begin(); isValid(); next()) { + Vec3r min, max; + cachedPolygon.getBBox(min, max); + area += (max[0] - min[0]) * (max[1] - min[1]); + ++numFaces; + } + area /= numFaces; + return area; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/OccluderSource.h b/source/blender/freestyle/intern/view_map/OccluderSource.h index fd7d9f38a0d..07df3b95347 100644 --- a/source/blender/freestyle/intern/view_map/OccluderSource.h +++ b/source/blender/freestyle/intern/view_map/OccluderSource.h @@ -27,49 +27,48 @@ #include "../winged_edge/WEdge.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class OccluderSource -{ - // Disallow copying and assignment - OccluderSource(const OccluderSource& other); - OccluderSource& operator=(const OccluderSource& other); +class OccluderSource { + // Disallow copying and assignment + OccluderSource(const OccluderSource &other); + OccluderSource &operator=(const OccluderSource &other); -public: - OccluderSource(const GridHelpers::Transform& transform, WingedEdge& we); - virtual ~OccluderSource(); + public: + OccluderSource(const GridHelpers::Transform &transform, WingedEdge &we); + virtual ~OccluderSource(); - void begin(); - virtual bool next(); - bool isValid(); + void begin(); + virtual bool next(); + bool isValid(); - WFace *getWFace(); - Polygon3r getCameraSpacePolygon(); - Polygon3r& getGridSpacePolygon(); + WFace *getWFace(); + Polygon3r getCameraSpacePolygon(); + Polygon3r &getGridSpacePolygon(); - virtual void getOccluderProscenium(real proscenium[4]); - virtual real averageOccluderArea(); + virtual void getOccluderProscenium(real proscenium[4]); + virtual real averageOccluderArea(); -protected: - WingedEdge& wingedEdge; - vector::const_iterator currentShape, shapesEnd; - vector::const_iterator currentFace, facesEnd; + protected: + WingedEdge &wingedEdge; + vector::const_iterator currentShape, shapesEnd; + vector::const_iterator currentFace, facesEnd; - bool valid; + bool valid; - Polygon3r cachedPolygon; - const GridHelpers::Transform& transform; + Polygon3r cachedPolygon; + const GridHelpers::Transform &transform; - void buildCachedPolygon(); + void buildCachedPolygon(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OccluderSource") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OccluderSource") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_OCCLUDER_SOURCE_H__ +#endif // __FREESTYLE_OCCLUDER_SOURCE_H__ diff --git a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp index 858e6b649eb..7e7f4e14882 100644 --- a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp @@ -25,90 +25,100 @@ namespace Freestyle { -Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource& source, const real proscenium[4], unsigned numFaces) -: GridDensityProvider(source), numFaces(numFaces) +Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source, + const real proscenium[4], + unsigned numFaces) + : GridDensityProvider(source), numFaces(numFaces) { - initialize (proscenium); + initialize(proscenium); } -Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform, unsigned numFaces) -: GridDensityProvider(source), numFaces(numFaces) +Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + unsigned numFaces) + : GridDensityProvider(source), numFaces(numFaces) { - real proscenium[4]; - calculateQuickProscenium(transform, bbox, proscenium); + real proscenium[4]; + calculateQuickProscenium(transform, bbox, proscenium); - initialize (proscenium); + initialize(proscenium); } -Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource& source, unsigned numFaces) -: GridDensityProvider(source), numFaces(numFaces) +Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source, unsigned numFaces) + : GridDensityProvider(source), numFaces(numFaces) { - real proscenium[4]; - calculateOptimalProscenium(source, proscenium); + real proscenium[4]; + calculateOptimalProscenium(source, proscenium); - initialize (proscenium); + initialize(proscenium); } -Pow23GridDensityProvider::~Pow23GridDensityProvider () {} +Pow23GridDensityProvider::~Pow23GridDensityProvider() +{ +} void Pow23GridDensityProvider::initialize(const real proscenium[4]) { - float prosceniumWidth = (proscenium[1] - proscenium[0]); - float prosceniumHeight = (proscenium[3] - proscenium[2]); - real cellArea = prosceniumWidth * prosceniumHeight / pow(numFaces, 2.0f / 3.0f); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea << "." << endl; - } - - _cellSize = sqrt(cellArea); - // Now we know how many cells make each side of our grid - _cellsX = ceil(prosceniumWidth / _cellSize); - _cellsY = ceil(prosceniumHeight / _cellSize); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Make sure the grid exceeds the proscenium by a small amount - float safetyZone = 0.1; - if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { - _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); - } - if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { - _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - } - - // Find grid origin - _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; - _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; + float prosceniumWidth = (proscenium[1] - proscenium[0]); + float prosceniumHeight = (proscenium[3] - proscenium[2]); + real cellArea = prosceniumWidth * prosceniumHeight / pow(numFaces, 2.0f / 3.0f); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea + << "." << endl; + } + + _cellSize = sqrt(cellArea); + // Now we know how many cells make each side of our grid + _cellsX = ceil(prosceniumWidth / _cellSize); + _cellsY = ceil(prosceniumHeight / _cellSize); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Make sure the grid exceeds the proscenium by a small amount + float safetyZone = 0.1; + if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) { + _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize); + } + if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) { + _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize); + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; + } + + // Find grid origin + _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize; + _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize; } Pow23GridDensityProviderFactory::Pow23GridDensityProviderFactory(unsigned numFaces) -: numFaces(numFaces) + : numFaces(numFaces) { } -Pow23GridDensityProviderFactory::~Pow23GridDensityProviderFactory () {} +Pow23GridDensityProviderFactory::~Pow23GridDensityProviderFactory() +{ +} -AutoPtr -Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) +AutoPtr Pow23GridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const real proscenium[4]) { - return AutoPtr(new Pow23GridDensityProvider(source, proscenium, numFaces)); + return AutoPtr(new Pow23GridDensityProvider(source, proscenium, numFaces)); } -AutoPtr -Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform) +AutoPtr Pow23GridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source, const BBox &bbox, const GridHelpers::Transform &transform) { - return AutoPtr(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); + return AutoPtr( + new Pow23GridDensityProvider(source, bbox, transform, numFaces)); } -AutoPtr Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr Pow23GridDensityProviderFactory::newGridDensityProvider( + OccluderSource &source) { - return AutoPtr(new Pow23GridDensityProvider(source, numFaces)); + return AutoPtr(new Pow23GridDensityProvider(source, numFaces)); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h index 72fc56e4ef1..52d57e3030e 100644 --- a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h @@ -26,41 +26,43 @@ namespace Freestyle { -class Pow23GridDensityProvider : public GridDensityProvider -{ - // Disallow copying and assignment - Pow23GridDensityProvider(const Pow23GridDensityProvider& other); - Pow23GridDensityProvider& operator=(const Pow23GridDensityProvider& other); +class Pow23GridDensityProvider : public GridDensityProvider { + // Disallow copying and assignment + Pow23GridDensityProvider(const Pow23GridDensityProvider &other); + Pow23GridDensityProvider &operator=(const Pow23GridDensityProvider &other); -public: - Pow23GridDensityProvider(OccluderSource& source, const real proscenium[4], unsigned numFaces); - Pow23GridDensityProvider(OccluderSource& source, const BBox& bbox, const GridHelpers::Transform& transform, - unsigned numFaces); - Pow23GridDensityProvider(OccluderSource& source, unsigned numFaces); - virtual ~Pow23GridDensityProvider(); + public: + Pow23GridDensityProvider(OccluderSource &source, const real proscenium[4], unsigned numFaces); + Pow23GridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform, + unsigned numFaces); + Pow23GridDensityProvider(OccluderSource &source, unsigned numFaces); + virtual ~Pow23GridDensityProvider(); -protected: - unsigned numFaces; + protected: + unsigned numFaces; -private: - void initialize(const real proscenium[4]); + private: + void initialize(const real proscenium[4]); }; -class Pow23GridDensityProviderFactory : public GridDensityProviderFactory -{ -public: - Pow23GridDensityProviderFactory(unsigned numFaces); - ~Pow23GridDensityProviderFactory(); +class Pow23GridDensityProviderFactory : public GridDensityProviderFactory { + public: + Pow23GridDensityProviderFactory(unsigned numFaces); + ~Pow23GridDensityProviderFactory(); - AutoPtr newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - AutoPtr newGridDensityProvider(OccluderSource& source, const BBox& bbox, - const GridHelpers::Transform& transform); - AutoPtr newGridDensityProvider(OccluderSource& source); + AutoPtr newGridDensityProvider(OccluderSource &source, + const real proscenium[4]); + AutoPtr newGridDensityProvider(OccluderSource &source, + const BBox &bbox, + const GridHelpers::Transform &transform); + AutoPtr newGridDensityProvider(OccluderSource &source); -protected: - unsigned numFaces; + protected: + unsigned numFaces; }; } /* namespace Freestyle */ -#endif // __FREESTYLE_POW_23_GRID_DENSITY_PROVIDER_H__ +#endif // __FREESTYLE_POW_23_GRID_DENSITY_PROVIDER_H__ diff --git a/source/blender/freestyle/intern/view_map/Silhouette.cpp b/source/blender/freestyle/intern/view_map/Silhouette.cpp index 7934ccf8671..73bf38107cd 100644 --- a/source/blender/freestyle/intern/view_map/Silhouette.cpp +++ b/source/blender/freestyle/intern/view_map/Silhouette.cpp @@ -34,178 +34,174 @@ namespace Freestyle { Nature::VertexNature SVertex::getNature() const { - Nature::VertexNature nature = Nature::S_VERTEX; - if (_pViewVertex) - nature |= _pViewVertex->getNature(); - return nature; + Nature::VertexNature nature = Nature::S_VERTEX; + if (_pViewVertex) + nature |= _pViewVertex->getNature(); + return nature; } SVertex *SVertex::castToSVertex() { - return this; + return this; } ViewVertex *SVertex::castToViewVertex() { - return _pViewVertex; + return _pViewVertex; } NonTVertex *SVertex::castToNonTVertex() { - return dynamic_cast(_pViewVertex); + return dynamic_cast(_pViewVertex); } TVertex *SVertex::castToTVertex() { - return dynamic_cast(_pViewVertex); + return dynamic_cast(_pViewVertex); } float SVertex::shape_importance() const { - return shape()->importance(); + return shape()->importance(); } #if 0 Material SVertex::material() const { - return _Shape->material(); + return _Shape->material(); } #endif Id SVertex::shape_id() const { - return _Shape->getId(); + return _Shape->getId(); } const SShape *SVertex::shape() const { - return _Shape; + return _Shape; } const int SVertex::qi() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->qi(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->qi(); } occluder_container::const_iterator SVertex::occluders_begin() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occluders_begin(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occluders_begin(); } occluder_container::const_iterator SVertex::occluders_end() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occluders_end(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occluders_end(); } bool SVertex::occluders_empty() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occluders_empty(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occluders_empty(); } int SVertex::occluders_size() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occluders_size(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occluders_size(); } -const Polygon3r& SVertex::occludee() const +const Polygon3r &SVertex::occludee() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occludee(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occludee(); } const SShape *SVertex::occluded_shape() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occluded_shape(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occluded_shape(); } const bool SVertex::occludee_empty() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->occludee_empty(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->occludee_empty(); } real SVertex::z_discontinuity() const { - if (getNature() & Nature::T_VERTEX) - Exception::raiseException(); - return (_FEdges[0])->z_discontinuity(); + if (getNature() & Nature::T_VERTEX) + Exception::raiseException(); + return (_FEdges[0])->z_discontinuity(); } FEdge *SVertex::fedge() { - if (getNature() & Nature::T_VERTEX) - return NULL; - return _FEdges[0]; -} - -FEdge *SVertex::getFEdge(Interface0D& inter) -{ - FEdge *result = NULL; - SVertex *iVertexB = dynamic_cast(&inter); - if (!iVertexB) - return result; - vector::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); - for (; fe != feend; ++fe) { - if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == iVertexB)) || - (((*fe)->vertexB() == this) && ((*fe)->vertexA() == iVertexB))) - { - result = (*fe); - } - } - if ((result == 0) && (getNature() & Nature::T_VERTEX)) { - SVertex *brother; - ViewVertex *vvertex = viewvertex(); - TVertex *tvertex = dynamic_cast(vvertex); - if (tvertex) { - brother = tvertex->frontSVertex(); - if (this == brother) - brother = tvertex->backSVertex(); - const vector& fedges = brother->fedges(); - for (fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) { - if ((((*fe)->vertexA() == brother) && ((*fe)->vertexB() == iVertexB)) || - (((*fe)->vertexB() == brother) && ((*fe)->vertexA() == iVertexB))) - { - result = (*fe); - } - } - } - } - if ((result == 0) && (iVertexB->getNature() & Nature::T_VERTEX)) { - SVertex *brother; - ViewVertex *vvertex = iVertexB->viewvertex(); - TVertex *tvertex = dynamic_cast(vvertex); - if (tvertex) { - brother = tvertex->frontSVertex(); - if (iVertexB == brother) - brother = tvertex->backSVertex(); - for (fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; ++fe) { - if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == brother)) || - (((*fe)->vertexB() == this) && ((*fe)->vertexA() == brother))) - { - result = (*fe); - } - } - } - } - - return result; + if (getNature() & Nature::T_VERTEX) + return NULL; + return _FEdges[0]; +} + +FEdge *SVertex::getFEdge(Interface0D &inter) +{ + FEdge *result = NULL; + SVertex *iVertexB = dynamic_cast(&inter); + if (!iVertexB) + return result; + vector::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); + for (; fe != feend; ++fe) { + if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == iVertexB)) || + (((*fe)->vertexB() == this) && ((*fe)->vertexA() == iVertexB))) { + result = (*fe); + } + } + if ((result == 0) && (getNature() & Nature::T_VERTEX)) { + SVertex *brother; + ViewVertex *vvertex = viewvertex(); + TVertex *tvertex = dynamic_cast(vvertex); + if (tvertex) { + brother = tvertex->frontSVertex(); + if (this == brother) + brother = tvertex->backSVertex(); + const vector &fedges = brother->fedges(); + for (fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) { + if ((((*fe)->vertexA() == brother) && ((*fe)->vertexB() == iVertexB)) || + (((*fe)->vertexB() == brother) && ((*fe)->vertexA() == iVertexB))) { + result = (*fe); + } + } + } + } + if ((result == 0) && (iVertexB->getNature() & Nature::T_VERTEX)) { + SVertex *brother; + ViewVertex *vvertex = iVertexB->viewvertex(); + TVertex *tvertex = dynamic_cast(vvertex); + if (tvertex) { + brother = tvertex->frontSVertex(); + if (iVertexB == brother) + brother = tvertex->backSVertex(); + for (fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; ++fe) { + if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == brother)) || + (((*fe)->vertexB() == this) && ((*fe)->vertexA() == brother))) { + result = (*fe); + } + } + } + } + + return result; } - /**********************************/ /* */ /* */ @@ -214,159 +210,158 @@ FEdge *SVertex::getFEdge(Interface0D& inter) /* */ /**********************************/ - int FEdge::viewedge_nature() const { - return _ViewEdge->getNature(); + return _ViewEdge->getNature(); } #if 0 float FEdge::viewedge_length() const { - return _ViewEdge->viewedge_length(); + return _ViewEdge->viewedge_length(); } #endif const SShape *FEdge::occluded_shape() const { - ViewShape *aShape = _ViewEdge->aShape(); - if (aShape == 0) - return 0; - return aShape->sshape(); + ViewShape *aShape = _ViewEdge->aShape(); + if (aShape == 0) + return 0; + return aShape->sshape(); } float FEdge::shape_importance() const { - return _VertexA->shape()->importance(); + return _VertexA->shape()->importance(); } int FEdge::invisibility() const { - return _ViewEdge->qi(); + return _ViewEdge->qi(); } occluder_container::const_iterator FEdge::occluders_begin() const { - return _ViewEdge->occluders_begin(); + return _ViewEdge->occluders_begin(); } occluder_container::const_iterator FEdge::occluders_end() const { - return _ViewEdge->occluders_end(); + return _ViewEdge->occluders_end(); } bool FEdge::occluders_empty() const { - return _ViewEdge->occluders_empty(); + return _ViewEdge->occluders_empty(); } int FEdge::occluders_size() const { - return _ViewEdge->occluders_size(); + return _ViewEdge->occluders_size(); } -const bool FEdge::occludee_empty() const +const bool FEdge::occludee_empty() const { - return _ViewEdge->occludee_empty(); + return _ViewEdge->occludee_empty(); } Id FEdge::shape_id() const { - return _VertexA->shape()->getId(); + return _VertexA->shape()->getId(); } const SShape *FEdge::shape() const { - return _VertexA->shape(); + return _VertexA->shape(); } real FEdge::z_discontinuity() const { - if (!(getNature() & Nature::SILHOUETTE) && !(getNature() & Nature::BORDER)) { - return 0; - } + if (!(getNature() & Nature::SILHOUETTE) && !(getNature() & Nature::BORDER)) { + return 0; + } - BBox box = ViewMap::getInstance()->getScene3dBBox(); + BBox box = ViewMap::getInstance()->getScene3dBBox(); - Vec3r bbox_size_vec(box.getMax() - box.getMin()); - real bboxsize = bbox_size_vec.norm(); - if (occludee_empty()) { - //return FLT_MAX; - return 1.0; - //return bboxsize; - } + Vec3r bbox_size_vec(box.getMax() - box.getMin()); + real bboxsize = bbox_size_vec.norm(); + if (occludee_empty()) { + //return FLT_MAX; + return 1.0; + //return bboxsize; + } #if 0 - real result; - z_discontinuity_functor _functor; - Evaluate >(&_functor, iCombination, result); + real result; + z_discontinuity_functor _functor; + Evaluate >(&_functor, iCombination, result); #endif - Vec3r middle((_VertexB->point3d() - _VertexA->point3d())); - middle /= 2; - Vec3r disc_vec(middle - _occludeeIntersection); - real res = disc_vec.norm() / bboxsize; + Vec3r middle((_VertexB->point3d() - _VertexA->point3d())); + middle /= 2; + Vec3r disc_vec(middle - _occludeeIntersection); + real res = disc_vec.norm() / bboxsize; - return res; - //return fabs((middle.z() - _occludeeIntersection.z())); + return res; + //return fabs((middle.z() - _occludeeIntersection.z())); } #if 0 float FEdge::local_average_depth(int iCombination ) const { - float result; - local_average_depth_functor functor; - Evaluate(&functor, iCombination, result); + float result; + local_average_depth_functor functor; + Evaluate(&functor, iCombination, result); - return result; + return result; } float FEdge::local_depth_variance(int iCombination ) const { - float result; + float result; - local_depth_variance_functor functor; + local_depth_variance_functor functor; - Evaluate(&functor, iCombination, result); + Evaluate(&functor, iCombination, result); - return result; + return result; } real FEdge::local_average_density( float sigma, int iCombination) const { - float result; + float result; - density_functor functor(sigma); + density_functor functor(sigma); - Evaluate(&functor, iCombination, result); + Evaluate(&functor, iCombination, result); - return result; + return result; } Vec3r FEdge::normal(int& oException /* = Exception::NO_EXCEPTION */) { - Vec3r Na = _VertexA->normal(oException); - if (oException != Exception::NO_EXCEPTION) - return Na; - Vec3r Nb = _VertexB->normal(oException); - if (oException != Exception::NO_EXCEPTION) - return Nb; - return (Na + Nb) / 2.0; + Vec3r Na = _VertexA->normal(oException); + if (oException != Exception::NO_EXCEPTION) + return Na; + Vec3r Nb = _VertexB->normal(oException); + if (oException != Exception::NO_EXCEPTION) + return Nb; + return (Na + Nb) / 2.0; } Vec3r FEdge::curvature2d_as_vector(int iCombination) const { - Vec3r result; - curvature2d_as_vector_functor _functor; - Evaluate >(&_functor, iCombination, result); - return result; + Vec3r result; + curvature2d_as_vector_functor _functor; + Evaluate >(&_functor, iCombination, result); + return result; } real FEdge::curvature2d_as_angle(int iCombination) const { - real result; - curvature2d_as_angle_functor _functor; - Evaluate >(&_functor, iCombination, result); - return result; + real result; + curvature2d_as_angle_functor _functor; + Evaluate >(&_functor, iCombination, result); + return result; } #endif @@ -381,18 +376,18 @@ real FEdge::curvature2d_as_angle(int iCombination) const #if 0 Material FEdge::material() const { - return _VertexA->shape()->material(); + return _VertexA->shape()->material(); } #endif -const FrsMaterial& FEdgeSharp::aFrsMaterial() const +const FrsMaterial &FEdgeSharp::aFrsMaterial() const { - return _VertexA->shape()->frs_material(_aFrsMaterialIndex); + return _VertexA->shape()->frs_material(_aFrsMaterialIndex); } -const FrsMaterial& FEdgeSharp::bFrsMaterial() const +const FrsMaterial &FEdgeSharp::bFrsMaterial() const { - return _VertexA->shape()->frs_material(_bFrsMaterialIndex); + return _VertexA->shape()->frs_material(_bFrsMaterialIndex); } /**********************************/ @@ -403,9 +398,9 @@ const FrsMaterial& FEdgeSharp::bFrsMaterial() const /* */ /**********************************/ -const FrsMaterial& FEdgeSmooth::frs_material() const +const FrsMaterial &FEdgeSmooth::frs_material() const { - return _VertexA->shape()->frs_material(_FrsMaterialIndex); + return _VertexA->shape()->frs_material(_FrsMaterialIndex); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/Silhouette.h b/source/blender/freestyle/intern/view_map/Silhouette.h index 8005203072d..510aedf6cbf 100644 --- a/source/blender/freestyle/intern/view_map/Silhouette.h +++ b/source/blender/freestyle/intern/view_map/Silhouette.h @@ -43,7 +43,7 @@ #include "../winged_edge/Curvature.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -53,7 +53,7 @@ namespace Freestyle { using namespace Geometry; class ViewShape; -typedef vector occluder_container; +typedef vector occluder_container; /**********************************/ /* */ @@ -68,387 +68,386 @@ class ViewVertex; class SShape; /*! Class to define a vertex of the embedding. */ -class SVertex : public Interface0D -{ -public: // Implementation of Interface0D - /*! Returns the string "SVertex" .*/ - virtual string getExactTypeName() const - { - return "SVertex"; - } - - // Data access methods - /*! Returns the 3D x coordinate of the vertex .*/ - virtual real getX() const - { - return _Point3D.x(); - } - - /*! Returns the 3D y coordinate of the vertex .*/ - virtual real getY() const - { - return _Point3D.y(); - } - - /*! Returns the 3D z coordinate of the vertex .*/ - virtual real getZ() const - { - return _Point3D.z(); - } - - /*! Returns the 3D point. */ - virtual Vec3r getPoint3D() const - { - return _Point3D; - } - - /*! Returns the projected 3D x coordinate of the vertex .*/ - virtual real getProjectedX() const - { - return _Point2D.x(); - } - - /*! Returns the projected 3D y coordinate of the vertex .*/ - virtual real getProjectedY() const - { - return _Point2D.y(); - } - - /*! Returns the projected 3D z coordinate of the vertex .*/ - virtual real getProjectedZ() const - { - return _Point2D.z(); - } - - /*! Returns the 2D point. */ - virtual Vec2r getPoint2D() const - { - return Vec2r(_Point2D.x(), _Point2D.y()); - } - - /*! Returns the FEdge that lies between this Svertex and the Interface0D given as argument. */ - virtual FEdge *getFEdge(Interface0D&); - - /*! Returns the Id of the vertex .*/ - virtual Id getId() const - { - return _Id; - } - - /*! Returns the nature of the vertex .*/ - virtual Nature::VertexNature getNature() const; - - /*! Cast the Interface0D in SVertex if it can be. */ - virtual SVertex *castToSVertex(); - - /*! Cast the Interface0D in ViewVertex if it can be. */ - virtual ViewVertex *castToViewVertex(); - - /*! Cast the Interface0D in NonTVertex if it can be. */ - virtual NonTVertex *castToNonTVertex(); - - /*! Cast the Interface0D in TVertex if it can be. */ - virtual TVertex *castToTVertex(); - -public: - typedef vector fedges_container; - -private: - Id _Id; - Vec3r _Point3D; - Vec3r _Point2D; - set _Normals; - vector _FEdges; // the edges containing this vertex - SShape *_Shape; // the shape to which belongs the vertex - ViewVertex *_pViewVertex; // The associated viewvertex, in case there is one. +class SVertex : public Interface0D { + public: // Implementation of Interface0D + /*! Returns the string "SVertex" .*/ + virtual string getExactTypeName() const + { + return "SVertex"; + } + + // Data access methods + /*! Returns the 3D x coordinate of the vertex .*/ + virtual real getX() const + { + return _Point3D.x(); + } + + /*! Returns the 3D y coordinate of the vertex .*/ + virtual real getY() const + { + return _Point3D.y(); + } + + /*! Returns the 3D z coordinate of the vertex .*/ + virtual real getZ() const + { + return _Point3D.z(); + } + + /*! Returns the 3D point. */ + virtual Vec3r getPoint3D() const + { + return _Point3D; + } + + /*! Returns the projected 3D x coordinate of the vertex .*/ + virtual real getProjectedX() const + { + return _Point2D.x(); + } + + /*! Returns the projected 3D y coordinate of the vertex .*/ + virtual real getProjectedY() const + { + return _Point2D.y(); + } + + /*! Returns the projected 3D z coordinate of the vertex .*/ + virtual real getProjectedZ() const + { + return _Point2D.z(); + } + + /*! Returns the 2D point. */ + virtual Vec2r getPoint2D() const + { + return Vec2r(_Point2D.x(), _Point2D.y()); + } + + /*! Returns the FEdge that lies between this Svertex and the Interface0D given as argument. */ + virtual FEdge *getFEdge(Interface0D &); + + /*! Returns the Id of the vertex .*/ + virtual Id getId() const + { + return _Id; + } + + /*! Returns the nature of the vertex .*/ + virtual Nature::VertexNature getNature() const; + + /*! Cast the Interface0D in SVertex if it can be. */ + virtual SVertex *castToSVertex(); + + /*! Cast the Interface0D in ViewVertex if it can be. */ + virtual ViewVertex *castToViewVertex(); + + /*! Cast the Interface0D in NonTVertex if it can be. */ + virtual NonTVertex *castToNonTVertex(); + + /*! Cast the Interface0D in TVertex if it can be. */ + virtual TVertex *castToTVertex(); + + public: + typedef vector fedges_container; + + private: + Id _Id; + Vec3r _Point3D; + Vec3r _Point2D; + set _Normals; + vector _FEdges; // the edges containing this vertex + SShape *_Shape; // the shape to which belongs the vertex + ViewVertex *_pViewVertex; // The associated viewvertex, in case there is one. #if 0 - real _curvatureFredo; - Vec2r _directionFredo; + real _curvatureFredo; + Vec2r _directionFredo; #endif - CurvatureInfo *_curvature_info; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor.*/ - inline SVertex() - { - _Id = 0; - userdata = NULL; - _Shape = NULL; - _pViewVertex = 0; - _curvature_info = 0; - } - - /*! Builds a SVertex from 3D coordinates and an Id. */ - inline SVertex(const Vec3r &iPoint3D, const Id& id) - { - _Point3D = iPoint3D; - _Id = id; - userdata = NULL; - _Shape = NULL; - _pViewVertex = 0; - _curvature_info = 0; - } - - /*! Copy constructor. */ - inline SVertex(SVertex& iBrother) - { - _Id = iBrother._Id; - _Point3D = iBrother.point3D(); - _Point2D = iBrother.point2D(); - _Normals = iBrother._Normals; - _FEdges = iBrother.fedges(); - _Shape = iBrother.shape(); - _pViewVertex = iBrother._pViewVertex; - if (!(iBrother._curvature_info)) - _curvature_info = 0; - else - _curvature_info = new CurvatureInfo(*(iBrother._curvature_info)); - iBrother.userdata = this; - userdata = 0; - } - - /*! Destructor. */ - virtual ~SVertex() - { - if (_curvature_info) - delete _curvature_info; - } - - /*! Cloning method. */ - virtual SVertex *duplicate() - { - SVertex *clone = new SVertex(*this); - return clone; - } - - /*! operator == */ - virtual bool operator==(const SVertex& iBrother) - { - return ((_Point2D == iBrother._Point2D) && (_Point3D == iBrother._Point3D)); - } - - /* accessors */ - inline const Vec3r& point3D() const - { - return _Point3D; - } - - inline const Vec3r& point2D() const - { - return _Point2D; - } - - /*! Returns the set of normals for this Vertex. - * In a smooth surface, a vertex has exactly one normal. - * In a sharp surface, a vertex can have any number of normals. - */ - inline set normals() - { - return _Normals; - } - - /*! Returns the number of different normals for this vertex. */ - inline unsigned normalsSize() const - { - return _Normals.size(); - } - - inline const vector& fedges() - { - return _FEdges; - } - - inline fedges_container::iterator fedges_begin() - { - return _FEdges.begin(); - } - - inline fedges_container::iterator fedges_end() - { - return _FEdges.end(); - } - - inline SShape *shape() - { - return _Shape; - } - - inline real z() const - { - return _Point2D[2]; - } - - /*! If this SVertex is also a ViewVertex, this method returns a pointer onto this ViewVertex. - * 0 is returned otherwise. - */ - inline ViewVertex *viewvertex() - { - return _pViewVertex; - } - - /*! modifiers */ - /*! Sets the 3D coordinates of the SVertex. */ - inline void setPoint3D(const Vec3r &iPoint3D) - { - _Point3D = iPoint3D; - } - - /*! Sets the 3D projected coordinates of the SVertex. */ - inline void setPoint2D(const Vec3r &iPoint2D) - { - _Point2D = iPoint2D; - } - - /*! Adds a normal to the Svertex's set of normals. If the same normal is already in the set, nothing changes. */ - inline void AddNormal(const Vec3r& iNormal) - { - _Normals.insert(iNormal); // if iNormal in the set already exists, nothing is done - } - - void setCurvatureInfo(CurvatureInfo *ci) - { - if (_curvature_info) // Q. is this an error condition? (T.K. 02-May-2011) - delete _curvature_info; - _curvature_info = ci; - } - - const CurvatureInfo *getCurvatureInfo() const - { - return _curvature_info; - } + CurvatureInfo *_curvature_info; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor.*/ + inline SVertex() + { + _Id = 0; + userdata = NULL; + _Shape = NULL; + _pViewVertex = 0; + _curvature_info = 0; + } + + /*! Builds a SVertex from 3D coordinates and an Id. */ + inline SVertex(const Vec3r &iPoint3D, const Id &id) + { + _Point3D = iPoint3D; + _Id = id; + userdata = NULL; + _Shape = NULL; + _pViewVertex = 0; + _curvature_info = 0; + } + + /*! Copy constructor. */ + inline SVertex(SVertex &iBrother) + { + _Id = iBrother._Id; + _Point3D = iBrother.point3D(); + _Point2D = iBrother.point2D(); + _Normals = iBrother._Normals; + _FEdges = iBrother.fedges(); + _Shape = iBrother.shape(); + _pViewVertex = iBrother._pViewVertex; + if (!(iBrother._curvature_info)) + _curvature_info = 0; + else + _curvature_info = new CurvatureInfo(*(iBrother._curvature_info)); + iBrother.userdata = this; + userdata = 0; + } + + /*! Destructor. */ + virtual ~SVertex() + { + if (_curvature_info) + delete _curvature_info; + } + + /*! Cloning method. */ + virtual SVertex *duplicate() + { + SVertex *clone = new SVertex(*this); + return clone; + } + + /*! operator == */ + virtual bool operator==(const SVertex &iBrother) + { + return ((_Point2D == iBrother._Point2D) && (_Point3D == iBrother._Point3D)); + } + + /* accessors */ + inline const Vec3r &point3D() const + { + return _Point3D; + } + + inline const Vec3r &point2D() const + { + return _Point2D; + } + + /*! Returns the set of normals for this Vertex. + * In a smooth surface, a vertex has exactly one normal. + * In a sharp surface, a vertex can have any number of normals. + */ + inline set normals() + { + return _Normals; + } + + /*! Returns the number of different normals for this vertex. */ + inline unsigned normalsSize() const + { + return _Normals.size(); + } + + inline const vector &fedges() + { + return _FEdges; + } + + inline fedges_container::iterator fedges_begin() + { + return _FEdges.begin(); + } + + inline fedges_container::iterator fedges_end() + { + return _FEdges.end(); + } + + inline SShape *shape() + { + return _Shape; + } + + inline real z() const + { + return _Point2D[2]; + } + + /*! If this SVertex is also a ViewVertex, this method returns a pointer onto this ViewVertex. + * 0 is returned otherwise. + */ + inline ViewVertex *viewvertex() + { + return _pViewVertex; + } + + /*! modifiers */ + /*! Sets the 3D coordinates of the SVertex. */ + inline void setPoint3D(const Vec3r &iPoint3D) + { + _Point3D = iPoint3D; + } + + /*! Sets the 3D projected coordinates of the SVertex. */ + inline void setPoint2D(const Vec3r &iPoint2D) + { + _Point2D = iPoint2D; + } + + /*! Adds a normal to the Svertex's set of normals. If the same normal is already in the set, nothing changes. */ + inline void AddNormal(const Vec3r &iNormal) + { + _Normals.insert(iNormal); // if iNormal in the set already exists, nothing is done + } + + void setCurvatureInfo(CurvatureInfo *ci) + { + if (_curvature_info) // Q. is this an error condition? (T.K. 02-May-2011) + delete _curvature_info; + _curvature_info = ci; + } + + const CurvatureInfo *getCurvatureInfo() const + { + return _curvature_info; + } #if 0 - /* Fredo's normal and curvature*/ - void setCurvatureFredo(real c) - { - _curvatureFredo = c; - } - - void setDirectionFredo(Vec2r d) - { - _directionFredo = d; - } - - real curvatureFredo () - { - return _curvatureFredo; - } - - const Vec2r directionFredo () - { - return _directionFredo; - } + /* Fredo's normal and curvature*/ + void setCurvatureFredo(real c) + { + _curvatureFredo = c; + } + + void setDirectionFredo(Vec2r d) + { + _directionFredo = d; + } + + real curvatureFredo () + { + return _curvatureFredo; + } + + const Vec2r directionFredo () + { + return _directionFredo; + } #endif - /*! Sets the Id */ - inline void setId(const Id& id) - { - _Id = id; - } - - inline void setFEdges(const vector& iFEdges) - { - _FEdges = iFEdges; - } - - inline void setShape(SShape *iShape) - { - _Shape = iShape; - } - - inline void setViewVertex(ViewVertex *iViewVertex) - { - _pViewVertex = iViewVertex; - } - - /*! Add an FEdge to the list of edges emanating from this SVertex. */ - inline void AddFEdge(FEdge *iFEdge) - { - _FEdges.push_back(iFEdge); - } - - /*! Remove an FEdge from the list of edges emanating from this SVertex. */ - inline void RemoveFEdge(FEdge *iFEdge) - { - for (vector::iterator fe = _FEdges.begin(), fend = _FEdges.end(); fe != fend; fe++) { - if (iFEdge == (*fe)) { - _FEdges.erase(fe); - break; - } - } - } - - /* replaces edge 1 by edge 2 in the list of edges */ - inline void Replace(FEdge *e1, FEdge *e2) - { - vector::iterator insertedfe; - for (vector::iterator fe = _FEdges.begin(), fend = _FEdges.end(); fe != fend; fe++) { - if ((*fe) == e1) { - insertedfe = _FEdges.insert(fe, e2);// inserts e2 before fe. - // returns an iterator pointing toward e2. fe is invalidated. - // we want to remove e1, but we can't use fe anymore: - ++insertedfe; // insertedfe points now to e1 - _FEdges.erase(insertedfe); - return; - } - } - } - -public: - /* Information access interface */ - FEdge *fedge(); // for non T vertex - - inline const Vec3r& point2d() const - { - return point2D(); - } - - inline const Vec3r& point3d() const - { - return point3D(); - } - - inline Vec3r normal() const - { - if (_Normals.size() == 1) - return (*(_Normals.begin())); - Exception::raiseException(); - return *(_Normals.begin()); - } - - //Material material() const ; - Id shape_id() const; - const SShape *shape() const; - float shape_importance() const; - - const int qi() const; - occluder_container::const_iterator occluders_begin() const; - occluder_container::const_iterator occluders_end() const; - bool occluders_empty() const; - int occluders_size() const; - const Polygon3r& occludee() const; - const SShape *occluded_shape() const; - const bool occludee_empty() const; - real z_discontinuity() const; + /*! Sets the Id */ + inline void setId(const Id &id) + { + _Id = id; + } + + inline void setFEdges(const vector &iFEdges) + { + _FEdges = iFEdges; + } + + inline void setShape(SShape *iShape) + { + _Shape = iShape; + } + + inline void setViewVertex(ViewVertex *iViewVertex) + { + _pViewVertex = iViewVertex; + } + + /*! Add an FEdge to the list of edges emanating from this SVertex. */ + inline void AddFEdge(FEdge *iFEdge) + { + _FEdges.push_back(iFEdge); + } + + /*! Remove an FEdge from the list of edges emanating from this SVertex. */ + inline void RemoveFEdge(FEdge *iFEdge) + { + for (vector::iterator fe = _FEdges.begin(), fend = _FEdges.end(); fe != fend; fe++) { + if (iFEdge == (*fe)) { + _FEdges.erase(fe); + break; + } + } + } + + /* replaces edge 1 by edge 2 in the list of edges */ + inline void Replace(FEdge *e1, FEdge *e2) + { + vector::iterator insertedfe; + for (vector::iterator fe = _FEdges.begin(), fend = _FEdges.end(); fe != fend; fe++) { + if ((*fe) == e1) { + insertedfe = _FEdges.insert(fe, e2); // inserts e2 before fe. + // returns an iterator pointing toward e2. fe is invalidated. + // we want to remove e1, but we can't use fe anymore: + ++insertedfe; // insertedfe points now to e1 + _FEdges.erase(insertedfe); + return; + } + } + } + + public: + /* Information access interface */ + FEdge *fedge(); // for non T vertex + + inline const Vec3r &point2d() const + { + return point2D(); + } + + inline const Vec3r &point3d() const + { + return point3D(); + } + + inline Vec3r normal() const + { + if (_Normals.size() == 1) + return (*(_Normals.begin())); + Exception::raiseException(); + return *(_Normals.begin()); + } + + //Material material() const ; + Id shape_id() const; + const SShape *shape() const; + float shape_importance() const; + + const int qi() const; + occluder_container::const_iterator occluders_begin() const; + occluder_container::const_iterator occluders_end() const; + bool occluders_empty() const; + int occluders_size() const; + const Polygon3r &occludee() const; + const SShape *occluded_shape() const; + const bool occludee_empty() const; + real z_discontinuity() const; #if 0 - inline float local_average_depth() const; - inline float local_depth_variance() const; - inline real local_average_density(float sigma = 2.3f) const; - inline Vec3r shaded_color() const; - inline Vec3r orientation2d() const; - inline Vec3r orientation3d() const; - inline Vec3r curvature2d_as_vector() const; - /*! angle in radians */ - inline real curvature2d_as_angle() const; + inline float local_average_depth() const; + inline float local_depth_variance() const; + inline real local_average_density(float sigma = 2.3f) const; + inline Vec3r shaded_color() const; + inline Vec3r orientation2d() const; + inline Vec3r orientation3d() const; + inline Vec3r curvature2d_as_vector() const; + /*! angle in radians */ + inline real curvature2d_as_angle() const; #endif #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertex") #endif }; @@ -471,493 +470,494 @@ class ViewEdge; * This class is specialized into a smooth and a sharp version since their properties slightly vary from * one to the other. */ -class FEdge : public Interface1D -{ -public: // Implementation of Interface0D - /*! Returns the string "FEdge". */ - virtual string getExactTypeName() const - { - return "FEdge"; - } - - // Data access methods - - /*! Returns the 2D length of the FEdge. */ - virtual real getLength2D() const - { - if (!_VertexA || !_VertexB) - return 0; - return (_VertexB->getPoint2D() - _VertexA->getPoint2D()).norm(); - } - - /*! Returns the Id of the FEdge. */ - virtual Id getId() const - { - return _Id; - } - -public: - // An edge can only be of one kind (SILHOUETTE or BORDER, etc...) - // For an multi-nature edge there must be several different FEdge. - // DEBUG: - // Vec3r A; - // Vec3r u; - // vector _Occludees; - // Vec3r intersection; - // vector _Cells; - -protected: - SVertex *_VertexA; - SVertex *_VertexB; - Id _Id; - Nature::EdgeNature _Nature; - //vector _Occluders; // visibility // NOT HANDLED BY THE COPY CONSTRUCTOR!! - - FEdge *_NextEdge; // next edge on the chain - FEdge *_PreviousEdge; - ViewEdge *_ViewEdge; - // Sometimes we need to deport the visibility computation onto another edge. For example the exact edges use - // edges of the mesh to compute their visibility - - Polygon3r _aFace; // The occluded face which lies on the right of a silhouette edge - Vec3r _occludeeIntersection; - bool _occludeeEmpty; - - bool _isSmooth; - - bool _isInImage; - - bool _isTemporary; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor */ - inline FEdge() - { - userdata = NULL; - _VertexA = NULL; - _VertexB = NULL; - _Nature = Nature::NO_FEATURE; - _NextEdge = NULL; - _PreviousEdge = NULL; - _ViewEdge = NULL; - //_hasVisibilityPoint = false; - _occludeeEmpty = true; - _isSmooth = false; - _isInImage = true; - _isTemporary = false; - } - - /*! Builds an FEdge going from vA to vB. */ - inline FEdge(SVertex *vA, SVertex *vB) - { - userdata = NULL; - _VertexA = vA; - _VertexB = vB; - _Nature = Nature::NO_FEATURE; - _NextEdge = NULL; - _PreviousEdge = NULL; - _ViewEdge = NULL; - //_hasVisibilityPoint = false; - _occludeeEmpty = true; - _isSmooth = false; - _isInImage = true; - _isTemporary = false; - } - - /*! Copy constructor */ - inline FEdge(FEdge& iBrother) - { - _VertexA = iBrother.vertexA(); - _VertexB = iBrother.vertexB(); - _NextEdge = iBrother.nextEdge(); - _PreviousEdge = iBrother._PreviousEdge; - _Nature = iBrother.getNature(); - _Id = iBrother._Id; - _ViewEdge = iBrother._ViewEdge; - //_hasVisibilityPoint = iBrother._hasVisibilityPoint; - //_VisibilityPointA = iBrother._VisibilityPointA; - //_VisibilityPointB = iBrother._VisibilityPointB; - _aFace = iBrother._aFace; - _occludeeEmpty = iBrother._occludeeEmpty; - _isSmooth = iBrother._isSmooth; - _isInImage = iBrother._isInImage; - _isTemporary = iBrother._isTemporary; - iBrother.userdata = this; - userdata = 0; - } - - /*! Destructor */ - virtual ~FEdge() {} - - /*! Cloning method. */ - virtual FEdge *duplicate() - { - FEdge *clone = new FEdge(*this); - return clone; - } - - /* accessors */ - /*! Returns the first SVertex. */ - inline SVertex *vertexA() - { - return _VertexA; - } - - /*! Returns the second SVertex. */ - inline SVertex *vertexB() - { - return _VertexB; - } - - /*! Returns the first SVertex if i=0, the seccond SVertex if i=1. */ - inline SVertex *operator[](const unsigned short int& i) const - { - return (i % 2 == 0) ? _VertexA : _VertexB; - } - - /*! Returns the nature of the FEdge. */ - inline Nature::EdgeNature getNature() const - { - return _Nature; - } - - /*! Returns the FEdge following this one in the ViewEdge. - * If this FEdge is the last of the ViewEdge, 0 is returned. - */ - inline FEdge *nextEdge() - { - return _NextEdge; - } - - /*! Returns the Edge preceding this one in the ViewEdge. - * If this FEdge is the first one of the ViewEdge, 0 is returned. - */ - inline FEdge *previousEdge() - { - return _PreviousEdge; - } - - inline SShape *shape() - { - return _VertexA->shape(); - } +class FEdge : public Interface1D { + public: // Implementation of Interface0D + /*! Returns the string "FEdge". */ + virtual string getExactTypeName() const + { + return "FEdge"; + } + + // Data access methods + + /*! Returns the 2D length of the FEdge. */ + virtual real getLength2D() const + { + if (!_VertexA || !_VertexB) + return 0; + return (_VertexB->getPoint2D() - _VertexA->getPoint2D()).norm(); + } + + /*! Returns the Id of the FEdge. */ + virtual Id getId() const + { + return _Id; + } + + public: + // An edge can only be of one kind (SILHOUETTE or BORDER, etc...) + // For an multi-nature edge there must be several different FEdge. + // DEBUG: + // Vec3r A; + // Vec3r u; + // vector _Occludees; + // Vec3r intersection; + // vector _Cells; + + protected: + SVertex *_VertexA; + SVertex *_VertexB; + Id _Id; + Nature::EdgeNature _Nature; + //vector _Occluders; // visibility // NOT HANDLED BY THE COPY CONSTRUCTOR!! + + FEdge *_NextEdge; // next edge on the chain + FEdge *_PreviousEdge; + ViewEdge *_ViewEdge; + // Sometimes we need to deport the visibility computation onto another edge. For example the exact edges use + // edges of the mesh to compute their visibility + + Polygon3r _aFace; // The occluded face which lies on the right of a silhouette edge + Vec3r _occludeeIntersection; + bool _occludeeEmpty; + + bool _isSmooth; + + bool _isInImage; + + bool _isTemporary; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor */ + inline FEdge() + { + userdata = NULL; + _VertexA = NULL; + _VertexB = NULL; + _Nature = Nature::NO_FEATURE; + _NextEdge = NULL; + _PreviousEdge = NULL; + _ViewEdge = NULL; + //_hasVisibilityPoint = false; + _occludeeEmpty = true; + _isSmooth = false; + _isInImage = true; + _isTemporary = false; + } + + /*! Builds an FEdge going from vA to vB. */ + inline FEdge(SVertex *vA, SVertex *vB) + { + userdata = NULL; + _VertexA = vA; + _VertexB = vB; + _Nature = Nature::NO_FEATURE; + _NextEdge = NULL; + _PreviousEdge = NULL; + _ViewEdge = NULL; + //_hasVisibilityPoint = false; + _occludeeEmpty = true; + _isSmooth = false; + _isInImage = true; + _isTemporary = false; + } + + /*! Copy constructor */ + inline FEdge(FEdge &iBrother) + { + _VertexA = iBrother.vertexA(); + _VertexB = iBrother.vertexB(); + _NextEdge = iBrother.nextEdge(); + _PreviousEdge = iBrother._PreviousEdge; + _Nature = iBrother.getNature(); + _Id = iBrother._Id; + _ViewEdge = iBrother._ViewEdge; + //_hasVisibilityPoint = iBrother._hasVisibilityPoint; + //_VisibilityPointA = iBrother._VisibilityPointA; + //_VisibilityPointB = iBrother._VisibilityPointB; + _aFace = iBrother._aFace; + _occludeeEmpty = iBrother._occludeeEmpty; + _isSmooth = iBrother._isSmooth; + _isInImage = iBrother._isInImage; + _isTemporary = iBrother._isTemporary; + iBrother.userdata = this; + userdata = 0; + } + + /*! Destructor */ + virtual ~FEdge() + { + } + + /*! Cloning method. */ + virtual FEdge *duplicate() + { + FEdge *clone = new FEdge(*this); + return clone; + } + + /* accessors */ + /*! Returns the first SVertex. */ + inline SVertex *vertexA() + { + return _VertexA; + } + + /*! Returns the second SVertex. */ + inline SVertex *vertexB() + { + return _VertexB; + } + + /*! Returns the first SVertex if i=0, the seccond SVertex if i=1. */ + inline SVertex *operator[](const unsigned short int &i) const + { + return (i % 2 == 0) ? _VertexA : _VertexB; + } + + /*! Returns the nature of the FEdge. */ + inline Nature::EdgeNature getNature() const + { + return _Nature; + } + + /*! Returns the FEdge following this one in the ViewEdge. + * If this FEdge is the last of the ViewEdge, 0 is returned. + */ + inline FEdge *nextEdge() + { + return _NextEdge; + } + + /*! Returns the Edge preceding this one in the ViewEdge. + * If this FEdge is the first one of the ViewEdge, 0 is returned. + */ + inline FEdge *previousEdge() + { + return _PreviousEdge; + } + + inline SShape *shape() + { + return _VertexA->shape(); + } #if 0 - inline int invisibility() const - { - return _Occluders.size(); - } + inline int invisibility() const + { + return _Occluders.size(); + } #endif - int invisibility() const; + int invisibility() const; #if 0 - inline const vector& occluders() const - { - return _Occluders; - } + inline const vector& occluders() const + { + return _Occluders; + } #endif - /*! Returns a pointer to the ViewEdge to which this FEdge belongs to. */ - inline ViewEdge *viewedge() const - { - return _ViewEdge; - } + /*! Returns a pointer to the ViewEdge to which this FEdge belongs to. */ + inline ViewEdge *viewedge() const + { + return _ViewEdge; + } - inline Vec3r center3d() - { - return Vec3r((_VertexA->point3D() + _VertexB->point3D()) / 2.0); - } + inline Vec3r center3d() + { + return Vec3r((_VertexA->point3D() + _VertexB->point3D()) / 2.0); + } - inline Vec3r center2d() - { - return Vec3r((_VertexA->point2D() + _VertexB->point2D()) / 2.0); - } + inline Vec3r center2d() + { + return Vec3r((_VertexA->point2D() + _VertexB->point2D()) / 2.0); + } #if 0 - inline bool hasVisibilityPoint() const - { - return _hasVisibilityPoint; - } - - inline Vec3r visibilityPointA() const - { - return _VisibilityPointA; - } - - inline Vec3r visibilityPointB() const - { - return _VisibilityPointB; - } + inline bool hasVisibilityPoint() const + { + return _hasVisibilityPoint; + } + + inline Vec3r visibilityPointA() const + { + return _VisibilityPointA; + } + + inline Vec3r visibilityPointB() const + { + return _VisibilityPointB; + } #endif - inline const Polygon3r& aFace() const - { - return _aFace; - } - - inline const Vec3r& getOccludeeIntersection() - { - return _occludeeIntersection; - } - - inline bool getOccludeeEmpty() - { - return _occludeeEmpty; - } - - /*! Returns true if this FEdge is a smooth FEdge. */ - inline bool isSmooth() const - { - return _isSmooth; - } - - inline bool isInImage () const - { - return _isInImage; - } - - inline bool isTemporary() const - { - return _isTemporary; - } - - /* modifiers */ - /*! Sets the first SVertex. */ - inline void setVertexA(SVertex *vA) - { - _VertexA = vA; - } - - /*! Sets the second SVertex. */ - inline void setVertexB(SVertex *vB) - { - _VertexB = vB; - } - - /*! Sets the FEdge Id . */ - inline void setId(const Id& id) - { - _Id = id; - } - - /*! Sets the pointer to the next FEdge. */ - inline void setNextEdge(FEdge *iEdge) - { - _NextEdge = iEdge; - } - - /*! Sets the pointer to the previous FEdge. */ - inline void setPreviousEdge(FEdge *iEdge) - { - _PreviousEdge = iEdge; - } - - /*! Sets the nature of this FEdge. */ - inline void setNature(Nature::EdgeNature iNature) - { - _Nature = iNature; - } + inline const Polygon3r &aFace() const + { + return _aFace; + } + + inline const Vec3r &getOccludeeIntersection() + { + return _occludeeIntersection; + } + + inline bool getOccludeeEmpty() + { + return _occludeeEmpty; + } + + /*! Returns true if this FEdge is a smooth FEdge. */ + inline bool isSmooth() const + { + return _isSmooth; + } + + inline bool isInImage() const + { + return _isInImage; + } + + inline bool isTemporary() const + { + return _isTemporary; + } + + /* modifiers */ + /*! Sets the first SVertex. */ + inline void setVertexA(SVertex *vA) + { + _VertexA = vA; + } + + /*! Sets the second SVertex. */ + inline void setVertexB(SVertex *vB) + { + _VertexB = vB; + } + + /*! Sets the FEdge Id . */ + inline void setId(const Id &id) + { + _Id = id; + } + + /*! Sets the pointer to the next FEdge. */ + inline void setNextEdge(FEdge *iEdge) + { + _NextEdge = iEdge; + } + + /*! Sets the pointer to the previous FEdge. */ + inline void setPreviousEdge(FEdge *iEdge) + { + _PreviousEdge = iEdge; + } + + /*! Sets the nature of this FEdge. */ + inline void setNature(Nature::EdgeNature iNature) + { + _Nature = iNature; + } #if 0 - inline void AddOccluder(Polygon3r& iPolygon) - { - _Occluders.push_back(iPolygon); - } + inline void AddOccluder(Polygon3r& iPolygon) + { + _Occluders.push_back(iPolygon); + } #endif - /*! Sets the ViewEdge to which this FEdge belongs to. */ - inline void setViewEdge(ViewEdge *iViewEdge) - { - _ViewEdge = iViewEdge; - } + /*! Sets the ViewEdge to which this FEdge belongs to. */ + inline void setViewEdge(ViewEdge *iViewEdge) + { + _ViewEdge = iViewEdge; + } #if 0 - inline void setHasVisibilityPoint(bool iBool) - { - _hasVisibilityPoint = iBool; - } - - inline void setVisibilityPointA(const Vec3r& iPoint) - { - _VisibilityPointA = iPoint; - } - - inline void setVisibilityPointB(const Vec3r& iPoint) - { - _VisibilityPointB = iPoint; - } + inline void setHasVisibilityPoint(bool iBool) + { + _hasVisibilityPoint = iBool; + } + + inline void setVisibilityPointA(const Vec3r& iPoint) + { + _VisibilityPointA = iPoint; + } + + inline void setVisibilityPointB(const Vec3r& iPoint) + { + _VisibilityPointB = iPoint; + } #endif - inline void setaFace(Polygon3r& iFace) - { - _aFace = iFace; - } - - inline void setOccludeeIntersection(const Vec3r& iPoint) - { - _occludeeIntersection = iPoint; - } - - inline void setOccludeeEmpty(bool iempty) - { - _occludeeEmpty = iempty; - } - - /*! Sets the flag telling whether this FEdge is smooth or sharp. - * true for Smooth, false for Sharp. - */ - inline void setSmooth(bool iFlag) - { - _isSmooth = iFlag; - } - - inline void setIsInImage (bool iFlag) - { - _isInImage = iFlag; - } - - inline void setTemporary(bool iFlag) - { - _isTemporary = iFlag; - } - - /* checks whether two FEdge have a common vertex. - * Returns a pointer on the common vertex if it exists, NULL otherwise. - */ - static inline SVertex *CommonVertex(FEdge *iEdge1, FEdge *iEdge2) - { - if ((NULL == iEdge1) || (NULL == iEdge2)) - return NULL; - - SVertex *sv1 = iEdge1->vertexA(); - SVertex *sv2 = iEdge1->vertexB(); - SVertex *sv3 = iEdge2->vertexA(); - SVertex *sv4 = iEdge2->vertexB(); - - if ((sv1 == sv3) || (sv1 == sv4)) { - return sv1; - } - else if ((sv2 == sv3) || (sv2 == sv4)) { - return sv2; - } - - return NULL; - } - - inline const SVertex *min2d() const - { - if (_VertexA->point2D() < _VertexB->point2D()) - return _VertexA; - else - return _VertexB; - } - - inline const SVertex *max2d() const - { - if (_VertexA->point2D() < _VertexB->point2D()) - return _VertexB; - else - return _VertexA; - } - - /* Information access interface */ - - //Material material() const; - Id shape_id() const; - const SShape *shape() const; - float shape_importance() const; - - inline const int qi() const - { - return invisibility(); - } - - occluder_container::const_iterator occluders_begin() const; - occluder_container::const_iterator occluders_end() const; - bool occluders_empty() const; - int occluders_size() const; - - inline const Polygon3r& occludee() const - { - return aFace(); - } - - const SShape *occluded_shape() const; + inline void setaFace(Polygon3r &iFace) + { + _aFace = iFace; + } + + inline void setOccludeeIntersection(const Vec3r &iPoint) + { + _occludeeIntersection = iPoint; + } + + inline void setOccludeeEmpty(bool iempty) + { + _occludeeEmpty = iempty; + } + + /*! Sets the flag telling whether this FEdge is smooth or sharp. + * true for Smooth, false for Sharp. + */ + inline void setSmooth(bool iFlag) + { + _isSmooth = iFlag; + } + + inline void setIsInImage(bool iFlag) + { + _isInImage = iFlag; + } + + inline void setTemporary(bool iFlag) + { + _isTemporary = iFlag; + } + + /* checks whether two FEdge have a common vertex. + * Returns a pointer on the common vertex if it exists, NULL otherwise. + */ + static inline SVertex *CommonVertex(FEdge *iEdge1, FEdge *iEdge2) + { + if ((NULL == iEdge1) || (NULL == iEdge2)) + return NULL; + + SVertex *sv1 = iEdge1->vertexA(); + SVertex *sv2 = iEdge1->vertexB(); + SVertex *sv3 = iEdge2->vertexA(); + SVertex *sv4 = iEdge2->vertexB(); + + if ((sv1 == sv3) || (sv1 == sv4)) { + return sv1; + } + else if ((sv2 == sv3) || (sv2 == sv4)) { + return sv2; + } + + return NULL; + } + + inline const SVertex *min2d() const + { + if (_VertexA->point2D() < _VertexB->point2D()) + return _VertexA; + else + return _VertexB; + } + + inline const SVertex *max2d() const + { + if (_VertexA->point2D() < _VertexB->point2D()) + return _VertexB; + else + return _VertexA; + } + + /* Information access interface */ + + //Material material() const; + Id shape_id() const; + const SShape *shape() const; + float shape_importance() const; + + inline const int qi() const + { + return invisibility(); + } + + occluder_container::const_iterator occluders_begin() const; + occluder_container::const_iterator occluders_end() const; + bool occluders_empty() const; + int occluders_size() const; + + inline const Polygon3r &occludee() const + { + return aFace(); + } + + const SShape *occluded_shape() const; #if 0 - inline const bool occludee_empty() const - { - return _occludeeEmpty; - } + inline const bool occludee_empty() const + { + return _occludeeEmpty; + } #endif - const bool occludee_empty() const; - real z_discontinuity() const; + const bool occludee_empty() const; + real z_discontinuity() const; #if 0 - inline float local_average_depth(int iCombination = 0) const; - inline float local_depth_variance(int iCombination = 0) const; - inline real local_average_density(float sigma = 2.3f, int iCombination = 0) const; - inline Vec3r shaded_color(int iCombination = 0) const {} + inline float local_average_depth(int iCombination = 0) const; + inline float local_depth_variance(int iCombination = 0) const; + inline real local_average_density(float sigma = 2.3f, int iCombination = 0) const; + inline Vec3r shaded_color(int iCombination = 0) const {} #endif - int viewedge_nature() const; + int viewedge_nature() const; - //float viewedge_length() const; + //float viewedge_length() const; - inline Vec3r orientation2d() const - { - return Vec3r(_VertexB->point2d() - _VertexA->point2d()); - } + inline Vec3r orientation2d() const + { + return Vec3r(_VertexB->point2d() - _VertexA->point2d()); + } - inline Vec3r orientation3d() const - { - return Vec3r(_VertexB->point3d() - _VertexA->point3d()); - } + inline Vec3r orientation3d() const + { + return Vec3r(_VertexB->point3d() - _VertexA->point3d()); + } #if 0 - inline real curvature2d() const - { - return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); - } + inline real curvature2d() const + { + return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0); + } - inline Vec3r curvature2d_as_vector(int iCombination = 0) const; + inline Vec3r curvature2d_as_vector(int iCombination = 0) const; - /* angle in degrees*/ - inline real curvature2d_as_angle(int iCombination = 0) const; + /* angle in degrees*/ + inline real curvature2d_as_angle(int iCombination = 0) const; #endif - // Iterator access (Interface1D) - /*! Returns an iterator over the 2 (!) SVertex pointing to the first SVertex. */ - virtual inline Interface0DIterator verticesBegin(); - - /*! Returns an iterator over the 2 (!) SVertex pointing after the last SVertex. */ - virtual inline Interface0DIterator verticesEnd(); - - /*! Returns an iterator over the FEdge points, pointing to the first point. The difference with verticesBegin() - * is that here we can iterate over points of the FEdge at a any given sampling. - * Indeed, for each iteration, a virtual point is created. - * \param t: - * The sampling with which we want to iterate over points of this FEdge. - */ - virtual inline Interface0DIterator pointsBegin(float t = 0.0f); - - /*! Returns an iterator over the FEdge points, pointing after the last point. The difference with verticesEnd() - * is that here we can iterate over points of the FEdge at a any given sampling. - * Indeed, for each iteration, a virtual point is created. - * \param t: - * The sampling with which we want to iterate over points of this FEdge. - */ - virtual inline Interface0DIterator pointsEnd(float t = 0.0f); + // Iterator access (Interface1D) + /*! Returns an iterator over the 2 (!) SVertex pointing to the first SVertex. */ + virtual inline Interface0DIterator verticesBegin(); + + /*! Returns an iterator over the 2 (!) SVertex pointing after the last SVertex. */ + virtual inline Interface0DIterator verticesEnd(); + + /*! Returns an iterator over the FEdge points, pointing to the first point. The difference with verticesBegin() + * is that here we can iterate over points of the FEdge at a any given sampling. + * Indeed, for each iteration, a virtual point is created. + * \param t: + * The sampling with which we want to iterate over points of this FEdge. + */ + virtual inline Interface0DIterator pointsBegin(float t = 0.0f); + + /*! Returns an iterator over the FEdge points, pointing after the last point. The difference with verticesEnd() + * is that here we can iterate over points of the FEdge at a any given sampling. + * Indeed, for each iteration, a virtual point is created. + * \param t: + * The sampling with which we want to iterate over points of this FEdge. + */ + virtual inline Interface0DIterator pointsEnd(float t = 0.0f); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdge") #endif }; @@ -968,162 +968,161 @@ public: namespace FEdgeInternal { -class SVertexIterator : public Interface0DIteratorNested -{ -public: - SVertexIterator() - { - _vertex = NULL; - _edge = NULL; - } - - SVertexIterator(const SVertexIterator& vi) - { - _vertex = vi._vertex; - _edge = vi._edge; - } - - SVertexIterator(SVertex *v, FEdge *edge) - { - _vertex = v; - _edge = edge; - } - - SVertexIterator& operator=(const SVertexIterator& vi) - { - _vertex = vi._vertex; - _edge = vi._edge; - return *this; - } - - virtual string getExactTypeName() const - { - return "SVertexIterator"; - } - - virtual SVertex& operator*() - { - return *_vertex; - } - - virtual SVertex *operator->() - { - return &(operator*()); - } - - virtual SVertexIterator& operator++() - { - increment(); - return *this; - } - - virtual SVertexIterator operator++(int) - { - SVertexIterator ret(*this); - increment(); - return ret; - } - - virtual SVertexIterator& operator--() - { - decrement(); - return *this; - } - - virtual SVertexIterator operator--(int) - { - SVertexIterator ret(*this); - decrement(); - return ret; - } - - virtual int increment() - { - if (_vertex == _edge->vertexB()) { - _vertex = 0; - return 0; - } - _vertex = _edge->vertexB(); - return 0; - } - - virtual int decrement() - { - if (_vertex == _edge->vertexA()) { - _vertex = 0; - return 0; - } - _vertex = _edge->vertexA(); - return 0; - } - - virtual bool isBegin() const - { - return _vertex == _edge->vertexA(); - } - - virtual bool isEnd() const - { - return _vertex == _edge->vertexB(); - } - - virtual bool operator==(const Interface0DIteratorNested& it) const - { - const SVertexIterator *it_exact = dynamic_cast(&it); - if (!it_exact) - return false; - return ((_vertex == it_exact->_vertex) && (_edge == it_exact->_edge)); - } - - virtual float t() const - { - if (_vertex == _edge->vertexA()) { - return 0.0f; - } - return ((float)_edge->getLength2D()); - } - virtual float u() const - { - if (_vertex == _edge->vertexA()) { - return 0.0f; - } - return 1.0f; - } - - virtual SVertexIterator *copy() const - { - return new SVertexIterator(*this); - } - -private: - SVertex *_vertex; - FEdge *_edge; +class SVertexIterator : public Interface0DIteratorNested { + public: + SVertexIterator() + { + _vertex = NULL; + _edge = NULL; + } + + SVertexIterator(const SVertexIterator &vi) + { + _vertex = vi._vertex; + _edge = vi._edge; + } + + SVertexIterator(SVertex *v, FEdge *edge) + { + _vertex = v; + _edge = edge; + } + + SVertexIterator &operator=(const SVertexIterator &vi) + { + _vertex = vi._vertex; + _edge = vi._edge; + return *this; + } + + virtual string getExactTypeName() const + { + return "SVertexIterator"; + } + + virtual SVertex &operator*() + { + return *_vertex; + } + + virtual SVertex *operator->() + { + return &(operator*()); + } + + virtual SVertexIterator &operator++() + { + increment(); + return *this; + } + + virtual SVertexIterator operator++(int) + { + SVertexIterator ret(*this); + increment(); + return ret; + } + + virtual SVertexIterator &operator--() + { + decrement(); + return *this; + } + + virtual SVertexIterator operator--(int) + { + SVertexIterator ret(*this); + decrement(); + return ret; + } + + virtual int increment() + { + if (_vertex == _edge->vertexB()) { + _vertex = 0; + return 0; + } + _vertex = _edge->vertexB(); + return 0; + } + + virtual int decrement() + { + if (_vertex == _edge->vertexA()) { + _vertex = 0; + return 0; + } + _vertex = _edge->vertexA(); + return 0; + } + + virtual bool isBegin() const + { + return _vertex == _edge->vertexA(); + } + + virtual bool isEnd() const + { + return _vertex == _edge->vertexB(); + } + + virtual bool operator==(const Interface0DIteratorNested &it) const + { + const SVertexIterator *it_exact = dynamic_cast(&it); + if (!it_exact) + return false; + return ((_vertex == it_exact->_vertex) && (_edge == it_exact->_edge)); + } + + virtual float t() const + { + if (_vertex == _edge->vertexA()) { + return 0.0f; + } + return ((float)_edge->getLength2D()); + } + virtual float u() const + { + if (_vertex == _edge->vertexA()) { + return 0.0f; + } + return 1.0f; + } + + virtual SVertexIterator *copy() const + { + return new SVertexIterator(*this); + } + + private: + SVertex *_vertex; + FEdge *_edge; }; -} // end of namespace FEdgeInternal +} // end of namespace FEdgeInternal // Iterator access (implementation) Interface0DIterator FEdge::verticesBegin() { - Interface0DIterator ret(new FEdgeInternal::SVertexIterator(_VertexA, this)); - return ret; + Interface0DIterator ret(new FEdgeInternal::SVertexIterator(_VertexA, this)); + return ret; } Interface0DIterator FEdge::verticesEnd() { - Interface0DIterator ret(new FEdgeInternal::SVertexIterator(0, this)); - return ret; + Interface0DIterator ret(new FEdgeInternal::SVertexIterator(0, this)); + return ret; } Interface0DIterator FEdge::pointsBegin(float /*t*/) { - return verticesBegin(); + return verticesBegin(); } Interface0DIterator FEdge::pointsEnd(float /*t*/) { - return verticesEnd(); + return verticesEnd(); } /*! Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial edge of the input mesh. @@ -1131,267 +1130,268 @@ Interface0DIterator FEdge::pointsEnd(float /*t*/) * by two faces of the mesh. Face a lies on its right whereas Face b lies on its left. * If it is a border edge, then it doesn't have any face on its right, and thus Face a = 0. */ -class FEdgeSharp : public FEdge -{ -protected: - Vec3r _aNormal; // When following the edge, normal of the right face - Vec3r _bNormal; // When following the edge, normal of the left face - unsigned _aFrsMaterialIndex; - unsigned _bFrsMaterialIndex; - bool _aFaceMark; - bool _bFaceMark; - -public: - /*! Returns the string "FEdgeSharp" . */ - virtual string getExactTypeName() const - { - return "FEdgeSharp"; - } - - /*! Default constructor. */ - inline FEdgeSharp() : FEdge() - { - _aFrsMaterialIndex = _bFrsMaterialIndex = 0; - _aFaceMark = _bFaceMark = false; - } - - /*! Builds an FEdgeSharp going from vA to vB. */ - inline FEdgeSharp(SVertex *vA, SVertex *vB) : FEdge(vA, vB) - { - _aFrsMaterialIndex = _bFrsMaterialIndex = 0; - _aFaceMark = _bFaceMark = false; - } - - /*! Copy constructor. */ - inline FEdgeSharp(FEdgeSharp& iBrother) : FEdge(iBrother) - { - _aNormal = iBrother._aNormal; - _bNormal = iBrother._bNormal; - _aFrsMaterialIndex = iBrother._aFrsMaterialIndex; - _bFrsMaterialIndex = iBrother._bFrsMaterialIndex; - _aFaceMark = iBrother._aFaceMark; - _bFaceMark = iBrother._bFaceMark; - } - - /*! Destructor. */ - virtual ~FEdgeSharp() {} - - /*! Cloning method. */ - virtual FEdge *duplicate() - { - FEdge *clone = new FEdgeSharp(*this); - return clone; - } - - /*! Returns the normal to the face lying on the right of the FEdge. If this FEdge is a border, - * it has no Face on its right and therefore, no normal. - */ - inline const Vec3r& normalA() - { - return _aNormal; - } - - /*! Returns the normal to the face lying on the left of the FEdge. */ - inline const Vec3r& normalB() - { - return _bNormal; - } - - /*! Returns the index of the material of the face lying on the - * right of the FEdge. If this FEdge is a border, - * it has no Face on its right and therefore, no material. - */ - inline unsigned aFrsMaterialIndex() const - { - return _aFrsMaterialIndex; - } - - /*! Returns the material of the face lying on the right of the FEdge. If this FEdge is a border, - * it has no Face on its right and therefore, no material. - */ - const FrsMaterial& aFrsMaterial() const; - - /*! Returns the index of the material of the face lying on the left of the FEdge. */ - inline unsigned bFrsMaterialIndex() const - { - return _bFrsMaterialIndex; - } - - /*! Returns the material of the face lying on the left of the FEdge. */ - const FrsMaterial& bFrsMaterial() const; - - /*! Returns the face mark of the face lying on the right of the FEdge. - * If this FEdge is a border, it has no Face on its right and thus false is returned. - */ - inline bool aFaceMark() const - { - return _aFaceMark; - } - - /*! Returns the face mark of the face lying on the left of the FEdge. */ - inline bool bFaceMark() const - { - return _bFaceMark; - } - - /*! Sets the normal to the face lying on the right of the FEdge. */ - inline void setNormalA(const Vec3r& iNormal) - { - _aNormal = iNormal; - } - - /*! Sets the normal to the face lying on the left of the FEdge. */ - inline void setNormalB(const Vec3r& iNormal) - { - _bNormal = iNormal; - } - - /*! Sets the index of the material lying on the right of the FEdge.*/ - inline void setaFrsMaterialIndex(unsigned i) - { - _aFrsMaterialIndex = i; - } - - /*! Sets the index of the material lying on the left of the FEdge.*/ - inline void setbFrsMaterialIndex(unsigned i) - { - _bFrsMaterialIndex = i; - } - - /*! Sets the face mark of the face lying on the right of the FEdge. */ - inline void setaFaceMark(bool iFaceMark) - { - _aFaceMark = iFaceMark; - } - - /*! Sets the face mark of the face lying on the left of the FEdge. */ - inline void setbFaceMark(bool iFaceMark) - { - _bFaceMark = iFaceMark; - } +class FEdgeSharp : public FEdge { + protected: + Vec3r _aNormal; // When following the edge, normal of the right face + Vec3r _bNormal; // When following the edge, normal of the left face + unsigned _aFrsMaterialIndex; + unsigned _bFrsMaterialIndex; + bool _aFaceMark; + bool _bFaceMark; + + public: + /*! Returns the string "FEdgeSharp" . */ + virtual string getExactTypeName() const + { + return "FEdgeSharp"; + } + + /*! Default constructor. */ + inline FEdgeSharp() : FEdge() + { + _aFrsMaterialIndex = _bFrsMaterialIndex = 0; + _aFaceMark = _bFaceMark = false; + } + + /*! Builds an FEdgeSharp going from vA to vB. */ + inline FEdgeSharp(SVertex *vA, SVertex *vB) : FEdge(vA, vB) + { + _aFrsMaterialIndex = _bFrsMaterialIndex = 0; + _aFaceMark = _bFaceMark = false; + } + + /*! Copy constructor. */ + inline FEdgeSharp(FEdgeSharp &iBrother) : FEdge(iBrother) + { + _aNormal = iBrother._aNormal; + _bNormal = iBrother._bNormal; + _aFrsMaterialIndex = iBrother._aFrsMaterialIndex; + _bFrsMaterialIndex = iBrother._bFrsMaterialIndex; + _aFaceMark = iBrother._aFaceMark; + _bFaceMark = iBrother._bFaceMark; + } + + /*! Destructor. */ + virtual ~FEdgeSharp() + { + } + + /*! Cloning method. */ + virtual FEdge *duplicate() + { + FEdge *clone = new FEdgeSharp(*this); + return clone; + } + + /*! Returns the normal to the face lying on the right of the FEdge. If this FEdge is a border, + * it has no Face on its right and therefore, no normal. + */ + inline const Vec3r &normalA() + { + return _aNormal; + } + + /*! Returns the normal to the face lying on the left of the FEdge. */ + inline const Vec3r &normalB() + { + return _bNormal; + } + + /*! Returns the index of the material of the face lying on the + * right of the FEdge. If this FEdge is a border, + * it has no Face on its right and therefore, no material. + */ + inline unsigned aFrsMaterialIndex() const + { + return _aFrsMaterialIndex; + } + + /*! Returns the material of the face lying on the right of the FEdge. If this FEdge is a border, + * it has no Face on its right and therefore, no material. + */ + const FrsMaterial &aFrsMaterial() const; + + /*! Returns the index of the material of the face lying on the left of the FEdge. */ + inline unsigned bFrsMaterialIndex() const + { + return _bFrsMaterialIndex; + } + + /*! Returns the material of the face lying on the left of the FEdge. */ + const FrsMaterial &bFrsMaterial() const; + + /*! Returns the face mark of the face lying on the right of the FEdge. + * If this FEdge is a border, it has no Face on its right and thus false is returned. + */ + inline bool aFaceMark() const + { + return _aFaceMark; + } + + /*! Returns the face mark of the face lying on the left of the FEdge. */ + inline bool bFaceMark() const + { + return _bFaceMark; + } + + /*! Sets the normal to the face lying on the right of the FEdge. */ + inline void setNormalA(const Vec3r &iNormal) + { + _aNormal = iNormal; + } + + /*! Sets the normal to the face lying on the left of the FEdge. */ + inline void setNormalB(const Vec3r &iNormal) + { + _bNormal = iNormal; + } + + /*! Sets the index of the material lying on the right of the FEdge.*/ + inline void setaFrsMaterialIndex(unsigned i) + { + _aFrsMaterialIndex = i; + } + + /*! Sets the index of the material lying on the left of the FEdge.*/ + inline void setbFrsMaterialIndex(unsigned i) + { + _bFrsMaterialIndex = i; + } + + /*! Sets the face mark of the face lying on the right of the FEdge. */ + inline void setaFaceMark(bool iFaceMark) + { + _aFaceMark = iFaceMark; + } + + /*! Sets the face mark of the face lying on the left of the FEdge. */ + inline void setbFaceMark(bool iFaceMark) + { + _bFaceMark = iFaceMark; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeSharp") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeSharp") #endif }; /*! Class defining a smooth edge. This kind of edge typically runs across a face of the input mesh. It can be * a silhouette, a ridge or valley, a suggestive contour. */ -class FEdgeSmooth : public FEdge -{ -protected: - Vec3r _Normal; - unsigned _FrsMaterialIndex; +class FEdgeSmooth : public FEdge { + protected: + Vec3r _Normal; + unsigned _FrsMaterialIndex; #if 0 - bool _hasVisibilityPoint; - Vec3r _VisibilityPointA; // The edge on which the visibility will be computed represented - Vec3r _VisibilityPointB; // using its 2 extremity points A and B + bool _hasVisibilityPoint; + Vec3r _VisibilityPointA; // The edge on which the visibility will be computed represented + Vec3r _VisibilityPointB; // using its 2 extremity points A and B #endif - void *_Face; // In case of exact silhouette, Face is the WFace crossed by Fedge - // NOT HANDLED BY THE COPY CONSTRUCTEUR - bool _FaceMark; - -public: - /*! Returns the string "FEdgeSmooth" . */ - virtual string getExactTypeName() const - { - return "FEdgeSmooth"; - } - - /*! Default constructor. */ - inline FEdgeSmooth() : FEdge() - { - _Face = NULL; - _FaceMark = false; - _FrsMaterialIndex = 0; - _isSmooth = true; - } - - /*! Builds an FEdgeSmooth going from vA to vB. */ - inline FEdgeSmooth(SVertex *vA, SVertex *vB) : FEdge(vA, vB) - { - _Face = NULL; - _FaceMark = false; - _FrsMaterialIndex = 0; - _isSmooth = true; - } - - /*! Copy constructor. */ - inline FEdgeSmooth(FEdgeSmooth& iBrother) : FEdge(iBrother) - { - _Normal = iBrother._Normal; - _Face = iBrother._Face; - _FaceMark = iBrother._FaceMark; - _FrsMaterialIndex = iBrother._FrsMaterialIndex; - _isSmooth = true; - } - - /*! Destructor. */ - virtual ~FEdgeSmooth() {} - - /*! Cloning method. */ - virtual FEdge *duplicate() - { - FEdge *clone = new FEdgeSmooth(*this); - return clone; - } - - inline void *face() const - { - return _Face; - } - - /*! Returns the face mark of the face it is running across. */ - inline bool faceMark() const - { - return _FaceMark; - } - - /*! Returns the normal to the Face it is running accross. */ - inline const Vec3r& normal() - { - return _Normal; - } - - /*! Returns the index of the material of the face it is running accross. */ - inline unsigned frs_materialIndex() const - { - return _FrsMaterialIndex; - } - - /*! Returns the material of the face it is running accross. */ - const FrsMaterial& frs_material() const; - - inline void setFace(void *iFace) - { - _Face = iFace; - } - - /*! Sets the face mark of the face it is running across. */ - inline void setFaceMark(bool iFaceMark) - { - _FaceMark = iFaceMark; - } - - /*! Sets the normal to the Face it is running accross. */ - inline void setNormal(const Vec3r& iNormal) - { - _Normal = iNormal; - } - - /*! Sets the index of the material of the face it is running accross. */ - inline void setFrsMaterialIndex(unsigned i) - { - _FrsMaterialIndex = i; - } + void *_Face; // In case of exact silhouette, Face is the WFace crossed by Fedge + // NOT HANDLED BY THE COPY CONSTRUCTEUR + bool _FaceMark; + + public: + /*! Returns the string "FEdgeSmooth" . */ + virtual string getExactTypeName() const + { + return "FEdgeSmooth"; + } + + /*! Default constructor. */ + inline FEdgeSmooth() : FEdge() + { + _Face = NULL; + _FaceMark = false; + _FrsMaterialIndex = 0; + _isSmooth = true; + } + + /*! Builds an FEdgeSmooth going from vA to vB. */ + inline FEdgeSmooth(SVertex *vA, SVertex *vB) : FEdge(vA, vB) + { + _Face = NULL; + _FaceMark = false; + _FrsMaterialIndex = 0; + _isSmooth = true; + } + + /*! Copy constructor. */ + inline FEdgeSmooth(FEdgeSmooth &iBrother) : FEdge(iBrother) + { + _Normal = iBrother._Normal; + _Face = iBrother._Face; + _FaceMark = iBrother._FaceMark; + _FrsMaterialIndex = iBrother._FrsMaterialIndex; + _isSmooth = true; + } + + /*! Destructor. */ + virtual ~FEdgeSmooth() + { + } + + /*! Cloning method. */ + virtual FEdge *duplicate() + { + FEdge *clone = new FEdgeSmooth(*this); + return clone; + } + + inline void *face() const + { + return _Face; + } + + /*! Returns the face mark of the face it is running across. */ + inline bool faceMark() const + { + return _FaceMark; + } + + /*! Returns the normal to the Face it is running accross. */ + inline const Vec3r &normal() + { + return _Normal; + } + + /*! Returns the index of the material of the face it is running accross. */ + inline unsigned frs_materialIndex() const + { + return _FrsMaterialIndex; + } + + /*! Returns the material of the face it is running accross. */ + const FrsMaterial &frs_material() const; + + inline void setFace(void *iFace) + { + _Face = iFace; + } + + /*! Sets the face mark of the face it is running across. */ + inline void setFaceMark(bool iFaceMark) + { + _FaceMark = iFaceMark; + } + + /*! Sets the normal to the Face it is running accross. */ + inline void setNormal(const Vec3r &iNormal) + { + _Normal = iNormal; + } + + /*! Sets the index of the material of the face it is running accross. */ + inline void setFrsMaterialIndex(unsigned i) + { + _FrsMaterialIndex = i; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeSmooth") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeSmooth") #endif }; - /**********************************/ /* */ /* */ @@ -1400,540 +1400,544 @@ public: /* */ /**********************************/ - /*! Class to define a feature shape. It is the gathering of feature elements from an identified input shape */ -class SShape -{ -private: - vector _chains; // list of fedges that are chains starting points. - vector _verticesList; // list of all vertices - vector _edgesList; // list of all edges - Id _Id; - string _Name; - string _LibraryPath; - BBox _BBox; - vector _FrsMaterials; - - float _importance; - - ViewShape *_ViewShape; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; // added by E.T. - - /*! Default constructor */ - inline SShape() - { - userdata = NULL; - _importance = 0.0f; - _ViewShape = NULL; - } - - /*! Copy constructor */ - inline SShape(SShape& iBrother) - { - userdata = NULL; - _Id = iBrother._Id; - _Name = iBrother._Name; - _LibraryPath = iBrother._LibraryPath; - _BBox = iBrother.bbox(); - _FrsMaterials = iBrother._FrsMaterials; - _importance = iBrother._importance; - _ViewShape = iBrother._ViewShape; - - //--------- - // vertices - //--------- - vector::iterator sv, svend; - vector& verticesList = iBrother.getVertexList(); - for (sv = verticesList.begin(), svend = verticesList.end(); sv != svend; sv++) { - SVertex *newv = new SVertex(*(*sv)); - newv->setShape(this); - _verticesList.push_back(newv); - } - - //------ - // edges - //------ - vector::iterator e, eend; - vector& edgesList = iBrother.getEdgeList(); - for (e = edgesList.begin(), eend = edgesList.end(); e != eend; e++) { - FEdge *newe = (*e)->duplicate(); - _edgesList.push_back(newe); - } - - //------------------------- - // starting chain edges - //------------------------- - vector::iterator fe, fend; - vector& fedges = iBrother.getChains(); - for (fe = fedges.begin(), fend = fedges.end(); fe != fend; fe++) { - _chains.push_back((FEdge *)((*fe)->userdata)); - } - - //------------------------- - // remap edges in vertices: - //------------------------- - for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { - const vector& fedgeList = (*sv)->fedges(); - vector newfedgelist; - for (vector::const_iterator fed = fedgeList.begin(), fedend = fedgeList.end(); - fed != fedend; - fed++) - { - FEdge *current = *fed; - newfedgelist.push_back((FEdge *)current->userdata); - } - (*sv)->setFEdges(newfedgelist); - } - - //------------------------------------- - // remap vertices and nextedge in edges: - //------------------------------------- - for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { - (*e)->setVertexA((SVertex *)((*e)->vertexA()->userdata)); - (*e)->setVertexB((SVertex *)((*e)->vertexB()->userdata)); - (*e)->setNextEdge((FEdge *)((*e)->nextEdge()->userdata)); - (*e)->setPreviousEdge((FEdge *)((*e)->previousEdge()->userdata)); - } - - // reset all brothers userdata to NULL: - //------------------------------------- - //--------- - // vertices - //--------- - for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { - (*sv)->userdata = NULL; - } - - //------ - // edges - //------ - for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { - (*e)->userdata = NULL; - } - } - - /*! Cloning method. */ - virtual SShape *duplicate() - { - SShape *clone = new SShape(*this); - return clone; - } - - /*! Destructor. */ - virtual inline ~SShape() - { - vector::iterator sv, svend; - vector::iterator e, eend; - if (0 != _verticesList.size()) { - for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { - delete (*sv); - } - _verticesList.clear(); - } - - if (0 != _edgesList.size()) { - for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { - delete (*e); - } - _edgesList.clear(); - } - - //! Clear the chains list - //----------------------- - if (0 != _chains.size()) { - _chains.clear(); - } - } - - /*! Adds a FEdge to the list of FEdges. */ - inline void AddEdge(FEdge *iEdge) - { - _edgesList.push_back(iEdge); - } - - /*! Adds a SVertex to the list of SVertex of this Shape. - * The SShape attribute of the SVertex is also set to 'this'. - */ - inline void AddNewVertex(SVertex *iv) - { - iv->setShape(this); - _verticesList.push_back(iv); - } - - inline void AddChain(FEdge *iEdge) - { - _chains.push_back(iEdge); - } - - inline SVertex *CreateSVertex(const Vec3r& P3D, const Vec3r& P2D, const Id& id) - { - SVertex *Ia = new SVertex(P3D, id); - Ia->setPoint2D(P2D); - AddNewVertex(Ia); - return Ia; - } - - /*! Splits an edge into several edges. - * The edge's vertices are passed rather than the edge itself. This way, all feature edges (SILHOUETTE, - * CREASE, BORDER) are splitted in the same time. - * The processed edges are flagged as done (using the userdata flag).One single new vertex is created whereas - * several splitted edges might created for the different kinds of edges. These new elements are added to the lists - * maintained by the shape. - * New chains are also created. - * ioA - * The first vertex for the edge that gets splitted - * ioB - * The second vertex for the edge that gets splitted - * iParameters - * A vector containing 2D real vectors indicating the parameters giving the intersections coordinates in - * 3D and in 2D. These intersections points must be sorted from B to A. - * Each parameter defines the intersection point I as I=A+T*AB. T<0 and T>1 are then incorrect insofar as - * they give intersections points that lie outside the segment. - * ioNewEdges - * The edges that are newly created (the initial edges are not included) are added to this list. - */ - inline void SplitEdge(FEdge *fe, const vector& iParameters, vector& ioNewEdges) - { - SVertex *ioA = fe->vertexA(); - SVertex *ioB = fe->vertexB(); - Vec3r A = ioA->point3D(); - Vec3r B = ioB->point3D(); - Vec3r a = ioA->point2D(); - Vec3r b = ioB->point2D(); - - Vec3r newpoint3d, newpoint2d; - vector intersections; - real t, T; - for (vector::const_iterator p = iParameters.begin(), pend = iParameters.end(); p != pend; p++) { - T = (*p)[0]; - t = (*p)[1]; - - if ((t < 0) || (t > 1)) - cerr << "Warning: Intersection out of range for edge " << ioA->getId() << " - " << ioB->getId() << endl; - - // compute the 3D and 2D coordinates for the intersections points: - newpoint3d = Vec3r(A + T * (B - A)); - newpoint2d = Vec3r(a + t * (b - a)); - - // create new SVertex: - // (we keep B's id) - SVertex *newVertex = new SVertex(newpoint3d, ioB->getId()); - newVertex->setPoint2D(newpoint2d); - - // Add this vertex to the intersections list: - intersections.push_back(newVertex); - - // Add this vertex to this sshape: - AddNewVertex(newVertex); - } - - for (vector::iterator sv = intersections.begin(), svend = intersections.end(); sv != svend; sv++) { - //SVertex *svA = fe->vertexA(); - SVertex *svB = fe->vertexB(); - - // We split edge AB into AA' and A'B. A' and A'B are created. - // AB becomes (address speaking) AA'. B is updated. - //-------------------------------------------------- - // The edge AB becomes edge AA'. - (fe)->setVertexB((*sv)); - // a new edge, A'B is created. - FEdge *newEdge; - if (fe->isSmooth()) { - newEdge = new FEdgeSmooth((*sv), svB); - FEdgeSmooth *se = dynamic_cast(newEdge); - FEdgeSmooth *fes = dynamic_cast(fe); - se->setFrsMaterialIndex(fes->frs_materialIndex()); - } - else { - newEdge = new FEdgeSharp((*sv), svB); - FEdgeSharp *se = dynamic_cast(newEdge); - FEdgeSharp *fes = dynamic_cast(fe); - se->setaFrsMaterialIndex(fes->aFrsMaterialIndex()); - se->setbFrsMaterialIndex(fes->bFrsMaterialIndex()); - } - - newEdge->setNature((fe)->getNature()); - - // to build a new chain: - AddChain(newEdge); - // add the new edge to the sshape edges list. - AddEdge(newEdge); - // add new edge to the list of new edges passed as argument: - ioNewEdges.push_back(newEdge); - - // update edge A'B for the next pointing edge - newEdge->setNextEdge((fe)->nextEdge()); - fe->nextEdge()->setPreviousEdge(newEdge); - Id id(fe->getId().getFirst(), fe->getId().getSecond() + 1); - newEdge->setId(fe->getId()); - fe->setId(id); - - // update edge AA' for the next pointing edge - //ioEdge->setNextEdge(newEdge); - (fe)->setNextEdge(NULL); - - // update vertex pointing edges list: - // -- vertex B -- - svB->Replace((fe), newEdge); - // -- vertex A' -- - (*sv)->AddFEdge((fe)); - (*sv)->AddFEdge(newEdge); - } - } - - /* splits an edge into 2 edges. The new vertex and edge are added to the sshape list of vertices and edges - * a new chain is also created. - * returns the new edge. - * ioEdge - * The edge that gets splitted - * newpoint - * x,y,z coordinates of the new point. - */ - inline FEdge *SplitEdgeIn2(FEdge *ioEdge, SVertex *ioNewVertex) - { - //soc unused - SVertex *A = ioEdge->vertexA(); - SVertex *B = ioEdge->vertexB(); - - // We split edge AB into AA' and A'B. A' and A'B are created. - // AB becomes (address speaking) AA'. B is updated. - //-------------------------------------------------- - // a new edge, A'B is created. - FEdge *newEdge; - if (ioEdge->isSmooth()) { - newEdge = new FEdgeSmooth(ioNewVertex, B); - FEdgeSmooth *se = dynamic_cast(newEdge); - FEdgeSmooth *fes = dynamic_cast(ioEdge); - se->setNormal(fes->normal()); - se->setFrsMaterialIndex(fes->frs_materialIndex()); - se->setFaceMark(fes->faceMark()); - } - else { - newEdge = new FEdgeSharp(ioNewVertex, B); - FEdgeSharp *se = dynamic_cast(newEdge); - FEdgeSharp *fes = dynamic_cast(ioEdge); - se->setNormalA(fes->normalA()); - se->setNormalB(fes->normalB()); - se->setaFrsMaterialIndex(fes->aFrsMaterialIndex()); - se->setbFrsMaterialIndex(fes->bFrsMaterialIndex()); - se->setaFaceMark(fes->aFaceMark()); - se->setbFaceMark(fes->bFaceMark()); - } - newEdge->setNature(ioEdge->getNature()); - - if (ioEdge->nextEdge() != 0) - ioEdge->nextEdge()->setPreviousEdge(newEdge); - - // update edge A'B for the next pointing edge - newEdge->setNextEdge(ioEdge->nextEdge()); - // update edge A'B for the previous pointing edge - newEdge->setPreviousEdge(0); // because it is now a TVertex - Id id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1); - newEdge->setId(ioEdge->getId()); - ioEdge->setId(id); - - // update edge AA' for the next pointing edge - ioEdge->setNextEdge(0); // because it is now a TVertex - - // update vertex pointing edges list: - // -- vertex B -- - B->Replace(ioEdge, newEdge); - // -- vertex A' -- - ioNewVertex->AddFEdge(ioEdge); - ioNewVertex->AddFEdge(newEdge); - - // to build a new chain: - AddChain(newEdge); - AddEdge(newEdge); // FIXME ?? - - // The edge AB becomes edge AA'. - ioEdge->setVertexB(ioNewVertex); - - if (ioEdge->isSmooth()) { - ((FEdgeSmooth *)newEdge)->setFace(((FEdgeSmooth *)ioEdge)->face()); - } - - return newEdge; - } - - /*! Sets the Bounding Box of the Shape */ - inline void setBBox(const BBox& iBBox) - { - _BBox = iBBox; - } - - /*! Compute the bbox of the sshape */ - inline void ComputeBBox() - { - if (0 == _verticesList.size()) - return; - - Vec3r firstVertex = _verticesList[0]->point3D(); - real XMax = firstVertex[0]; - real YMax = firstVertex[1]; - real ZMax = firstVertex[2]; - - real XMin = firstVertex[0]; - real YMin = firstVertex[1]; - real ZMin = firstVertex[2]; - - vector::iterator v, vend; - // parse all the coordinates to find the Xmax, YMax, ZMax - for (v = _verticesList.begin(), vend = _verticesList.end(); v != vend; v++) { - Vec3r vertex = (*v)->point3D(); - // X - real x = vertex[0]; - if (x > XMax) - XMax = x; - else if (x < XMin) - XMin = x; - - // Y - real y = vertex[1]; - if (y > YMax) - YMax = y; - else if (y < YMin) - YMin = y; - - // Z - real z = vertex[2]; - if (z > ZMax) - ZMax = z; - else if (z < ZMin) - ZMin = z; - } - - setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); - } - - inline void RemoveEdgeFromChain(FEdge *iEdge) - { - for (vector::iterator fe = _chains.begin(), feend = _chains.end(); fe != feend; fe++) { - if (iEdge == (*fe)) { - _chains.erase(fe); - break; - } - } - } - - inline void RemoveEdge(FEdge *iEdge) - { - for (vector::iterator fe = _edgesList.begin(), feend = _edgesList.end(); fe != feend; fe++) { - if (iEdge == (*fe)) { - _edgesList.erase(fe); - break; - } - } - } - - /* accessors */ - /*! Returns the list of SVertex of the Shape. */ - inline vector& getVertexList() - { - return _verticesList; - } - - /*! Returns the list of FEdges of the Shape. */ - inline vector& getEdgeList() - { - return _edgesList; - } - - inline vector& getChains() - { - return _chains; - } - - /*! Returns the bounding box of the shape. */ - inline const BBox& bbox() - { - return _BBox; - } - - /*! Returns the ith material of the shape. */ - inline const FrsMaterial& frs_material(unsigned i) const - { - return _FrsMaterials[i]; - } - - /*! Returns the list of materials of the Shape. */ - inline const vector& frs_materials() const - { - return _FrsMaterials; - } - - inline ViewShape *viewShape() - { - return _ViewShape; - } - - inline float importance() const - { - return _importance; - } - - /*! Returns the Id of the Shape. */ - inline Id getId() const - { - return _Id; - } - - /*! Returns the name of the Shape. */ - inline const string& getName() const - { - return _Name; - } - - /*! Returns the library path of the Shape. */ - inline const string& getLibraryPath() const - { - return _LibraryPath; - } - - /* Modififers */ - /*! Sets the Id of the shape.*/ - inline void setId(Id id) - { - _Id = id; - } - - /*! Sets the name of the shape.*/ - inline void setName(const string& name) - { - _Name = name; - } - - /*! Sets the library path of the shape.*/ - inline void setLibraryPath(const string& path) - { - _LibraryPath = path; - } - - /*! Sets the list of materials for the shape */ - inline void setFrsMaterials(const vector& iMaterials) - { - _FrsMaterials = iMaterials; - } - - inline void setViewShape(ViewShape *iShape) - { - _ViewShape = iShape; - } - - inline void setImportance(float importance) - { - _importance = importance; - } +class SShape { + private: + vector _chains; // list of fedges that are chains starting points. + vector _verticesList; // list of all vertices + vector _edgesList; // list of all edges + Id _Id; + string _Name; + string _LibraryPath; + BBox _BBox; + vector _FrsMaterials; + + float _importance; + + ViewShape *_ViewShape; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; // added by E.T. + + /*! Default constructor */ + inline SShape() + { + userdata = NULL; + _importance = 0.0f; + _ViewShape = NULL; + } + + /*! Copy constructor */ + inline SShape(SShape &iBrother) + { + userdata = NULL; + _Id = iBrother._Id; + _Name = iBrother._Name; + _LibraryPath = iBrother._LibraryPath; + _BBox = iBrother.bbox(); + _FrsMaterials = iBrother._FrsMaterials; + _importance = iBrother._importance; + _ViewShape = iBrother._ViewShape; + + //--------- + // vertices + //--------- + vector::iterator sv, svend; + vector &verticesList = iBrother.getVertexList(); + for (sv = verticesList.begin(), svend = verticesList.end(); sv != svend; sv++) { + SVertex *newv = new SVertex(*(*sv)); + newv->setShape(this); + _verticesList.push_back(newv); + } + + //------ + // edges + //------ + vector::iterator e, eend; + vector &edgesList = iBrother.getEdgeList(); + for (e = edgesList.begin(), eend = edgesList.end(); e != eend; e++) { + FEdge *newe = (*e)->duplicate(); + _edgesList.push_back(newe); + } + + //------------------------- + // starting chain edges + //------------------------- + vector::iterator fe, fend; + vector &fedges = iBrother.getChains(); + for (fe = fedges.begin(), fend = fedges.end(); fe != fend; fe++) { + _chains.push_back((FEdge *)((*fe)->userdata)); + } + + //------------------------- + // remap edges in vertices: + //------------------------- + for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { + const vector &fedgeList = (*sv)->fedges(); + vector newfedgelist; + for (vector::const_iterator fed = fedgeList.begin(), fedend = fedgeList.end(); + fed != fedend; + fed++) { + FEdge *current = *fed; + newfedgelist.push_back((FEdge *)current->userdata); + } + (*sv)->setFEdges(newfedgelist); + } + + //------------------------------------- + // remap vertices and nextedge in edges: + //------------------------------------- + for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { + (*e)->setVertexA((SVertex *)((*e)->vertexA()->userdata)); + (*e)->setVertexB((SVertex *)((*e)->vertexB()->userdata)); + (*e)->setNextEdge((FEdge *)((*e)->nextEdge()->userdata)); + (*e)->setPreviousEdge((FEdge *)((*e)->previousEdge()->userdata)); + } + + // reset all brothers userdata to NULL: + //------------------------------------- + //--------- + // vertices + //--------- + for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { + (*sv)->userdata = NULL; + } + + //------ + // edges + //------ + for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { + (*e)->userdata = NULL; + } + } + + /*! Cloning method. */ + virtual SShape *duplicate() + { + SShape *clone = new SShape(*this); + return clone; + } + + /*! Destructor. */ + virtual inline ~SShape() + { + vector::iterator sv, svend; + vector::iterator e, eend; + if (0 != _verticesList.size()) { + for (sv = _verticesList.begin(), svend = _verticesList.end(); sv != svend; sv++) { + delete (*sv); + } + _verticesList.clear(); + } + + if (0 != _edgesList.size()) { + for (e = _edgesList.begin(), eend = _edgesList.end(); e != eend; e++) { + delete (*e); + } + _edgesList.clear(); + } + + //! Clear the chains list + //----------------------- + if (0 != _chains.size()) { + _chains.clear(); + } + } + + /*! Adds a FEdge to the list of FEdges. */ + inline void AddEdge(FEdge *iEdge) + { + _edgesList.push_back(iEdge); + } + + /*! Adds a SVertex to the list of SVertex of this Shape. + * The SShape attribute of the SVertex is also set to 'this'. + */ + inline void AddNewVertex(SVertex *iv) + { + iv->setShape(this); + _verticesList.push_back(iv); + } + + inline void AddChain(FEdge *iEdge) + { + _chains.push_back(iEdge); + } + + inline SVertex *CreateSVertex(const Vec3r &P3D, const Vec3r &P2D, const Id &id) + { + SVertex *Ia = new SVertex(P3D, id); + Ia->setPoint2D(P2D); + AddNewVertex(Ia); + return Ia; + } + + /*! Splits an edge into several edges. + * The edge's vertices are passed rather than the edge itself. This way, all feature edges (SILHOUETTE, + * CREASE, BORDER) are splitted in the same time. + * The processed edges are flagged as done (using the userdata flag).One single new vertex is created whereas + * several splitted edges might created for the different kinds of edges. These new elements are added to the lists + * maintained by the shape. + * New chains are also created. + * ioA + * The first vertex for the edge that gets splitted + * ioB + * The second vertex for the edge that gets splitted + * iParameters + * A vector containing 2D real vectors indicating the parameters giving the intersections coordinates in + * 3D and in 2D. These intersections points must be sorted from B to A. + * Each parameter defines the intersection point I as I=A+T*AB. T<0 and T>1 are then incorrect insofar as + * they give intersections points that lie outside the segment. + * ioNewEdges + * The edges that are newly created (the initial edges are not included) are added to this list. + */ + inline void SplitEdge(FEdge *fe, const vector &iParameters, vector &ioNewEdges) + { + SVertex *ioA = fe->vertexA(); + SVertex *ioB = fe->vertexB(); + Vec3r A = ioA->point3D(); + Vec3r B = ioB->point3D(); + Vec3r a = ioA->point2D(); + Vec3r b = ioB->point2D(); + + Vec3r newpoint3d, newpoint2d; + vector intersections; + real t, T; + for (vector::const_iterator p = iParameters.begin(), pend = iParameters.end(); + p != pend; + p++) { + T = (*p)[0]; + t = (*p)[1]; + + if ((t < 0) || (t > 1)) + cerr << "Warning: Intersection out of range for edge " << ioA->getId() << " - " + << ioB->getId() << endl; + + // compute the 3D and 2D coordinates for the intersections points: + newpoint3d = Vec3r(A + T * (B - A)); + newpoint2d = Vec3r(a + t * (b - a)); + + // create new SVertex: + // (we keep B's id) + SVertex *newVertex = new SVertex(newpoint3d, ioB->getId()); + newVertex->setPoint2D(newpoint2d); + + // Add this vertex to the intersections list: + intersections.push_back(newVertex); + + // Add this vertex to this sshape: + AddNewVertex(newVertex); + } + + for (vector::iterator sv = intersections.begin(), svend = intersections.end(); + sv != svend; + sv++) { + //SVertex *svA = fe->vertexA(); + SVertex *svB = fe->vertexB(); + + // We split edge AB into AA' and A'B. A' and A'B are created. + // AB becomes (address speaking) AA'. B is updated. + //-------------------------------------------------- + // The edge AB becomes edge AA'. + (fe)->setVertexB((*sv)); + // a new edge, A'B is created. + FEdge *newEdge; + if (fe->isSmooth()) { + newEdge = new FEdgeSmooth((*sv), svB); + FEdgeSmooth *se = dynamic_cast(newEdge); + FEdgeSmooth *fes = dynamic_cast(fe); + se->setFrsMaterialIndex(fes->frs_materialIndex()); + } + else { + newEdge = new FEdgeSharp((*sv), svB); + FEdgeSharp *se = dynamic_cast(newEdge); + FEdgeSharp *fes = dynamic_cast(fe); + se->setaFrsMaterialIndex(fes->aFrsMaterialIndex()); + se->setbFrsMaterialIndex(fes->bFrsMaterialIndex()); + } + + newEdge->setNature((fe)->getNature()); + + // to build a new chain: + AddChain(newEdge); + // add the new edge to the sshape edges list. + AddEdge(newEdge); + // add new edge to the list of new edges passed as argument: + ioNewEdges.push_back(newEdge); + + // update edge A'B for the next pointing edge + newEdge->setNextEdge((fe)->nextEdge()); + fe->nextEdge()->setPreviousEdge(newEdge); + Id id(fe->getId().getFirst(), fe->getId().getSecond() + 1); + newEdge->setId(fe->getId()); + fe->setId(id); + + // update edge AA' for the next pointing edge + //ioEdge->setNextEdge(newEdge); + (fe)->setNextEdge(NULL); + + // update vertex pointing edges list: + // -- vertex B -- + svB->Replace((fe), newEdge); + // -- vertex A' -- + (*sv)->AddFEdge((fe)); + (*sv)->AddFEdge(newEdge); + } + } + + /* splits an edge into 2 edges. The new vertex and edge are added to the sshape list of vertices and edges + * a new chain is also created. + * returns the new edge. + * ioEdge + * The edge that gets splitted + * newpoint + * x,y,z coordinates of the new point. + */ + inline FEdge *SplitEdgeIn2(FEdge *ioEdge, SVertex *ioNewVertex) + { + //soc unused - SVertex *A = ioEdge->vertexA(); + SVertex *B = ioEdge->vertexB(); + + // We split edge AB into AA' and A'B. A' and A'B are created. + // AB becomes (address speaking) AA'. B is updated. + //-------------------------------------------------- + // a new edge, A'B is created. + FEdge *newEdge; + if (ioEdge->isSmooth()) { + newEdge = new FEdgeSmooth(ioNewVertex, B); + FEdgeSmooth *se = dynamic_cast(newEdge); + FEdgeSmooth *fes = dynamic_cast(ioEdge); + se->setNormal(fes->normal()); + se->setFrsMaterialIndex(fes->frs_materialIndex()); + se->setFaceMark(fes->faceMark()); + } + else { + newEdge = new FEdgeSharp(ioNewVertex, B); + FEdgeSharp *se = dynamic_cast(newEdge); + FEdgeSharp *fes = dynamic_cast(ioEdge); + se->setNormalA(fes->normalA()); + se->setNormalB(fes->normalB()); + se->setaFrsMaterialIndex(fes->aFrsMaterialIndex()); + se->setbFrsMaterialIndex(fes->bFrsMaterialIndex()); + se->setaFaceMark(fes->aFaceMark()); + se->setbFaceMark(fes->bFaceMark()); + } + newEdge->setNature(ioEdge->getNature()); + + if (ioEdge->nextEdge() != 0) + ioEdge->nextEdge()->setPreviousEdge(newEdge); + + // update edge A'B for the next pointing edge + newEdge->setNextEdge(ioEdge->nextEdge()); + // update edge A'B for the previous pointing edge + newEdge->setPreviousEdge(0); // because it is now a TVertex + Id id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1); + newEdge->setId(ioEdge->getId()); + ioEdge->setId(id); + + // update edge AA' for the next pointing edge + ioEdge->setNextEdge(0); // because it is now a TVertex + + // update vertex pointing edges list: + // -- vertex B -- + B->Replace(ioEdge, newEdge); + // -- vertex A' -- + ioNewVertex->AddFEdge(ioEdge); + ioNewVertex->AddFEdge(newEdge); + + // to build a new chain: + AddChain(newEdge); + AddEdge(newEdge); // FIXME ?? + + // The edge AB becomes edge AA'. + ioEdge->setVertexB(ioNewVertex); + + if (ioEdge->isSmooth()) { + ((FEdgeSmooth *)newEdge)->setFace(((FEdgeSmooth *)ioEdge)->face()); + } + + return newEdge; + } + + /*! Sets the Bounding Box of the Shape */ + inline void setBBox(const BBox &iBBox) + { + _BBox = iBBox; + } + + /*! Compute the bbox of the sshape */ + inline void ComputeBBox() + { + if (0 == _verticesList.size()) + return; + + Vec3r firstVertex = _verticesList[0]->point3D(); + real XMax = firstVertex[0]; + real YMax = firstVertex[1]; + real ZMax = firstVertex[2]; + + real XMin = firstVertex[0]; + real YMin = firstVertex[1]; + real ZMin = firstVertex[2]; + + vector::iterator v, vend; + // parse all the coordinates to find the Xmax, YMax, ZMax + for (v = _verticesList.begin(), vend = _verticesList.end(); v != vend; v++) { + Vec3r vertex = (*v)->point3D(); + // X + real x = vertex[0]; + if (x > XMax) + XMax = x; + else if (x < XMin) + XMin = x; + + // Y + real y = vertex[1]; + if (y > YMax) + YMax = y; + else if (y < YMin) + YMin = y; + + // Z + real z = vertex[2]; + if (z > ZMax) + ZMax = z; + else if (z < ZMin) + ZMin = z; + } + + setBBox(BBox(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + } + + inline void RemoveEdgeFromChain(FEdge *iEdge) + { + for (vector::iterator fe = _chains.begin(), feend = _chains.end(); fe != feend; + fe++) { + if (iEdge == (*fe)) { + _chains.erase(fe); + break; + } + } + } + + inline void RemoveEdge(FEdge *iEdge) + { + for (vector::iterator fe = _edgesList.begin(), feend = _edgesList.end(); fe != feend; + fe++) { + if (iEdge == (*fe)) { + _edgesList.erase(fe); + break; + } + } + } + + /* accessors */ + /*! Returns the list of SVertex of the Shape. */ + inline vector &getVertexList() + { + return _verticesList; + } + + /*! Returns the list of FEdges of the Shape. */ + inline vector &getEdgeList() + { + return _edgesList; + } + + inline vector &getChains() + { + return _chains; + } + + /*! Returns the bounding box of the shape. */ + inline const BBox &bbox() + { + return _BBox; + } + + /*! Returns the ith material of the shape. */ + inline const FrsMaterial &frs_material(unsigned i) const + { + return _FrsMaterials[i]; + } + + /*! Returns the list of materials of the Shape. */ + inline const vector &frs_materials() const + { + return _FrsMaterials; + } + + inline ViewShape *viewShape() + { + return _ViewShape; + } + + inline float importance() const + { + return _importance; + } + + /*! Returns the Id of the Shape. */ + inline Id getId() const + { + return _Id; + } + + /*! Returns the name of the Shape. */ + inline const string &getName() const + { + return _Name; + } + + /*! Returns the library path of the Shape. */ + inline const string &getLibraryPath() const + { + return _LibraryPath; + } + + /* Modififers */ + /*! Sets the Id of the shape.*/ + inline void setId(Id id) + { + _Id = id; + } + + /*! Sets the name of the shape.*/ + inline void setName(const string &name) + { + _Name = name; + } + + /*! Sets the library path of the shape.*/ + inline void setLibraryPath(const string &path) + { + _LibraryPath = path; + } + + /*! Sets the list of materials for the shape */ + inline void setFrsMaterials(const vector &iMaterials) + { + _FrsMaterials = iMaterials; + } + + inline void setViewShape(ViewShape *iShape) + { + _ViewShape = iShape; + } + + inline void setImportance(float importance) + { + _importance = importance; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SShape") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SShape") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_SILHOUETTE_H__ +#endif // __FREESTYLE_SILHOUETTE_H__ diff --git a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp index 39893e61dc5..7d105a662b8 100644 --- a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp +++ b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.cpp @@ -37,37 +37,37 @@ namespace Freestyle { Vec3r SilhouetteGeomEngine::_Viewpoint = Vec3r(0, 0, 0); real SilhouetteGeomEngine::_translation[3] = {0, 0, 0}; real SilhouetteGeomEngine::_modelViewMatrix[4][4] = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}, + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, }; real SilhouetteGeomEngine::_projectionMatrix[4][4] = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}, + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, }; real SilhouetteGeomEngine::_transform[4][4] = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}, + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, }; int SilhouetteGeomEngine::_viewport[4] = {1, 1, 1, 1}; real SilhouetteGeomEngine::_Focal = 0.0; real SilhouetteGeomEngine::_glProjectionMatrix[4][4] = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}, + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, }; real SilhouetteGeomEngine::_glModelViewMatrix[4][4] = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1}, + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, }; real SilhouetteGeomEngine::_znear = 0.0; real SilhouetteGeomEngine::_zfar = 100.0; @@ -75,214 +75,218 @@ bool SilhouetteGeomEngine::_isOrthographicProjection = false; SilhouetteGeomEngine *SilhouetteGeomEngine::_pInstance = NULL; -void SilhouetteGeomEngine::setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], - const int iViewport[4], real iFocal) +void SilhouetteGeomEngine::setTransform(const real iModelViewMatrix[4][4], + const real iProjectionMatrix[4][4], + const int iViewport[4], + real iFocal) { - unsigned int i, j; - _translation[0] = iModelViewMatrix[3][0]; - _translation[1] = iModelViewMatrix[3][1]; - _translation[2] = iModelViewMatrix[3][2]; + unsigned int i, j; + _translation[0] = iModelViewMatrix[3][0]; + _translation[1] = iModelViewMatrix[3][1]; + _translation[2] = iModelViewMatrix[3][2]; - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - _modelViewMatrix[i][j] = iModelViewMatrix[j][i]; - _glModelViewMatrix[i][j] = iModelViewMatrix[i][j]; - } - } + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + _modelViewMatrix[i][j] = iModelViewMatrix[j][i]; + _glModelViewMatrix[i][j] = iModelViewMatrix[i][j]; + } + } - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - _projectionMatrix[i][j] = iProjectionMatrix[j][i]; - _glProjectionMatrix[i][j] = iProjectionMatrix[i][j]; - } - } + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + _projectionMatrix[i][j] = iProjectionMatrix[j][i]; + _glProjectionMatrix[i][j] = iProjectionMatrix[i][j]; + } + } - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - _transform[i][j] = 0; - for (unsigned int k = 0; k < 4; k++) - _transform[i][j] += _projectionMatrix[i][k] * _modelViewMatrix[k][j]; - } - } + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + _transform[i][j] = 0; + for (unsigned int k = 0; k < 4; k++) + _transform[i][j] += _projectionMatrix[i][k] * _modelViewMatrix[k][j]; + } + } - for (i = 0; i < 4; i++) { - _viewport[i] = iViewport[i]; - } - _Focal = iFocal; + for (i = 0; i < 4; i++) { + _viewport[i] = iViewport[i]; + } + _Focal = iFocal; - _isOrthographicProjection = (iProjectionMatrix[3][3] != 0.0); + _isOrthographicProjection = (iProjectionMatrix[3][3] != 0.0); } void SilhouetteGeomEngine::setFrustum(real iZNear, real iZFar) { - _znear = iZNear; - _zfar = iZFar; + _znear = iZNear; + _zfar = iZFar; } void SilhouetteGeomEngine::retrieveViewport(int viewport[4]) { - memcpy(viewport, _viewport, 4 * sizeof(int)); + memcpy(viewport, _viewport, 4 * sizeof(int)); } -void SilhouetteGeomEngine::ProjectSilhouette(vector& ioVertices) +void SilhouetteGeomEngine::ProjectSilhouette(vector &ioVertices) { - Vec3r newPoint; - vector::iterator sv, svend; - for (sv = ioVertices.begin(), svend = ioVertices.end(); sv != svend; sv++) { - GeomUtils::fromWorldToImage((*sv)->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport); - (*sv)->setPoint2D(newPoint); - } + Vec3r newPoint; + vector::iterator sv, svend; + for (sv = ioVertices.begin(), svend = ioVertices.end(); sv != svend; sv++) { + GeomUtils::fromWorldToImage( + (*sv)->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport); + (*sv)->setPoint2D(newPoint); + } } void SilhouetteGeomEngine::ProjectSilhouette(SVertex *ioVertex) { - Vec3r newPoint; - GeomUtils::fromWorldToImage(ioVertex->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport); - ioVertex->setPoint2D(newPoint); + Vec3r newPoint; + GeomUtils::fromWorldToImage( + ioVertex->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport); + ioVertex->setPoint2D(newPoint); } real SilhouetteGeomEngine::ImageToWorldParameter(FEdge *fe, real t) { - if (_isOrthographicProjection) - return t; + if (_isOrthographicProjection) + return t; - // we need to compute for each parameter t the corresponding parameter T which gives the intersection in 3D. - real T; + // we need to compute for each parameter t the corresponding parameter T which gives the intersection in 3D. + real T; - // suffix w for world, c for camera, r for retina, i for image - Vec3r Aw = (fe)->vertexA()->point3D(); - Vec3r Bw = (fe)->vertexB()->point3D(); - Vec3r Ac, Bc; - GeomUtils::fromWorldToCamera(Aw, Ac, _modelViewMatrix); - GeomUtils::fromWorldToCamera(Bw, Bc, _modelViewMatrix); - Vec3r ABc = Bc - Ac; + // suffix w for world, c for camera, r for retina, i for image + Vec3r Aw = (fe)->vertexA()->point3D(); + Vec3r Bw = (fe)->vertexB()->point3D(); + Vec3r Ac, Bc; + GeomUtils::fromWorldToCamera(Aw, Ac, _modelViewMatrix); + GeomUtils::fromWorldToCamera(Bw, Bc, _modelViewMatrix); + Vec3r ABc = Bc - Ac; #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Ac " << Ac << endl; - cout << "Bc " << Bc << endl; - cout << "ABc " << ABc << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Ac " << Ac << endl; + cout << "Bc " << Bc << endl; + cout << "ABc " << ABc << endl; + } #endif - Vec3r Ai = (fe)->vertexA()->point2D(); - Vec3r Bi = (fe)->vertexB()->point2D(); - Vec3r Ii = Ai + t * (Bi - Ai); // the intersection point in the 2D image space - Vec3r Ir, Ic; - GeomUtils::fromImageToRetina(Ii, Ir, _viewport); + Vec3r Ai = (fe)->vertexA()->point2D(); + Vec3r Bi = (fe)->vertexB()->point2D(); + Vec3r Ii = Ai + t * (Bi - Ai); // the intersection point in the 2D image space + Vec3r Ir, Ic; + GeomUtils::fromImageToRetina(Ii, Ir, _viewport); - real alpha, beta, denom; - real m11 = _projectionMatrix[0][0]; - real m13 = _projectionMatrix[0][2]; - real m22 = _projectionMatrix[1][1]; - real m23 = _projectionMatrix[1][2]; + real alpha, beta, denom; + real m11 = _projectionMatrix[0][0]; + real m13 = _projectionMatrix[0][2]; + real m22 = _projectionMatrix[1][1]; + real m23 = _projectionMatrix[1][2]; - if (fabs(ABc[0]) > 1.0e-6) { - alpha = ABc[2] / ABc[0]; - beta = Ac[2] - alpha * Ac[0]; - denom = alpha * (Ir[0] + m13) + m11; - if (fabs(denom) < 1.0e-6) - goto iter; - Ic[0] = -beta * (Ir[0] + m13) / denom; + if (fabs(ABc[0]) > 1.0e-6) { + alpha = ABc[2] / ABc[0]; + beta = Ac[2] - alpha * Ac[0]; + denom = alpha * (Ir[0] + m13) + m11; + if (fabs(denom) < 1.0e-6) + goto iter; + Ic[0] = -beta * (Ir[0] + m13) / denom; #if 0 - Ic[1] = -(Ir[1] + m23) * (alpha * Ic[0] + beta) / m22; - Ic[2] = alpha * (Ic[0] - Ac[0]) + Ac[2]; + Ic[1] = -(Ir[1] + m23) * (alpha * Ic[0] + beta) / m22; + Ic[2] = alpha * (Ic[0] - Ac[0]) + Ac[2]; #endif - T = (Ic[0] - Ac[0]) / ABc[0]; - - } - else if (fabs(ABc[1]) > 1.0e-6) { - alpha = ABc[2] / ABc[1]; - beta = Ac[2] - alpha * Ac[1]; - denom = alpha * (Ir[1] + m23) + m22; - if (fabs(denom) < 1.0e-6) - goto iter; - Ic[1] = -beta * (Ir[1] + m23) / denom; + T = (Ic[0] - Ac[0]) / ABc[0]; + } + else if (fabs(ABc[1]) > 1.0e-6) { + alpha = ABc[2] / ABc[1]; + beta = Ac[2] - alpha * Ac[1]; + denom = alpha * (Ir[1] + m23) + m22; + if (fabs(denom) < 1.0e-6) + goto iter; + Ic[1] = -beta * (Ir[1] + m23) / denom; #if 0 - Ic[0] = -(Ir[0] + m13) * (alpha * Ic[1] + beta) / m11; - Ic[2] = alpha * (Ic[1] - Ac[1]) + Ac[2]; + Ic[0] = -(Ir[0] + m13) * (alpha * Ic[1] + beta) / m11; + Ic[2] = alpha * (Ic[1] - Ac[1]) + Ac[2]; #endif - T = (Ic[1] - Ac[1]) / ABc[1]; - } - else { -iter: - bool x_coords, less_than; - if (fabs(Bi[0] - Ai[0]) > 1.0e-6) { - x_coords = true; - less_than = Ai[0] < Bi[0]; - } - else { - x_coords = false; - less_than = Ai[1] < Bi[1]; - } - Vec3r Pc, Pr, Pi; - real T_sta = 0.0; - real T_end = 1.0; - real delta_x, delta_y, dist, dist_threshold = 1.0e-6; - int i, max_iters = 100; - for (i = 0; i < max_iters; i++) { - T = T_sta + 0.5 * (T_end - T_sta); - Pc = Ac + T * ABc; - GeomUtils::fromCameraToRetina(Pc, Pr, _projectionMatrix); - GeomUtils::fromRetinaToImage(Pr, Pi, _viewport); - delta_x = Ii[0] - Pi[0]; - delta_y = Ii[1] - Pi[1]; - dist = sqrt(delta_x * delta_x + delta_y * delta_y); - if (dist < dist_threshold) - break; - if (x_coords) { - if (less_than) { - if (Pi[0] < Ii[0]) - T_sta = T; - else - T_end = T; - } - else { - if (Pi[0] > Ii[0]) - T_sta = T; - else - T_end = T; - } - } - else { - if (less_than) { - if (Pi[1] < Ii[1]) - T_sta = T; - else - T_end = T; - } - else { - if (Pi[1] > Ii[1]) - T_sta = T; - else - T_end = T; - } - } - } + T = (Ic[1] - Ac[1]) / ABc[1]; + } + else { + iter: + bool x_coords, less_than; + if (fabs(Bi[0] - Ai[0]) > 1.0e-6) { + x_coords = true; + less_than = Ai[0] < Bi[0]; + } + else { + x_coords = false; + less_than = Ai[1] < Bi[1]; + } + Vec3r Pc, Pr, Pi; + real T_sta = 0.0; + real T_end = 1.0; + real delta_x, delta_y, dist, dist_threshold = 1.0e-6; + int i, max_iters = 100; + for (i = 0; i < max_iters; i++) { + T = T_sta + 0.5 * (T_end - T_sta); + Pc = Ac + T * ABc; + GeomUtils::fromCameraToRetina(Pc, Pr, _projectionMatrix); + GeomUtils::fromRetinaToImage(Pr, Pi, _viewport); + delta_x = Ii[0] - Pi[0]; + delta_y = Ii[1] - Pi[1]; + dist = sqrt(delta_x * delta_x + delta_y * delta_y); + if (dist < dist_threshold) + break; + if (x_coords) { + if (less_than) { + if (Pi[0] < Ii[0]) + T_sta = T; + else + T_end = T; + } + else { + if (Pi[0] > Ii[0]) + T_sta = T; + else + T_end = T; + } + } + else { + if (less_than) { + if (Pi[1] < Ii[1]) + T_sta = T; + else + T_end = T; + } + else { + if (Pi[1] > Ii[1]) + T_sta = T; + else + T_end = T; + } + } + } #if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "SilhouetteGeomEngine::ImageToWorldParameter(): #iters = " << i << ", dist = " << dist << "\n"; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "SilhouetteGeomEngine::ImageToWorldParameter(): #iters = " << i << ", dist = " << dist << "\n"; + } #endif - if (i == max_iters && G.debug & G_DEBUG_FREESTYLE) { - cout << "SilhouetteGeomEngine::ImageToWorldParameter(): reached to max_iters (dist = " << dist << ")\n"; - } - } + if (i == max_iters && G.debug & G_DEBUG_FREESTYLE) { + cout << "SilhouetteGeomEngine::ImageToWorldParameter(): reached to max_iters (dist = " + << dist << ")\n"; + } + } - return T; + return T; } -Vec3r SilhouetteGeomEngine::WorldToImage(const Vec3r& M) +Vec3r SilhouetteGeomEngine::WorldToImage(const Vec3r &M) { - Vec3r newPoint; - GeomUtils::fromWorldToImage(M, newPoint, _transform, _viewport); - return newPoint; + Vec3r newPoint; + GeomUtils::fromWorldToImage(M, newPoint, _transform, _viewport); + return newPoint; } -Vec3r SilhouetteGeomEngine::CameraToImage(const Vec3r& M) +Vec3r SilhouetteGeomEngine::CameraToImage(const Vec3r &M) { - Vec3r newPoint, p; - GeomUtils::fromCameraToRetina(M, p, _projectionMatrix); - GeomUtils::fromRetinaToImage(p, newPoint, _viewport); - return newPoint; + Vec3r newPoint, p; + GeomUtils::fromCameraToRetina(M, p, _projectionMatrix); + GeomUtils::fromRetinaToImage(p, newPoint, _viewport); + return newPoint; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.h b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.h index 6e46979026a..306eb3a55be 100644 --- a/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.h +++ b/source/blender/freestyle/intern/view_map/SilhouetteGeomEngine.h @@ -30,7 +30,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -40,99 +40,100 @@ using namespace Geometry; class SVertex; class FEdge; -class SilhouetteGeomEngine -{ -private: - // The viewpoint under which the silhouette has to be computed - static Vec3r _Viewpoint; - static real _translation[3]; - // the model view matrix (_modelViewMatrix[i][j] means element of line i and column j) - static real _modelViewMatrix[4][4]; - // the projection matrix (_projectionMatrix[i][j] means element of line i and column j) - static real _projectionMatrix[4][4]; - // the global transformation from world to screen (projection included) - // (_transform[i][j] means element of line i and column j) - static real _transform[4][4]; - // the viewport - static int _viewport[4]; - static real _Focal; - - static real _znear; - static real _zfar; - - // GL style (column major) projection matrix - static real _glProjectionMatrix[4][4]; - // GL style (column major) model view matrix - static real _glModelViewMatrix[4][4]; - - static bool _isOrthographicProjection; - - static SilhouetteGeomEngine *_pInstance; - -public: - /*! retrieves an instance on the singleton */ - static SilhouetteGeomEngine *getInstance() - { - if (_pInstance == NULL) { - _pInstance = new SilhouetteGeomEngine; - } - return _pInstance; - } - - /*! Sets the current viewpoint */ - static inline void setViewpoint(const Vec3r& ivp) - { - _Viewpoint = ivp; - } - - /*! Sets the current transformation - * iModelViewMatrix - * The 4x4 model view matrix, in column major order (openGL like). - * iProjection matrix - * The 4x4 projection matrix, in column major order (openGL like). - * iViewport - * The viewport. 4 real array: origin.x, origin.y, width, length - * iFocal - * The focal length - */ - static void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], - const int iViewport[4], real iFocal); - - /*! Sets the current znear and zfar */ - static void setFrustum(real iZNear, real iZFar); - - /* accessors */ - static void retrieveViewport(int viewport[4]); - - /*! Projects the silhouette in camera coordinates - * This method modifies the ioEdges passed as argument. - * ioVertices - * The vertices to project. It is modified during the operation. - */ - static void ProjectSilhouette(std::vector& ioVertices); - static void ProjectSilhouette(SVertex *ioVertex); - - /*! transforms the parameter t defining a 2D intersection for edge fe in order to obtain - * the parameter giving the corresponding 3D intersection. - * Returns the 3D parameter - * fe - * The edge - * t - * The parameter for the 2D intersection. - */ - static real ImageToWorldParameter(FEdge *fe, real t); - - /*! From world to image */ - static Vec3r WorldToImage(const Vec3r& M); - - /*! From camera to image */ - static Vec3r CameraToImage(const Vec3r& M); +class SilhouetteGeomEngine { + private: + // The viewpoint under which the silhouette has to be computed + static Vec3r _Viewpoint; + static real _translation[3]; + // the model view matrix (_modelViewMatrix[i][j] means element of line i and column j) + static real _modelViewMatrix[4][4]; + // the projection matrix (_projectionMatrix[i][j] means element of line i and column j) + static real _projectionMatrix[4][4]; + // the global transformation from world to screen (projection included) + // (_transform[i][j] means element of line i and column j) + static real _transform[4][4]; + // the viewport + static int _viewport[4]; + static real _Focal; + + static real _znear; + static real _zfar; + + // GL style (column major) projection matrix + static real _glProjectionMatrix[4][4]; + // GL style (column major) model view matrix + static real _glModelViewMatrix[4][4]; + + static bool _isOrthographicProjection; + + static SilhouetteGeomEngine *_pInstance; + + public: + /*! retrieves an instance on the singleton */ + static SilhouetteGeomEngine *getInstance() + { + if (_pInstance == NULL) { + _pInstance = new SilhouetteGeomEngine; + } + return _pInstance; + } + + /*! Sets the current viewpoint */ + static inline void setViewpoint(const Vec3r &ivp) + { + _Viewpoint = ivp; + } + + /*! Sets the current transformation + * iModelViewMatrix + * The 4x4 model view matrix, in column major order (openGL like). + * iProjection matrix + * The 4x4 projection matrix, in column major order (openGL like). + * iViewport + * The viewport. 4 real array: origin.x, origin.y, width, length + * iFocal + * The focal length + */ + static void setTransform(const real iModelViewMatrix[4][4], + const real iProjectionMatrix[4][4], + const int iViewport[4], + real iFocal); + + /*! Sets the current znear and zfar */ + static void setFrustum(real iZNear, real iZFar); + + /* accessors */ + static void retrieveViewport(int viewport[4]); + + /*! Projects the silhouette in camera coordinates + * This method modifies the ioEdges passed as argument. + * ioVertices + * The vertices to project. It is modified during the operation. + */ + static void ProjectSilhouette(std::vector &ioVertices); + static void ProjectSilhouette(SVertex *ioVertex); + + /*! transforms the parameter t defining a 2D intersection for edge fe in order to obtain + * the parameter giving the corresponding 3D intersection. + * Returns the 3D parameter + * fe + * The edge + * t + * The parameter for the 2D intersection. + */ + static real ImageToWorldParameter(FEdge *fe, real t); + + /*! From world to image */ + static Vec3r WorldToImage(const Vec3r &M); + + /*! From camera to image */ + static Vec3r CameraToImage(const Vec3r &M); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SilhouetteGeomEngine") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SilhouetteGeomEngine") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_SILHOUETTE_GEOM_ENGINE_H__ +#endif // __FREESTYLE_SILHOUETTE_GEOM_ENGINE_H__ diff --git a/source/blender/freestyle/intern/view_map/SphericalGrid.cpp b/source/blender/freestyle/intern/view_map/SphericalGrid.cpp index 03a50331dc9..1a7f01d288f 100644 --- a/source/blender/freestyle/intern/view_map/SphericalGrid.cpp +++ b/source/blender/freestyle/intern/view_map/SphericalGrid.cpp @@ -38,207 +38,224 @@ namespace Freestyle { // Cell ///////// -SphericalGrid::Cell::Cell() {} +SphericalGrid::Cell::Cell() +{ +} -SphericalGrid::Cell::~Cell() {} +SphericalGrid::Cell::~Cell() +{ +} void SphericalGrid::Cell::setDimensions(real x, real y, real sizeX, real sizeY) { - const real epsilon = 1.0e-06; - boundary[0] = x - epsilon; - boundary[1] = x + sizeX + epsilon; - boundary[2] = y - epsilon; - boundary[3] = y + sizeY + epsilon; + const real epsilon = 1.0e-06; + boundary[0] = x - epsilon; + boundary[1] = x + sizeX + epsilon; + boundary[2] = y - epsilon; + boundary[3] = y + sizeY + epsilon; } bool SphericalGrid::Cell::compareOccludersByShallowestPoint(const SphericalGrid::OccluderData *a, const SphericalGrid::OccluderData *b) { - return a->shallowest < b->shallowest; + return a->shallowest < b->shallowest; } void SphericalGrid::Cell::indexPolygons() { - // Sort occluders by their shallowest points. - sort(faces.begin(), faces.end(), compareOccludersByShallowestPoint); + // Sort occluders by their shallowest points. + sort(faces.begin(), faces.end(), compareOccludersByShallowestPoint); } // Iterator ////////////////// -SphericalGrid::Iterator::Iterator(SphericalGrid& grid, Vec3r& center, real /*epsilon*/) -: _target(SphericalGrid::Transform::sphericalProjection(center)), _foundOccludee(false) +SphericalGrid::Iterator::Iterator(SphericalGrid &grid, Vec3r ¢er, real /*epsilon*/) + : _target(SphericalGrid::Transform::sphericalProjection(center)), _foundOccludee(false) { - // Find target cell - _cell = grid.findCell(_target); + // Find target cell + _cell = grid.findCell(_target); #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Searching for occluders of edge centered at " << _target << " in cell [" << - _cell->boundary[0] << ", " << _cell->boundary[1] << ", " << _cell->boundary[2] << - ", " << _cell->boundary[3] << "] (" << _cell->faces.size() << " occluders)" << endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Searching for occluders of edge centered at " << _target << " in cell [" + << _cell->boundary[0] << ", " << _cell->boundary[1] << ", " << _cell->boundary[2] << ", " + << _cell->boundary[3] << "] (" << _cell->faces.size() << " occluders)" << endl; + } #endif - // Set iterator - _current = _cell->faces.begin(); + // Set iterator + _current = _cell->faces.begin(); } -SphericalGrid::Iterator::~Iterator() {} +SphericalGrid::Iterator::~Iterator() +{ +} // SphericalGrid ///////////////// -SphericalGrid::SphericalGrid(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap, - Vec3r& viewpoint, bool enableQI) -: _viewpoint(viewpoint), _enableQI(enableQI) -{ - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Generate Cell structure" << endl; - } - // Generate Cell structure - assignCells(source, density, viewMap); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Distribute occluders" << endl; - } - // Fill Cells - distributePolygons(source); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Reorganize cells" << endl; - } - // Reorganize Cells - reorganizeCells(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Ready to use SphericalGrid" << endl; - } -} - -SphericalGrid::~SphericalGrid() {} - -void SphericalGrid::assignCells(OccluderSource& /*source*/, GridDensityProvider& density, ViewMap *viewMap) -{ - _cellSize = density.cellSize(); - _cellsX = density.cellsX(); - _cellsY = density.cellsY(); - _cellOrigin[0] = density.cellOrigin(0); - _cellOrigin[1] = density.cellOrigin(1); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Using " << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl; - cout << "Cell origin: " << _cellOrigin[0] << ", " << _cellOrigin[1] << endl; - } - - // Now allocate the cell table and fill it with default (empty) cells - _cells.resize(_cellsX * _cellsY); - for (cellContainer::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { - (*i) = NULL; - } - - // Identify cells that will be used, and set the dimensions for each - ViewMap::fedges_container& fedges = viewMap->FEdges(); - for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; ++f) { - if ((*f)->isInImage()) { - Vec3r point = SphericalGrid::Transform::sphericalProjection((*f)->center3d()); - unsigned i, j; - getCellCoordinates(point, i, j); - if (_cells[i * _cellsY + j] == NULL) { - // This is an uninitialized cell - real x, y, width, height; - - x = _cellOrigin[0] + _cellSize * i; - width = _cellSize; - - y = _cellOrigin[1] + _cellSize * j; - height = _cellSize; - - // Initialize cell - Cell *b = _cells[i * _cellsY + j] = new Cell(); - b->setDimensions(x, y, width, height); - } - } - } -} - -void SphericalGrid::distributePolygons(OccluderSource& source) -{ - unsigned long nFaces = 0; - unsigned long nKeptFaces = 0; - - for (source.begin(); source.isValid(); source.next()) { - OccluderData *occluder = NULL; - - try { - if (insertOccluder(source, occluder)) { - _faces.push_back(occluder); - ++nKeptFaces; - } - } - catch (...) { - // If an exception was thrown, _faces.push_back() cannot have succeeded. Occluder is not owned by anyone, - // and must be deleted. If the exception was thrown before or during new OccluderData(), then - // occluder is NULL, and this delete is harmless. - delete occluder; - throw; - } - ++nFaces; - } - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Distributed " << nFaces << " occluders. Retained " << nKeptFaces << "." << endl; - } +SphericalGrid::SphericalGrid(OccluderSource &source, + GridDensityProvider &density, + ViewMap *viewMap, + Vec3r &viewpoint, + bool enableQI) + : _viewpoint(viewpoint), _enableQI(enableQI) +{ + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Generate Cell structure" << endl; + } + // Generate Cell structure + assignCells(source, density, viewMap); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Distribute occluders" << endl; + } + // Fill Cells + distributePolygons(source); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Reorganize cells" << endl; + } + // Reorganize Cells + reorganizeCells(); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Ready to use SphericalGrid" << endl; + } +} + +SphericalGrid::~SphericalGrid() +{ +} + +void SphericalGrid::assignCells(OccluderSource & /*source*/, + GridDensityProvider &density, + ViewMap *viewMap) +{ + _cellSize = density.cellSize(); + _cellsX = density.cellsX(); + _cellsY = density.cellsY(); + _cellOrigin[0] = density.cellOrigin(0); + _cellOrigin[1] = density.cellOrigin(1); + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Using " << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." + << endl; + cout << "Cell origin: " << _cellOrigin[0] << ", " << _cellOrigin[1] << endl; + } + + // Now allocate the cell table and fill it with default (empty) cells + _cells.resize(_cellsX * _cellsY); + for (cellContainer::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { + (*i) = NULL; + } + + // Identify cells that will be used, and set the dimensions for each + ViewMap::fedges_container &fedges = viewMap->FEdges(); + for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; + ++f) { + if ((*f)->isInImage()) { + Vec3r point = SphericalGrid::Transform::sphericalProjection((*f)->center3d()); + unsigned i, j; + getCellCoordinates(point, i, j); + if (_cells[i * _cellsY + j] == NULL) { + // This is an uninitialized cell + real x, y, width, height; + + x = _cellOrigin[0] + _cellSize * i; + width = _cellSize; + + y = _cellOrigin[1] + _cellSize * j; + height = _cellSize; + + // Initialize cell + Cell *b = _cells[i * _cellsY + j] = new Cell(); + b->setDimensions(x, y, width, height); + } + } + } +} + +void SphericalGrid::distributePolygons(OccluderSource &source) +{ + unsigned long nFaces = 0; + unsigned long nKeptFaces = 0; + + for (source.begin(); source.isValid(); source.next()) { + OccluderData *occluder = NULL; + + try { + if (insertOccluder(source, occluder)) { + _faces.push_back(occluder); + ++nKeptFaces; + } + } + catch (...) { + // If an exception was thrown, _faces.push_back() cannot have succeeded. Occluder is not owned by anyone, + // and must be deleted. If the exception was thrown before or during new OccluderData(), then + // occluder is NULL, and this delete is harmless. + delete occluder; + throw; + } + ++nFaces; + } + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Distributed " << nFaces << " occluders. Retained " << nKeptFaces << "." << endl; + } } void SphericalGrid::reorganizeCells() { - // Sort the occluders by shallowest point - for (vector::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { - if (*i != NULL) { - (*i)->indexPolygons(); - } - } + // Sort the occluders by shallowest point + for (vector::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) { + if (*i != NULL) { + (*i)->indexPolygons(); + } + } } -void SphericalGrid::getCellCoordinates(const Vec3r& point, unsigned& x, unsigned& y) +void SphericalGrid::getCellCoordinates(const Vec3r &point, unsigned &x, unsigned &y) { - x = min(_cellsX - 1, (unsigned) floor (max((double) 0.0f, point[0] - _cellOrigin[0]) / _cellSize)); - y = min(_cellsY - 1, (unsigned) floor (max((double) 0.0f, point[1] - _cellOrigin[1]) / _cellSize)); + x = min(_cellsX - 1, (unsigned)floor(max((double)0.0f, point[0] - _cellOrigin[0]) / _cellSize)); + y = min(_cellsY - 1, (unsigned)floor(max((double)0.0f, point[1] - _cellOrigin[1]) / _cellSize)); } -SphericalGrid::Cell *SphericalGrid::findCell(const Vec3r& point) +SphericalGrid::Cell *SphericalGrid::findCell(const Vec3r &point) { - unsigned x, y; - getCellCoordinates(point, x, y); - return _cells[x * _cellsY + y]; + unsigned x, y; + getCellCoordinates(point, x, y); + return _cells[x * _cellsY + y]; } bool SphericalGrid::orthographicProjection() const { - return false; + return false; } -const Vec3r& SphericalGrid::viewpoint() const +const Vec3r &SphericalGrid::viewpoint() const { - return _viewpoint; + return _viewpoint; } bool SphericalGrid::enableQI() const { - return _enableQI; + return _enableQI; } -SphericalGrid::Transform::Transform () : GridHelpers::Transform() {} +SphericalGrid::Transform::Transform() : GridHelpers::Transform() +{ +} -Vec3r SphericalGrid::Transform::operator()(const Vec3r& point) const +Vec3r SphericalGrid::Transform::operator()(const Vec3r &point) const { - return sphericalProjection(point); + return sphericalProjection(point); } -Vec3r SphericalGrid::Transform::sphericalProjection(const Vec3r& M) +Vec3r SphericalGrid::Transform::sphericalProjection(const Vec3r &M) { - Vec3r newPoint; + Vec3r newPoint; - newPoint[0] = ::atan(M[0] / M[2]); - newPoint[1] = ::atan(M[1] / M[2]); - newPoint[2] = ::sqrt(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]); + newPoint[0] = ::atan(M[0] / M[2]); + newPoint[1] = ::atan(M[1] / M[2]); + newPoint[2] = ::sqrt(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]); - return newPoint; + return newPoint; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/SphericalGrid.h b/source/blender/freestyle/intern/view_map/SphericalGrid.h index 19c2461ce01..ae00c270c1d 100644 --- a/source/blender/freestyle/intern/view_map/SphericalGrid.h +++ b/source/blender/freestyle/intern/view_map/SphericalGrid.h @@ -44,388 +44,389 @@ #include "BKE_global.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class SphericalGrid -{ -public: - // Helper classes - struct OccluderData - { - explicit OccluderData (OccluderSource& source, Polygon3r& p); - Polygon3r poly; - Polygon3r cameraSpacePolygon; - real shallowest, deepest; - // N.B. We could, of course, store face in poly's userdata member, like the old ViewMapBuilder code does. - // However, code comments make it clear that userdata is deprecated, so we avoid the temptation to save - // 4 or 8 bytes. - WFace *face; +class SphericalGrid { + public: + // Helper classes + struct OccluderData { + explicit OccluderData(OccluderSource &source, Polygon3r &p); + Polygon3r poly; + Polygon3r cameraSpacePolygon; + real shallowest, deepest; + // N.B. We could, of course, store face in poly's userdata member, like the old ViewMapBuilder code does. + // However, code comments make it clear that userdata is deprecated, so we avoid the temptation to save + // 4 or 8 bytes. + WFace *face; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid:OccluderData") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid:OccluderData") #endif - }; - -private: - struct Cell - { - // Can't store Cell in a vector without copy and assign - //Cell(const Cell& other); - //Cell& operator=(const Cell& other); - - explicit Cell(); - ~Cell(); - - static bool compareOccludersByShallowestPoint(const OccluderData *a, const OccluderData *b); - - void setDimensions(real x, real y, real sizeX, real sizeY); - void checkAndInsert(OccluderSource& source, Polygon3r& poly, OccluderData*& occluder); - void indexPolygons(); - - real boundary[4]; - //deque faces; - vector faces; - }; - -public: - /*! Iterator needs to allow the user to avoid full 3D comparison in two cases: - * - * (1) Where (*current)->deepest < target[2], where the occluder is unambiguously in front of the target point. - * - * (2) Where (*current)->shallowest > target[2], where the occluder is unambiguously in back of the target point. - * - * In addition, when used by OptimizedFindOccludee, Iterator should stop iterating as soon as it has an occludee - * candidate and (*current)->shallowest > candidate[2], because at that point forward no new occluder could - * possibly be a better occludee. - */ - - class Iterator - { - public: - // epsilon is not used in this class, but other grids with the same interface may need an epsilon - explicit Iterator(SphericalGrid& grid, Vec3r& center, real epsilon = 1.0e-06); - ~Iterator(); - void initBeforeTarget(); - void initAfterTarget(); - void nextOccluder(); - void nextOccludee(); - bool validBeforeTarget(); - bool validAfterTarget(); - WFace *getWFace() const; - Polygon3r *getCameraSpacePolygon(); - void reportDepth(Vec3r origin, Vec3r u, real t); - private: - bool testOccluder(bool wantOccludee); - void markCurrentOccludeeCandidate(real depth); - - Cell *_cell; - Vec3r _target; - bool _foundOccludee; - real _occludeeDepth; - //deque::iterator _current, _occludeeCandidate; - vector::iterator _current, _occludeeCandidate; + }; + + private: + struct Cell { + // Can't store Cell in a vector without copy and assign + //Cell(const Cell& other); + //Cell& operator=(const Cell& other); + + explicit Cell(); + ~Cell(); + + static bool compareOccludersByShallowestPoint(const OccluderData *a, const OccluderData *b); + + void setDimensions(real x, real y, real sizeX, real sizeY); + void checkAndInsert(OccluderSource &source, Polygon3r &poly, OccluderData *&occluder); + void indexPolygons(); + + real boundary[4]; + //deque faces; + vector faces; + }; + + public: + /*! Iterator needs to allow the user to avoid full 3D comparison in two cases: + * + * (1) Where (*current)->deepest < target[2], where the occluder is unambiguously in front of the target point. + * + * (2) Where (*current)->shallowest > target[2], where the occluder is unambiguously in back of the target point. + * + * In addition, when used by OptimizedFindOccludee, Iterator should stop iterating as soon as it has an occludee + * candidate and (*current)->shallowest > candidate[2], because at that point forward no new occluder could + * possibly be a better occludee. + */ + + class Iterator { + public: + // epsilon is not used in this class, but other grids with the same interface may need an epsilon + explicit Iterator(SphericalGrid &grid, Vec3r ¢er, real epsilon = 1.0e-06); + ~Iterator(); + void initBeforeTarget(); + void initAfterTarget(); + void nextOccluder(); + void nextOccludee(); + bool validBeforeTarget(); + bool validAfterTarget(); + WFace *getWFace() const; + Polygon3r *getCameraSpacePolygon(); + void reportDepth(Vec3r origin, Vec3r u, real t); + + private: + bool testOccluder(bool wantOccludee); + void markCurrentOccludeeCandidate(real depth); + + Cell *_cell; + Vec3r _target; + bool _foundOccludee; + real _occludeeDepth; + //deque::iterator _current, _occludeeCandidate; + vector::iterator _current, _occludeeCandidate; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid:Iterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid:Iterator") #endif - - }; - - class Transform : public GridHelpers::Transform - { - public: - explicit Transform(); - explicit Transform(Transform& other); - Vec3r operator()(const Vec3r& point) const; - static Vec3r sphericalProjection(const Vec3r& M); - }; - -private: - // Prevent implicit copies and assignments. - SphericalGrid(const SphericalGrid& other); - SphericalGrid& operator=(const SphericalGrid& other); - -public: - explicit SphericalGrid(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap, - Vec3r& viewpoint, bool enableQI); - virtual ~SphericalGrid(); - - // Generate Cell structure - void assignCells(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap); - // Fill Cells - void distributePolygons(OccluderSource& source); - // Insert one polygon into each matching cell, return true if any cell consumes the polygon - bool insertOccluder(OccluderSource& source, OccluderData*& occluder); - // Sort occluders in each cell - void reorganizeCells(); - - Cell *findCell(const Vec3r& point); - - // Accessors: - bool orthographicProjection() const; - const Vec3r& viewpoint() const; - bool enableQI() const; - -private: - void getCellCoordinates(const Vec3r& point, unsigned& x, unsigned& y); - - typedef PointerSequence, Cell*> cellContainer; - //typedef PointerSequence, OccluderData*> occluderContainer; - typedef PointerSequence, OccluderData*> occluderContainer; - unsigned _cellsX, _cellsY; - float _cellSize; - float _cellOrigin[2]; - cellContainer _cells; - occluderContainer _faces; - Vec3r _viewpoint; - bool _enableQI; + }; + + class Transform : public GridHelpers::Transform { + public: + explicit Transform(); + explicit Transform(Transform &other); + Vec3r operator()(const Vec3r &point) const; + static Vec3r sphericalProjection(const Vec3r &M); + }; + + private: + // Prevent implicit copies and assignments. + SphericalGrid(const SphericalGrid &other); + SphericalGrid &operator=(const SphericalGrid &other); + + public: + explicit SphericalGrid(OccluderSource &source, + GridDensityProvider &density, + ViewMap *viewMap, + Vec3r &viewpoint, + bool enableQI); + virtual ~SphericalGrid(); + + // Generate Cell structure + void assignCells(OccluderSource &source, GridDensityProvider &density, ViewMap *viewMap); + // Fill Cells + void distributePolygons(OccluderSource &source); + // Insert one polygon into each matching cell, return true if any cell consumes the polygon + bool insertOccluder(OccluderSource &source, OccluderData *&occluder); + // Sort occluders in each cell + void reorganizeCells(); + + Cell *findCell(const Vec3r &point); + + // Accessors: + bool orthographicProjection() const; + const Vec3r &viewpoint() const; + bool enableQI() const; + + private: + void getCellCoordinates(const Vec3r &point, unsigned &x, unsigned &y); + + typedef PointerSequence, Cell *> cellContainer; + //typedef PointerSequence, OccluderData*> occluderContainer; + typedef PointerSequence, OccluderData *> occluderContainer; + unsigned _cellsX, _cellsY; + float _cellSize; + float _cellOrigin[2]; + cellContainer _cells; + occluderContainer _faces; + Vec3r _viewpoint; + bool _enableQI; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SphericalGrid") #endif }; inline void SphericalGrid::Iterator::initBeforeTarget() { - _current = _cell->faces.begin(); - while (_current != _cell->faces.end() && !testOccluder(false)) { - ++_current; - } + _current = _cell->faces.begin(); + while (_current != _cell->faces.end() && !testOccluder(false)) { + ++_current; + } } inline void SphericalGrid::Iterator::initAfterTarget() { - if (_foundOccludee) { + if (_foundOccludee) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tStarting occludee search from occludeeCandidate at depth " << - _occludeeDepth << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth + << std::endl; + } #endif - _current = _occludeeCandidate; - return; - } + _current = _occludeeCandidate; + return; + } #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tStarting occludee search from current position" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tStarting occludee search from current position" << std::endl; + } #endif - while (_current != _cell->faces.end() && !testOccluder(true)) { - ++_current; - } + while (_current != _cell->faces.end() && !testOccluder(true)) { + ++_current; + } } inline bool SphericalGrid::Iterator::testOccluder(bool wantOccludee) { - // End-of-list is not even a valid iterator position - if (_current == _cell->faces.end()) { - // Returning true seems strange, but it will break us out of whatever loop is calling testOccluder, and - // _current=_cell->face.end() will make the calling routine give up. - return true; - } + // End-of-list is not even a valid iterator position + if (_current == _cell->faces.end()) { + // Returning true seems strange, but it will break us out of whatever loop is calling testOccluder, and + // _current=_cell->face.end() will make the calling routine give up. + return true; + } #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\tTesting occluder " << (*_current)->poly.getVertices()[0]; - for (unsigned int i = 1; i < (*_current)->poly.getVertices().size(); ++i) { - std::cout << ", " << (*_current)->poly.getVertices()[i]; - } - std::cout << " from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\tTesting occluder " << (*_current)->poly.getVertices()[0]; + for (unsigned int i = 1; i < (*_current)->poly.getVertices().size(); ++i) { + std::cout << ", " << (*_current)->poly.getVertices()[i]; + } + std::cout << " from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl; + } #endif - // If we have an occluder candidate and we are unambiguously after it, abort - if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) { + // If we have an occluder candidate and we are unambiguously after it, abort + if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl; + } #endif - _current = _cell->faces.end(); + _current = _cell->faces.end(); - // See note above - return true; - } + // See note above + return true; + } - // Specific continue or stop conditions when searching for each type - if (wantOccludee) { - if ((*_current)->deepest < _target[2]) { + // Specific continue or stop conditions when searching for each type + if (wantOccludee) { + if ((*_current)->deepest < _target[2]) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tSkipping: shallower than target while looking for occludee" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tSkipping: shallower than target while looking for occludee" << std::endl; + } #endif - return false; - } - } - else { - if ((*_current)->shallowest > _target[2]) { + return false; + } + } + else { + if ((*_current)->shallowest > _target[2]) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tStopping: deeper than target while looking for occluder" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tStopping: deeper than target while looking for occluder" << std::endl; + } #endif - return true; - } - } + return true; + } + } - // Depthwise, this is a valid occluder. + // Depthwise, this is a valid occluder. - // Check to see if target is in the 2D bounding box - Vec3r bbMin, bbMax; - (*_current)->poly.getBBox(bbMin, bbMax); - if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] || _target[1] > bbMax[1]) { + // Check to see if target is in the 2D bounding box + Vec3r bbMin, bbMax; + (*_current)->poly.getBBox(bbMin, bbMax); + if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] || + _target[1] > bbMax[1]) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tSkipping: bounding box violation" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tSkipping: bounding box violation" << std::endl; + } #endif - return false; - } + return false; + } - // We've done all the corner cutting we can. Let the caller work out whether or not the geometry is correct. - return true; + // We've done all the corner cutting we can. Let the caller work out whether or not the geometry is correct. + return true; } inline void SphericalGrid::Iterator::reportDepth(Vec3r origin, Vec3r u, real t) { - // The reported depth is the length of a ray in camera space. We need to convert it into the distance from viewpoint - // If origin is the viewpoint, depth == t. A future optimization could allow the caller to tell us if origin is - // viewponit or target, at the cost of changing the OptimizedGrid API. - real depth = (origin + u * t).norm(); + // The reported depth is the length of a ray in camera space. We need to convert it into the distance from viewpoint + // If origin is the viewpoint, depth == t. A future optimization could allow the caller to tell us if origin is + // viewponit or target, at the cost of changing the OptimizedGrid API. + real depth = (origin + u * t).norm(); #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tReporting depth of occluder/ee: " << depth; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tReporting depth of occluder/ee: " << depth; + } #endif - if (depth > _target[2]) { + if (depth > _target[2]) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << " is deeper than target" << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << " is deeper than target" << std::endl; + } #endif - // If the current occluder is the best occludee so far, save it. - if (! _foundOccludee || _occludeeDepth > depth) { - markCurrentOccludeeCandidate(depth); - } - } - else { + // If the current occluder is the best occludee so far, save it. + if (!_foundOccludee || _occludeeDepth > depth) { + markCurrentOccludeeCandidate(depth); + } + } + else { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << std::endl; + } #endif - } + } } inline void SphericalGrid::Iterator::nextOccluder() { - if (_current != _cell->faces.end()) { - do { - ++_current; - } while (_current != _cell->faces.end() && !testOccluder(false)); - } + if (_current != _cell->faces.end()) { + do { + ++_current; + } while (_current != _cell->faces.end() && !testOccluder(false)); + } } inline void SphericalGrid::Iterator::nextOccludee() { - if (_current != _cell->faces.end()) { - do { - ++_current; - } while (_current != _cell->faces.end() && !testOccluder(true)); - } + if (_current != _cell->faces.end()) { + do { + ++_current; + } while (_current != _cell->faces.end() && !testOccluder(true)); + } } inline bool SphericalGrid::Iterator::validBeforeTarget() { - return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2]; + return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2]; } inline bool SphericalGrid::Iterator::validAfterTarget() { - return _current != _cell->faces.end(); + return _current != _cell->faces.end(); } inline void SphericalGrid::Iterator::markCurrentOccludeeCandidate(real depth) { #if SPHERICAL_GRID_LOGGING - if (G.debug & G_DEBUG_FREESTYLE) { - std::cout << "\t\tFound occludeeCandidate at depth " << depth << std::endl; - } + if (G.debug & G_DEBUG_FREESTYLE) { + std::cout << "\t\tFound occludeeCandidate at depth " << depth << std::endl; + } #endif - _occludeeCandidate = _current; - _occludeeDepth = depth; - _foundOccludee = true; + _occludeeCandidate = _current; + _occludeeDepth = depth; + _foundOccludee = true; } inline WFace *SphericalGrid::Iterator::getWFace() const { - return (*_current)->face; + return (*_current)->face; } inline Polygon3r *SphericalGrid::Iterator::getCameraSpacePolygon() { - return &((*_current)->cameraSpacePolygon); + return &((*_current)->cameraSpacePolygon); } -inline SphericalGrid::OccluderData::OccluderData (OccluderSource& source, Polygon3r& p) -: poly(p), cameraSpacePolygon(source.getCameraSpacePolygon()), face(source.getWFace()) +inline SphericalGrid::OccluderData::OccluderData(OccluderSource &source, Polygon3r &p) + : poly(p), cameraSpacePolygon(source.getCameraSpacePolygon()), face(source.getWFace()) { - const Vec3r viewpoint(0, 0, 0); - // Get the point on the camera-space polygon that is closest to the viewpoint - // shallowest is the distance from the viewpoint to that point - shallowest = GridHelpers::distancePointToPolygon(viewpoint, cameraSpacePolygon); - - // Get the point on the camera-space polygon that is furthest from the viewpoint - // deepest is the distance from the viewpoint to that point - deepest = cameraSpacePolygon.getVertices()[2].norm(); - for (unsigned int i = 0; i < 2; ++i) { - real t = cameraSpacePolygon.getVertices()[i].norm(); - if (t > deepest) { - deepest = t; - } - } + const Vec3r viewpoint(0, 0, 0); + // Get the point on the camera-space polygon that is closest to the viewpoint + // shallowest is the distance from the viewpoint to that point + shallowest = GridHelpers::distancePointToPolygon(viewpoint, cameraSpacePolygon); + + // Get the point on the camera-space polygon that is furthest from the viewpoint + // deepest is the distance from the viewpoint to that point + deepest = cameraSpacePolygon.getVertices()[2].norm(); + for (unsigned int i = 0; i < 2; ++i) { + real t = cameraSpacePolygon.getVertices()[i].norm(); + if (t > deepest) { + deepest = t; + } + } } -inline void SphericalGrid::Cell::checkAndInsert(OccluderSource& source, Polygon3r& poly, OccluderData*& occluder) +inline void SphericalGrid::Cell::checkAndInsert(OccluderSource &source, + Polygon3r &poly, + OccluderData *&occluder) { - if (GridHelpers::insideProscenium (boundary, poly)) { - if (occluder == NULL) { - // Disposal of occluder will be handled in SphericalGrid::distributePolygons(), - // or automatically by SphericalGrid::_faces; - occluder = new OccluderData(source, poly); - } - faces.push_back(occluder); - } + if (GridHelpers::insideProscenium(boundary, poly)) { + if (occluder == NULL) { + // Disposal of occluder will be handled in SphericalGrid::distributePolygons(), + // or automatically by SphericalGrid::_faces; + occluder = new OccluderData(source, poly); + } + faces.push_back(occluder); + } } -inline bool SphericalGrid::insertOccluder(OccluderSource& source, OccluderData*& occluder) +inline bool SphericalGrid::insertOccluder(OccluderSource &source, OccluderData *&occluder) { - Polygon3r& poly(source.getGridSpacePolygon()); - occluder = NULL; - - Vec3r bbMin, bbMax; - poly.getBBox(bbMin, bbMax); - // Check overlapping cells - unsigned startX, startY, endX, endY; - getCellCoordinates(bbMin, startX, startY); - getCellCoordinates(bbMax, endX, endY); - - for (unsigned int i = startX; i <= endX; ++i) { - for (unsigned int j = startY; j <= endY; ++j) { - if (_cells[i * _cellsY + j] != NULL) { - _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder); - } - } - } - - return occluder != NULL; + Polygon3r &poly(source.getGridSpacePolygon()); + occluder = NULL; + + Vec3r bbMin, bbMax; + poly.getBBox(bbMin, bbMax); + // Check overlapping cells + unsigned startX, startY, endX, endY; + getCellCoordinates(bbMin, startX, startY); + getCellCoordinates(bbMax, endX, endY); + + for (unsigned int i = startX; i <= endX; ++i) { + for (unsigned int j = startY; j <= endY; ++j) { + if (_cells[i * _cellsY + j] != NULL) { + _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder); + } + } + } + + return occluder != NULL; } } /* namespace Freestyle */ -#endif // __FREESTYLE_SPHERICAL_GRID_H__ +#endif // __FREESTYLE_SPHERICAL_GRID_H__ diff --git a/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp b/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp index bb9f8069610..94541b2c312 100644 --- a/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp +++ b/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp @@ -43,249 +43,257 @@ using namespace Geometry; SteerableViewMap::SteerableViewMap(unsigned int nbOrientations) { - _nbOrientations = nbOrientations; - _bound = cos(M_PI / (float)_nbOrientations); - for (unsigned int i = 0; i < _nbOrientations; ++i) { - _directions.push_back(Vec2d(cos((float)i * M_PI / (float)_nbOrientations), - sin((float)i * M_PI / (float)_nbOrientations))); - } - Build(); + _nbOrientations = nbOrientations; + _bound = cos(M_PI / (float)_nbOrientations); + for (unsigned int i = 0; i < _nbOrientations; ++i) { + _directions.push_back(Vec2d(cos((float)i * M_PI / (float)_nbOrientations), + sin((float)i * M_PI / (float)_nbOrientations))); + } + Build(); } void SteerableViewMap::Build() { - _imagesPyramids = new ImagePyramid *[_nbOrientations + 1]; // one more map to store the complete visible VM - memset((_imagesPyramids), 0, (_nbOrientations + 1) * sizeof(ImagePyramid *)); + _imagesPyramids = + new ImagePyramid *[_nbOrientations + 1]; // one more map to store the complete visible VM + memset((_imagesPyramids), 0, (_nbOrientations + 1) * sizeof(ImagePyramid *)); } -SteerableViewMap::SteerableViewMap(const SteerableViewMap& iBrother) +SteerableViewMap::SteerableViewMap(const SteerableViewMap &iBrother) { - _nbOrientations = iBrother._nbOrientations; - unsigned int i; - _bound = iBrother._bound; - _directions = iBrother._directions; - _mapping = iBrother._mapping; - _imagesPyramids = new ImagePyramid *[_nbOrientations + 1]; // one more map to store the complete visible VM - for (i = 0; i <= _nbOrientations; ++i) - _imagesPyramids[i] = new GaussianPyramid(*(dynamic_cast(iBrother._imagesPyramids[i]))); + _nbOrientations = iBrother._nbOrientations; + unsigned int i; + _bound = iBrother._bound; + _directions = iBrother._directions; + _mapping = iBrother._mapping; + _imagesPyramids = + new ImagePyramid *[_nbOrientations + 1]; // one more map to store the complete visible VM + for (i = 0; i <= _nbOrientations; ++i) + _imagesPyramids[i] = new GaussianPyramid( + *(dynamic_cast(iBrother._imagesPyramids[i]))); } SteerableViewMap::~SteerableViewMap() { - Clear(); + Clear(); } void SteerableViewMap::Clear() { - unsigned int i; - if (_imagesPyramids) { - for (i = 0; i <= _nbOrientations; ++i) { - if (_imagesPyramids[i]) - delete (_imagesPyramids)[i]; - } - delete[] _imagesPyramids; - _imagesPyramids = 0; - } - if (!_mapping.empty()) { - for (map::iterator m = _mapping.begin(), mend = _mapping.end(); m != mend; ++m) { - delete[] (*m).second; - } - _mapping.clear(); - } + unsigned int i; + if (_imagesPyramids) { + for (i = 0; i <= _nbOrientations; ++i) { + if (_imagesPyramids[i]) + delete (_imagesPyramids)[i]; + } + delete[] _imagesPyramids; + _imagesPyramids = 0; + } + if (!_mapping.empty()) { + for (map::iterator m = _mapping.begin(), mend = _mapping.end(); + m != mend; + ++m) { + delete[](*m).second; + } + _mapping.clear(); + } } void SteerableViewMap::Reset() { - Clear(); - Build(); + Clear(); + Build(); } -double SteerableViewMap::ComputeWeight(const Vec2d& dir, unsigned i) +double SteerableViewMap::ComputeWeight(const Vec2d &dir, unsigned i) { - double dotp = fabs(dir * _directions[i]); - if (dotp < _bound) - return 0.0; - if (dotp > 1.0) - dotp = 1.0; + double dotp = fabs(dir * _directions[i]); + if (dotp < _bound) + return 0.0; + if (dotp > 1.0) + dotp = 1.0; - return cos((float)_nbOrientations / 2.0 * acos(dotp)); + return cos((float)_nbOrientations / 2.0 * acos(dotp)); } double *SteerableViewMap::AddFEdge(FEdge *iFEdge) { - unsigned i; - unsigned id = iFEdge->getId().getFirst(); - map::iterator o = _mapping.find(id); - if (o != _mapping.end()) { - return (*o).second; - } - double *res = new double[_nbOrientations]; - for (i = 0; i < _nbOrientations; ++i) { - res[i] = 0.0; - } - Vec3r o2d3 = iFEdge->orientation2d(); - Vec2r o2d2(o2d3.x(), o2d3.y()); - real norm = o2d2.norm(); - if (norm < 1.0e-6) { - return res; - } - o2d2 /= norm; - - for (i = 0; i < _nbOrientations; ++i) { - res[i] = ComputeWeight(o2d2, i); - } - _mapping[id] = res; - return res; + unsigned i; + unsigned id = iFEdge->getId().getFirst(); + map::iterator o = _mapping.find(id); + if (o != _mapping.end()) { + return (*o).second; + } + double *res = new double[_nbOrientations]; + for (i = 0; i < _nbOrientations; ++i) { + res[i] = 0.0; + } + Vec3r o2d3 = iFEdge->orientation2d(); + Vec2r o2d2(o2d3.x(), o2d3.y()); + real norm = o2d2.norm(); + if (norm < 1.0e-6) { + return res; + } + o2d2 /= norm; + + for (i = 0; i < _nbOrientations; ++i) { + res[i] = ComputeWeight(o2d2, i); + } + _mapping[id] = res; + return res; } -unsigned SteerableViewMap::getSVMNumber(const Vec2f& orient) +unsigned SteerableViewMap::getSVMNumber(const Vec2f &orient) { - Vec2f dir(orient); - //soc unsigned res = 0; - real norm = dir.norm(); - if (norm < 1.0e-6) { - return _nbOrientations + 1; - } - dir /= norm; - double maxw = 0.0f; - unsigned winner = _nbOrientations + 1; - for (unsigned int i = 0; i < _nbOrientations; ++i) { - double w = ComputeWeight(dir, i); - if (w > maxw) { - maxw = w; - winner = i; - } - } - return winner; + Vec2f dir(orient); + //soc unsigned res = 0; + real norm = dir.norm(); + if (norm < 1.0e-6) { + return _nbOrientations + 1; + } + dir /= norm; + double maxw = 0.0f; + unsigned winner = _nbOrientations + 1; + for (unsigned int i = 0; i < _nbOrientations; ++i) { + double w = ComputeWeight(dir, i); + if (w > maxw) { + maxw = w; + winner = i; + } + } + return winner; } unsigned SteerableViewMap::getSVMNumber(unsigned id) { - map::iterator o = _mapping.find(id); - if (o != _mapping.end()) { - double *wvalues = (*o).second; - double maxw = 0.0; - unsigned winner = _nbOrientations + 1; - for (unsigned i = 0; i < _nbOrientations; ++i) { - double w = wvalues[i]; - if (w > maxw) { - maxw = w; - winner = i; - } - } - return winner; - } - return _nbOrientations + 1; + map::iterator o = _mapping.find(id); + if (o != _mapping.end()) { + double *wvalues = (*o).second; + double maxw = 0.0; + unsigned winner = _nbOrientations + 1; + for (unsigned i = 0; i < _nbOrientations; ++i) { + double w = wvalues[i]; + if (w > maxw) { + maxw = w; + winner = i; + } + } + return winner; + } + return _nbOrientations + 1; } -void SteerableViewMap::buildImagesPyramids(GrayImage **steerableBases, bool copy, unsigned iNbLevels, float iSigma) +void SteerableViewMap::buildImagesPyramids(GrayImage **steerableBases, + bool copy, + unsigned iNbLevels, + float iSigma) { - for (unsigned int i = 0; i <= _nbOrientations; ++i) { - ImagePyramid *svm = (_imagesPyramids)[i]; - if (svm) - delete svm; - if (copy) - svm = new GaussianPyramid(*(steerableBases[i]), iNbLevels, iSigma); - else - svm = new GaussianPyramid(steerableBases[i], iNbLevels, iSigma); - _imagesPyramids[i] = svm; - } + for (unsigned int i = 0; i <= _nbOrientations; ++i) { + ImagePyramid *svm = (_imagesPyramids)[i]; + if (svm) + delete svm; + if (copy) + svm = new GaussianPyramid(*(steerableBases[i]), iNbLevels, iSigma); + else + svm = new GaussianPyramid(steerableBases[i], iNbLevels, iSigma); + _imagesPyramids[i] = svm; + } } float SteerableViewMap::readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y) { - ImagePyramid *pyramid = _imagesPyramids[iOrientation]; - if (!pyramid) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: this steerable ViewMap level doesn't exist" << endl; - } - return 0.0f; - } - if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) - return 0; - //float v = pyramid->pixel(x, pyramid->height() - 1 - y, iLevel) * 255.0f; - // We encode both the directionality and the lines counting on 8 bits (because of frame buffer). Thus, we allow - // until 8 lines to pass through the same pixel, so that we can discretize the Pi/_nbOrientations angle into - // 32 slices. Therefore, for example, in the vertical direction, a vertical line will have the value 32 on - // each pixel it passes through. - float v = pyramid->pixel(x, pyramid->height() - 1 - y, iLevel) / 32.0f; - return v; + ImagePyramid *pyramid = _imagesPyramids[iOrientation]; + if (!pyramid) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: this steerable ViewMap level doesn't exist" << endl; + } + return 0.0f; + } + if ((x < 0) || (x >= pyramid->width()) || (y < 0) || (y >= pyramid->height())) + return 0; + //float v = pyramid->pixel(x, pyramid->height() - 1 - y, iLevel) * 255.0f; + // We encode both the directionality and the lines counting on 8 bits (because of frame buffer). Thus, we allow + // until 8 lines to pass through the same pixel, so that we can discretize the Pi/_nbOrientations angle into + // 32 slices. Therefore, for example, in the vertical direction, a vertical line will have the value 32 on + // each pixel it passes through. + float v = pyramid->pixel(x, pyramid->height() - 1 - y, iLevel) / 32.0f; + return v; } float SteerableViewMap::readCompleteViewMapPixel(int iLevel, int x, int y) { - return readSteerableViewMapPixel(_nbOrientations, iLevel, x, y); + return readSteerableViewMapPixel(_nbOrientations, iLevel, x, y); } unsigned int SteerableViewMap::getNumberOfPyramidLevels() const { - if (_imagesPyramids[0]) - return _imagesPyramids[0]->getNumberOfLevels(); - return 0; + if (_imagesPyramids[0]) + return _imagesPyramids[0]->getNumberOfLevels(); + return 0; } void SteerableViewMap::saveSteerableViewMap() const { - for (unsigned int i = 0; i <= _nbOrientations; ++i) { - if (_imagesPyramids[i] == 0) { - cerr << "SteerableViewMap warning: orientation " << i << - " of steerable View Map whas not been computed yet" << endl; - continue; - } - int ow = _imagesPyramids[i]->width(0); - int oh = _imagesPyramids[i]->height(0); - - //soc QString base("SteerableViewMap"); - string base("SteerableViewMap"); - stringstream filename; - - for (int j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) { //soc - float coeff = 1.0f; // 1 / 255.0f; // 100 * 255; // * pow(2, j); - //soc QImage qtmp(ow, oh, QImage::Format_RGB32); - ImBuf *ibuf = IMB_allocImBuf(ow, oh, 32, IB_rect); - int rowbytes = ow * 4; - char *pix; - - for (int y = 0; y < oh; ++y) { //soc - for (int x = 0; x < ow; ++x) { //soc - int c = (int)(coeff * _imagesPyramids[i]->pixel(x, y, j)); - if (c > 255) - c = 255; - //int c = (int)(_imagesPyramids[i]->pixel(x, y, j)); - - //soc qtmp.setPixel(x, y, qRgb(c, c, c)); - pix = (char *)ibuf->rect + y * rowbytes + x * 4; - pix[0] = pix[1] = pix[2] = c; - } - } - - //soc qtmp.save(base+QString::number(i)+"-"+QString::number(j)+".png", "PNG"); - filename << base; - filename << i << "-" << j << ".png"; - ibuf->ftype = IMB_FTYPE_PNG; - IMB_saveiff(ibuf, const_cast(filename.str().c_str()), 0); - } + for (unsigned int i = 0; i <= _nbOrientations; ++i) { + if (_imagesPyramids[i] == 0) { + cerr << "SteerableViewMap warning: orientation " << i + << " of steerable View Map whas not been computed yet" << endl; + continue; + } + int ow = _imagesPyramids[i]->width(0); + int oh = _imagesPyramids[i]->height(0); + + //soc QString base("SteerableViewMap"); + string base("SteerableViewMap"); + stringstream filename; + + for (int j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) { //soc + float coeff = 1.0f; // 1 / 255.0f; // 100 * 255; // * pow(2, j); + //soc QImage qtmp(ow, oh, QImage::Format_RGB32); + ImBuf *ibuf = IMB_allocImBuf(ow, oh, 32, IB_rect); + int rowbytes = ow * 4; + char *pix; + + for (int y = 0; y < oh; ++y) { //soc + for (int x = 0; x < ow; ++x) { //soc + int c = (int)(coeff * _imagesPyramids[i]->pixel(x, y, j)); + if (c > 255) + c = 255; + //int c = (int)(_imagesPyramids[i]->pixel(x, y, j)); + + //soc qtmp.setPixel(x, y, qRgb(c, c, c)); + pix = (char *)ibuf->rect + y * rowbytes + x * 4; + pix[0] = pix[1] = pix[2] = c; + } + } + + //soc qtmp.save(base+QString::number(i)+"-"+QString::number(j)+".png", "PNG"); + filename << base; + filename << i << "-" << j << ".png"; + ibuf->ftype = IMB_FTYPE_PNG; + IMB_saveiff(ibuf, const_cast(filename.str().c_str()), 0); + } #if 0 - QString base("SteerableViewMap"); - for (unsigned j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) { - GrayImage *img = _imagesPyramids[i]->getLevel(j); - int ow = img->width(); - int oh = img->height(); - float coeff = 1.0f; // 100 * 255; // * pow(2, j); - QImage qtmp(ow, oh, 32); - for (unsigned int y = 0; y < oh; ++y) { - for (unsigned int x = 0; x < ow; ++x) { - int c = (int)(coeff * img->pixel(x, y)); - if (c > 255) - c = 255; - //int c = (int)(_imagesPyramids[i]->pixel(x, y, j)); - qtmp.setPixel(x, y, qRgb(c, c, c)); - } - } - qtmp.save(base + QString::number(i) + "-" + QString::number(j) + ".png", "PNG"); - } + QString base("SteerableViewMap"); + for (unsigned j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) { + GrayImage *img = _imagesPyramids[i]->getLevel(j); + int ow = img->width(); + int oh = img->height(); + float coeff = 1.0f; // 100 * 255; // * pow(2, j); + QImage qtmp(ow, oh, 32); + for (unsigned int y = 0; y < oh; ++y) { + for (unsigned int x = 0; x < ow; ++x) { + int c = (int)(coeff * img->pixel(x, y)); + if (c > 255) + c = 255; + //int c = (int)(_imagesPyramids[i]->pixel(x, y, j)); + qtmp.setPixel(x, y, qRgb(c, c, c)); + } + } + qtmp.save(base + QString::number(i) + "-" + QString::number(j) + ".png", "PNG"); + } #endif - } + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/SteerableViewMap.h b/source/blender/freestyle/intern/view_map/SteerableViewMap.h index 608d64703f4..16f57f39737 100644 --- a/source/blender/freestyle/intern/view_map/SteerableViewMap.h +++ b/source/blender/freestyle/intern/view_map/SteerableViewMap.h @@ -29,7 +29,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -45,109 +45,110 @@ class GrayImage; /*! This class checks for every FEdge in which steerable it belongs and stores the mapping allowing to retrieve * this information from the FEdge Id. */ -class SteerableViewMap -{ -protected: - // for each vector the list of nbOrientations weights corresponding to its contributions - // to the nbOrientations directional maps - map _mapping; - unsigned _nbOrientations; - ImagePyramid **_imagesPyramids; // the pyramids of images storing the different SVM - - // internal - double _bound; // cos(Pi/N) - vector _directions; - -public: - SteerableViewMap(unsigned int nbOrientations = 4); - SteerableViewMap(const SteerableViewMap& iBrother); - virtual ~SteerableViewMap(); - - /*! Resets everything */ - virtual void Reset(); - - /*! Adds a FEdge to steerable VM. - * Returns the nbOrientations weights corresponding to the FEdge contributions to the nbOrientations - * directional maps. - */ - double *AddFEdge(FEdge *iFEdge); - - /*! Compute the weight of direction dir for orientation iNOrientation */ - double ComputeWeight(const Vec2d& dir, unsigned iNOrientation); - - /*! Returns the number of the SVM to which a direction belongs to. - * \param dir: - * The direction - */ - unsigned getSVMNumber(const Vec2f& dir); - - /*! Returns the number of the SVM to which a FEdge belongs most. - * \param id: - * The First element of the Id struct of the FEdge we're interested in. - */ - unsigned getSVMNumber(unsigned id); - - /*! Builds _nbOrientations+1 pyramids of images from the _nbOrientations+1 base images of the steerable viewmap. - * \param steerableBases: - * The _nbOrientations+1 images constituting the basis for the steerable pyramid. - * \param copy: - * If false, the data is not duplicated, and Canvas deals with the memory management of these - * _nbOrientations+1 images. If true, data is copied, and it's up to the caller to delete the images. - * \param iNbLevels: - * The number of levels desired for each pyramid. - * If iNbLevels == 0, the complete pyramid is built. - * \param iSigma: - * The sigma that will be used for the gaussian blur - */ - void buildImagesPyramids(GrayImage **steerableBases, bool copy = false, unsigned iNbLevels = 4, - float iSigma = 1.0f); - - /*! Reads a pixel value in one of the VewMap density steerable pyramids. - * Returns a value between 0 and 1. - * \param iOrientation: - * the number telling which orientation we need to check. - * There are _nbOrientations+1 oriented ViewMaps: - * 0 -> the ViewMap containing every horizontal lines - * 1 -> the ViewMap containing every lines whose orientation is around PI/4 - * 2 -> the ViewMap containing every vertical lines - * 3 -> the ViewMap containing every lines whose orientation is around 3PI/4 - * 4 -> the complete ViewMap - * \param iLevel: - * The level of the pyramid we want to read - * \param x: - * The abscissa of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. - * \param y: - * The ordinate of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. - */ - float readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y); - - /*! Reads a pixel in the one of the level of the pyramid containing the images of the complete ViewMap. - * Returns a value between 0 and 1. - * Equivalent to : readSteerableViewMapPixel(nbOrientations, x, y) - */ - float readCompleteViewMapPixel(int iLevel, int x, int y); - - /*! Returns the number of levels in the pyramids */ - unsigned int getNumberOfPyramidLevels() const; - - /*! Returns the number of orientations */ - unsigned int getNumberOfOrientations() const - { - return _nbOrientations; - } - - /*! for debug purposes */ - void saveSteerableViewMap() const; - -protected: - void Clear(); - void Build(); +class SteerableViewMap { + protected: + // for each vector the list of nbOrientations weights corresponding to its contributions + // to the nbOrientations directional maps + map _mapping; + unsigned _nbOrientations; + ImagePyramid **_imagesPyramids; // the pyramids of images storing the different SVM + + // internal + double _bound; // cos(Pi/N) + vector _directions; + + public: + SteerableViewMap(unsigned int nbOrientations = 4); + SteerableViewMap(const SteerableViewMap &iBrother); + virtual ~SteerableViewMap(); + + /*! Resets everything */ + virtual void Reset(); + + /*! Adds a FEdge to steerable VM. + * Returns the nbOrientations weights corresponding to the FEdge contributions to the nbOrientations + * directional maps. + */ + double *AddFEdge(FEdge *iFEdge); + + /*! Compute the weight of direction dir for orientation iNOrientation */ + double ComputeWeight(const Vec2d &dir, unsigned iNOrientation); + + /*! Returns the number of the SVM to which a direction belongs to. + * \param dir: + * The direction + */ + unsigned getSVMNumber(const Vec2f &dir); + + /*! Returns the number of the SVM to which a FEdge belongs most. + * \param id: + * The First element of the Id struct of the FEdge we're interested in. + */ + unsigned getSVMNumber(unsigned id); + + /*! Builds _nbOrientations+1 pyramids of images from the _nbOrientations+1 base images of the steerable viewmap. + * \param steerableBases: + * The _nbOrientations+1 images constituting the basis for the steerable pyramid. + * \param copy: + * If false, the data is not duplicated, and Canvas deals with the memory management of these + * _nbOrientations+1 images. If true, data is copied, and it's up to the caller to delete the images. + * \param iNbLevels: + * The number of levels desired for each pyramid. + * If iNbLevels == 0, the complete pyramid is built. + * \param iSigma: + * The sigma that will be used for the gaussian blur + */ + void buildImagesPyramids(GrayImage **steerableBases, + bool copy = false, + unsigned iNbLevels = 4, + float iSigma = 1.0f); + + /*! Reads a pixel value in one of the VewMap density steerable pyramids. + * Returns a value between 0 and 1. + * \param iOrientation: + * the number telling which orientation we need to check. + * There are _nbOrientations+1 oriented ViewMaps: + * 0 -> the ViewMap containing every horizontal lines + * 1 -> the ViewMap containing every lines whose orientation is around PI/4 + * 2 -> the ViewMap containing every vertical lines + * 3 -> the ViewMap containing every lines whose orientation is around 3PI/4 + * 4 -> the complete ViewMap + * \param iLevel: + * The level of the pyramid we want to read + * \param x: + * The abscissa of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. + * \param y: + * The ordinate of the desired pixel specified in level0 coordinate system. The origin is the lower left corner. + */ + float readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y); + + /*! Reads a pixel in the one of the level of the pyramid containing the images of the complete ViewMap. + * Returns a value between 0 and 1. + * Equivalent to : readSteerableViewMapPixel(nbOrientations, x, y) + */ + float readCompleteViewMapPixel(int iLevel, int x, int y); + + /*! Returns the number of levels in the pyramids */ + unsigned int getNumberOfPyramidLevels() const; + + /*! Returns the number of orientations */ + unsigned int getNumberOfOrientations() const + { + return _nbOrientations; + } + + /*! for debug purposes */ + void saveSteerableViewMap() const; + + protected: + void Clear(); + void Build(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SteerableViewMap") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SteerableViewMap") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_STEERABLE_VIEW_MAP_H__ +#endif // __FREESTYLE_STEERABLE_VIEW_MAP_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp index 0ec008ebf2b..8896918e60d 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp @@ -33,712 +33,721 @@ namespace Freestyle { void ViewEdgeXBuilder::Init(ViewShape *oVShape) { - if (NULL == oVShape) - return; + if (NULL == oVShape) + return; - // for design conveniance, we store the current SShape. - _pCurrentSShape = oVShape->sshape(); - if (0 == _pCurrentSShape) - return; + // for design conveniance, we store the current SShape. + _pCurrentSShape = oVShape->sshape(); + if (0 == _pCurrentSShape) + return; - _pCurrentVShape = oVShape; + _pCurrentVShape = oVShape; - // Reset previous data - //-------------------- - if (!_SVertexMap.empty()) - _SVertexMap.clear(); + // Reset previous data + //-------------------- + if (!_SVertexMap.empty()) + _SVertexMap.clear(); } -void ViewEdgeXBuilder::BuildViewEdges(WXShape *iWShape, ViewShape *oVShape, vector& ioVEdges, - vector& ioVVertices, vector& ioFEdges, - vector& ioSVertices) +void ViewEdgeXBuilder::BuildViewEdges(WXShape *iWShape, + ViewShape *oVShape, + vector &ioVEdges, + vector &ioVVertices, + vector &ioFEdges, + vector &ioSVertices) { - // Reinit structures - Init(oVShape); - - /* ViewEdge *vedge; */ /* UNUSED */ - // Let us build the smooth stuff - //---------------------------------------- - // We parse all faces to find the ones that contain smooth edges - vector& wfaces = iWShape->GetFaceList(); - vector::iterator wf, wfend; - WXFace *wxf; - for (wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; wf++) { - wxf = dynamic_cast(*wf); - if (false == ((wxf))->hasSmoothEdges()) // does it contain at least one smooth edge ? - continue; - // parse all smooth layers: - vector& smoothLayers = wxf->getSmoothLayers(); - for (vector::iterator sl = smoothLayers.begin(), slend = smoothLayers.end(); sl != slend; ++sl) { - if (!(*sl)->hasSmoothEdge()) - continue; - if (stopSmoothViewEdge((*sl))) // has it been parsed already ? - continue; - // here we know that we're dealing with a face layer that has not been processed yet and that contains - // a smooth edge. - /* vedge =*/ /* UNUSED */ BuildSmoothViewEdge(OWXFaceLayer(*sl, true)); - } - } - - // Now let's build sharp view edges: - //---------------------------------- - // Reset all userdata for WXEdge structure - //---------------------------------------- - //iWShape->ResetUserData(); - - WXEdge *wxe; - vector& wedges = iWShape->getEdgeList(); - //------------------------------ - for (vector::iterator we = wedges.begin(), weend = wedges.end(); we != weend; we++) { - wxe = dynamic_cast(*we); - if (Nature::NO_FEATURE == wxe->nature()) - continue; - - if (!stopSharpViewEdge(wxe)) { - bool b = true; - if (wxe->order() == -1) - b = false; - BuildSharpViewEdge(OWXEdge(wxe, b)); - } - } - - // Reset all userdata for WXEdge structure - //---------------------------------------- - iWShape->ResetUserData(); - - // Add all these new edges to the scene's feature edges list: - //----------------------------------------------------------- - vector& newedges = _pCurrentSShape->getEdgeList(); - vector& newVertices = _pCurrentSShape->getVertexList(); - vector& newVVertices = _pCurrentVShape->vertices(); - vector& newVEdges = _pCurrentVShape->edges(); - - // inserts in ioFEdges, at its end, all the edges of newedges - ioFEdges.insert(ioFEdges.end(), newedges.begin(), newedges.end()); - ioSVertices.insert(ioSVertices.end(), newVertices.begin(), newVertices.end()); - ioVVertices.insert(ioVVertices.end(), newVVertices.begin(), newVVertices.end()); - ioVEdges.insert(ioVEdges.end(), newVEdges.begin(), newVEdges.end()); + // Reinit structures + Init(oVShape); + + /* ViewEdge *vedge; */ /* UNUSED */ + // Let us build the smooth stuff + //---------------------------------------- + // We parse all faces to find the ones that contain smooth edges + vector &wfaces = iWShape->GetFaceList(); + vector::iterator wf, wfend; + WXFace *wxf; + for (wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; wf++) { + wxf = dynamic_cast(*wf); + if (false == ((wxf))->hasSmoothEdges()) // does it contain at least one smooth edge ? + continue; + // parse all smooth layers: + vector &smoothLayers = wxf->getSmoothLayers(); + for (vector::iterator sl = smoothLayers.begin(), slend = smoothLayers.end(); + sl != slend; + ++sl) { + if (!(*sl)->hasSmoothEdge()) + continue; + if (stopSmoothViewEdge((*sl))) // has it been parsed already ? + continue; + // here we know that we're dealing with a face layer that has not been processed yet and that contains + // a smooth edge. + /* vedge =*//* UNUSED */ BuildSmoothViewEdge(OWXFaceLayer(*sl, true)); + } + } + + // Now let's build sharp view edges: + //---------------------------------- + // Reset all userdata for WXEdge structure + //---------------------------------------- + //iWShape->ResetUserData(); + + WXEdge *wxe; + vector &wedges = iWShape->getEdgeList(); + //------------------------------ + for (vector::iterator we = wedges.begin(), weend = wedges.end(); we != weend; we++) { + wxe = dynamic_cast(*we); + if (Nature::NO_FEATURE == wxe->nature()) + continue; + + if (!stopSharpViewEdge(wxe)) { + bool b = true; + if (wxe->order() == -1) + b = false; + BuildSharpViewEdge(OWXEdge(wxe, b)); + } + } + + // Reset all userdata for WXEdge structure + //---------------------------------------- + iWShape->ResetUserData(); + + // Add all these new edges to the scene's feature edges list: + //----------------------------------------------------------- + vector &newedges = _pCurrentSShape->getEdgeList(); + vector &newVertices = _pCurrentSShape->getVertexList(); + vector &newVVertices = _pCurrentVShape->vertices(); + vector &newVEdges = _pCurrentVShape->edges(); + + // inserts in ioFEdges, at its end, all the edges of newedges + ioFEdges.insert(ioFEdges.end(), newedges.begin(), newedges.end()); + ioSVertices.insert(ioSVertices.end(), newVertices.begin(), newVertices.end()); + ioVVertices.insert(ioVVertices.end(), newVVertices.begin(), newVVertices.end()); + ioVEdges.insert(ioVEdges.end(), newVEdges.begin(), newVEdges.end()); } -ViewEdge *ViewEdgeXBuilder::BuildSmoothViewEdge(const OWXFaceLayer& iFaceLayer) +ViewEdge *ViewEdgeXBuilder::BuildSmoothViewEdge(const OWXFaceLayer &iFaceLayer) { - // Find first edge: - OWXFaceLayer first = iFaceLayer; - OWXFaceLayer currentFace = first; - - // bidirectional chaining. - // first direction - list facesChain; - unsigned size = 0; - while (!stopSmoothViewEdge(currentFace.fl)) { - facesChain.push_back(currentFace); - ++size; - currentFace.fl->userdata = (void *)1; // processed - // Find the next edge! - currentFace = FindNextFaceLayer(currentFace); - } - OWXFaceLayer end = facesChain.back(); - // second direction - currentFace = FindPreviousFaceLayer(first); - while (!stopSmoothViewEdge(currentFace.fl)) { - facesChain.push_front(currentFace); - ++size; - currentFace.fl->userdata = (void *)1; // processed - // Find the previous edge! - currentFace = FindPreviousFaceLayer(currentFace); - } - first = facesChain.front(); - - if (iFaceLayer.fl->nature() & Nature::RIDGE) { - if (size < 4) { - return 0; - } - } - - // Start a new chain edges - ViewEdge *newVEdge = new ViewEdge; - newVEdge->setId(_currentViewId); - ++_currentViewId; - - _pCurrentVShape->AddEdge(newVEdge); - - // build FEdges - FEdge *feprevious = NULL; - FEdge *fefirst = NULL; - FEdge *fe = NULL; - for (list::iterator fl = facesChain.begin(), flend = facesChain.end(); fl != flend; ++fl) { - fe = BuildSmoothFEdge(feprevious, (*fl)); - if (feprevious && fe == feprevious) - continue; - fe->setViewEdge(newVEdge); - if (!fefirst) - fefirst = fe; - feprevious = fe; - } - // Store the chain starting edge: - _pCurrentSShape->AddChain(fefirst); - newVEdge->setNature(iFaceLayer.fl->nature()); - newVEdge->setFEdgeA(fefirst); - newVEdge->setFEdgeB(fe); - - // is it a closed loop ? - if ((first == end) && (size != 1)) { - fefirst->setPreviousEdge(fe); - fe->setNextEdge(fefirst); - newVEdge->setA(0); - newVEdge->setB(0); - } - else { - ViewVertex *vva = MakeViewVertex(fefirst->vertexA()); - ViewVertex *vvb = MakeViewVertex(fe->vertexB()); - - ((NonTVertex *)vva)->AddOutgoingViewEdge(newVEdge); - ((NonTVertex *)vvb)->AddIncomingViewEdge(newVEdge); - - newVEdge->setA(vva); - newVEdge->setB(vvb); - } - - return newVEdge; + // Find first edge: + OWXFaceLayer first = iFaceLayer; + OWXFaceLayer currentFace = first; + + // bidirectional chaining. + // first direction + list facesChain; + unsigned size = 0; + while (!stopSmoothViewEdge(currentFace.fl)) { + facesChain.push_back(currentFace); + ++size; + currentFace.fl->userdata = (void *)1; // processed + // Find the next edge! + currentFace = FindNextFaceLayer(currentFace); + } + OWXFaceLayer end = facesChain.back(); + // second direction + currentFace = FindPreviousFaceLayer(first); + while (!stopSmoothViewEdge(currentFace.fl)) { + facesChain.push_front(currentFace); + ++size; + currentFace.fl->userdata = (void *)1; // processed + // Find the previous edge! + currentFace = FindPreviousFaceLayer(currentFace); + } + first = facesChain.front(); + + if (iFaceLayer.fl->nature() & Nature::RIDGE) { + if (size < 4) { + return 0; + } + } + + // Start a new chain edges + ViewEdge *newVEdge = new ViewEdge; + newVEdge->setId(_currentViewId); + ++_currentViewId; + + _pCurrentVShape->AddEdge(newVEdge); + + // build FEdges + FEdge *feprevious = NULL; + FEdge *fefirst = NULL; + FEdge *fe = NULL; + for (list::iterator fl = facesChain.begin(), flend = facesChain.end(); fl != flend; + ++fl) { + fe = BuildSmoothFEdge(feprevious, (*fl)); + if (feprevious && fe == feprevious) + continue; + fe->setViewEdge(newVEdge); + if (!fefirst) + fefirst = fe; + feprevious = fe; + } + // Store the chain starting edge: + _pCurrentSShape->AddChain(fefirst); + newVEdge->setNature(iFaceLayer.fl->nature()); + newVEdge->setFEdgeA(fefirst); + newVEdge->setFEdgeB(fe); + + // is it a closed loop ? + if ((first == end) && (size != 1)) { + fefirst->setPreviousEdge(fe); + fe->setNextEdge(fefirst); + newVEdge->setA(0); + newVEdge->setB(0); + } + else { + ViewVertex *vva = MakeViewVertex(fefirst->vertexA()); + ViewVertex *vvb = MakeViewVertex(fe->vertexB()); + + ((NonTVertex *)vva)->AddOutgoingViewEdge(newVEdge); + ((NonTVertex *)vvb)->AddIncomingViewEdge(newVEdge); + + newVEdge->setA(vva); + newVEdge->setB(vvb); + } + + return newVEdge; } -ViewEdge *ViewEdgeXBuilder::BuildSharpViewEdge(const OWXEdge& iWEdge) +ViewEdge *ViewEdgeXBuilder::BuildSharpViewEdge(const OWXEdge &iWEdge) { - // Start a new sharp chain edges - ViewEdge *newVEdge = new ViewEdge; - newVEdge->setId(_currentViewId); - ++_currentViewId; - unsigned size = 0; - - _pCurrentVShape->AddEdge(newVEdge); - - // Find first edge: - OWXEdge firstWEdge = iWEdge; - /* OWXEdge previousWEdge = firstWEdge; */ /* UNUSED */ - OWXEdge currentWEdge = firstWEdge; - list edgesChain; + // Start a new sharp chain edges + ViewEdge *newVEdge = new ViewEdge; + newVEdge->setId(_currentViewId); + ++_currentViewId; + unsigned size = 0; + + _pCurrentVShape->AddEdge(newVEdge); + + // Find first edge: + OWXEdge firstWEdge = iWEdge; + /* OWXEdge previousWEdge = firstWEdge; */ /* UNUSED */ + OWXEdge currentWEdge = firstWEdge; + list edgesChain; #if 0 /* TK 02-Sep-2012 Experimental fix for incorrect view edge visibility. */ - // bidirectional chaining - // first direction: - while (!stopSharpViewEdge(currentWEdge.e)) { - edgesChain.push_back(currentWEdge); - ++size; - currentWEdge.e->userdata = (void *)1; // processed - // Find the next edge! - currentWEdge = FindNextWEdge(currentWEdge); - } - OWXEdge endWEdge = edgesChain.back(); - // second direction - currentWEdge = FindPreviousWEdge(firstWEdge); - while (!stopSharpViewEdge(currentWEdge.e)) { - edgesChain.push_front(currentWEdge); - ++size; - currentWEdge.e->userdata = (void *)1; // processed - // Find the previous edge! - currentWEdge = FindPreviousWEdge(currentWEdge); - } + // bidirectional chaining + // first direction: + while (!stopSharpViewEdge(currentWEdge.e)) { + edgesChain.push_back(currentWEdge); + ++size; + currentWEdge.e->userdata = (void *)1; // processed + // Find the next edge! + currentWEdge = FindNextWEdge(currentWEdge); + } + OWXEdge endWEdge = edgesChain.back(); + // second direction + currentWEdge = FindPreviousWEdge(firstWEdge); + while (!stopSharpViewEdge(currentWEdge.e)) { + edgesChain.push_front(currentWEdge); + ++size; + currentWEdge.e->userdata = (void *)1; // processed + // Find the previous edge! + currentWEdge = FindPreviousWEdge(currentWEdge); + } #else - edgesChain.push_back(currentWEdge); - ++size; - currentWEdge.e->userdata = (void *)1; // processed - OWXEdge endWEdge = edgesChain.back(); + edgesChain.push_back(currentWEdge); + ++size; + currentWEdge.e->userdata = (void *)1; // processed + OWXEdge endWEdge = edgesChain.back(); #endif - firstWEdge = edgesChain.front(); - - // build FEdges - FEdge *feprevious = NULL; - FEdge *fefirst = NULL; - FEdge *fe = NULL; - for (list::iterator we = edgesChain.begin(), weend = edgesChain.end(); we != weend; ++we) { - fe = BuildSharpFEdge(feprevious, (*we)); - fe->setViewEdge(newVEdge); - if (!fefirst) - fefirst = fe; - feprevious = fe; - } - // Store the chain starting edge: - _pCurrentSShape->AddChain(fefirst); - newVEdge->setNature(iWEdge.e->nature()); - newVEdge->setFEdgeA(fefirst); - newVEdge->setFEdgeB(fe); - - // is it a closed loop ? - if ((firstWEdge == endWEdge) && (size != 1)) { - fefirst->setPreviousEdge(fe); - fe->setNextEdge(fefirst); - newVEdge->setA(0); - newVEdge->setB(0); - } - else { - ViewVertex *vva = MakeViewVertex(fefirst->vertexA()); - ViewVertex *vvb = MakeViewVertex(fe->vertexB()); - - ((NonTVertex *)vva)->AddOutgoingViewEdge(newVEdge); - ((NonTVertex *)vvb)->AddIncomingViewEdge(newVEdge); - - newVEdge->setA(vva); - newVEdge->setB(vvb); - } - - return newVEdge; + firstWEdge = edgesChain.front(); + + // build FEdges + FEdge *feprevious = NULL; + FEdge *fefirst = NULL; + FEdge *fe = NULL; + for (list::iterator we = edgesChain.begin(), weend = edgesChain.end(); we != weend; + ++we) { + fe = BuildSharpFEdge(feprevious, (*we)); + fe->setViewEdge(newVEdge); + if (!fefirst) + fefirst = fe; + feprevious = fe; + } + // Store the chain starting edge: + _pCurrentSShape->AddChain(fefirst); + newVEdge->setNature(iWEdge.e->nature()); + newVEdge->setFEdgeA(fefirst); + newVEdge->setFEdgeB(fe); + + // is it a closed loop ? + if ((firstWEdge == endWEdge) && (size != 1)) { + fefirst->setPreviousEdge(fe); + fe->setNextEdge(fefirst); + newVEdge->setA(0); + newVEdge->setB(0); + } + else { + ViewVertex *vva = MakeViewVertex(fefirst->vertexA()); + ViewVertex *vvb = MakeViewVertex(fe->vertexB()); + + ((NonTVertex *)vva)->AddOutgoingViewEdge(newVEdge); + ((NonTVertex *)vvb)->AddIncomingViewEdge(newVEdge); + + newVEdge->setA(vva); + newVEdge->setB(vvb); + } + + return newVEdge; } -OWXFaceLayer ViewEdgeXBuilder::FindNextFaceLayer(const OWXFaceLayer& iFaceLayer) +OWXFaceLayer ViewEdgeXBuilder::FindNextFaceLayer(const OWXFaceLayer &iFaceLayer) { - WXFace *nextFace = NULL; - WOEdge *woeend; - real tend; - if (iFaceLayer.order) { - woeend = iFaceLayer.fl->getSmoothEdge()->woeb(); - tend = iFaceLayer.fl->getSmoothEdge()->tb(); - } - else { - woeend = iFaceLayer.fl->getSmoothEdge()->woea(); - tend = iFaceLayer.fl->getSmoothEdge()->ta(); - } - // special case of EDGE_VERTEX config: - if ((tend == 0.0) || (tend == 1.0)) { - WVertex *nextVertex; - if (tend == 0.0) - nextVertex = woeend->GetaVertex(); - else - nextVertex = woeend->GetbVertex(); - if (nextVertex->isBoundary()) // if it's a non-manifold vertex -> ignore - return OWXFaceLayer(0, true); - bool found = false; - WVertex::face_iterator f = nextVertex->faces_begin(); - WVertex::face_iterator fend = nextVertex->faces_end(); - while ((!found) && (f != fend)) { - nextFace = dynamic_cast(*f); - if ((0 != nextFace) && (nextFace != iFaceLayer.fl->getFace())) { - vector sameNatureLayers; - nextFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); - // don't know... Maybe should test whether this face has also a vertex_edge configuration. - if (sameNatureLayers.size() == 1) { - WXFaceLayer *winner = sameNatureLayers[0]; - // check face mark continuity - if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) - return OWXFaceLayer(NULL, true); - if (woeend == winner->getSmoothEdge()->woea()->twin()) - return OWXFaceLayer(winner, true); - else - return OWXFaceLayer(winner, false); - } - } - ++f; - } - } - else { - nextFace = dynamic_cast(iFaceLayer.fl->getFace()->GetBordingFace(woeend)); - if (!nextFace) - return OWXFaceLayer(NULL, true); - // if the next face layer has either no smooth edge or no smooth edge of same nature, no next face - if (!nextFace->hasSmoothEdges()) - return OWXFaceLayer(NULL, true); - vector sameNatureLayers; - nextFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); - // don't know how to deal with several edges of same nature on a single face - if ((sameNatureLayers.empty()) || (sameNatureLayers.size() != 1)) { - return OWXFaceLayer(NULL, true); - } - else { - WXFaceLayer *winner = sameNatureLayers[0]; - // check face mark continuity - if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) - return OWXFaceLayer(NULL, true); - if (woeend == winner->getSmoothEdge()->woea()->twin()) - return OWXFaceLayer(winner, true); - else - return OWXFaceLayer(winner, false); - } - } - return OWXFaceLayer(NULL, true); + WXFace *nextFace = NULL; + WOEdge *woeend; + real tend; + if (iFaceLayer.order) { + woeend = iFaceLayer.fl->getSmoothEdge()->woeb(); + tend = iFaceLayer.fl->getSmoothEdge()->tb(); + } + else { + woeend = iFaceLayer.fl->getSmoothEdge()->woea(); + tend = iFaceLayer.fl->getSmoothEdge()->ta(); + } + // special case of EDGE_VERTEX config: + if ((tend == 0.0) || (tend == 1.0)) { + WVertex *nextVertex; + if (tend == 0.0) + nextVertex = woeend->GetaVertex(); + else + nextVertex = woeend->GetbVertex(); + if (nextVertex->isBoundary()) // if it's a non-manifold vertex -> ignore + return OWXFaceLayer(0, true); + bool found = false; + WVertex::face_iterator f = nextVertex->faces_begin(); + WVertex::face_iterator fend = nextVertex->faces_end(); + while ((!found) && (f != fend)) { + nextFace = dynamic_cast(*f); + if ((0 != nextFace) && (nextFace != iFaceLayer.fl->getFace())) { + vector sameNatureLayers; + nextFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); + // don't know... Maybe should test whether this face has also a vertex_edge configuration. + if (sameNatureLayers.size() == 1) { + WXFaceLayer *winner = sameNatureLayers[0]; + // check face mark continuity + if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) + return OWXFaceLayer(NULL, true); + if (woeend == winner->getSmoothEdge()->woea()->twin()) + return OWXFaceLayer(winner, true); + else + return OWXFaceLayer(winner, false); + } + } + ++f; + } + } + else { + nextFace = dynamic_cast(iFaceLayer.fl->getFace()->GetBordingFace(woeend)); + if (!nextFace) + return OWXFaceLayer(NULL, true); + // if the next face layer has either no smooth edge or no smooth edge of same nature, no next face + if (!nextFace->hasSmoothEdges()) + return OWXFaceLayer(NULL, true); + vector sameNatureLayers; + nextFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); + // don't know how to deal with several edges of same nature on a single face + if ((sameNatureLayers.empty()) || (sameNatureLayers.size() != 1)) { + return OWXFaceLayer(NULL, true); + } + else { + WXFaceLayer *winner = sameNatureLayers[0]; + // check face mark continuity + if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) + return OWXFaceLayer(NULL, true); + if (woeend == winner->getSmoothEdge()->woea()->twin()) + return OWXFaceLayer(winner, true); + else + return OWXFaceLayer(winner, false); + } + } + return OWXFaceLayer(NULL, true); } -OWXFaceLayer ViewEdgeXBuilder::FindPreviousFaceLayer(const OWXFaceLayer& iFaceLayer) +OWXFaceLayer ViewEdgeXBuilder::FindPreviousFaceLayer(const OWXFaceLayer &iFaceLayer) { - WXFace *previousFace = NULL; - WOEdge *woebegin; - real tend; - if (iFaceLayer.order) { - woebegin = iFaceLayer.fl->getSmoothEdge()->woea(); - tend = iFaceLayer.fl->getSmoothEdge()->ta(); - } - else { - woebegin = iFaceLayer.fl->getSmoothEdge()->woeb(); - tend = iFaceLayer.fl->getSmoothEdge()->tb(); - } - - // special case of EDGE_VERTEX config: - if ((tend == 0.0) || (tend == 1.0)) { - WVertex *previousVertex; - if (tend == 0.0) - previousVertex = woebegin->GetaVertex(); - else - previousVertex = woebegin->GetbVertex(); - if (previousVertex->isBoundary()) // if it's a non-manifold vertex -> ignore - return OWXFaceLayer(NULL, true); - bool found = false; - WVertex::face_iterator f = previousVertex->faces_begin(); - WVertex::face_iterator fend = previousVertex->faces_end(); - for (; (!found) && (f != fend); ++f) { - previousFace = dynamic_cast(*f); - if ((0 != previousFace) && (previousFace != iFaceLayer.fl->getFace())) { - vector sameNatureLayers; - previousFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); - // don't know... Maybe should test whether this face has also a vertex_edge configuration - if (sameNatureLayers.size() == 1) { - WXFaceLayer *winner = sameNatureLayers[0]; - // check face mark continuity - if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) - return OWXFaceLayer(NULL, true); - if (woebegin == winner->getSmoothEdge()->woeb()->twin()) - return OWXFaceLayer(winner, true); - else - return OWXFaceLayer(winner, false); - } - } - } - } - else { - previousFace = dynamic_cast(iFaceLayer.fl->getFace()->GetBordingFace(woebegin)); - if (0 == previousFace) - return OWXFaceLayer(NULL, true); - // if the next face layer has either no smooth edge or no smooth edge of same nature, no next face - if (!previousFace->hasSmoothEdges()) - return OWXFaceLayer(NULL, true); - vector sameNatureLayers; - previousFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); - // don't know how to deal with several edges of same nature on a single face - if ((sameNatureLayers.empty()) || (sameNatureLayers.size() != 1)) { - return OWXFaceLayer(NULL, true); - } - else { - WXFaceLayer *winner = sameNatureLayers[0]; - // check face mark continuity - if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) - return OWXFaceLayer(NULL, true); - if (woebegin == winner->getSmoothEdge()->woeb()->twin()) - return OWXFaceLayer(winner, true); - else - return OWXFaceLayer(winner, false); - } - } - return OWXFaceLayer(NULL, true); + WXFace *previousFace = NULL; + WOEdge *woebegin; + real tend; + if (iFaceLayer.order) { + woebegin = iFaceLayer.fl->getSmoothEdge()->woea(); + tend = iFaceLayer.fl->getSmoothEdge()->ta(); + } + else { + woebegin = iFaceLayer.fl->getSmoothEdge()->woeb(); + tend = iFaceLayer.fl->getSmoothEdge()->tb(); + } + + // special case of EDGE_VERTEX config: + if ((tend == 0.0) || (tend == 1.0)) { + WVertex *previousVertex; + if (tend == 0.0) + previousVertex = woebegin->GetaVertex(); + else + previousVertex = woebegin->GetbVertex(); + if (previousVertex->isBoundary()) // if it's a non-manifold vertex -> ignore + return OWXFaceLayer(NULL, true); + bool found = false; + WVertex::face_iterator f = previousVertex->faces_begin(); + WVertex::face_iterator fend = previousVertex->faces_end(); + for (; (!found) && (f != fend); ++f) { + previousFace = dynamic_cast(*f); + if ((0 != previousFace) && (previousFace != iFaceLayer.fl->getFace())) { + vector sameNatureLayers; + previousFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); + // don't know... Maybe should test whether this face has also a vertex_edge configuration + if (sameNatureLayers.size() == 1) { + WXFaceLayer *winner = sameNatureLayers[0]; + // check face mark continuity + if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) + return OWXFaceLayer(NULL, true); + if (woebegin == winner->getSmoothEdge()->woeb()->twin()) + return OWXFaceLayer(winner, true); + else + return OWXFaceLayer(winner, false); + } + } + } + } + else { + previousFace = dynamic_cast(iFaceLayer.fl->getFace()->GetBordingFace(woebegin)); + if (0 == previousFace) + return OWXFaceLayer(NULL, true); + // if the next face layer has either no smooth edge or no smooth edge of same nature, no next face + if (!previousFace->hasSmoothEdges()) + return OWXFaceLayer(NULL, true); + vector sameNatureLayers; + previousFace->retrieveSmoothEdgesLayers(iFaceLayer.fl->nature(), sameNatureLayers); + // don't know how to deal with several edges of same nature on a single face + if ((sameNatureLayers.empty()) || (sameNatureLayers.size() != 1)) { + return OWXFaceLayer(NULL, true); + } + else { + WXFaceLayer *winner = sameNatureLayers[0]; + // check face mark continuity + if (winner->getFace()->GetMark() != iFaceLayer.fl->getFace()->GetMark()) + return OWXFaceLayer(NULL, true); + if (woebegin == winner->getSmoothEdge()->woeb()->twin()) + return OWXFaceLayer(winner, true); + else + return OWXFaceLayer(winner, false); + } + } + return OWXFaceLayer(NULL, true); } -FEdge *ViewEdgeXBuilder::BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer& ifl) +FEdge *ViewEdgeXBuilder::BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer &ifl) { - WOEdge *woea, *woeb; - real ta, tb; - SVertex *va, *vb; - FEdgeSmooth *fe; - // retrieve exact silhouette data - WXSmoothEdge *se = ifl.fl->getSmoothEdge(); - - if (ifl.order) { - woea = se->woea(); - woeb = se->woeb(); - ta = se->ta(); - tb = se->tb(); - } - else { - woea = se->woeb(); - woeb = se->woea(); - ta = se->tb(); - tb = se->ta(); - } - - Vec3r normal; - // Make the 2 Svertices - if (feprevious == 0) { // that means that we don't have any vertex already built for that face - Vec3r A1(woea->GetaVertex()->GetVertex()); - Vec3r A2(woea->GetbVertex()->GetVertex()); - Vec3r A(A1 + ta * (A2 - A1)); - - va = MakeSVertex(A, false); - // Set normal: - Vec3r NA1(ifl.fl->getFace()->GetVertexNormal(woea->GetaVertex())); - Vec3r NA2(ifl.fl->getFace()->GetVertexNormal(woea->GetbVertex())); - Vec3r na((1 - ta) * NA1 + ta * NA2); - na.normalize(); - va->AddNormal(na); - normal = na; - - // Set CurvatureInfo - CurvatureInfo *curvature_info_a = - new CurvatureInfo(*(dynamic_cast(woea->GetaVertex())->curvatures()), - *(dynamic_cast(woea->GetbVertex())->curvatures()), ta); - va->setCurvatureInfo(curvature_info_a); - } - else { - va = feprevious->vertexB(); - } - - Vec3r B1(woeb->GetaVertex()->GetVertex()); - Vec3r B2(woeb->GetbVertex()->GetVertex()); - Vec3r B(B1 + tb * (B2 - B1)); - - if (feprevious && (B - va->point3D()).norm() < 1.0e-6) - return feprevious; - - vb = MakeSVertex(B, false); - // Set normal: - Vec3r NB1(ifl.fl->getFace()->GetVertexNormal(woeb->GetaVertex())); - Vec3r NB2(ifl.fl->getFace()->GetVertexNormal(woeb->GetbVertex())); - Vec3r nb((1 - tb) * NB1 + tb * NB2); - nb.normalize(); - normal += nb; - vb->AddNormal(nb); - - // Set CurvatureInfo - CurvatureInfo *curvature_info_b = - new CurvatureInfo(*(dynamic_cast(woeb->GetaVertex())->curvatures()), - *(dynamic_cast(woeb->GetbVertex())->curvatures()), tb); - vb->setCurvatureInfo(curvature_info_b); - - // Creates the corresponding feature edge - fe = new FEdgeSmooth(va, vb); - fe->setNature(ifl.fl->nature()); - fe->setId(_currentFId); - fe->setFrsMaterialIndex(ifl.fl->getFace()->frs_materialIndex()); - fe->setFace(ifl.fl->getFace()); - fe->setFaceMark(ifl.fl->getFace()->GetMark()); - if (feprevious == 0) - normal.normalize(); - fe->setNormal(normal); - fe->setPreviousEdge(feprevious); - if (feprevious) - feprevious->setNextEdge(fe); - _pCurrentSShape->AddEdge(fe); - va->AddFEdge(fe); - vb->AddFEdge(fe); - - ++_currentFId; - ifl.fl->userdata = fe; - return fe; + WOEdge *woea, *woeb; + real ta, tb; + SVertex *va, *vb; + FEdgeSmooth *fe; + // retrieve exact silhouette data + WXSmoothEdge *se = ifl.fl->getSmoothEdge(); + + if (ifl.order) { + woea = se->woea(); + woeb = se->woeb(); + ta = se->ta(); + tb = se->tb(); + } + else { + woea = se->woeb(); + woeb = se->woea(); + ta = se->tb(); + tb = se->ta(); + } + + Vec3r normal; + // Make the 2 Svertices + if (feprevious == 0) { // that means that we don't have any vertex already built for that face + Vec3r A1(woea->GetaVertex()->GetVertex()); + Vec3r A2(woea->GetbVertex()->GetVertex()); + Vec3r A(A1 + ta * (A2 - A1)); + + va = MakeSVertex(A, false); + // Set normal: + Vec3r NA1(ifl.fl->getFace()->GetVertexNormal(woea->GetaVertex())); + Vec3r NA2(ifl.fl->getFace()->GetVertexNormal(woea->GetbVertex())); + Vec3r na((1 - ta) * NA1 + ta * NA2); + na.normalize(); + va->AddNormal(na); + normal = na; + + // Set CurvatureInfo + CurvatureInfo *curvature_info_a = new CurvatureInfo( + *(dynamic_cast(woea->GetaVertex())->curvatures()), + *(dynamic_cast(woea->GetbVertex())->curvatures()), + ta); + va->setCurvatureInfo(curvature_info_a); + } + else { + va = feprevious->vertexB(); + } + + Vec3r B1(woeb->GetaVertex()->GetVertex()); + Vec3r B2(woeb->GetbVertex()->GetVertex()); + Vec3r B(B1 + tb * (B2 - B1)); + + if (feprevious && (B - va->point3D()).norm() < 1.0e-6) + return feprevious; + + vb = MakeSVertex(B, false); + // Set normal: + Vec3r NB1(ifl.fl->getFace()->GetVertexNormal(woeb->GetaVertex())); + Vec3r NB2(ifl.fl->getFace()->GetVertexNormal(woeb->GetbVertex())); + Vec3r nb((1 - tb) * NB1 + tb * NB2); + nb.normalize(); + normal += nb; + vb->AddNormal(nb); + + // Set CurvatureInfo + CurvatureInfo *curvature_info_b = new CurvatureInfo( + *(dynamic_cast(woeb->GetaVertex())->curvatures()), + *(dynamic_cast(woeb->GetbVertex())->curvatures()), + tb); + vb->setCurvatureInfo(curvature_info_b); + + // Creates the corresponding feature edge + fe = new FEdgeSmooth(va, vb); + fe->setNature(ifl.fl->nature()); + fe->setId(_currentFId); + fe->setFrsMaterialIndex(ifl.fl->getFace()->frs_materialIndex()); + fe->setFace(ifl.fl->getFace()); + fe->setFaceMark(ifl.fl->getFace()->GetMark()); + if (feprevious == 0) + normal.normalize(); + fe->setNormal(normal); + fe->setPreviousEdge(feprevious); + if (feprevious) + feprevious->setNextEdge(fe); + _pCurrentSShape->AddEdge(fe); + va->AddFEdge(fe); + vb->AddFEdge(fe); + + ++_currentFId; + ifl.fl->userdata = fe; + return fe; } bool ViewEdgeXBuilder::stopSmoothViewEdge(WXFaceLayer *iFaceLayer) { - if (NULL == iFaceLayer) - return true; - if (iFaceLayer->userdata == 0) - return false; - return true; + if (NULL == iFaceLayer) + return true; + if (iFaceLayer->userdata == 0) + return false; + return true; } int ViewEdgeXBuilder::retrieveFaceMarks(WXEdge *iEdge) { - WFace *aFace = iEdge->GetaFace(); - WFace *bFace = iEdge->GetbFace(); - int result = 0; - if (aFace && aFace->GetMark()) - result += 1; - if (bFace && bFace->GetMark()) - result += 2; - return result; + WFace *aFace = iEdge->GetaFace(); + WFace *bFace = iEdge->GetbFace(); + int result = 0; + if (aFace && aFace->GetMark()) + result += 1; + if (bFace && bFace->GetMark()) + result += 2; + return result; } -OWXEdge ViewEdgeXBuilder::FindNextWEdge(const OWXEdge& iEdge) +OWXEdge ViewEdgeXBuilder::FindNextWEdge(const OWXEdge &iEdge) { - if (Nature::NO_FEATURE == iEdge.e->nature()) - return OWXEdge(NULL, true); - - WVertex *v; - if (true == iEdge.order) - v = iEdge.e->GetbVertex(); - else - v = iEdge.e->GetaVertex(); - - if (((WXVertex *)v)->isFeature()) - return 0; /* XXX eeek? NULL? OWXEdge(NULL, true/false)?*/ - - int faceMarks = retrieveFaceMarks(iEdge.e); - vector& vEdges = (v)->GetEdges(); - for (vector::iterator ve = vEdges.begin(), veend = vEdges.end(); ve != veend; ve++) { - WXEdge *wxe = dynamic_cast(*ve); - if (wxe == iEdge.e) - continue; // same edge as the one processed - - if (wxe->nature() != iEdge.e->nature()) - continue; - - // check face mark continuity - if (retrieveFaceMarks(wxe) != faceMarks) - continue; - - if (wxe->GetaVertex() == v) { - // That means that the face necesarily lies on the edge left. - // So the vertex order is OK. - return OWXEdge(wxe, true); - } - else { - // That means that the face necesarily lies on the edge left. - // So the vertex order is OK. - return OWXEdge(wxe, false); - } - } - // we did not find: - return OWXEdge(NULL, true); + if (Nature::NO_FEATURE == iEdge.e->nature()) + return OWXEdge(NULL, true); + + WVertex *v; + if (true == iEdge.order) + v = iEdge.e->GetbVertex(); + else + v = iEdge.e->GetaVertex(); + + if (((WXVertex *)v)->isFeature()) + return 0; /* XXX eeek? NULL? OWXEdge(NULL, true/false)?*/ + + int faceMarks = retrieveFaceMarks(iEdge.e); + vector &vEdges = (v)->GetEdges(); + for (vector::iterator ve = vEdges.begin(), veend = vEdges.end(); ve != veend; ve++) { + WXEdge *wxe = dynamic_cast(*ve); + if (wxe == iEdge.e) + continue; // same edge as the one processed + + if (wxe->nature() != iEdge.e->nature()) + continue; + + // check face mark continuity + if (retrieveFaceMarks(wxe) != faceMarks) + continue; + + if (wxe->GetaVertex() == v) { + // That means that the face necesarily lies on the edge left. + // So the vertex order is OK. + return OWXEdge(wxe, true); + } + else { + // That means that the face necesarily lies on the edge left. + // So the vertex order is OK. + return OWXEdge(wxe, false); + } + } + // we did not find: + return OWXEdge(NULL, true); } -OWXEdge ViewEdgeXBuilder::FindPreviousWEdge(const OWXEdge& iEdge) +OWXEdge ViewEdgeXBuilder::FindPreviousWEdge(const OWXEdge &iEdge) { - if (Nature::NO_FEATURE == iEdge.e->nature()) - return OWXEdge(NULL, true); - - WVertex *v; - if (true == iEdge.order) - v = iEdge.e->GetaVertex(); - else - v = iEdge.e->GetbVertex(); - - if (((WXVertex *)v)->isFeature()) - return 0; - - int faceMarks = retrieveFaceMarks(iEdge.e); - vector& vEdges = (v)->GetEdges(); - for (vector::iterator ve = vEdges.begin(), veend = vEdges.end(); ve != veend; ve++) { - WXEdge *wxe = dynamic_cast(*ve); - if (wxe == iEdge.e) - continue; // same edge as the one processed - - if (wxe->nature() != iEdge.e->nature()) - continue; - - // check face mark continuity - if (retrieveFaceMarks(wxe) != faceMarks) - continue; - - if (wxe->GetbVertex() == v) { - return OWXEdge(wxe, true); - } - else { - return OWXEdge(wxe, false); - } - } - // we did not find: - return OWXEdge(NULL, true); + if (Nature::NO_FEATURE == iEdge.e->nature()) + return OWXEdge(NULL, true); + + WVertex *v; + if (true == iEdge.order) + v = iEdge.e->GetaVertex(); + else + v = iEdge.e->GetbVertex(); + + if (((WXVertex *)v)->isFeature()) + return 0; + + int faceMarks = retrieveFaceMarks(iEdge.e); + vector &vEdges = (v)->GetEdges(); + for (vector::iterator ve = vEdges.begin(), veend = vEdges.end(); ve != veend; ve++) { + WXEdge *wxe = dynamic_cast(*ve); + if (wxe == iEdge.e) + continue; // same edge as the one processed + + if (wxe->nature() != iEdge.e->nature()) + continue; + + // check face mark continuity + if (retrieveFaceMarks(wxe) != faceMarks) + continue; + + if (wxe->GetbVertex() == v) { + return OWXEdge(wxe, true); + } + else { + return OWXEdge(wxe, false); + } + } + // we did not find: + return OWXEdge(NULL, true); } -FEdge *ViewEdgeXBuilder::BuildSharpFEdge(FEdge *feprevious, const OWXEdge& iwe) +FEdge *ViewEdgeXBuilder::BuildSharpFEdge(FEdge *feprevious, const OWXEdge &iwe) { - SVertex *va, *vb; - FEdgeSharp *fe; - Vec3r vA, vB; - if (iwe.order) { - vA = iwe.e->GetaVertex()->GetVertex(); - vB = iwe.e->GetbVertex()->GetVertex(); - } - else { - vA = iwe.e->GetbVertex()->GetVertex(); - vB = iwe.e->GetaVertex()->GetVertex(); - } - // Make the 2 SVertex - va = MakeSVertex(vA, true); - vb = MakeSVertex(vB, true); - - // get the faces normals and the material indices - Vec3r normalA, normalB; - unsigned matA(0), matB(0); - bool faceMarkA = false, faceMarkB = false; - if (iwe.order) { - normalB = (iwe.e->GetbFace()->GetNormal()); - matB = (iwe.e->GetbFace()->frs_materialIndex()); - faceMarkB = (iwe.e->GetbFace()->GetMark()); - if (!(iwe.e->nature() & Nature::BORDER)) { - normalA = (iwe.e->GetaFace()->GetNormal()); - matA = (iwe.e->GetaFace()->frs_materialIndex()); - faceMarkA = (iwe.e->GetaFace()->GetMark()); - } - } - else { - normalA = (iwe.e->GetbFace()->GetNormal()); - matA = (iwe.e->GetbFace()->frs_materialIndex()); - faceMarkA = (iwe.e->GetbFace()->GetMark()); - if (!(iwe.e->nature() & Nature::BORDER)) { - normalB = (iwe.e->GetaFace()->GetNormal()); - matB = (iwe.e->GetaFace()->frs_materialIndex()); - faceMarkB = (iwe.e->GetaFace()->GetMark()); - } - } - // Creates the corresponding feature edge - fe = new FEdgeSharp(va, vb); - fe->setNature(iwe.e->nature()); - fe->setId(_currentFId); - fe->setaFrsMaterialIndex(matA); - fe->setbFrsMaterialIndex(matB); - fe->setaFaceMark(faceMarkA); - fe->setbFaceMark(faceMarkB); - fe->setNormalA(normalA); - fe->setNormalB(normalB); - fe->setPreviousEdge(feprevious); - if (feprevious) - feprevious->setNextEdge(fe); - _pCurrentSShape->AddEdge(fe); - va->AddFEdge(fe); - vb->AddFEdge(fe); - //Add normals: - va->AddNormal(normalA); - va->AddNormal(normalB); - vb->AddNormal(normalA); - vb->AddNormal(normalB); - - ++_currentFId; - iwe.e->userdata = fe; - return fe; + SVertex *va, *vb; + FEdgeSharp *fe; + Vec3r vA, vB; + if (iwe.order) { + vA = iwe.e->GetaVertex()->GetVertex(); + vB = iwe.e->GetbVertex()->GetVertex(); + } + else { + vA = iwe.e->GetbVertex()->GetVertex(); + vB = iwe.e->GetaVertex()->GetVertex(); + } + // Make the 2 SVertex + va = MakeSVertex(vA, true); + vb = MakeSVertex(vB, true); + + // get the faces normals and the material indices + Vec3r normalA, normalB; + unsigned matA(0), matB(0); + bool faceMarkA = false, faceMarkB = false; + if (iwe.order) { + normalB = (iwe.e->GetbFace()->GetNormal()); + matB = (iwe.e->GetbFace()->frs_materialIndex()); + faceMarkB = (iwe.e->GetbFace()->GetMark()); + if (!(iwe.e->nature() & Nature::BORDER)) { + normalA = (iwe.e->GetaFace()->GetNormal()); + matA = (iwe.e->GetaFace()->frs_materialIndex()); + faceMarkA = (iwe.e->GetaFace()->GetMark()); + } + } + else { + normalA = (iwe.e->GetbFace()->GetNormal()); + matA = (iwe.e->GetbFace()->frs_materialIndex()); + faceMarkA = (iwe.e->GetbFace()->GetMark()); + if (!(iwe.e->nature() & Nature::BORDER)) { + normalB = (iwe.e->GetaFace()->GetNormal()); + matB = (iwe.e->GetaFace()->frs_materialIndex()); + faceMarkB = (iwe.e->GetaFace()->GetMark()); + } + } + // Creates the corresponding feature edge + fe = new FEdgeSharp(va, vb); + fe->setNature(iwe.e->nature()); + fe->setId(_currentFId); + fe->setaFrsMaterialIndex(matA); + fe->setbFrsMaterialIndex(matB); + fe->setaFaceMark(faceMarkA); + fe->setbFaceMark(faceMarkB); + fe->setNormalA(normalA); + fe->setNormalB(normalB); + fe->setPreviousEdge(feprevious); + if (feprevious) + feprevious->setNextEdge(fe); + _pCurrentSShape->AddEdge(fe); + va->AddFEdge(fe); + vb->AddFEdge(fe); + //Add normals: + va->AddNormal(normalA); + va->AddNormal(normalB); + vb->AddNormal(normalA); + vb->AddNormal(normalB); + + ++_currentFId; + iwe.e->userdata = fe; + return fe; } bool ViewEdgeXBuilder::stopSharpViewEdge(WXEdge *iEdge) { - if (NULL == iEdge) - return true; - if (iEdge->userdata == 0) - return false; - return true; + if (NULL == iEdge) + return true; + if (iEdge->userdata == 0) + return false; + return true; } -SVertex *ViewEdgeXBuilder::MakeSVertex(Vec3r& iPoint) +SVertex *ViewEdgeXBuilder::MakeSVertex(Vec3r &iPoint) { - SVertex *va = new SVertex(iPoint, _currentSVertexId); - SilhouetteGeomEngine::ProjectSilhouette(va); - ++_currentSVertexId; - // Add the svertex to the SShape svertex list: - _pCurrentSShape->AddNewVertex(va); - return va; + SVertex *va = new SVertex(iPoint, _currentSVertexId); + SilhouetteGeomEngine::ProjectSilhouette(va); + ++_currentSVertexId; + // Add the svertex to the SShape svertex list: + _pCurrentSShape->AddNewVertex(va); + return va; } -SVertex *ViewEdgeXBuilder::MakeSVertex(Vec3r& iPoint, bool shared) +SVertex *ViewEdgeXBuilder::MakeSVertex(Vec3r &iPoint, bool shared) { - SVertex *va; - if (!shared) { - va = MakeSVertex(iPoint); - } - else { - // Check whether the iPoint is already in the table - SVertexMap::const_iterator found = _SVertexMap.find(iPoint); - if (shared && found != _SVertexMap.end()) { - va = (*found).second; - } - else { - va = MakeSVertex(iPoint); - // Add the svertex into the table using iPoint as the key - _SVertexMap[iPoint] = va; - } - } - return va; + SVertex *va; + if (!shared) { + va = MakeSVertex(iPoint); + } + else { + // Check whether the iPoint is already in the table + SVertexMap::const_iterator found = _SVertexMap.find(iPoint); + if (shared && found != _SVertexMap.end()) { + va = (*found).second; + } + else { + va = MakeSVertex(iPoint); + // Add the svertex into the table using iPoint as the key + _SVertexMap[iPoint] = va; + } + } + return va; } ViewVertex *ViewEdgeXBuilder::MakeViewVertex(SVertex *iSVertex) { - ViewVertex *vva = iSVertex->viewvertex(); - if (vva) - return vva; - vva = new NonTVertex(iSVertex); - // Add the view vertex to the ViewShape svertex list: - _pCurrentVShape->AddVertex(vva); - return vva; + ViewVertex *vva = iSVertex->viewvertex(); + if (vva) + return vva; + vva = new NonTVertex(iSVertex); + // Add the view vertex to the ViewShape svertex list: + _pCurrentVShape->AddVertex(vva); + return vva; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h index fbe0ee8be0f..6f3604a1029 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h @@ -26,13 +26,13 @@ #include #include -#if 0 // soc -#if defined(__GNUC__) && (__GNUC__ >= 3) +#if 0 // soc +# if defined(__GNUC__) && (__GNUC__ >= 3) //hash_map is not part of the C++ standard anymore; hash_map.h has been kept though for backward compatibility -# include -#else -# include -#endif +# include +# else +# include +# endif #endif #include "Interface1D.h" @@ -42,7 +42,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -54,117 +54,112 @@ using namespace Geometry; class SVertex; /*! Defines a hash table used for searching the SVertex */ -struct SVertexHasher -{ +struct SVertexHasher { #define _MUL 950706376UL #define _MOD 2147483647UL - inline size_t operator()(const Vec3r& p) const - { - size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD; - res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD; - return ((res +(unsigned long)(p[2]) * _MUL)) % _MOD; - } + inline size_t operator()(const Vec3r &p) const + { + size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD; + res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD; + return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD; + } #undef _MUL #undef _MOD }; // Key_compare predicate for hash_map. In particular, return false if equal. -struct epsilonEquals -{ - bool operator()(const Vec3r& v1, const Vec3r& v2) const - { - real norm = (v1 - v2).norm(); - return (norm < 1.0e-06); - } +struct epsilonEquals { + bool operator()(const Vec3r &v1, const Vec3r &v2) const + { + real norm = (v1 - v2).norm(); + return (norm < 1.0e-06); + } }; - // typedef hash_map SVertexMap; typedef map SVertexMap; class WXFaceLayer; /*! class to describe an oriented smooth edge */ -class OWXFaceLayer -{ -public: - WXFaceLayer *fl; - bool order; - - OWXFaceLayer() - { - fl = NULL; - order = true; - } - - OWXFaceLayer(WXFaceLayer *ifl, bool iOrder = true) - { - fl = ifl; - order = iOrder; - } - - OWXFaceLayer& operator=(const OWXFaceLayer& iBrother) - { - fl = iBrother.fl; - order = iBrother.order; - return *this; - } - - bool operator==(const OWXFaceLayer& b) - { - return ((fl == b.fl) && (order == b.order)); - } - - bool operator!=(const OWXFaceLayer& b) - { - return !(*this == b); - } +class OWXFaceLayer { + public: + WXFaceLayer *fl; + bool order; + + OWXFaceLayer() + { + fl = NULL; + order = true; + } + + OWXFaceLayer(WXFaceLayer *ifl, bool iOrder = true) + { + fl = ifl; + order = iOrder; + } + + OWXFaceLayer &operator=(const OWXFaceLayer &iBrother) + { + fl = iBrother.fl; + order = iBrother.order; + return *this; + } + + bool operator==(const OWXFaceLayer &b) + { + return ((fl == b.fl) && (order == b.order)); + } + + bool operator!=(const OWXFaceLayer &b) + { + return !(*this == b); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OWXFaceLayer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OWXFaceLayer") #endif }; class WXEdge; /*! class to describe an oriented sharp edge */ -class OWXEdge -{ -public: - WXEdge *e; - bool order; - - OWXEdge() - { - e = NULL; - order = true; - } - - OWXEdge(WXEdge *ie, bool iOrder = true) - { - e = ie; - order = iOrder; - } - - OWXEdge& operator=(const OWXEdge& iBrother) - { - e = iBrother.e; - order = iBrother.order; - return *this; - } - - bool operator==(const OWXEdge& b) - { - return ((e == b.e) && (order == b.order)); - } - - bool operator!=(const OWXEdge& b) - { - return !(*this == b); - } +class OWXEdge { + public: + WXEdge *e; + bool order; + + OWXEdge() + { + e = NULL; + order = true; + } + + OWXEdge(WXEdge *ie, bool iOrder = true) + { + e = ie; + order = iOrder; + } + + OWXEdge &operator=(const OWXEdge &iBrother) + { + e = iBrother.e; + order = iBrother.order; + return *this; + } + + bool operator==(const OWXEdge &b) + { + return ((e == b.e) && (order == b.order)); + } + + bool operator!=(const OWXEdge &b) + { + return !(*this == b); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OWXEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:OWXEdge") #endif }; @@ -177,117 +172,121 @@ class ViewVertex; class ViewEdge; class ViewShape; -class ViewEdgeXBuilder -{ -protected: - int _currentViewId; // Id for view edges - int _currentFId; // Id for FEdges - int _currentSVertexId; // Id for SVertex - -public: - inline ViewEdgeXBuilder() - { - _currentViewId = 1; - _currentFId = 0; - _currentSVertexId = 0; - } - - virtual ~ViewEdgeXBuilder() {} - - /*! Builds a view shape from a WXShape in which the feature edges are flagged - * Builds chains of feature edges (so ViewEdges) from a WXShape - * iWShape - * The Winged Edge structure in which all silhouette edges and vertices are flagged. - * oViewShape - * The Silhouette Shape in which the chains must be added. - * ioVEdges - * The list of new ViewEdges. - * ioVVertices - * THe new ViewVertices - * ioFEdges - * A list in which all new FEdges are added - * ioSVertices - * A list of SVertex where all created SVertex are added. - */ - virtual void BuildViewEdges(WXShape *iWShape, ViewShape *oVShape, std::vector& ioVEdges, - std::vector& ioVVertices, std::vector& ioFEdges, - std::vector& ioSVertices); - - /*! Builds a smooth view edge, starting the face iFace. */ - ViewEdge *BuildSmoothViewEdge(const OWXFaceLayer& iFaceLayer); - - /*! Makes a sharp viewedge */ - ViewEdge *BuildSharpViewEdge(const OWXEdge& iWEdge); - -public: - /*! accessors */ - inline int currentViewId() const - { - return _currentViewId; - } - - inline int currentFId() const - { - return _currentFId; - } - - inline int currentSVertexId() const - { - return _currentSVertexId; - } - - /*! modifiers */ - inline void setCurrentViewId(int id) - { - _currentViewId = id; - } - - inline void setCurrentFId(int id) - { - _currentFId = id; - } - - inline void setCurrentSVertexId(int id) - { - _currentSVertexId = id; - } - -protected: - /*! Init the view edges building */ - virtual void Init(ViewShape *oVShape); - - // SMOOTH // - /*! checks whether a face has already been processed or not */ - bool stopSmoothViewEdge(WXFaceLayer *iFaceLayer); - OWXFaceLayer FindNextFaceLayer(const OWXFaceLayer& iFaceLayer); - OWXFaceLayer FindPreviousFaceLayer(const OWXFaceLayer& iFaceLayer); - FEdge *BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer& ifl); - - // SHARP // - /*! checks whether a WEdge has already been processed or not */ - bool stopSharpViewEdge(WXEdge *iFace); - int retrieveFaceMarks(WXEdge *iEdge); - OWXEdge FindNextWEdge(const OWXEdge& iEdge); - OWXEdge FindPreviousWEdge(const OWXEdge& iEdge); - FEdge *BuildSharpFEdge(FEdge *feprevious, const OWXEdge& iwe); - - // GENERAL // - /*! Instanciate a SVertex */ - SVertex *MakeSVertex(Vec3r& iPoint); - /*! Instanciate a SVertex if it hasn't been already created */ - SVertex *MakeSVertex(Vec3r& iPoint, bool shared); - /*! instanciate a ViewVertex from a SVertex, if it doesn't exist yet */ - ViewVertex *MakeViewVertex(SVertex *iSVertex); - - //oldtmp values - //IdHashTable _hashtable; - //VVIdHashTable _multivertexHashTable; - SVertexMap _SVertexMap; - SShape *_pCurrentSShape; - ViewShape *_pCurrentVShape; +class ViewEdgeXBuilder { + protected: + int _currentViewId; // Id for view edges + int _currentFId; // Id for FEdges + int _currentSVertexId; // Id for SVertex + + public: + inline ViewEdgeXBuilder() + { + _currentViewId = 1; + _currentFId = 0; + _currentSVertexId = 0; + } + + virtual ~ViewEdgeXBuilder() + { + } + + /*! Builds a view shape from a WXShape in which the feature edges are flagged + * Builds chains of feature edges (so ViewEdges) from a WXShape + * iWShape + * The Winged Edge structure in which all silhouette edges and vertices are flagged. + * oViewShape + * The Silhouette Shape in which the chains must be added. + * ioVEdges + * The list of new ViewEdges. + * ioVVertices + * THe new ViewVertices + * ioFEdges + * A list in which all new FEdges are added + * ioSVertices + * A list of SVertex where all created SVertex are added. + */ + virtual void BuildViewEdges(WXShape *iWShape, + ViewShape *oVShape, + std::vector &ioVEdges, + std::vector &ioVVertices, + std::vector &ioFEdges, + std::vector &ioSVertices); + + /*! Builds a smooth view edge, starting the face iFace. */ + ViewEdge *BuildSmoothViewEdge(const OWXFaceLayer &iFaceLayer); + + /*! Makes a sharp viewedge */ + ViewEdge *BuildSharpViewEdge(const OWXEdge &iWEdge); + + public: + /*! accessors */ + inline int currentViewId() const + { + return _currentViewId; + } + + inline int currentFId() const + { + return _currentFId; + } + + inline int currentSVertexId() const + { + return _currentSVertexId; + } + + /*! modifiers */ + inline void setCurrentViewId(int id) + { + _currentViewId = id; + } + + inline void setCurrentFId(int id) + { + _currentFId = id; + } + + inline void setCurrentSVertexId(int id) + { + _currentSVertexId = id; + } + + protected: + /*! Init the view edges building */ + virtual void Init(ViewShape *oVShape); + + // SMOOTH // + /*! checks whether a face has already been processed or not */ + bool stopSmoothViewEdge(WXFaceLayer *iFaceLayer); + OWXFaceLayer FindNextFaceLayer(const OWXFaceLayer &iFaceLayer); + OWXFaceLayer FindPreviousFaceLayer(const OWXFaceLayer &iFaceLayer); + FEdge *BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer &ifl); + + // SHARP // + /*! checks whether a WEdge has already been processed or not */ + bool stopSharpViewEdge(WXEdge *iFace); + int retrieveFaceMarks(WXEdge *iEdge); + OWXEdge FindNextWEdge(const OWXEdge &iEdge); + OWXEdge FindPreviousWEdge(const OWXEdge &iEdge); + FEdge *BuildSharpFEdge(FEdge *feprevious, const OWXEdge &iwe); + + // GENERAL // + /*! Instanciate a SVertex */ + SVertex *MakeSVertex(Vec3r &iPoint); + /*! Instanciate a SVertex if it hasn't been already created */ + SVertex *MakeSVertex(Vec3r &iPoint, bool shared); + /*! instanciate a ViewVertex from a SVertex, if it doesn't exist yet */ + ViewVertex *MakeViewVertex(SVertex *iSVertex); + + //oldtmp values + //IdHashTable _hashtable; + //VVIdHashTable _multivertexHashTable; + SVertexMap _SVertexMap; + SShape *_pCurrentSShape; + ViewShape *_pCurrentVShape; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeXBuilder") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeXBuilder") #endif }; diff --git a/source/blender/freestyle/intern/view_map/ViewMap.cpp b/source/blender/freestyle/intern/view_map/ViewMap.cpp index d23a87d7159..7c72e44fc10 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMap.cpp @@ -41,230 +41,243 @@ ViewMap *ViewMap::_pInstance = NULL; ViewMap::~ViewMap() { - // The view vertices must be deleted here as some of them are shared between two shapes: - for (vector::iterator vv = _VVertices.begin(), vvend = _VVertices.end(); vv != vvend; vv++) { - delete (*vv); - } - _VVertices.clear(); + // The view vertices must be deleted here as some of them are shared between two shapes: + for (vector::iterator vv = _VVertices.begin(), vvend = _VVertices.end(); + vv != vvend; + vv++) { + delete (*vv); + } + _VVertices.clear(); - for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; vs++) { - delete (*vs); - } - _VShapes.clear(); + for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; + vs++) { + delete (*vs); + } + _VShapes.clear(); - _FEdges.clear(); - _SVertices.clear(); - _VEdges.clear(); + _FEdges.clear(); + _SVertices.clear(); + _VEdges.clear(); } void ViewMap::Clean() { - vector tmpEdges; - - for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; vs++) { - vector& edges = (*vs)->sshape()->getEdgeList(); - for (vector::iterator it = edges.begin(), itend = edges.end(); it != itend; it++) { - if ((*it)->isTemporary()) { - (*it)->setTemporary(false); // avoid being counted multiple times - tmpEdges.push_back(*it); - } - } - } - - for (vector::iterator it = tmpEdges.begin(), itend = tmpEdges.end(); it != itend; it++) { - for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; vs++) { - (*vs)->sshape()->RemoveEdge(*it); - } - (*it)->vertexA()->RemoveFEdge(*it); - (*it)->vertexB()->RemoveFEdge(*it); - delete (*it); - } + vector tmpEdges; + + for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; + vs++) { + vector &edges = (*vs)->sshape()->getEdgeList(); + for (vector::iterator it = edges.begin(), itend = edges.end(); it != itend; it++) { + if ((*it)->isTemporary()) { + (*it)->setTemporary(false); // avoid being counted multiple times + tmpEdges.push_back(*it); + } + } + } + + for (vector::iterator it = tmpEdges.begin(), itend = tmpEdges.end(); it != itend; + it++) { + for (vector::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; + vs++) { + (*vs)->sshape()->RemoveEdge(*it); + } + (*it)->vertexA()->RemoveFEdge(*it); + (*it)->vertexB()->RemoveFEdge(*it); + delete (*it); + } } ViewShape *ViewMap::viewShape(unsigned id) { - int index = _shapeIdToIndex[id]; - return _VShapes[ index ]; + int index = _shapeIdToIndex[id]; + return _VShapes[index]; } void ViewMap::AddViewShape(ViewShape *iVShape) { - _shapeIdToIndex[iVShape->getId().getFirst()] = _VShapes.size(); - _VShapes.push_back(iVShape); + _shapeIdToIndex[iVShape->getId().getFirst()] = _VShapes.size(); + _VShapes.push_back(iVShape); } const FEdge *ViewMap::getClosestFEdge(real x, real y) const { - // find the closest of this candidates: - real minDist = DBL_MAX; - FEdge *winner = NULL; - for (fedges_container::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; fe++) { - Vec2d A((*fe)->vertexA()->point2D()[0], (*fe)->vertexA()->point2D()[1]); - Vec2d B((*fe)->vertexB()->point2D()[0], (*fe)->vertexB()->point2D()[1]); - real dist = GeomUtils::distPointSegment(Vec2r(x, y), A, B); - if (dist < minDist) { - minDist = dist; - winner = (*fe); - } - } + // find the closest of this candidates: + real minDist = DBL_MAX; + FEdge *winner = NULL; + for (fedges_container::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; + fe++) { + Vec2d A((*fe)->vertexA()->point2D()[0], (*fe)->vertexA()->point2D()[1]); + Vec2d B((*fe)->vertexB()->point2D()[0], (*fe)->vertexB()->point2D()[1]); + real dist = GeomUtils::distPointSegment(Vec2r(x, y), A, B); + if (dist < minDist) { + minDist = dist; + winner = (*fe); + } + } - return winner; + return winner; } const ViewEdge *ViewMap::getClosestViewEdge(real x, real y) const { - // find the closest of this candidates: - real minDist = DBL_MAX; - FEdge *winner = NULL; - for (fedges_container::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; fe++) { - Vec2d A((*fe)->vertexA()->point2D()[0], (*fe)->vertexA()->point2D()[1]); - Vec2d B((*fe)->vertexB()->point2D()[0], (*fe)->vertexB()->point2D()[1]); - real dist = GeomUtils::distPointSegment(Vec2r(x, y), A, B); - if (dist < minDist) { - minDist = dist; - winner = (*fe); - } - } - if (!winner) - return NULL; - - return winner->viewedge(); -} - - -TVertex *ViewMap::CreateTVertex(const Vec3r& iA3D, const Vec3r& iA2D, FEdge *iFEdgeA, - const Vec3r& iB3D, const Vec3r& iB2D, FEdge *iFEdgeB, const Id& id) -{ - ViewShape *vshapeA = iFEdgeA->viewedge()->viewShape(); - SShape *shapeA = iFEdgeA->shape(); - ViewShape *vshapeB = iFEdgeB->viewedge()->viewShape(); - SShape *shapeB = iFEdgeB->shape(); - - SVertex *Ia = shapeA->CreateSVertex(iA3D, iA2D, iFEdgeA->vertexA()->getId()); - SVertex *Ib = shapeB->CreateSVertex(iB3D, iB2D, iFEdgeB->vertexA()->getId()); - - // depending on which of these 2 svertices is the nearest from the viewpoint, we're going to build the TVertex - // by giving them in an order or another (the first one must be the nearest) - real dista = Ia->point2D()[2]; - real distb = Ib->point2D()[2]; - - TVertex *tvertex; - if (dista < distb) - tvertex = new TVertex(Ia, Ib); - else - tvertex = new TVertex(Ib, Ia); - - tvertex->setId(id); - - // add these vertices to the view map - AddViewVertex(tvertex); - AddSVertex(Ia); - AddSVertex(Ib); - - // and this T Vertex to the view shapes: - vshapeA->AddVertex(tvertex); - vshapeB->AddVertex(tvertex); - - return tvertex; -} - -ViewVertex *ViewMap::InsertViewVertex(SVertex *iVertex, vector& newViewEdges) -{ - NonTVertex *vva = dynamic_cast(iVertex->viewvertex()); - if (vva) - return vva; - // because it is not already a ViewVertex, this SVertex must have only 2 FEdges. The incoming one still belongs - // to ioEdge, the outgoing one now belongs to newVEdge - const vector& fedges = iVertex->fedges(); - if (fedges.size() != 2) { - cerr << "ViewMap warning: Can't split the ViewEdge" << endl; - return NULL; - } - FEdge *fend(NULL), *fbegin(NULL); - for (vector::const_iterator fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) { - if ((*fe)->vertexB() == iVertex) { - fend = (*fe); - } - if ((*fe)->vertexA() == iVertex) { - fbegin = (*fe); - } - if ((fbegin != NULL) && (fend != NULL)) - break; - } - ViewEdge *ioEdge = fbegin->viewedge(); - ViewShape *vshape = ioEdge->viewShape(); - vva = new NonTVertex(iVertex); - // if the ViewEdge is a closed loop, we don't create a new VEdge - if (ioEdge->A() == 0) { - // closed loop - ioEdge->setA(vva); - ioEdge->setB(vva); - // update sshape - vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeA()); - vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeB()); - - ioEdge->setFEdgeA(fbegin); - ioEdge->setFEdgeB(fend); - - // Update FEdges - fend->setNextEdge(NULL); - fbegin->setPreviousEdge(NULL); - - // update new View Vertex: - vva->AddOutgoingViewEdge(ioEdge); - vva->AddIncomingViewEdge(ioEdge); - - vshape->sshape()->AddChain(ioEdge->fedgeA()); - vshape->sshape()->AddChain(ioEdge->fedgeB()); - } - else { - // Create new ViewEdge - ViewEdge *newVEdge = new ViewEdge(vva, ioEdge->B(), fbegin, ioEdge->fedgeB(), vshape); - newVEdge->setId(Id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1)); - newVEdge->setNature(ioEdge->getNature()); - //newVEdge->UpdateFEdges(); // done in the ViewEdge constructor - // Update old ViewEdge - ioEdge->setB(vva); - ioEdge->setFEdgeB(fend); - - // Update FEdges - fend->setNextEdge(NULL); - fbegin->setPreviousEdge(NULL); - - // update new View Vertex: - vva->AddOutgoingViewEdge(newVEdge); - vva->AddIncomingViewEdge(ioEdge); - - NonTVertex *vvb = dynamic_cast(newVEdge->B()); - if (vvb) - vvb->Replace(ioEdge, newVEdge); - - // update ViewShape - //vshape->AddEdge(newVEdge); - // update SShape - vshape->sshape()->AddChain(fbegin); - // update ViewMap - //_VEdges.push_back(newVEdge); - newViewEdges.push_back(newVEdge); - } - - // update ViewShape - vshape->AddVertex(vva); - - // update ViewMap - _VVertices.push_back(vva); - - return vva; + // find the closest of this candidates: + real minDist = DBL_MAX; + FEdge *winner = NULL; + for (fedges_container::const_iterator fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; + fe++) { + Vec2d A((*fe)->vertexA()->point2D()[0], (*fe)->vertexA()->point2D()[1]); + Vec2d B((*fe)->vertexB()->point2D()[0], (*fe)->vertexB()->point2D()[1]); + real dist = GeomUtils::distPointSegment(Vec2r(x, y), A, B); + if (dist < minDist) { + minDist = dist; + winner = (*fe); + } + } + if (!winner) + return NULL; + + return winner->viewedge(); +} + +TVertex *ViewMap::CreateTVertex(const Vec3r &iA3D, + const Vec3r &iA2D, + FEdge *iFEdgeA, + const Vec3r &iB3D, + const Vec3r &iB2D, + FEdge *iFEdgeB, + const Id &id) +{ + ViewShape *vshapeA = iFEdgeA->viewedge()->viewShape(); + SShape *shapeA = iFEdgeA->shape(); + ViewShape *vshapeB = iFEdgeB->viewedge()->viewShape(); + SShape *shapeB = iFEdgeB->shape(); + + SVertex *Ia = shapeA->CreateSVertex(iA3D, iA2D, iFEdgeA->vertexA()->getId()); + SVertex *Ib = shapeB->CreateSVertex(iB3D, iB2D, iFEdgeB->vertexA()->getId()); + + // depending on which of these 2 svertices is the nearest from the viewpoint, we're going to build the TVertex + // by giving them in an order or another (the first one must be the nearest) + real dista = Ia->point2D()[2]; + real distb = Ib->point2D()[2]; + + TVertex *tvertex; + if (dista < distb) + tvertex = new TVertex(Ia, Ib); + else + tvertex = new TVertex(Ib, Ia); + + tvertex->setId(id); + + // add these vertices to the view map + AddViewVertex(tvertex); + AddSVertex(Ia); + AddSVertex(Ib); + + // and this T Vertex to the view shapes: + vshapeA->AddVertex(tvertex); + vshapeB->AddVertex(tvertex); + + return tvertex; +} + +ViewVertex *ViewMap::InsertViewVertex(SVertex *iVertex, vector &newViewEdges) +{ + NonTVertex *vva = dynamic_cast(iVertex->viewvertex()); + if (vva) + return vva; + // because it is not already a ViewVertex, this SVertex must have only 2 FEdges. The incoming one still belongs + // to ioEdge, the outgoing one now belongs to newVEdge + const vector &fedges = iVertex->fedges(); + if (fedges.size() != 2) { + cerr << "ViewMap warning: Can't split the ViewEdge" << endl; + return NULL; + } + FEdge *fend(NULL), *fbegin(NULL); + for (vector::const_iterator fe = fedges.begin(), feend = fedges.end(); fe != feend; + ++fe) { + if ((*fe)->vertexB() == iVertex) { + fend = (*fe); + } + if ((*fe)->vertexA() == iVertex) { + fbegin = (*fe); + } + if ((fbegin != NULL) && (fend != NULL)) + break; + } + ViewEdge *ioEdge = fbegin->viewedge(); + ViewShape *vshape = ioEdge->viewShape(); + vva = new NonTVertex(iVertex); + // if the ViewEdge is a closed loop, we don't create a new VEdge + if (ioEdge->A() == 0) { + // closed loop + ioEdge->setA(vva); + ioEdge->setB(vva); + // update sshape + vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeA()); + vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeB()); + + ioEdge->setFEdgeA(fbegin); + ioEdge->setFEdgeB(fend); + + // Update FEdges + fend->setNextEdge(NULL); + fbegin->setPreviousEdge(NULL); + + // update new View Vertex: + vva->AddOutgoingViewEdge(ioEdge); + vva->AddIncomingViewEdge(ioEdge); + + vshape->sshape()->AddChain(ioEdge->fedgeA()); + vshape->sshape()->AddChain(ioEdge->fedgeB()); + } + else { + // Create new ViewEdge + ViewEdge *newVEdge = new ViewEdge(vva, ioEdge->B(), fbegin, ioEdge->fedgeB(), vshape); + newVEdge->setId(Id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1)); + newVEdge->setNature(ioEdge->getNature()); + //newVEdge->UpdateFEdges(); // done in the ViewEdge constructor + // Update old ViewEdge + ioEdge->setB(vva); + ioEdge->setFEdgeB(fend); + + // Update FEdges + fend->setNextEdge(NULL); + fbegin->setPreviousEdge(NULL); + + // update new View Vertex: + vva->AddOutgoingViewEdge(newVEdge); + vva->AddIncomingViewEdge(ioEdge); + + NonTVertex *vvb = dynamic_cast(newVEdge->B()); + if (vvb) + vvb->Replace(ioEdge, newVEdge); + + // update ViewShape + //vshape->AddEdge(newVEdge); + // update SShape + vshape->sshape()->AddChain(fbegin); + // update ViewMap + //_VEdges.push_back(newVEdge); + newViewEdges.push_back(newVEdge); + } + + // update ViewShape + vshape->AddVertex(vva); + + // update ViewMap + _VVertices.push_back(vva); + + return vva; } #if 0 FEdge *ViewMap::Connect(FEdge *ioEdge, SVertex *ioVertex, vector& oNewVEdges) { - SShape *sshape = ioEdge->shape(); - FEdge *newFEdge = sshape->SplitEdgeIn2(ioEdge, ioVertex); - AddFEdge(newFEdge); - InsertViewVertex(ioVertex, oNewVEdges); - return newFEdge; + SShape *sshape = ioEdge->shape(); + FEdge *newFEdge = sshape->SplitEdgeIn2(ioEdge, ioVertex); + AddFEdge(newFEdge); + InsertViewVertex(ioVertex, oNewVEdges); + return newFEdge; } #endif @@ -277,219 +290,231 @@ FEdge *ViewMap::Connect(FEdge *ioEdge, SVertex *ioVertex, vector& oNe /**********************************/ // is dve1 before dve2 ? (does it have a smaller angle ?) -static bool ViewEdgeComp(ViewVertex::directedViewEdge& dve1, ViewVertex::directedViewEdge& dve2) -{ - FEdge *fe1; - if (dve1.second) - fe1 = dve1.first->fedgeB(); - else - fe1 = dve1.first->fedgeA(); - FEdge *fe2; - if (dve2.second) - fe2 = dve2.first->fedgeB(); - else - fe2 = dve2.first->fedgeA(); - - Vec3r V1 = fe1->orientation2d(); - Vec2r v1(V1.x(), V1.y()); - v1.normalize(); - Vec3r V2 = fe2->orientation2d(); - Vec2r v2(V2.x(), V2.y()); - v2.normalize(); - if (v1.y() > 0) { - if (v2.y() < 0) - return true; - else - return (v1.x() > v2.x()); - } - else { - if (v2.y() > 0) - return false; - else - return (v1.x() < v2.x()); - } - return false; +static bool ViewEdgeComp(ViewVertex::directedViewEdge &dve1, ViewVertex::directedViewEdge &dve2) +{ + FEdge *fe1; + if (dve1.second) + fe1 = dve1.first->fedgeB(); + else + fe1 = dve1.first->fedgeA(); + FEdge *fe2; + if (dve2.second) + fe2 = dve2.first->fedgeB(); + else + fe2 = dve2.first->fedgeA(); + + Vec3r V1 = fe1->orientation2d(); + Vec2r v1(V1.x(), V1.y()); + v1.normalize(); + Vec3r V2 = fe2->orientation2d(); + Vec2r v2(V2.x(), V2.y()); + v2.normalize(); + if (v1.y() > 0) { + if (v2.y() < 0) + return true; + else + return (v1.x() > v2.x()); + } + else { + if (v2.y() > 0) + return false; + else + return (v1.x() < v2.x()); + } + return false; } void TVertex::setFrontEdgeA(ViewEdge *iFrontEdgeA, bool incoming) { - if (!iFrontEdgeA) { - cerr << "Warning: null pointer passed as argument of TVertex::setFrontEdgeA()" << endl; - return; - } - _FrontEdgeA = directedViewEdge(iFrontEdgeA, incoming); - if (!_sortedEdges.empty()) { - edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(**dve, _FrontEdgeA); ++dve); - _sortedEdges.insert( dve, &_FrontEdgeA); - } - else { - _sortedEdges.push_back(&_FrontEdgeA); - } + if (!iFrontEdgeA) { + cerr << "Warning: null pointer passed as argument of TVertex::setFrontEdgeA()" << endl; + return; + } + _FrontEdgeA = directedViewEdge(iFrontEdgeA, incoming); + if (!_sortedEdges.empty()) { + edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(**dve, _FrontEdgeA); ++dve) + ; + _sortedEdges.insert(dve, &_FrontEdgeA); + } + else { + _sortedEdges.push_back(&_FrontEdgeA); + } } void TVertex::setFrontEdgeB(ViewEdge *iFrontEdgeB, bool incoming) { - if (!iFrontEdgeB) { - cerr << "Warning: null pointer passed as argument of TVertex::setFrontEdgeB()" << endl; - return; - } - _FrontEdgeB = directedViewEdge(iFrontEdgeB, incoming); - if (!_sortedEdges.empty()) { - edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(**dve, _FrontEdgeB); ++dve); - _sortedEdges.insert(dve, &_FrontEdgeB); - } - else { - _sortedEdges.push_back(&_FrontEdgeB); - } + if (!iFrontEdgeB) { + cerr << "Warning: null pointer passed as argument of TVertex::setFrontEdgeB()" << endl; + return; + } + _FrontEdgeB = directedViewEdge(iFrontEdgeB, incoming); + if (!_sortedEdges.empty()) { + edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(**dve, _FrontEdgeB); ++dve) + ; + _sortedEdges.insert(dve, &_FrontEdgeB); + } + else { + _sortedEdges.push_back(&_FrontEdgeB); + } } void TVertex::setBackEdgeA(ViewEdge *iBackEdgeA, bool incoming) { - if (!iBackEdgeA) { - cerr << "Warning: null pointer passed as argument of TVertex::setBackEdgeA()" << endl; - return; - } - _BackEdgeA = directedViewEdge(iBackEdgeA, incoming); - if (!_sortedEdges.empty()) { - edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(**dve, _BackEdgeA); ++dve); - _sortedEdges.insert(dve, &_BackEdgeA); - } - else { - _sortedEdges.push_back(&_BackEdgeA); - } + if (!iBackEdgeA) { + cerr << "Warning: null pointer passed as argument of TVertex::setBackEdgeA()" << endl; + return; + } + _BackEdgeA = directedViewEdge(iBackEdgeA, incoming); + if (!_sortedEdges.empty()) { + edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(**dve, _BackEdgeA); ++dve) + ; + _sortedEdges.insert(dve, &_BackEdgeA); + } + else { + _sortedEdges.push_back(&_BackEdgeA); + } } void TVertex::setBackEdgeB(ViewEdge *iBackEdgeB, bool incoming) { - if (!iBackEdgeB) { - cerr << "Warning: null pointer passed as argument of TVertex::setBackEdgeB()" << endl; - return; - } - _BackEdgeB = directedViewEdge(iBackEdgeB, incoming); - if (!_sortedEdges.empty()) { - edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(**dve, _BackEdgeB); ++dve); - _sortedEdges.insert(dve, &_BackEdgeB); - } - else { - _sortedEdges.push_back(&_BackEdgeB); - } + if (!iBackEdgeB) { + cerr << "Warning: null pointer passed as argument of TVertex::setBackEdgeB()" << endl; + return; + } + _BackEdgeB = directedViewEdge(iBackEdgeB, incoming); + if (!_sortedEdges.empty()) { + edge_pointers_container::iterator dve = _sortedEdges.begin(), dveend = _sortedEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(**dve, _BackEdgeB); ++dve) + ; + _sortedEdges.insert(dve, &_BackEdgeB); + } + else { + _sortedEdges.push_back(&_BackEdgeB); + } } void TVertex::Replace(ViewEdge *iOld, ViewEdge *iNew) { - // theoritically, we only replace edges for which this - // view vertex is the B vertex - if ((iOld == _FrontEdgeA.first) && (_FrontEdgeA.first->B() == this)) { - _FrontEdgeA.first = iNew; - return; - } - if ((iOld == _FrontEdgeB.first) && (_FrontEdgeB.first->B() == this)) { - _FrontEdgeB.first = iNew; - return; - } - if ((iOld == _BackEdgeA.first) && (_BackEdgeA.first->B() == this)) { - _BackEdgeA.first = iNew; - return; - } - if ((iOld == _BackEdgeB.first) && (_BackEdgeB.first->B() == this)) { - _BackEdgeB.first = iNew; - return; - } + // theoritically, we only replace edges for which this + // view vertex is the B vertex + if ((iOld == _FrontEdgeA.first) && (_FrontEdgeA.first->B() == this)) { + _FrontEdgeA.first = iNew; + return; + } + if ((iOld == _FrontEdgeB.first) && (_FrontEdgeB.first->B() == this)) { + _FrontEdgeB.first = iNew; + return; + } + if ((iOld == _BackEdgeA.first) && (_BackEdgeA.first->B() == this)) { + _BackEdgeA.first = iNew; + return; + } + if ((iOld == _BackEdgeB.first) && (_BackEdgeB.first->B() == this)) { + _BackEdgeB.first = iNew; + return; + } } /*! iterators access */ ViewVertex::edge_iterator TVertex::edges_begin() { - //return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, _FrontEdgeA); - return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + //return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, _FrontEdgeA); + return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); } ViewVertex::const_edge_iterator TVertex::edges_begin() const { - //return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, _FrontEdgeA); - return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + //return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, _FrontEdgeA); + return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); } ViewVertex::edge_iterator TVertex::edges_end() { - //return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, directedViewEdge(0,true)); - return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); + //return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, directedViewEdge(0,true)); + return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); } ViewVertex::const_edge_iterator TVertex::edges_end() const { - //return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, directedViewEdge(0, true)); - return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); + //return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, directedViewEdge(0, true)); + return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); } ViewVertex::edge_iterator TVertex::edges_iterator(ViewEdge *iEdge) { - for (edge_pointers_container::iterator it = _sortedEdges.begin(), itend = _sortedEdges.end(); it != itend; it++) { - if ((*it)->first == iEdge) - return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), it); - } - return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + for (edge_pointers_container::iterator it = _sortedEdges.begin(), itend = _sortedEdges.end(); + it != itend; + it++) { + if ((*it)->first == iEdge) + return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), it); + } + return edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); #if 0 - directedViewEdge dEdge; - if (_FrontEdgeA.first == iEdge) - dEdge = _FrontEdgeA; - else if (_FrontEdgeB.first == iEdge) - dEdge = _FrontEdgeB; - else if (_BackEdgeA.first == iEdge) - dEdge = _BackEdgeA; - else if (_BackEdgeB.first == iEdge) - dEdge = _BackEdgeB; - return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, dEdge); + directedViewEdge dEdge; + if (_FrontEdgeA.first == iEdge) + dEdge = _FrontEdgeA; + else if (_FrontEdgeB.first == iEdge) + dEdge = _FrontEdgeB; + else if (_BackEdgeA.first == iEdge) + dEdge = _BackEdgeA; + else if (_BackEdgeB.first == iEdge) + dEdge = _BackEdgeB; + return edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, dEdge); #endif } ViewVertex::const_edge_iterator TVertex::edges_iterator(ViewEdge *iEdge) const { - for (edge_pointers_container::const_iterator it = _sortedEdges.begin(), itend = _sortedEdges.end(); - it != itend; - it++) - { - if ((*it)->first == iEdge) - return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), it); - } - return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + for (edge_pointers_container::const_iterator it = _sortedEdges.begin(), + itend = _sortedEdges.end(); + it != itend; + it++) { + if ((*it)->first == iEdge) + return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), it); + } + return const_edge_iterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); #if 0 - directedViewEdge dEdge; - if (_FrontEdgeA.first == iEdge) - dEdge = _FrontEdgeA; - else if (_FrontEdgeB.first == iEdge) - dEdge = _FrontEdgeB; - else if (_BackEdgeA.first == iEdge) - dEdge = _BackEdgeA; - else if (_BackEdgeB.first == iEdge) - dEdge = _BackEdgeB; - return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, dEdge); + directedViewEdge dEdge; + if (_FrontEdgeA.first == iEdge) + dEdge = _FrontEdgeA; + else if (_FrontEdgeB.first == iEdge) + dEdge = _FrontEdgeB; + else if (_BackEdgeA.first == iEdge) + dEdge = _BackEdgeA; + else if (_BackEdgeB.first == iEdge) + dEdge = _BackEdgeB; + return const_edge_iterator(_FrontEdgeA, _FrontEdgeB, _BackEdgeA, _BackEdgeB, dEdge); #endif } ViewVertexInternal::orientedViewEdgeIterator TVertex::edgesBegin() { - return ViewVertexInternal::orientedViewEdgeIterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + return ViewVertexInternal::orientedViewEdgeIterator( + _sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); } ViewVertexInternal::orientedViewEdgeIterator TVertex::edgesEnd() { - return ViewVertexInternal::orientedViewEdgeIterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); + return ViewVertexInternal::orientedViewEdgeIterator( + _sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.end()); } ViewVertexInternal::orientedViewEdgeIterator TVertex::edgesIterator(ViewEdge *iEdge) { - for (edge_pointers_container::iterator it = _sortedEdges.begin(), itend = _sortedEdges.end(); it != itend; it++) { - if ((*it)->first == iEdge) - return ViewVertexInternal::orientedViewEdgeIterator(_sortedEdges.begin(), _sortedEdges.end(), it); - } - return ViewVertexInternal::orientedViewEdgeIterator(_sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); + for (edge_pointers_container::iterator it = _sortedEdges.begin(), itend = _sortedEdges.end(); + it != itend; + it++) { + if ((*it)->first == iEdge) + return ViewVertexInternal::orientedViewEdgeIterator( + _sortedEdges.begin(), _sortedEdges.end(), it); + } + return ViewVertexInternal::orientedViewEdgeIterator( + _sortedEdges.begin(), _sortedEdges.end(), _sortedEdges.begin()); } /**********************************/ @@ -502,88 +527,98 @@ ViewVertexInternal::orientedViewEdgeIterator TVertex::edgesIterator(ViewEdge *iE void NonTVertex::AddOutgoingViewEdge(ViewEdge *iVEdge) { - // let's keep the viewedges ordered in CCW order in the 2D image plan - directedViewEdge idve(iVEdge, false); - if (!_ViewEdges.empty()) { - edges_container::iterator dve = _ViewEdges.begin(), dveend = _ViewEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(*dve, idve); ++dve); - _ViewEdges.insert(dve, idve); - } - else { - _ViewEdges.push_back(idve); - } + // let's keep the viewedges ordered in CCW order in the 2D image plan + directedViewEdge idve(iVEdge, false); + if (!_ViewEdges.empty()) { + edges_container::iterator dve = _ViewEdges.begin(), dveend = _ViewEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(*dve, idve); ++dve) + ; + _ViewEdges.insert(dve, idve); + } + else { + _ViewEdges.push_back(idve); + } } void NonTVertex::AddIncomingViewEdge(ViewEdge *iVEdge) { - // let's keep the viewedges ordered in CCW order in the 2D image plan - directedViewEdge idve(iVEdge, true); - if (!_ViewEdges.empty()) { - edges_container::iterator dve = _ViewEdges.begin(), dveend = _ViewEdges.end(); - for (; (dve != dveend) && ViewEdgeComp(*dve, idve); ++dve); - _ViewEdges.insert(dve, idve); - } - else { - _ViewEdges.push_back(idve); - } + // let's keep the viewedges ordered in CCW order in the 2D image plan + directedViewEdge idve(iVEdge, true); + if (!_ViewEdges.empty()) { + edges_container::iterator dve = _ViewEdges.begin(), dveend = _ViewEdges.end(); + for (; (dve != dveend) && ViewEdgeComp(*dve, idve); ++dve) + ; + _ViewEdges.insert(dve, idve); + } + else { + _ViewEdges.push_back(idve); + } } /*! iterators access */ ViewVertex::edge_iterator NonTVertex::edges_begin() { - return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } ViewVertex::const_edge_iterator NonTVertex::edges_begin() const { - return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } ViewVertex::edge_iterator NonTVertex::edges_end() { - return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); + return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); } ViewVertex::const_edge_iterator NonTVertex::edges_end() const { - return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); + return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); } ViewVertex::edge_iterator NonTVertex::edges_iterator(ViewEdge *iEdge) { - for (edges_container::iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); it != itend; it++) { - if ((it)->first == iEdge) - return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), it); - } - return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + for (edges_container::iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); it != itend; + it++) { + if ((it)->first == iEdge) + return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), it); + } + return edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } ViewVertex::const_edge_iterator NonTVertex::edges_iterator(ViewEdge *iEdge) const { - for (edges_container::const_iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); it != itend; it++) { - if ((it)->first == iEdge) - return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), it); - } - return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + for (edges_container::const_iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); + it != itend; + it++) { + if ((it)->first == iEdge) + return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), it); + } + return const_edge_iterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } ViewVertexInternal::orientedViewEdgeIterator NonTVertex::edgesBegin() { - return ViewVertexInternal::orientedViewEdgeIterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + return ViewVertexInternal::orientedViewEdgeIterator( + _ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } ViewVertexInternal::orientedViewEdgeIterator NonTVertex::edgesEnd() { - return ViewVertexInternal::orientedViewEdgeIterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); + return ViewVertexInternal::orientedViewEdgeIterator( + _ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.end()); } ViewVertexInternal::orientedViewEdgeIterator NonTVertex::edgesIterator(ViewEdge *iEdge) { - for (edges_container::iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); it != itend; it++) { - if ((it)->first == iEdge) - return ViewVertexInternal::orientedViewEdgeIterator(_ViewEdges.begin(), _ViewEdges.end(), it); - } - return ViewVertexInternal::orientedViewEdgeIterator(_ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); + for (edges_container::iterator it = _ViewEdges.begin(), itend = _ViewEdges.end(); it != itend; + it++) { + if ((it)->first == iEdge) + return ViewVertexInternal::orientedViewEdgeIterator( + _ViewEdges.begin(), _ViewEdges.end(), it); + } + return ViewVertexInternal::orientedViewEdgeIterator( + _ViewEdges.begin(), _ViewEdges.end(), _ViewEdges.begin()); } /**********************************/ @@ -596,160 +631,161 @@ ViewVertexInternal::orientedViewEdgeIterator NonTVertex::edgesIterator(ViewEdge real ViewEdge::getLength2D() const { - float length = 0.0f; - ViewEdge::const_fedge_iterator itlast = fedge_iterator_last(); - ViewEdge::const_fedge_iterator it = fedge_iterator_begin(), itend = fedge_iterator_end(); - Vec2r seg; - do { - seg = Vec2r((*it)->orientation2d()[0], (*it)->orientation2d()[1]); - length += seg.norm(); - ++it; - } while ((it != itend) && (it != itlast)); - return length; + float length = 0.0f; + ViewEdge::const_fedge_iterator itlast = fedge_iterator_last(); + ViewEdge::const_fedge_iterator it = fedge_iterator_begin(), itend = fedge_iterator_end(); + Vec2r seg; + do { + seg = Vec2r((*it)->orientation2d()[0], (*it)->orientation2d()[1]); + length += seg.norm(); + ++it; + } while ((it != itend) && (it != itlast)); + return length; } //! view edge iterator ViewEdge::edge_iterator ViewEdge::ViewEdge_iterator() { - return edge_iterator(this); + return edge_iterator(this); } ViewEdge::const_edge_iterator ViewEdge::ViewEdge_iterator() const { - return const_edge_iterator((ViewEdge *)this); + return const_edge_iterator((ViewEdge *)this); } //! feature edge iterator ViewEdge::fedge_iterator ViewEdge::fedge_iterator_begin() { - return fedge_iterator(this->_FEdgeA, this->_FEdgeB); + return fedge_iterator(this->_FEdgeA, this->_FEdgeB); } ViewEdge::const_fedge_iterator ViewEdge::fedge_iterator_begin() const { - return const_fedge_iterator(this->_FEdgeA, this->_FEdgeB); + return const_fedge_iterator(this->_FEdgeA, this->_FEdgeB); } ViewEdge::fedge_iterator ViewEdge::fedge_iterator_last() { - return fedge_iterator(this->_FEdgeB, this->_FEdgeB); + return fedge_iterator(this->_FEdgeB, this->_FEdgeB); } ViewEdge::const_fedge_iterator ViewEdge::fedge_iterator_last() const { - return const_fedge_iterator(this->_FEdgeB, this->_FEdgeB); + return const_fedge_iterator(this->_FEdgeB, this->_FEdgeB); } ViewEdge::fedge_iterator ViewEdge::fedge_iterator_end() { - return fedge_iterator(0, this->_FEdgeB); + return fedge_iterator(0, this->_FEdgeB); } ViewEdge::const_fedge_iterator ViewEdge::fedge_iterator_end() const { - return const_fedge_iterator(0, this->_FEdgeB); + return const_fedge_iterator(0, this->_FEdgeB); } //! embedding vertex iterator ViewEdge::const_vertex_iterator ViewEdge::vertices_begin() const { - return const_vertex_iterator(this->_FEdgeA->vertexA(), 0, _FEdgeA); + return const_vertex_iterator(this->_FEdgeA->vertexA(), 0, _FEdgeA); } ViewEdge::vertex_iterator ViewEdge::vertices_begin() { - return vertex_iterator(this->_FEdgeA->vertexA(), 0, _FEdgeA); + return vertex_iterator(this->_FEdgeA->vertexA(), 0, _FEdgeA); } ViewEdge::const_vertex_iterator ViewEdge::vertices_last() const { - return const_vertex_iterator(this->_FEdgeB->vertexB(), _FEdgeB, 0); + return const_vertex_iterator(this->_FEdgeB->vertexB(), _FEdgeB, 0); } ViewEdge::vertex_iterator ViewEdge::vertices_last() { - return vertex_iterator(this->_FEdgeB->vertexB(), _FEdgeB, 0); + return vertex_iterator(this->_FEdgeB->vertexB(), _FEdgeB, 0); } ViewEdge::const_vertex_iterator ViewEdge::vertices_end() const { - return const_vertex_iterator(0, _FEdgeB, 0); + return const_vertex_iterator(0, _FEdgeB, 0); } ViewEdge::vertex_iterator ViewEdge::vertices_end() { - return vertex_iterator(0, _FEdgeB, 0); + return vertex_iterator(0, _FEdgeB, 0); } Interface0DIterator ViewEdge::verticesBegin() { - Interface0DIterator ret(new ViewEdgeInternal::SVertexIterator(this->_FEdgeA->vertexA(), - this->_FEdgeA->vertexA(), NULL, _FEdgeA, 0.0f)); - return ret; + Interface0DIterator ret(new ViewEdgeInternal::SVertexIterator( + this->_FEdgeA->vertexA(), this->_FEdgeA->vertexA(), NULL, _FEdgeA, 0.0f)); + return ret; } Interface0DIterator ViewEdge::verticesEnd() { - Interface0DIterator ret(new ViewEdgeInternal::SVertexIterator(NULL, this->_FEdgeA->vertexA(), - _FEdgeB, NULL, getLength2D())); - return ret; + Interface0DIterator ret(new ViewEdgeInternal::SVertexIterator( + NULL, this->_FEdgeA->vertexA(), _FEdgeB, NULL, getLength2D())); + return ret; } Interface0DIterator ViewEdge::pointsBegin(float /*t*/) { - return verticesBegin(); + return verticesBegin(); } Interface0DIterator ViewEdge::pointsEnd(float /*t*/) { - return verticesEnd(); + return verticesEnd(); } - /**********************************/ - /* */ - /* */ - /* ViewShape */ - /* */ - /* */ - /**********************************/ +/**********************************/ +/* */ +/* */ +/* ViewShape */ +/* */ +/* */ +/**********************************/ ViewShape::~ViewShape() { - _Vertices.clear(); + _Vertices.clear(); - if (!(_Edges.empty())) { - for (vector::iterator e = _Edges.begin(), eend = _Edges.end(); e != eend; e++) { - delete (*e); - } - _Edges.clear(); - } + if (!(_Edges.empty())) { + for (vector::iterator e = _Edges.begin(), eend = _Edges.end(); e != eend; e++) { + delete (*e); + } + _Edges.clear(); + } - if (_SShape) { - delete _SShape; - _SShape = NULL; - } + if (_SShape) { + delete _SShape; + _SShape = NULL; + } } void ViewShape::RemoveEdge(ViewEdge *iViewEdge) { - FEdge *fedge = iViewEdge->fedgeA(); - for (vector::iterator ve = _Edges.begin(), veend = _Edges.end(); ve != veend; ve++) { - if (iViewEdge == (*ve)) { - _Edges.erase(ve); - _SShape->RemoveEdge(fedge); - break; - } - } + FEdge *fedge = iViewEdge->fedgeA(); + for (vector::iterator ve = _Edges.begin(), veend = _Edges.end(); ve != veend; ve++) { + if (iViewEdge == (*ve)) { + _Edges.erase(ve); + _SShape->RemoveEdge(fedge); + break; + } + } } void ViewShape::RemoveVertex(ViewVertex *iViewVertex) { - for (vector::iterator vv = _Vertices.begin(), vvend = _Vertices.end(); vv != vvend; vv++) { - if (iViewVertex == (*vv)) { - _Vertices.erase(vv); - break; - } - } + for (vector::iterator vv = _Vertices.begin(), vvend = _Vertices.end(); vv != vvend; + vv++) { + if (iViewVertex == (*vv)) { + _Vertices.erase(vv); + break; + } + } } /**********************************/ @@ -762,13 +798,13 @@ void ViewShape::RemoveVertex(ViewVertex *iViewVertex) void ViewEdge::UpdateFEdges() { - FEdge *currentEdge = _FEdgeA; - do { - currentEdge->setViewEdge(this); - currentEdge = currentEdge->nextEdge(); - } while ((currentEdge != NULL) && (currentEdge != _FEdgeB)); - // last one - _FEdgeB->setViewEdge(this); + FEdge *currentEdge = _FEdgeA; + do { + currentEdge->setViewEdge(this); + currentEdge = currentEdge->nextEdge(); + } while ((currentEdge != NULL) && (currentEdge != _FEdgeB)); + // last one + _FEdgeB->setViewEdge(this); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ViewMap.h b/source/blender/freestyle/intern/view_map/ViewMap.h index 4f0f50fbee2..b25e13d990f 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.h +++ b/source/blender/freestyle/intern/view_map/ViewMap.h @@ -26,7 +26,7 @@ #include "Interface0D.h" #include "Interface1D.h" -#include "Silhouette.h" // defines the embedding +#include "Silhouette.h" // defines the embedding #include "../geometry/GeomUtils.h" @@ -34,7 +34,7 @@ #include "../system/FreestyleConfig.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -47,7 +47,6 @@ namespace Freestyle { /* */ /**********************************/ - /* Density * Mean area depth value * distance to a point @@ -59,182 +58,186 @@ class ViewShape; class TVertex; /*! Class defining the ViewMap.*/ -class ViewMap -{ -public: - typedef vector viewedges_container; - typedef vector viewvertices_container; - typedef vector viewshapes_container; - typedef vector svertices_container; - typedef vector fedges_container; - typedef map id_to_index_map; - -private: - static ViewMap *_pInstance; - viewshapes_container _VShapes; // view shapes - viewedges_container _VEdges; // view edges - viewvertices_container _VVertices; // view vertices - fedges_container _FEdges; // feature edges (embedded edges) - svertices_container _SVertices; // embedded vertices - BBox _scene3DBBox; - // Mapping between the WShape or VShape id to the VShape index in the _VShapes vector. Used in the method - // viewShape(int id) to access a shape from its id. - id_to_index_map _shapeIdToIndex; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor. */ - ViewMap() - { - _pInstance = this; - userdata = NULL; - } - - /*! Destructor. */ - virtual ~ViewMap(); - - /*! Gets the viewedge the nearest to the 2D position specified as argument */ - const ViewEdge *getClosestViewEdge(real x, real y) const; - - /*! Gets the Fedge the nearest to the 2D position specified as argument */ - const FEdge *getClosestFEdge(real x, real y) const; - - /* accessors */ - /*! The ViewMap is a singleton class. This static method returns the instance of the ViewMap. */ - static inline ViewMap *getInstance() - { - return _pInstance; - } - - /* Returns the list of ViewShapes of the scene. */ - inline viewshapes_container& ViewShapes() - { - return _VShapes; - } - - /* Returns the list of ViewEdges of the scene. */ - inline viewedges_container& ViewEdges() - { - return _VEdges; - } - - /* Returns the list of ViewVertices of the scene. */ - inline viewvertices_container& ViewVertices() - { - return _VVertices; - } - - /* Returns the list of FEdges of the scene. */ - inline fedges_container& FEdges() - { - return _FEdges; - } - - /* Returns the list of SVertices of the scene. */ - inline svertices_container& SVertices() - { - return _SVertices; - } - - /* Returns an iterator pointing onto the first ViewEdge of the list. */ - inline viewedges_container::iterator viewedges_begin() - { - return _VEdges.begin(); - } - - inline viewedges_container::iterator viewedges_end() - { - return _VEdges.end(); - } - - inline int viewedges_size() - { - return _VEdges.size(); - } - - ViewShape *viewShape(unsigned index); - - id_to_index_map& shapeIdToIndexMap() - { - return _shapeIdToIndex; - } - - /*! Returns the scene 3D bounding box. */ - inline BBox getScene3dBBox() const - { - return _scene3DBBox; - } - - /* modifiers */ - void AddViewShape(ViewShape *iVShape); - - inline void AddViewEdge(ViewEdge *iVEdge) - { - _VEdges.push_back(iVEdge); - } - - inline void AddViewVertex(ViewVertex *iVVertex) - { - _VVertices.push_back(iVVertex); - } - - inline void AddFEdge(FEdge *iFEdge) - { - _FEdges.push_back(iFEdge); - } - - inline void AddSVertex(SVertex *iSVertex) - { - _SVertices.push_back(iSVertex); - } - - /*! Sets the scene 3D bounding box. */ - inline void setScene3dBBox(const BBox& bbox) - { - _scene3DBBox = bbox; - } - - /* Creates a T vertex in the view map. - * A T vertex is the intersection between 2 FEdges (before these ones are splitted). - * The TVertex is a 2D intersection but it corresponds to a 3D point on each of the 2 FEdges. - * iA3D - * The 3D coordinates of the point corresponding to the intersection on the first edge. - * iA2D - * The x,y,z 2D coordinates of the projection of iA3D - * iFEdgeA - * The first FEdge - * iB3D - * The 3D coordinates of the point corresponding to the intersection on the second edge. - * iB2D - * The x,y,z 2D coordinates of the projection of iB3D - * iFEdgeB - * The second FEdge - * id - * The id that must be given to that TVertex - */ - TVertex *CreateTVertex(const Vec3r& iA3D, const Vec3r& iA2D, FEdge *iFEdgeA, const Vec3r& iB3D, const Vec3r& iB2D, - FEdge *iFEdgeB, const Id& id); - - /* Updates the structures to take into account the fact that a SVertex must now be considered as a ViewVertex - * iVertex - * The SVertex on top of which the ViewVertex is built (it is necessarily a NonTVertex because it is a SVertex) - * newViewEdges - * The new ViewEdges that must be add to the ViewMap - */ - ViewVertex *InsertViewVertex(SVertex *iVertex, vector& newViewEdges); - - /* connects a FEdge to the graph trough a SVertex */ - //FEdge *Connect(FEdge *ioEdge, SVertex *ioVertex); - - /* Clean temporary FEdges created by chaining */ - virtual void Clean(); +class ViewMap { + public: + typedef vector viewedges_container; + typedef vector viewvertices_container; + typedef vector viewshapes_container; + typedef vector svertices_container; + typedef vector fedges_container; + typedef map id_to_index_map; + + private: + static ViewMap *_pInstance; + viewshapes_container _VShapes; // view shapes + viewedges_container _VEdges; // view edges + viewvertices_container _VVertices; // view vertices + fedges_container _FEdges; // feature edges (embedded edges) + svertices_container _SVertices; // embedded vertices + BBox _scene3DBBox; + // Mapping between the WShape or VShape id to the VShape index in the _VShapes vector. Used in the method + // viewShape(int id) to access a shape from its id. + id_to_index_map _shapeIdToIndex; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor. */ + ViewMap() + { + _pInstance = this; + userdata = NULL; + } + + /*! Destructor. */ + virtual ~ViewMap(); + + /*! Gets the viewedge the nearest to the 2D position specified as argument */ + const ViewEdge *getClosestViewEdge(real x, real y) const; + + /*! Gets the Fedge the nearest to the 2D position specified as argument */ + const FEdge *getClosestFEdge(real x, real y) const; + + /* accessors */ + /*! The ViewMap is a singleton class. This static method returns the instance of the ViewMap. */ + static inline ViewMap *getInstance() + { + return _pInstance; + } + + /* Returns the list of ViewShapes of the scene. */ + inline viewshapes_container &ViewShapes() + { + return _VShapes; + } + + /* Returns the list of ViewEdges of the scene. */ + inline viewedges_container &ViewEdges() + { + return _VEdges; + } + + /* Returns the list of ViewVertices of the scene. */ + inline viewvertices_container &ViewVertices() + { + return _VVertices; + } + + /* Returns the list of FEdges of the scene. */ + inline fedges_container &FEdges() + { + return _FEdges; + } + + /* Returns the list of SVertices of the scene. */ + inline svertices_container &SVertices() + { + return _SVertices; + } + + /* Returns an iterator pointing onto the first ViewEdge of the list. */ + inline viewedges_container::iterator viewedges_begin() + { + return _VEdges.begin(); + } + + inline viewedges_container::iterator viewedges_end() + { + return _VEdges.end(); + } + + inline int viewedges_size() + { + return _VEdges.size(); + } + + ViewShape *viewShape(unsigned index); + + id_to_index_map &shapeIdToIndexMap() + { + return _shapeIdToIndex; + } + + /*! Returns the scene 3D bounding box. */ + inline BBox getScene3dBBox() const + { + return _scene3DBBox; + } + + /* modifiers */ + void AddViewShape(ViewShape *iVShape); + + inline void AddViewEdge(ViewEdge *iVEdge) + { + _VEdges.push_back(iVEdge); + } + + inline void AddViewVertex(ViewVertex *iVVertex) + { + _VVertices.push_back(iVVertex); + } + + inline void AddFEdge(FEdge *iFEdge) + { + _FEdges.push_back(iFEdge); + } + + inline void AddSVertex(SVertex *iSVertex) + { + _SVertices.push_back(iSVertex); + } + + /*! Sets the scene 3D bounding box. */ + inline void setScene3dBBox(const BBox &bbox) + { + _scene3DBBox = bbox; + } + + /* Creates a T vertex in the view map. + * A T vertex is the intersection between 2 FEdges (before these ones are splitted). + * The TVertex is a 2D intersection but it corresponds to a 3D point on each of the 2 FEdges. + * iA3D + * The 3D coordinates of the point corresponding to the intersection on the first edge. + * iA2D + * The x,y,z 2D coordinates of the projection of iA3D + * iFEdgeA + * The first FEdge + * iB3D + * The 3D coordinates of the point corresponding to the intersection on the second edge. + * iB2D + * The x,y,z 2D coordinates of the projection of iB3D + * iFEdgeB + * The second FEdge + * id + * The id that must be given to that TVertex + */ + TVertex *CreateTVertex(const Vec3r &iA3D, + const Vec3r &iA2D, + FEdge *iFEdgeA, + const Vec3r &iB3D, + const Vec3r &iB2D, + FEdge *iFEdgeB, + const Id &id); + + /* Updates the structures to take into account the fact that a SVertex must now be considered as a ViewVertex + * iVertex + * The SVertex on top of which the ViewVertex is built (it is necessarily a NonTVertex because it is a SVertex) + * newViewEdges + * The new ViewEdges that must be add to the ViewMap + */ + ViewVertex *InsertViewVertex(SVertex *iVertex, vector &newViewEdges); + + /* connects a FEdge to the graph trough a SVertex */ + //FEdge *Connect(FEdge *ioEdge, SVertex *ioVertex); + + /* Clean temporary FEdges created by chaining */ + virtual void Clean(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMap") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMap") #endif }; @@ -256,7 +259,7 @@ class edge_nonconst_traits; template class edge_iterator_base; class orientedViewEdgeIterator; -} // end of namespace ViewEdgeInternal +} // namespace ViewVertexInternal /*! Class to define a view vertex. * A view vertex is a feature vertex corresponding to a point of the image graph, where the characteristics of an @@ -265,106 +268,111 @@ class orientedViewEdgeIterator; * NonTVertex when it corresponds to a vertex of the initial input mesh (it is the case for vertices such as corners * for example). Thus, this class can be specialized into two classes, the TVertex class and the NonTVertex class. */ -class ViewVertex : public Interface0D -{ -public: // Implementation of Interface0D - /*! Returns the string "ViewVertex". */ - virtual string getExactTypeName() const - { - return "ViewVertex"; - } - -public: - friend class ViewShape; - typedef pair directedViewEdge; // if bool = true, the ViewEdge is incoming - - typedef vector edges_container; - - typedef ViewVertexInternal::edge_iterator_base edge_iterator; - typedef ViewVertexInternal::edge_iterator_base const_edge_iterator; - -private: - Nature::VertexNature _Nature; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor.*/ - inline ViewVertex() - { - userdata = NULL; - _Nature = Nature::VIEW_VERTEX; - } - - inline ViewVertex(Nature::VertexNature nature) - { - userdata = NULL; - _Nature = Nature::VIEW_VERTEX | nature; - } - -protected: - /*! Copy constructor. */ - inline ViewVertex(ViewVertex& iBrother) - { - _Nature = iBrother._Nature; - iBrother.userdata = this; - userdata = NULL; - } - - /*! Cloning method. */ - virtual ViewVertex *duplicate() = 0; - -public: - /*! Destructor. */ - virtual ~ViewVertex() {} - - /* accessors */ - /*! Returns the nature of the vertex .*/ - virtual Nature::VertexNature getNature() const - { - return _Nature; - } - - /* modifiers */ - /*! Sets the nature of the vertex. */ - inline void setNature(Nature::VertexNature iNature) - { - _Nature = iNature; - } - - /* Replaces old edge by new edge */ - virtual void Replace(ViewEdge *, ViewEdge *) {} - -public: - /* iterators access */ - // allows iteration on the edges that comes from/goes to this vertex in CCW order (order defined in 2D in the - // image plan) - virtual edge_iterator edges_begin() = 0; - virtual const_edge_iterator edges_begin() const = 0; - virtual edge_iterator edges_end() = 0; - virtual const_edge_iterator edges_end() const = 0; - virtual edge_iterator edges_iterator(ViewEdge *iEdge) = 0; - virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const = 0; - - // Iterator access - /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first - * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges - * and to get the orientation for each ViewEdge (incoming/outgoing). - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin() = 0; - - /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd() = 0; - - /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge) = 0; +class ViewVertex : public Interface0D { + public: // Implementation of Interface0D + /*! Returns the string "ViewVertex". */ + virtual string getExactTypeName() const + { + return "ViewVertex"; + } + + public: + friend class ViewShape; + typedef pair directedViewEdge; // if bool = true, the ViewEdge is incoming + + typedef vector edges_container; + + typedef ViewVertexInternal::edge_iterator_base + edge_iterator; + typedef ViewVertexInternal::edge_iterator_base + const_edge_iterator; + + private: + Nature::VertexNature _Nature; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor.*/ + inline ViewVertex() + { + userdata = NULL; + _Nature = Nature::VIEW_VERTEX; + } + + inline ViewVertex(Nature::VertexNature nature) + { + userdata = NULL; + _Nature = Nature::VIEW_VERTEX | nature; + } + + protected: + /*! Copy constructor. */ + inline ViewVertex(ViewVertex &iBrother) + { + _Nature = iBrother._Nature; + iBrother.userdata = this; + userdata = NULL; + } + + /*! Cloning method. */ + virtual ViewVertex *duplicate() = 0; + + public: + /*! Destructor. */ + virtual ~ViewVertex() + { + } + + /* accessors */ + /*! Returns the nature of the vertex .*/ + virtual Nature::VertexNature getNature() const + { + return _Nature; + } + + /* modifiers */ + /*! Sets the nature of the vertex. */ + inline void setNature(Nature::VertexNature iNature) + { + _Nature = iNature; + } + + /* Replaces old edge by new edge */ + virtual void Replace(ViewEdge *, ViewEdge *) + { + } + + public: + /* iterators access */ + // allows iteration on the edges that comes from/goes to this vertex in CCW order (order defined in 2D in the + // image plan) + virtual edge_iterator edges_begin() = 0; + virtual const_edge_iterator edges_begin() const = 0; + virtual edge_iterator edges_end() = 0; + virtual const_edge_iterator edges_end() const = 0; + virtual edge_iterator edges_iterator(ViewEdge *iEdge) = 0; + virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const = 0; + + // Iterator access + /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first + * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges + * and to get the orientation for each ViewEdge (incoming/outgoing). + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin() = 0; + + /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd() = 0; + + /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge) = 0; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewVertex") #endif }; @@ -382,265 +390,264 @@ public: * Basically the front edge hides part of the back edge. * So, among the back edges, 1 is of invisibility n and the other of visibility n+1 */ -class TVertex : public ViewVertex -{ -public: - typedef vector edge_pointers_container; - -public: // Implementation of Interface0D - /*! Returns the string "TVertex". */ - virtual string getExactTypeName() const - { - return "TVertex"; - } - - // Data access methods - /* Returns the 3D x coordinate of the vertex. Ambiguous in this case. */ - virtual real getX() const - { - cerr << "Warning: getX() undefined for this point" << endl; - return _FrontSVertex->point3D().x(); - } - - virtual real getY() const - { - cerr << "Warning: getX() undefined for this point" << endl; - return _FrontSVertex->point3D().y(); - } - - virtual real getZ() const - { - cerr << "Warning: getX() undefined for this point" << endl; - return _FrontSVertex->point3D().z(); - } - - /*! Returns the 3D point. */ - virtual Vec3r getPoint3D() const - { - cerr << "Warning: getPoint3D() undefined for this point" << endl; - return _FrontSVertex->getPoint3D(); - } - - /*! Returns the projected 3D x coordinate of the vertex. */ - virtual real getProjectedX() const - { - return _FrontSVertex->point2D().x(); - } - - /*! Returns the projected 3D y coordinate of the vertex. */ - virtual real getProjectedY() const - { - return _FrontSVertex->point2D().y(); - } - - virtual real getProjectedZ() const - { - return _FrontSVertex->point2D().z(); - } - - /*! Returns the 2D point. */ - virtual Vec2r getPoint2D() const - { - return _FrontSVertex->getPoint2D(); - } - - /*! Returns the Id of the TVertex. */ - virtual Id getId() const - { - return _Id; - } - - /*! Cast the Interface0D in SVertex if it can be. */ - // it can't - virtual ViewVertex *castToViewVertex() - { - return this; - } - - /*! Cast the Interface0D in TVertex if it can be. */ - virtual TVertex *castToTVertex() - { - return this; - } - -private: - SVertex *_FrontSVertex; - SVertex *_BackSVertex; - directedViewEdge _FrontEdgeA; - directedViewEdge _FrontEdgeB; - directedViewEdge _BackEdgeA; - directedViewEdge _BackEdgeB; - Id _Id; // id to identify t vertices . these id will be negative in order not to be mixed with NonTVertex ids. - edge_pointers_container _sortedEdges; // the list of the four ViewEdges, ordered in CCW order (in the image plan) - -public: - /*! Default constructor.*/ - inline TVertex() : ViewVertex(Nature::T_VERTEX) - { - _FrontSVertex = NULL; - _BackSVertex = NULL; - _FrontEdgeA.first = 0; - _FrontEdgeB.first = 0; - _BackEdgeA.first = 0; - _BackEdgeB.first = 0; - } - - inline TVertex(SVertex *svFront, SVertex *svBack) : ViewVertex(Nature::T_VERTEX) - { - _FrontSVertex = svFront; - _BackSVertex = svBack; - _FrontEdgeA.first = 0; - _FrontEdgeB.first = 0; - _BackEdgeA.first = 0; - _BackEdgeB.first = 0; - svFront->setViewVertex(this); - svBack->setViewVertex(this); - } - -protected: - /*! Copy constructor. */ - inline TVertex(TVertex& iBrother) : ViewVertex(iBrother) - { - _FrontSVertex = iBrother._FrontSVertex; - _BackSVertex = iBrother._BackSVertex; - _FrontEdgeA = iBrother._FrontEdgeA; - _FrontEdgeB = iBrother._FrontEdgeB; - _BackEdgeA = iBrother._BackEdgeA; - _BackEdgeB = iBrother._BackEdgeB; - _sortedEdges = iBrother._sortedEdges; - } - - /*! Cloning method. */ - virtual ViewVertex *duplicate() - { - TVertex *clone = new TVertex(*this); - return clone; - } - -public: - /* accessors */ - /*! Returns the SVertex that is closer to the viewpoint. */ - inline SVertex *frontSVertex() - { - return _FrontSVertex; - } - - /*! Returns the SVertex that is further away from the viewpoint. */ - inline SVertex *backSVertex() - { - return _BackSVertex; - } - - inline directedViewEdge& frontEdgeA() - { - return _FrontEdgeA; - } - - inline directedViewEdge& frontEdgeB() - { - return _FrontEdgeB; - } - - inline directedViewEdge& backEdgeA() - { - return _BackEdgeA; - } - - inline directedViewEdge& backEdgeB() - { - return _BackEdgeB; - } - - /* modifiers */ - /*! Sets the SVertex that is closer to the viewpoint. */ - inline void setFrontSVertex(SVertex *iFrontSVertex) - { - _FrontSVertex = iFrontSVertex; - _FrontSVertex->setViewVertex(this); - } - - /*! Sets the SVertex that is further away from the viewpoint. */ - inline void setBackSVertex(SVertex *iBackSVertex) - { - _BackSVertex = iBackSVertex; - _BackSVertex->setViewVertex(this); - } - - void setFrontEdgeA(ViewEdge *iFrontEdgeA, bool incoming = true); - void setFrontEdgeB(ViewEdge *iFrontEdgeB, bool incoming = true); - void setBackEdgeA(ViewEdge *iBackEdgeA, bool incoming = true); - void setBackEdgeB(ViewEdge *iBackEdgeB, bool incoming = true); - - /*! Sets the Id. */ - inline void setId(const Id& iId) - { - _Id = iId; - } - - /*! Returns the SVertex (among the 2) belonging to the FEdge iFEdge */ - inline SVertex *getSVertex(FEdge *iFEdge) - { - const vector& vfEdges = _FrontSVertex->fedges(); - vector::const_iterator fe, fend; - for (fe = vfEdges.begin(), fend = vfEdges.end(); fe != fend; fe++) { - if ((*fe) == iFEdge) - return _FrontSVertex; - } - - const vector& vbEdges = _BackSVertex->fedges(); - for (fe = vbEdges.begin(), fend = vbEdges.end(); fe != fend; fe++) { - if ((*fe) == iFEdge) - return _BackSVertex; - } - return NULL; - } - - virtual void Replace(ViewEdge *iOld, ViewEdge *iNew); - - /*! returns the mate edge of iEdgeA. - * For example, if iEdgeA is frontEdgeA, then frontEdgeB is returned. If iEdgeA is frontEdgeB then frontEdgeA - * is returned. Same for back edges - */ - virtual ViewEdge *mate(ViewEdge *iEdgeA) - { - if (iEdgeA == _FrontEdgeA.first) - return _FrontEdgeB.first; - if (iEdgeA == _FrontEdgeB.first) - return _FrontEdgeA.first; - if (iEdgeA == _BackEdgeA.first) - return _BackEdgeB.first; - if (iEdgeA == _BackEdgeB.first) - return _BackEdgeA.first; - return NULL; - } - - /* iterators access */ - virtual edge_iterator edges_begin(); - virtual const_edge_iterator edges_begin() const; - virtual edge_iterator edges_end(); - virtual const_edge_iterator edges_end() const; - virtual edge_iterator edges_iterator(ViewEdge *iEdge); - virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const; - - /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first - * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges - * and to get the orientation for each ViewEdge (incoming/outgoing). - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin(); - - /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd(); - - /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge); +class TVertex : public ViewVertex { + public: + typedef vector edge_pointers_container; + + public: // Implementation of Interface0D + /*! Returns the string "TVertex". */ + virtual string getExactTypeName() const + { + return "TVertex"; + } + + // Data access methods + /* Returns the 3D x coordinate of the vertex. Ambiguous in this case. */ + virtual real getX() const + { + cerr << "Warning: getX() undefined for this point" << endl; + return _FrontSVertex->point3D().x(); + } + + virtual real getY() const + { + cerr << "Warning: getX() undefined for this point" << endl; + return _FrontSVertex->point3D().y(); + } + + virtual real getZ() const + { + cerr << "Warning: getX() undefined for this point" << endl; + return _FrontSVertex->point3D().z(); + } + + /*! Returns the 3D point. */ + virtual Vec3r getPoint3D() const + { + cerr << "Warning: getPoint3D() undefined for this point" << endl; + return _FrontSVertex->getPoint3D(); + } + + /*! Returns the projected 3D x coordinate of the vertex. */ + virtual real getProjectedX() const + { + return _FrontSVertex->point2D().x(); + } + + /*! Returns the projected 3D y coordinate of the vertex. */ + virtual real getProjectedY() const + { + return _FrontSVertex->point2D().y(); + } + + virtual real getProjectedZ() const + { + return _FrontSVertex->point2D().z(); + } + + /*! Returns the 2D point. */ + virtual Vec2r getPoint2D() const + { + return _FrontSVertex->getPoint2D(); + } + + /*! Returns the Id of the TVertex. */ + virtual Id getId() const + { + return _Id; + } + + /*! Cast the Interface0D in SVertex if it can be. */ + // it can't + virtual ViewVertex *castToViewVertex() + { + return this; + } + + /*! Cast the Interface0D in TVertex if it can be. */ + virtual TVertex *castToTVertex() + { + return this; + } + + private: + SVertex *_FrontSVertex; + SVertex *_BackSVertex; + directedViewEdge _FrontEdgeA; + directedViewEdge _FrontEdgeB; + directedViewEdge _BackEdgeA; + directedViewEdge _BackEdgeB; + Id _Id; // id to identify t vertices . these id will be negative in order not to be mixed with NonTVertex ids. + edge_pointers_container + _sortedEdges; // the list of the four ViewEdges, ordered in CCW order (in the image plan) + + public: + /*! Default constructor.*/ + inline TVertex() : ViewVertex(Nature::T_VERTEX) + { + _FrontSVertex = NULL; + _BackSVertex = NULL; + _FrontEdgeA.first = 0; + _FrontEdgeB.first = 0; + _BackEdgeA.first = 0; + _BackEdgeB.first = 0; + } + + inline TVertex(SVertex *svFront, SVertex *svBack) : ViewVertex(Nature::T_VERTEX) + { + _FrontSVertex = svFront; + _BackSVertex = svBack; + _FrontEdgeA.first = 0; + _FrontEdgeB.first = 0; + _BackEdgeA.first = 0; + _BackEdgeB.first = 0; + svFront->setViewVertex(this); + svBack->setViewVertex(this); + } + + protected: + /*! Copy constructor. */ + inline TVertex(TVertex &iBrother) : ViewVertex(iBrother) + { + _FrontSVertex = iBrother._FrontSVertex; + _BackSVertex = iBrother._BackSVertex; + _FrontEdgeA = iBrother._FrontEdgeA; + _FrontEdgeB = iBrother._FrontEdgeB; + _BackEdgeA = iBrother._BackEdgeA; + _BackEdgeB = iBrother._BackEdgeB; + _sortedEdges = iBrother._sortedEdges; + } + + /*! Cloning method. */ + virtual ViewVertex *duplicate() + { + TVertex *clone = new TVertex(*this); + return clone; + } + + public: + /* accessors */ + /*! Returns the SVertex that is closer to the viewpoint. */ + inline SVertex *frontSVertex() + { + return _FrontSVertex; + } + + /*! Returns the SVertex that is further away from the viewpoint. */ + inline SVertex *backSVertex() + { + return _BackSVertex; + } + + inline directedViewEdge &frontEdgeA() + { + return _FrontEdgeA; + } + + inline directedViewEdge &frontEdgeB() + { + return _FrontEdgeB; + } + + inline directedViewEdge &backEdgeA() + { + return _BackEdgeA; + } + + inline directedViewEdge &backEdgeB() + { + return _BackEdgeB; + } + + /* modifiers */ + /*! Sets the SVertex that is closer to the viewpoint. */ + inline void setFrontSVertex(SVertex *iFrontSVertex) + { + _FrontSVertex = iFrontSVertex; + _FrontSVertex->setViewVertex(this); + } + + /*! Sets the SVertex that is further away from the viewpoint. */ + inline void setBackSVertex(SVertex *iBackSVertex) + { + _BackSVertex = iBackSVertex; + _BackSVertex->setViewVertex(this); + } + + void setFrontEdgeA(ViewEdge *iFrontEdgeA, bool incoming = true); + void setFrontEdgeB(ViewEdge *iFrontEdgeB, bool incoming = true); + void setBackEdgeA(ViewEdge *iBackEdgeA, bool incoming = true); + void setBackEdgeB(ViewEdge *iBackEdgeB, bool incoming = true); + + /*! Sets the Id. */ + inline void setId(const Id &iId) + { + _Id = iId; + } + + /*! Returns the SVertex (among the 2) belonging to the FEdge iFEdge */ + inline SVertex *getSVertex(FEdge *iFEdge) + { + const vector &vfEdges = _FrontSVertex->fedges(); + vector::const_iterator fe, fend; + for (fe = vfEdges.begin(), fend = vfEdges.end(); fe != fend; fe++) { + if ((*fe) == iFEdge) + return _FrontSVertex; + } + + const vector &vbEdges = _BackSVertex->fedges(); + for (fe = vbEdges.begin(), fend = vbEdges.end(); fe != fend; fe++) { + if ((*fe) == iFEdge) + return _BackSVertex; + } + return NULL; + } + + virtual void Replace(ViewEdge *iOld, ViewEdge *iNew); + + /*! returns the mate edge of iEdgeA. + * For example, if iEdgeA is frontEdgeA, then frontEdgeB is returned. If iEdgeA is frontEdgeB then frontEdgeA + * is returned. Same for back edges + */ + virtual ViewEdge *mate(ViewEdge *iEdgeA) + { + if (iEdgeA == _FrontEdgeA.first) + return _FrontEdgeB.first; + if (iEdgeA == _FrontEdgeB.first) + return _FrontEdgeA.first; + if (iEdgeA == _BackEdgeA.first) + return _BackEdgeB.first; + if (iEdgeA == _BackEdgeB.first) + return _BackEdgeA.first; + return NULL; + } + + /* iterators access */ + virtual edge_iterator edges_begin(); + virtual const_edge_iterator edges_begin() const; + virtual edge_iterator edges_end(); + virtual const_edge_iterator edges_end() const; + virtual edge_iterator edges_iterator(ViewEdge *iEdge); + virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const; + + /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first + * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges + * and to get the orientation for each ViewEdge (incoming/outgoing). + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin(); + + /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd(); + + /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TVertex") #endif }; - /**********************************/ /* */ /* */ @@ -649,210 +656,212 @@ public: /* */ /**********************************/ - // (non T vertex) /*! View vertex for corners, cusps, etc... * Associated to a single SVertex. * Can be associated to 2 or several view edges */ -class NonTVertex : public ViewVertex -{ -public: - typedef vector edges_container; - -public: // Implementation of Interface0D - /*! Returns the string "ViewVertex". */ - virtual string getExactTypeName() const - { - return "NonTVertex"; - } - - // Data access methods - /*! Returns the 3D x coordinate of the vertex. */ - virtual real getX() const - { - return _SVertex->point3D().x(); - } - - /*! Returns the 3D y coordinate of the vertex. */ - virtual real getY() const - { - return _SVertex->point3D().y(); - } - - /*! Returns the 3D z coordinate of the vertex. */ - virtual real getZ() const - { - return _SVertex->point3D().z(); - } - - /*! Returns the 3D point. */ - virtual Vec3r getPoint3D() const - { - return _SVertex->getPoint3D(); - } - - /*! Returns the projected 3D x coordinate of the vertex. */ - virtual real getProjectedX() const - { - return _SVertex->point2D().x(); - } - - /*! Returns the projected 3D y coordinate of the vertex. */ - virtual real getProjectedY() const - { - return _SVertex->point2D().y(); - } - - /*! Returns the projected 3D z coordinate of the vertex. */ - virtual real getProjectedZ() const - { - return _SVertex->point2D().z(); - } - - /*! Returns the 2D point. */ - virtual Vec2r getPoint2D() const - { - return _SVertex->getPoint2D(); - } - - /*! Returns the Id of the vertex. */ - virtual Id getId() const - { - return _SVertex->getId(); - } - - /*! Cast the Interface0D in SVertex if it can be. */ - virtual SVertex *castToSVertex() - { - return _SVertex; - } - - /*! Cast the Interface0D in ViewVertex if it can be. */ - virtual ViewVertex *castToViewVertex() - { - return this; - } - - /*! Cast the Interface0D in NonTVertex if it can be. */ - virtual NonTVertex *castToNonTVertex() - { - return this; - } - -private: - SVertex *_SVertex; - edges_container _ViewEdges; - -public: - /*! Default constructor.*/ - inline NonTVertex() : ViewVertex(Nature::NON_T_VERTEX) - { - _SVertex = NULL; - } - - /*! Builds a NonTVertex from a SVertex. */ - inline NonTVertex(SVertex *iSVertex) : ViewVertex(Nature::NON_T_VERTEX) - { - _SVertex = iSVertex; - _SVertex->setViewVertex(this); - } - -protected: - /*! Copy constructor. */ - inline NonTVertex(NonTVertex& iBrother) : ViewVertex(iBrother) - { - _SVertex = iBrother._SVertex; - _SVertex->setViewVertex(this); - _ViewEdges = iBrother._ViewEdges; - } - - /*! Cloning method. */ - virtual ViewVertex *duplicate() - { - NonTVertex *clone = new NonTVertex(*this); - return clone; - } - -public: - /*! destructor. */ - virtual ~NonTVertex() {} - - /* accessors */ - /*! Returns the SVertex on top of which this NonTVertex is built. */ - inline SVertex *svertex() - { - return _SVertex; - } - - inline edges_container& viewedges() - { - return _ViewEdges; - } - - /* modifiers */ - /*! Sets the SVertex on top of which this NonTVertex is built. */ - inline void setSVertex(SVertex *iSVertex) - { - _SVertex = iSVertex; - _SVertex->setViewVertex(this); - } - - inline void setViewEdges(const vector& iViewEdges) - { - _ViewEdges = iViewEdges; - } - - void AddIncomingViewEdge(ViewEdge *iVEdge); - void AddOutgoingViewEdge(ViewEdge *iVEdge); - - inline void AddViewEdge(ViewEdge *iVEdge, bool incoming = true) - { - if (incoming) - AddIncomingViewEdge(iVEdge); - else - AddOutgoingViewEdge(iVEdge); - } - - /* Replaces old edge by new edge */ - virtual void Replace(ViewEdge *iOld, ViewEdge *iNew) - { - edges_container::iterator insertedve; - for (edges_container::iterator ve = _ViewEdges.begin(), vend = _ViewEdges.end(); ve != vend; ve++) { - if ((ve)->first == iOld) { - insertedve = _ViewEdges.insert(ve, directedViewEdge(iNew, ve->second));// inserts e2 before ve. - // returns an iterator pointing toward e2. ve is invalidated. - // we want to remove e1, but we can't use ve anymore: - insertedve++; // insertedve points now to e1 - _ViewEdges.erase(insertedve); - return; - } - } - } - - /* iterators access */ - virtual edge_iterator edges_begin(); - virtual const_edge_iterator edges_begin() const; - virtual edge_iterator edges_end(); - virtual const_edge_iterator edges_end() const; - virtual edge_iterator edges_iterator(ViewEdge *iEdge); - virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const; - - /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first - * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges - * and to get the orientation for each ViewEdge (incoming/outgoing). - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin(); - - /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. - */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd(); - - /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ - virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge); +class NonTVertex : public ViewVertex { + public: + typedef vector edges_container; + + public: // Implementation of Interface0D + /*! Returns the string "ViewVertex". */ + virtual string getExactTypeName() const + { + return "NonTVertex"; + } + + // Data access methods + /*! Returns the 3D x coordinate of the vertex. */ + virtual real getX() const + { + return _SVertex->point3D().x(); + } + + /*! Returns the 3D y coordinate of the vertex. */ + virtual real getY() const + { + return _SVertex->point3D().y(); + } + + /*! Returns the 3D z coordinate of the vertex. */ + virtual real getZ() const + { + return _SVertex->point3D().z(); + } + + /*! Returns the 3D point. */ + virtual Vec3r getPoint3D() const + { + return _SVertex->getPoint3D(); + } + + /*! Returns the projected 3D x coordinate of the vertex. */ + virtual real getProjectedX() const + { + return _SVertex->point2D().x(); + } + + /*! Returns the projected 3D y coordinate of the vertex. */ + virtual real getProjectedY() const + { + return _SVertex->point2D().y(); + } + + /*! Returns the projected 3D z coordinate of the vertex. */ + virtual real getProjectedZ() const + { + return _SVertex->point2D().z(); + } + + /*! Returns the 2D point. */ + virtual Vec2r getPoint2D() const + { + return _SVertex->getPoint2D(); + } + + /*! Returns the Id of the vertex. */ + virtual Id getId() const + { + return _SVertex->getId(); + } + + /*! Cast the Interface0D in SVertex if it can be. */ + virtual SVertex *castToSVertex() + { + return _SVertex; + } + + /*! Cast the Interface0D in ViewVertex if it can be. */ + virtual ViewVertex *castToViewVertex() + { + return this; + } + + /*! Cast the Interface0D in NonTVertex if it can be. */ + virtual NonTVertex *castToNonTVertex() + { + return this; + } + + private: + SVertex *_SVertex; + edges_container _ViewEdges; + + public: + /*! Default constructor.*/ + inline NonTVertex() : ViewVertex(Nature::NON_T_VERTEX) + { + _SVertex = NULL; + } + + /*! Builds a NonTVertex from a SVertex. */ + inline NonTVertex(SVertex *iSVertex) : ViewVertex(Nature::NON_T_VERTEX) + { + _SVertex = iSVertex; + _SVertex->setViewVertex(this); + } + + protected: + /*! Copy constructor. */ + inline NonTVertex(NonTVertex &iBrother) : ViewVertex(iBrother) + { + _SVertex = iBrother._SVertex; + _SVertex->setViewVertex(this); + _ViewEdges = iBrother._ViewEdges; + } + + /*! Cloning method. */ + virtual ViewVertex *duplicate() + { + NonTVertex *clone = new NonTVertex(*this); + return clone; + } + + public: + /*! destructor. */ + virtual ~NonTVertex() + { + } + + /* accessors */ + /*! Returns the SVertex on top of which this NonTVertex is built. */ + inline SVertex *svertex() + { + return _SVertex; + } + + inline edges_container &viewedges() + { + return _ViewEdges; + } + + /* modifiers */ + /*! Sets the SVertex on top of which this NonTVertex is built. */ + inline void setSVertex(SVertex *iSVertex) + { + _SVertex = iSVertex; + _SVertex->setViewVertex(this); + } + + inline void setViewEdges(const vector &iViewEdges) + { + _ViewEdges = iViewEdges; + } + + void AddIncomingViewEdge(ViewEdge *iVEdge); + void AddOutgoingViewEdge(ViewEdge *iVEdge); + + inline void AddViewEdge(ViewEdge *iVEdge, bool incoming = true) + { + if (incoming) + AddIncomingViewEdge(iVEdge); + else + AddOutgoingViewEdge(iVEdge); + } + + /* Replaces old edge by new edge */ + virtual void Replace(ViewEdge *iOld, ViewEdge *iNew) + { + edges_container::iterator insertedve; + for (edges_container::iterator ve = _ViewEdges.begin(), vend = _ViewEdges.end(); ve != vend; + ve++) { + if ((ve)->first == iOld) { + insertedve = _ViewEdges.insert( + ve, directedViewEdge(iNew, ve->second)); // inserts e2 before ve. + // returns an iterator pointing toward e2. ve is invalidated. + // we want to remove e1, but we can't use ve anymore: + insertedve++; // insertedve points now to e1 + _ViewEdges.erase(insertedve); + return; + } + } + } + + /* iterators access */ + virtual edge_iterator edges_begin(); + virtual const_edge_iterator edges_begin() const; + virtual edge_iterator edges_end(); + virtual const_edge_iterator edges_end() const; + virtual edge_iterator edges_iterator(ViewEdge *iEdge); + virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const; + + /*! Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first + * ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges + * and to get the orientation for each ViewEdge (incoming/outgoing). + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin(); + + /*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge. + */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd(); + + /*! Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. */ + virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NonTVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NonTVertex") #endif }; @@ -880,502 +889,499 @@ template class edge_iterator_base; template class fedge_iterator_base; template class vertex_iterator_base; -} // end of namespace ViewEdgeInternal +} // end of namespace ViewEdgeInternal /*! Class defining a ViewEdge. A ViewEdge in an edge of the image graph. it connects two ViewVertex. * It is made by connecting a set of FEdges. */ -class ViewEdge : public Interface1D -{ -public: // Implementation of Interface0D - /*! Returns the string "ViewEdge". */ - virtual string getExactTypeName() const - { - return "ViewEdge"; - } - - // Data access methods - /*! Returns the Id of the vertex. */ - virtual Id getId() const - { - return _Id; - } - - /*! Returns the nature of the ViewEdge. */ - virtual Nature::EdgeNature getNature() const - { - return _Nature; - } - -public: - typedef SVertex vertex_type; - friend class ViewShape; - // for ViewEdge iterator - typedef ViewEdgeInternal::edge_iterator_base > edge_iterator; - typedef ViewEdgeInternal::edge_iterator_base > const_edge_iterator; - // for fedge iterator - typedef ViewEdgeInternal::fedge_iterator_base > fedge_iterator; - typedef ViewEdgeInternal::fedge_iterator_base > const_fedge_iterator; - // for svertex iterator - typedef ViewEdgeInternal::vertex_iterator_base > vertex_iterator; - typedef ViewEdgeInternal::vertex_iterator_base > const_vertex_iterator; - -private: - ViewVertex *__A; // edge starting vertex - ViewVertex *__B; // edge ending vertex - Nature::EdgeNature _Nature; // nature of view edge - ViewShape *_Shape; // shape to which the view edge belongs - FEdge *_FEdgeA; // first edge of the embedded fedges chain - FEdge *_FEdgeB; // last edge of the embedded fedges chain - Id _Id; - unsigned _ChainingTimeStamp; - // The silhouette view edge separates 2 2D spaces. The one on the left is necessarly the Shape _Shape (the one to - // which this edge belongs to) and _aShape is the one on its right - // NOT HANDLED BY THE COPY CONSTRUCTOR - ViewShape *_aShape; - int _qi; - vector _Occluders; - bool _isInImage; - - // tmp - Id *_splittingId; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor. */ - inline ViewEdge() - { - __A = NULL; - __B = NULL; - _FEdgeA = NULL; - _FEdgeB = NULL; - _ChainingTimeStamp = 0; - _qi = 0; - _aShape = NULL; - userdata = NULL; - _splittingId = NULL; - _isInImage = true; - } - - inline ViewEdge(ViewVertex *iA, ViewVertex *iB) - { - __A = iA; - __B = iB; - _FEdgeA = NULL; - _FEdgeB = NULL; - _Shape = 0; - _ChainingTimeStamp = 0; - _qi = 0; - _aShape = NULL; - userdata = NULL; - _splittingId = NULL; - _isInImage = true; - } - - inline ViewEdge(ViewVertex *iA, ViewVertex *iB, FEdge *iFEdgeA) - { - __A = iA; - __B = iB; - _FEdgeA = iFEdgeA; - _FEdgeB = NULL; - _Shape = NULL; - _ChainingTimeStamp = 0; - _qi = 0; - _aShape = NULL; - userdata = NULL; - _splittingId = NULL; - _isInImage = true; - } - - inline ViewEdge(ViewVertex *iA, ViewVertex *iB, FEdge *iFEdgeA, FEdge *iFEdgeB, ViewShape *iShape) - { - __A = iA; - __B = iB; - _FEdgeA = iFEdgeA; - _FEdgeB = iFEdgeB; - _Shape = iShape; - _ChainingTimeStamp = 0; - _qi = 0; - _aShape = NULL; - userdata = NULL; - _splittingId = NULL; - _isInImage = true; - UpdateFEdges(); // tells every FEdge between iFEdgeA and iFEdgeB that this is theit ViewEdge - } - -//soc protected: - /*! Copy constructor. */ - inline ViewEdge(ViewEdge& iBrother) - { - __A = iBrother.__A; - __B = iBrother.__B; - _FEdgeA = iBrother._FEdgeA; - _FEdgeB = iBrother._FEdgeB; - _Nature = iBrother._Nature; - _Shape = NULL; - _Id = iBrother._Id; - _ChainingTimeStamp = iBrother._ChainingTimeStamp; - _aShape = iBrother._aShape; - _qi = iBrother._qi; - _splittingId = NULL; - _isInImage = iBrother._isInImage; - iBrother.userdata = this; - userdata = NULL; - } - - /*! Cloning method. */ - virtual ViewEdge *duplicate() - { - ViewEdge *clone = new ViewEdge(*this); - return clone; - } - -public: - /*! Destructor. */ - virtual ~ViewEdge() - { +class ViewEdge : public Interface1D { + public: // Implementation of Interface0D + /*! Returns the string "ViewEdge". */ + virtual string getExactTypeName() const + { + return "ViewEdge"; + } + + // Data access methods + /*! Returns the Id of the vertex. */ + virtual Id getId() const + { + return _Id; + } + + /*! Returns the nature of the ViewEdge. */ + virtual Nature::EdgeNature getNature() const + { + return _Nature; + } + + public: + typedef SVertex vertex_type; + friend class ViewShape; + // for ViewEdge iterator + typedef ViewEdgeInternal::edge_iterator_base> edge_iterator; + typedef ViewEdgeInternal::edge_iterator_base> const_edge_iterator; + // for fedge iterator + typedef ViewEdgeInternal::fedge_iterator_base> fedge_iterator; + typedef ViewEdgeInternal::fedge_iterator_base> const_fedge_iterator; + // for svertex iterator + typedef ViewEdgeInternal::vertex_iterator_base> vertex_iterator; + typedef ViewEdgeInternal::vertex_iterator_base> const_vertex_iterator; + + private: + ViewVertex *__A; // edge starting vertex + ViewVertex *__B; // edge ending vertex + Nature::EdgeNature _Nature; // nature of view edge + ViewShape *_Shape; // shape to which the view edge belongs + FEdge *_FEdgeA; // first edge of the embedded fedges chain + FEdge *_FEdgeB; // last edge of the embedded fedges chain + Id _Id; + unsigned _ChainingTimeStamp; + // The silhouette view edge separates 2 2D spaces. The one on the left is necessarly the Shape _Shape (the one to + // which this edge belongs to) and _aShape is the one on its right + // NOT HANDLED BY THE COPY CONSTRUCTOR + ViewShape *_aShape; + int _qi; + vector _Occluders; + bool _isInImage; + + // tmp + Id *_splittingId; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor. */ + inline ViewEdge() + { + __A = NULL; + __B = NULL; + _FEdgeA = NULL; + _FEdgeB = NULL; + _ChainingTimeStamp = 0; + _qi = 0; + _aShape = NULL; + userdata = NULL; + _splittingId = NULL; + _isInImage = true; + } + + inline ViewEdge(ViewVertex *iA, ViewVertex *iB) + { + __A = iA; + __B = iB; + _FEdgeA = NULL; + _FEdgeB = NULL; + _Shape = 0; + _ChainingTimeStamp = 0; + _qi = 0; + _aShape = NULL; + userdata = NULL; + _splittingId = NULL; + _isInImage = true; + } + + inline ViewEdge(ViewVertex *iA, ViewVertex *iB, FEdge *iFEdgeA) + { + __A = iA; + __B = iB; + _FEdgeA = iFEdgeA; + _FEdgeB = NULL; + _Shape = NULL; + _ChainingTimeStamp = 0; + _qi = 0; + _aShape = NULL; + userdata = NULL; + _splittingId = NULL; + _isInImage = true; + } + + inline ViewEdge( + ViewVertex *iA, ViewVertex *iB, FEdge *iFEdgeA, FEdge *iFEdgeB, ViewShape *iShape) + { + __A = iA; + __B = iB; + _FEdgeA = iFEdgeA; + _FEdgeB = iFEdgeB; + _Shape = iShape; + _ChainingTimeStamp = 0; + _qi = 0; + _aShape = NULL; + userdata = NULL; + _splittingId = NULL; + _isInImage = true; + UpdateFEdges(); // tells every FEdge between iFEdgeA and iFEdgeB that this is theit ViewEdge + } + + //soc protected: + /*! Copy constructor. */ + inline ViewEdge(ViewEdge &iBrother) + { + __A = iBrother.__A; + __B = iBrother.__B; + _FEdgeA = iBrother._FEdgeA; + _FEdgeB = iBrother._FEdgeB; + _Nature = iBrother._Nature; + _Shape = NULL; + _Id = iBrother._Id; + _ChainingTimeStamp = iBrother._ChainingTimeStamp; + _aShape = iBrother._aShape; + _qi = iBrother._qi; + _splittingId = NULL; + _isInImage = iBrother._isInImage; + iBrother.userdata = this; + userdata = NULL; + } + + /*! Cloning method. */ + virtual ViewEdge *duplicate() + { + ViewEdge *clone = new ViewEdge(*this); + return clone; + } + + public: + /*! Destructor. */ + virtual ~ViewEdge() + { #if 0 - if (_aFace) { - delete _aFace; - _aFace = NULL; - } + if (_aFace) { + delete _aFace; + _aFace = NULL; + } #endif - // only the last splitted deletes this id - if (_splittingId) { - if (*_splittingId == _Id) - delete _splittingId; - } - } - - /* accessors */ - /*! Returns the first ViewVertex. */ - inline ViewVertex *A() - { - return __A; - } - - /*! Returns the second ViewVertex. */ - inline ViewVertex *B() - { - return __B; - } - - /*! Returns the first FEdge that constitues this ViewEdge. */ - inline FEdge *fedgeA() - { - return _FEdgeA; - } - - /*! Returns the last FEdge that constitues this ViewEdge. */ - inline FEdge *fedgeB() - { - return _FEdgeB; - } - - /*! Returns the ViewShape to which this ViewEdge belongs to .*/ - inline ViewShape *viewShape() - { - return _Shape; - } - - /*! Returns the shape that is occluded by the ViewShape to which this ViewEdge belongs to. If no object is occluded, - * NULL is returned. - * \return The occluded ViewShape. - */ - inline ViewShape *aShape() - { - return _aShape; - } - - /*! Tells whether this ViewEdge forms a closed loop or not. */ - inline bool isClosed() - { - if (!__B) - return true; - return false; - } - - /*! Returns the time stamp of this ViewEdge. */ - inline unsigned getChainingTimeStamp() - { - return _ChainingTimeStamp; - } - - inline const ViewShape *aShape() const - { - return _aShape; - } - - inline const ViewShape *bShape() const - { - return _Shape; - } - - inline vector& occluders() - { - return _Occluders; - } - - inline Id *splittingId() - { - return _splittingId; - } - - inline bool isInImage() const - { - return _isInImage; - } - - /* modifiers */ - /*! Sets the first ViewVertex of the ViewEdge. */ - inline void setA(ViewVertex *iA) - { - __A = iA; - } - - /*! Sets the last ViewVertex of the ViewEdge. */ - inline void setB(ViewVertex *iB) - { - __B = iB; - } - - /*! Sets the nature of the ViewEdge. */ - inline void setNature(Nature::EdgeNature iNature) - { - _Nature = iNature; - } - - /*! Sets the first FEdge of the ViewEdge. */ - inline void setFEdgeA(FEdge *iFEdge) - { - _FEdgeA = iFEdge; - } - - /*! Sets the last FEdge of the ViewEdge. */ - inline void setFEdgeB(FEdge *iFEdge) - { - _FEdgeB = iFEdge; - } - - /*! Sets the ViewShape to which this ViewEdge belongs to.*/ - inline void setShape(ViewShape *iVShape) - { - _Shape = iVShape; - } - - /*! Sets the ViewEdge id. */ - inline void setId(const Id& id) - { - _Id = id; - } - - /*! Sets Viewedge to this for all embedded fedges */ - void UpdateFEdges(); - - /*! Sets the occluded ViewShape */ - inline void setaShape(ViewShape *iShape) - { - _aShape = iShape; - } - - /*! Sets the quantitative invisibility value. */ - inline void setQI(int qi) - { - _qi = qi; - } - - /*! Sets the time stamp value. */ - inline void setChainingTimeStamp(unsigned ts) - { - _ChainingTimeStamp = ts; - } - - inline void AddOccluder(ViewShape *iShape) - { - _Occluders.push_back(iShape); - } - - inline void setSplittingId(Id *id) - { - _splittingId = id; - } - - inline void setIsInImage(bool iFlag) - { - _isInImage = iFlag; - } - - /* stroke interface definition */ - inline bool intersect_2d_area(const Vec2r& iMin, const Vec2r& iMax) const - { - // parse edges to check if one of them is intersection the region: - FEdge *current = _FEdgeA; - do { - if (GeomUtils::intersect2dSeg2dArea(iMin, iMax, - Vec2r(current->vertexA()->point2D()[0], - current->vertexA()->point2D()[1]), - Vec2r(current->vertexB()->point2D()[0], - current->vertexB()->point2D()[1]))) - { - return true; - } - current = current->nextEdge(); - } while ((current != 0) && (current != _FEdgeA)); - - return false; - } - - inline bool include_in_2d_area(const Vec2r& iMin, const Vec2r& iMax) const - { - // parse edges to check if all of them are intersection the region: - FEdge *current = _FEdgeA; - - do { - if (!GeomUtils::include2dSeg2dArea(iMin, iMax, - Vec2r(current->vertexA()->point2D()[0], - current->vertexA()->point2D()[1]), - Vec2r(current->vertexB()->point2D()[0], - current->vertexB()->point2D()[1]))) - { - return false; - } - current = current->nextEdge(); - } while ((current != 0) && (current != _FEdgeA)); - - return true; - } - - /* Information access interface */ + // only the last splitted deletes this id + if (_splittingId) { + if (*_splittingId == _Id) + delete _splittingId; + } + } + + /* accessors */ + /*! Returns the first ViewVertex. */ + inline ViewVertex *A() + { + return __A; + } + + /*! Returns the second ViewVertex. */ + inline ViewVertex *B() + { + return __B; + } + + /*! Returns the first FEdge that constitues this ViewEdge. */ + inline FEdge *fedgeA() + { + return _FEdgeA; + } + + /*! Returns the last FEdge that constitues this ViewEdge. */ + inline FEdge *fedgeB() + { + return _FEdgeB; + } + + /*! Returns the ViewShape to which this ViewEdge belongs to .*/ + inline ViewShape *viewShape() + { + return _Shape; + } + + /*! Returns the shape that is occluded by the ViewShape to which this ViewEdge belongs to. If no object is occluded, + * NULL is returned. + * \return The occluded ViewShape. + */ + inline ViewShape *aShape() + { + return _aShape; + } + + /*! Tells whether this ViewEdge forms a closed loop or not. */ + inline bool isClosed() + { + if (!__B) + return true; + return false; + } + + /*! Returns the time stamp of this ViewEdge. */ + inline unsigned getChainingTimeStamp() + { + return _ChainingTimeStamp; + } + + inline const ViewShape *aShape() const + { + return _aShape; + } + + inline const ViewShape *bShape() const + { + return _Shape; + } + + inline vector &occluders() + { + return _Occluders; + } + + inline Id *splittingId() + { + return _splittingId; + } + + inline bool isInImage() const + { + return _isInImage; + } + + /* modifiers */ + /*! Sets the first ViewVertex of the ViewEdge. */ + inline void setA(ViewVertex *iA) + { + __A = iA; + } + + /*! Sets the last ViewVertex of the ViewEdge. */ + inline void setB(ViewVertex *iB) + { + __B = iB; + } + + /*! Sets the nature of the ViewEdge. */ + inline void setNature(Nature::EdgeNature iNature) + { + _Nature = iNature; + } + + /*! Sets the first FEdge of the ViewEdge. */ + inline void setFEdgeA(FEdge *iFEdge) + { + _FEdgeA = iFEdge; + } + + /*! Sets the last FEdge of the ViewEdge. */ + inline void setFEdgeB(FEdge *iFEdge) + { + _FEdgeB = iFEdge; + } + + /*! Sets the ViewShape to which this ViewEdge belongs to.*/ + inline void setShape(ViewShape *iVShape) + { + _Shape = iVShape; + } + + /*! Sets the ViewEdge id. */ + inline void setId(const Id &id) + { + _Id = id; + } + + /*! Sets Viewedge to this for all embedded fedges */ + void UpdateFEdges(); + + /*! Sets the occluded ViewShape */ + inline void setaShape(ViewShape *iShape) + { + _aShape = iShape; + } + + /*! Sets the quantitative invisibility value. */ + inline void setQI(int qi) + { + _qi = qi; + } + + /*! Sets the time stamp value. */ + inline void setChainingTimeStamp(unsigned ts) + { + _ChainingTimeStamp = ts; + } + + inline void AddOccluder(ViewShape *iShape) + { + _Occluders.push_back(iShape); + } + + inline void setSplittingId(Id *id) + { + _splittingId = id; + } + + inline void setIsInImage(bool iFlag) + { + _isInImage = iFlag; + } + + /* stroke interface definition */ + inline bool intersect_2d_area(const Vec2r &iMin, const Vec2r &iMax) const + { + // parse edges to check if one of them is intersection the region: + FEdge *current = _FEdgeA; + do { + if (GeomUtils::intersect2dSeg2dArea( + iMin, + iMax, + Vec2r(current->vertexA()->point2D()[0], current->vertexA()->point2D()[1]), + Vec2r(current->vertexB()->point2D()[0], current->vertexB()->point2D()[1]))) { + return true; + } + current = current->nextEdge(); + } while ((current != 0) && (current != _FEdgeA)); + + return false; + } + + inline bool include_in_2d_area(const Vec2r &iMin, const Vec2r &iMax) const + { + // parse edges to check if all of them are intersection the region: + FEdge *current = _FEdgeA; + + do { + if (!GeomUtils::include2dSeg2dArea( + iMin, + iMax, + Vec2r(current->vertexA()->point2D()[0], current->vertexA()->point2D()[1]), + Vec2r(current->vertexB()->point2D()[0], current->vertexB()->point2D()[1]))) { + return false; + } + current = current->nextEdge(); + } while ((current != 0) && (current != _FEdgeA)); + + return true; + } + + /* Information access interface */ #if 0 - inline Nature::EdgeNature viewedge_nature() const - { - return getNature(); - } + inline Nature::EdgeNature viewedge_nature() const + { + return getNature(); + } - float viewedge_length() const; + float viewedge_length() const; #endif - /*! Returns the 2D length of the Viewedge. */ - real getLength2D() const; + /*! Returns the 2D length of the Viewedge. */ + real getLength2D() const; #if 0 - inline Material material() const - { - return _FEdgeA->vertexA()->shape()->material(); - } + inline Material material() const + { + return _FEdgeA->vertexA()->shape()->material(); + } #endif - inline int qi() const - { - return _qi; - } - - inline occluder_container::const_iterator occluders_begin() const - { - return _Occluders.begin(); - } - - inline occluder_container::const_iterator occluders_end() const - { - return _Occluders.end(); - } - - inline int occluders_size() const - { - return _Occluders.size(); - } - - inline bool occluders_empty() const - { - return _Occluders.empty(); - } - - inline const Polygon3r& occludee() const - { - return (_FEdgeA->aFace()); - } - - inline const SShape *occluded_shape() const; - - inline const bool occludee_empty() const - { - if (_aShape == 0) - return true; - return false; - } - - //inline real z_discontinuity(int iCombination = 0) const; - - inline Id shape_id() const - { - return _FEdgeA->vertexA()->shape()->getId(); - } - - inline const SShape *shape() const - { - return _FEdgeA->vertexA()->shape(); - } - - inline float shape_importance() const - { - return _FEdgeA->shape_importance(); - } - - /* iterators access */ - // view edge iterator - edge_iterator ViewEdge_iterator(); - const_edge_iterator ViewEdge_iterator() const; - // feature edge iterator - fedge_iterator fedge_iterator_begin(); - const_fedge_iterator fedge_iterator_begin() const; - fedge_iterator fedge_iterator_last(); - const_fedge_iterator fedge_iterator_last() const; - fedge_iterator fedge_iterator_end(); - const_fedge_iterator fedge_iterator_end() const; - // embedding vertex iterator - const_vertex_iterator vertices_begin() const; - vertex_iterator vertices_begin(); - const_vertex_iterator vertices_last() const; - vertex_iterator vertices_last(); - const_vertex_iterator vertices_end() const; - vertex_iterator vertices_end(); - - // Iterator access (Interface1D) - /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. - * The returned Interface0DIterator points to the first SVertex of the ViewEdge. - */ - virtual Interface0DIterator verticesBegin(); - - /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. - * The returned Interface0DIterator points after the last SVertex of the ViewEdge. - */ - virtual Interface0DIterator verticesEnd(); - - /*! Returns an Interface0DIterator to iterate over the points of this ViewEdge at a given resolution. - * The returned Interface0DIterator points on the first Point of the ViewEdge. - * \param t: - * the sampling value. - */ - virtual Interface0DIterator pointsBegin(float t = 0.0f); - - /*! Returns an Interface0DIterator to iterate over the points of this ViewEdge at a given resolution. - * The returned Interface0DIterator points after the last Point of the ViewEdge. - * \param t: - * the sampling value. - */ - virtual Interface0DIterator pointsEnd(float t = 0.0f); + inline int qi() const + { + return _qi; + } + + inline occluder_container::const_iterator occluders_begin() const + { + return _Occluders.begin(); + } + + inline occluder_container::const_iterator occluders_end() const + { + return _Occluders.end(); + } + + inline int occluders_size() const + { + return _Occluders.size(); + } + + inline bool occluders_empty() const + { + return _Occluders.empty(); + } + + inline const Polygon3r &occludee() const + { + return (_FEdgeA->aFace()); + } + + inline const SShape *occluded_shape() const; + + inline const bool occludee_empty() const + { + if (_aShape == 0) + return true; + return false; + } + + //inline real z_discontinuity(int iCombination = 0) const; + + inline Id shape_id() const + { + return _FEdgeA->vertexA()->shape()->getId(); + } + + inline const SShape *shape() const + { + return _FEdgeA->vertexA()->shape(); + } + + inline float shape_importance() const + { + return _FEdgeA->shape_importance(); + } + + /* iterators access */ + // view edge iterator + edge_iterator ViewEdge_iterator(); + const_edge_iterator ViewEdge_iterator() const; + // feature edge iterator + fedge_iterator fedge_iterator_begin(); + const_fedge_iterator fedge_iterator_begin() const; + fedge_iterator fedge_iterator_last(); + const_fedge_iterator fedge_iterator_last() const; + fedge_iterator fedge_iterator_end(); + const_fedge_iterator fedge_iterator_end() const; + // embedding vertex iterator + const_vertex_iterator vertices_begin() const; + vertex_iterator vertices_begin(); + const_vertex_iterator vertices_last() const; + vertex_iterator vertices_last(); + const_vertex_iterator vertices_end() const; + vertex_iterator vertices_end(); + + // Iterator access (Interface1D) + /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. + * The returned Interface0DIterator points to the first SVertex of the ViewEdge. + */ + virtual Interface0DIterator verticesBegin(); + + /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. + * The returned Interface0DIterator points after the last SVertex of the ViewEdge. + */ + virtual Interface0DIterator verticesEnd(); + + /*! Returns an Interface0DIterator to iterate over the points of this ViewEdge at a given resolution. + * The returned Interface0DIterator points on the first Point of the ViewEdge. + * \param t: + * the sampling value. + */ + virtual Interface0DIterator pointsBegin(float t = 0.0f); + + /*! Returns an Interface0DIterator to iterate over the points of this ViewEdge at a given resolution. + * The returned Interface0DIterator points after the last Point of the ViewEdge. + * \param t: + * the sampling value. + */ + virtual Interface0DIterator pointsEnd(float t = 0.0f); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdge") #endif }; - /**********************************/ /* */ /* */ @@ -1385,239 +1391,235 @@ public: /**********************************/ /*! Class gathering the elements of the ViewMap (ViewVertex, ViewEdge) that are issued from the same input shape. */ -class ViewShape -{ -private: - vector _Vertices; - vector _Edges; - SShape *_SShape; - -public: - /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). - */ - void *userdata; - - /*! Default constructor.*/ - inline ViewShape() - { - userdata = NULL; - _SShape = NULL; - } - - /*! Builds a ViewShape from a SShape. */ - inline ViewShape(SShape *iSShape) - { - userdata = NULL; - _SShape = iSShape; - //_SShape->setViewShape(this); - } - - /*! Copy constructor. */ - inline ViewShape(ViewShape& iBrother) - { - userdata = NULL; - vector::iterator vv, vvend; - vector::iterator ve, veend; - - _SShape = iBrother._SShape; - - vector& vvertices = iBrother.vertices(); - // duplicate vertices - for (vv = vvertices.begin(), vvend = vvertices.end(); vv != vvend; vv++) { - ViewVertex *newVertex = (*vv)->duplicate(); - AddVertex(newVertex); - } - - vector& vvedges = iBrother.edges(); - // duplicate edges - for (ve = vvedges.begin(), veend = vvedges.end(); ve != veend; ve++) { - ViewEdge *newEdge = (*ve)->duplicate(); - AddEdge(newEdge); // here the shape is set as the edge's shape - } - - //------------------------- - // remap edges in vertices: - //------------------------- - for (vv = _Vertices.begin(), vvend = _Vertices.end(); vv != vvend; vv++) { - switch ((*vv)->getNature()) { - case Nature::T_VERTEX: - { - TVertex *v = (TVertex *)(*vv); - ViewEdge *veFrontA = (ViewEdge *)(v)->frontEdgeA().first->userdata; - ViewEdge *veFrontB = (ViewEdge *)(v)->frontEdgeB().first->userdata; - ViewEdge *veBackA = (ViewEdge *)(v)->backEdgeA().first->userdata; - ViewEdge *veBackB = (ViewEdge *)(v)->backEdgeB().first->userdata; - - v->setFrontEdgeA(veFrontA, v->frontEdgeA().second); - v->setFrontEdgeB(veFrontB, v->frontEdgeB().second); - v->setBackEdgeA(veBackA, v->backEdgeA().second); - v->setBackEdgeB(veBackB, v->backEdgeB().second); - } - break; - case Nature::NON_T_VERTEX: - { - NonTVertex *v = (NonTVertex *)(*vv); - vector& vedges = (v)->viewedges(); - vector newEdges; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); - ve != veend; - ve++) - { - ViewEdge *current = (ViewEdge *)((ve)->first)->userdata; - newEdges.push_back(ViewVertex::directedViewEdge(current, ve->second)); - } - (v)->setViewEdges(newEdges); - } - break; - default: - break; - } - } - - //------------------------------------- - // remap vertices in edges: - //------------------------------------- - for (ve = _Edges.begin(), veend = _Edges.end(); ve != veend; ve++) { - (*ve)->setA((ViewVertex *)((*ve)->A()->userdata)); - (*ve)->setB((ViewVertex *)((*ve)->B()->userdata)); - //--------------------------------------- - // Update all embedded FEdges - //--------------------------------------- - (*ve)->UpdateFEdges(); - } - - // reset all brothers userdata to NULL: - //------------------------------------- - //--------- - // vertices - //--------- - for (vv = vvertices.begin(), vvend = vvertices.end(); vv != vvend; vv++) { - (*vv)->userdata = NULL; - } - - //------ - // edges - //------ - for (ve = vvedges.begin(), veend = vvedges.end(); ve != veend; ve++) { - (*ve)->userdata = NULL; - } - } - - /*! Cloning method. */ - virtual ViewShape *duplicate() - { - ViewShape *clone = new ViewShape(*this); - return clone; - } - - /*! Destructor. */ - virtual ~ViewShape(); - - /* splits a view edge into several view edges. - * fe - * The FEdge that gets splitted - * iViewVertices - * The view vertices corresponding to the different intersections for the edge fe. - * This list need to be sorted such as the first view vertex is the farther away from fe->vertexA. - * ioNewEdges - * The feature edges that are newly created (the initial edges are not included) are added to this list. - * ioNewViewEdges - * The view edges that are newly created (the initial edges are not included) are added to this list. - */ - inline void SplitEdge(FEdge *fe, const vector& iViewVertices, vector& ioNewEdges, - vector& ioNewViewEdges); - - /* accessors */ - /*! Returns the SShape on top of which this ViewShape is built. */ - inline SShape *sshape() - { - return _SShape; - } - - /*! Returns the SShape on top of which this ViewShape is built. */ - inline const SShape *sshape() const - { - return _SShape; - } - - /*! Returns the list of ViewVertex contained in this ViewShape. */ - inline vector& vertices() - { - return _Vertices; - } - - /*! Returns the list of ViewEdge contained in this ViewShape. */ - inline vector& edges() - { - return _Edges; - } - - /*! Returns the ViewShape id. */ - inline Id getId() const - { - return _SShape->getId(); - } - - /*! Returns the ViewShape name. */ - inline const string& getName() const - { - return _SShape->getName(); - } - - /*! Returns the ViewShape library path. */ - inline const string& getLibraryPath() const - { - return _SShape->getLibraryPath(); - } - - /* modifiers */ - /*! Sets the SShape on top of which the ViewShape is built. */ - inline void setSShape(SShape *iSShape) - { - _SShape = iSShape; - } - - /*! Sets the list of ViewVertex contained in this ViewShape. */ - inline void setVertices(const vector& iVertices) - { - _Vertices = iVertices; - } - - /*! Sets the list of ViewEdge contained in this ViewShape. */ - inline void setEdges(const vector& iEdges) - { - _Edges = iEdges; - } - - /*! Adds a ViewVertex to the list. */ - inline void AddVertex(ViewVertex *iVertex) - { - _Vertices.push_back(iVertex); - //_SShape->AddNewVertex(iVertex->svertex()); - } - - /*! Adds a ViewEdge to the list */ - inline void AddEdge(ViewEdge *iEdge) - { - _Edges.push_back(iEdge); - iEdge->setShape(this); - //_SShape->AddNewEdge(iEdge->fedge()); - } - - /* removes the view edge iViewEdge in the View Shape and the associated FEdge chain entry in the underlying SShape - */ - void RemoveEdge(ViewEdge *iViewEdge); - - /* removes the view vertex iViewVertex in the View Shape. */ - void RemoveVertex(ViewVertex *iViewVertex); +class ViewShape { + private: + vector _Vertices; + vector _Edges; + SShape *_SShape; + + public: + /*! A field that can be used by the user to store any data. + * This field must be reseted afterwards using ResetUserData(). + */ + void *userdata; + + /*! Default constructor.*/ + inline ViewShape() + { + userdata = NULL; + _SShape = NULL; + } + + /*! Builds a ViewShape from a SShape. */ + inline ViewShape(SShape *iSShape) + { + userdata = NULL; + _SShape = iSShape; + //_SShape->setViewShape(this); + } + + /*! Copy constructor. */ + inline ViewShape(ViewShape &iBrother) + { + userdata = NULL; + vector::iterator vv, vvend; + vector::iterator ve, veend; + + _SShape = iBrother._SShape; + + vector &vvertices = iBrother.vertices(); + // duplicate vertices + for (vv = vvertices.begin(), vvend = vvertices.end(); vv != vvend; vv++) { + ViewVertex *newVertex = (*vv)->duplicate(); + AddVertex(newVertex); + } + + vector &vvedges = iBrother.edges(); + // duplicate edges + for (ve = vvedges.begin(), veend = vvedges.end(); ve != veend; ve++) { + ViewEdge *newEdge = (*ve)->duplicate(); + AddEdge(newEdge); // here the shape is set as the edge's shape + } + + //------------------------- + // remap edges in vertices: + //------------------------- + for (vv = _Vertices.begin(), vvend = _Vertices.end(); vv != vvend; vv++) { + switch ((*vv)->getNature()) { + case Nature::T_VERTEX: { + TVertex *v = (TVertex *)(*vv); + ViewEdge *veFrontA = (ViewEdge *)(v)->frontEdgeA().first->userdata; + ViewEdge *veFrontB = (ViewEdge *)(v)->frontEdgeB().first->userdata; + ViewEdge *veBackA = (ViewEdge *)(v)->backEdgeA().first->userdata; + ViewEdge *veBackB = (ViewEdge *)(v)->backEdgeB().first->userdata; + + v->setFrontEdgeA(veFrontA, v->frontEdgeA().second); + v->setFrontEdgeB(veFrontB, v->frontEdgeB().second); + v->setBackEdgeA(veBackA, v->backEdgeA().second); + v->setBackEdgeB(veBackB, v->backEdgeB().second); + } break; + case Nature::NON_T_VERTEX: { + NonTVertex *v = (NonTVertex *)(*vv); + vector &vedges = (v)->viewedges(); + vector newEdges; + for (vector::iterator ve = vedges.begin(), + veend = vedges.end(); + ve != veend; + ve++) { + ViewEdge *current = (ViewEdge *)((ve)->first)->userdata; + newEdges.push_back(ViewVertex::directedViewEdge(current, ve->second)); + } + (v)->setViewEdges(newEdges); + } break; + default: + break; + } + } + + //------------------------------------- + // remap vertices in edges: + //------------------------------------- + for (ve = _Edges.begin(), veend = _Edges.end(); ve != veend; ve++) { + (*ve)->setA((ViewVertex *)((*ve)->A()->userdata)); + (*ve)->setB((ViewVertex *)((*ve)->B()->userdata)); + //--------------------------------------- + // Update all embedded FEdges + //--------------------------------------- + (*ve)->UpdateFEdges(); + } + + // reset all brothers userdata to NULL: + //------------------------------------- + //--------- + // vertices + //--------- + for (vv = vvertices.begin(), vvend = vvertices.end(); vv != vvend; vv++) { + (*vv)->userdata = NULL; + } + + //------ + // edges + //------ + for (ve = vvedges.begin(), veend = vvedges.end(); ve != veend; ve++) { + (*ve)->userdata = NULL; + } + } + + /*! Cloning method. */ + virtual ViewShape *duplicate() + { + ViewShape *clone = new ViewShape(*this); + return clone; + } + + /*! Destructor. */ + virtual ~ViewShape(); + + /* splits a view edge into several view edges. + * fe + * The FEdge that gets splitted + * iViewVertices + * The view vertices corresponding to the different intersections for the edge fe. + * This list need to be sorted such as the first view vertex is the farther away from fe->vertexA. + * ioNewEdges + * The feature edges that are newly created (the initial edges are not included) are added to this list. + * ioNewViewEdges + * The view edges that are newly created (the initial edges are not included) are added to this list. + */ + inline void SplitEdge(FEdge *fe, + const vector &iViewVertices, + vector &ioNewEdges, + vector &ioNewViewEdges); + + /* accessors */ + /*! Returns the SShape on top of which this ViewShape is built. */ + inline SShape *sshape() + { + return _SShape; + } + + /*! Returns the SShape on top of which this ViewShape is built. */ + inline const SShape *sshape() const + { + return _SShape; + } + + /*! Returns the list of ViewVertex contained in this ViewShape. */ + inline vector &vertices() + { + return _Vertices; + } + + /*! Returns the list of ViewEdge contained in this ViewShape. */ + inline vector &edges() + { + return _Edges; + } + + /*! Returns the ViewShape id. */ + inline Id getId() const + { + return _SShape->getId(); + } + + /*! Returns the ViewShape name. */ + inline const string &getName() const + { + return _SShape->getName(); + } + + /*! Returns the ViewShape library path. */ + inline const string &getLibraryPath() const + { + return _SShape->getLibraryPath(); + } + + /* modifiers */ + /*! Sets the SShape on top of which the ViewShape is built. */ + inline void setSShape(SShape *iSShape) + { + _SShape = iSShape; + } + + /*! Sets the list of ViewVertex contained in this ViewShape. */ + inline void setVertices(const vector &iVertices) + { + _Vertices = iVertices; + } + + /*! Sets the list of ViewEdge contained in this ViewShape. */ + inline void setEdges(const vector &iEdges) + { + _Edges = iEdges; + } + + /*! Adds a ViewVertex to the list. */ + inline void AddVertex(ViewVertex *iVertex) + { + _Vertices.push_back(iVertex); + //_SShape->AddNewVertex(iVertex->svertex()); + } + + /*! Adds a ViewEdge to the list */ + inline void AddEdge(ViewEdge *iEdge) + { + _Edges.push_back(iEdge); + iEdge->setShape(this); + //_SShape->AddNewEdge(iEdge->fedge()); + } + + /* removes the view edge iViewEdge in the View Shape and the associated FEdge chain entry in the underlying SShape + */ + void RemoveEdge(ViewEdge *iViewEdge); + + /* removes the view vertex iViewVertex in the View Shape. */ + void RemoveVertex(ViewVertex *iViewVertex); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewShape") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewShape") #endif }; - /* * ############################################# * ############################################# @@ -1631,116 +1633,118 @@ public: */ /* for inline functions */ -void ViewShape::SplitEdge(FEdge *fe, const vector& iViewVertices, vector& ioNewEdges, - vector& ioNewViewEdges) +void ViewShape::SplitEdge(FEdge *fe, + const vector &iViewVertices, + vector &ioNewEdges, + vector &ioNewViewEdges) { - ViewEdge *vEdge = fe->viewedge(); - - // We first need to sort the view vertices from farther to closer to fe->vertexA - SVertex *sv, *sv2; - ViewVertex *vva, *vvb; - vector::const_iterator vv, vvend; - for (vv = iViewVertices.begin(), vvend = iViewVertices.end(); vv != vvend; vv++) { - // Add the viewvertices to the ViewShape - AddVertex((*vv)); - - // retrieve the correct SVertex from the view vertex - //-------------------------------------------------- - sv = (*vv)->frontSVertex(); - sv2 = (*vv)->backSVertex(); - - if (sv->shape() != sv2->shape()) { - if (sv->shape() != _SShape) - sv = sv2; - } - else { - // if the shape is the same we can safely differ the two vertices using their ids: - if (sv->getId() != fe->vertexA()->getId()) - sv = sv2; - } - - vva = vEdge->A(); - vvb = vEdge->B(); - - // We split Fedge AB into AA' and A'B. A' and A'B are created. - // AB becomes (address speaking) AA'. B is updated. - //-------------------------------------------------- - SShape *shape = fe->shape(); - - // a new edge, A'B is created. - FEdge *newEdge = shape->SplitEdgeIn2(fe, sv); - /* One of the two FEdges (fe and newEdge) may have a 2D length less than M_EPSILON. - * (22 Feb 2011, T.K.) - */ - - ioNewEdges.push_back(newEdge); - ViewEdge *newVEdge; - - if ((vva == 0) || (vvb == 0)) { // that means we're dealing with a closed viewedge (loop) - // remove the chain that was starting by the fedge A of vEdge (which is different from fe !!!!) - shape->RemoveEdgeFromChain(vEdge->fedgeA()); - // we set - vEdge->setA(*vv); - vEdge->setB(*vv); - vEdge->setFEdgeA(newEdge); - //FEdge *previousEdge = newEdge->previousEdge(); - vEdge->setFEdgeB(fe); - newVEdge = vEdge; - vEdge->fedgeA()->setViewEdge(newVEdge); - } - else { - // while we create the view edge, it updates the "ViewEdge" pointer of every underlying FEdges to this. - newVEdge = new ViewEdge((*vv), vvb); //, newEdge, vEdge->fedgeB()); - newVEdge->setNature((fe)->getNature()); - newVEdge->setFEdgeA(newEdge); - //newVEdge->setFEdgeB(fe); - // If our original viewedge is made of one FEdge, then - if ((vEdge->fedgeA() == vEdge->fedgeB()) || (fe == vEdge->fedgeB())) - newVEdge->setFEdgeB(newEdge); - else - newVEdge->setFEdgeB(vEdge->fedgeB()); //MODIF - - Id *newId = vEdge->splittingId(); - if (newId == 0) { - newId = new Id(vEdge->getId()); - vEdge->setSplittingId(newId); - } - newId->setSecond(newId->getSecond() + 1); - newVEdge->setId(*newId); - newVEdge->setSplittingId(newId); + ViewEdge *vEdge = fe->viewedge(); + + // We first need to sort the view vertices from farther to closer to fe->vertexA + SVertex *sv, *sv2; + ViewVertex *vva, *vvb; + vector::const_iterator vv, vvend; + for (vv = iViewVertices.begin(), vvend = iViewVertices.end(); vv != vvend; vv++) { + // Add the viewvertices to the ViewShape + AddVertex((*vv)); + + // retrieve the correct SVertex from the view vertex + //-------------------------------------------------- + sv = (*vv)->frontSVertex(); + sv2 = (*vv)->backSVertex(); + + if (sv->shape() != sv2->shape()) { + if (sv->shape() != _SShape) + sv = sv2; + } + else { + // if the shape is the same we can safely differ the two vertices using their ids: + if (sv->getId() != fe->vertexA()->getId()) + sv = sv2; + } + + vva = vEdge->A(); + vvb = vEdge->B(); + + // We split Fedge AB into AA' and A'B. A' and A'B are created. + // AB becomes (address speaking) AA'. B is updated. + //-------------------------------------------------- + SShape *shape = fe->shape(); + + // a new edge, A'B is created. + FEdge *newEdge = shape->SplitEdgeIn2(fe, sv); + /* One of the two FEdges (fe and newEdge) may have a 2D length less than M_EPSILON. + * (22 Feb 2011, T.K.) + */ + + ioNewEdges.push_back(newEdge); + ViewEdge *newVEdge; + + if ((vva == 0) || (vvb == 0)) { // that means we're dealing with a closed viewedge (loop) + // remove the chain that was starting by the fedge A of vEdge (which is different from fe !!!!) + shape->RemoveEdgeFromChain(vEdge->fedgeA()); + // we set + vEdge->setA(*vv); + vEdge->setB(*vv); + vEdge->setFEdgeA(newEdge); + //FEdge *previousEdge = newEdge->previousEdge(); + vEdge->setFEdgeB(fe); + newVEdge = vEdge; + vEdge->fedgeA()->setViewEdge(newVEdge); + } + else { + // while we create the view edge, it updates the "ViewEdge" pointer of every underlying FEdges to this. + newVEdge = new ViewEdge((*vv), vvb); //, newEdge, vEdge->fedgeB()); + newVEdge->setNature((fe)->getNature()); + newVEdge->setFEdgeA(newEdge); + //newVEdge->setFEdgeB(fe); + // If our original viewedge is made of one FEdge, then + if ((vEdge->fedgeA() == vEdge->fedgeB()) || (fe == vEdge->fedgeB())) + newVEdge->setFEdgeB(newEdge); + else + newVEdge->setFEdgeB(vEdge->fedgeB()); //MODIF + + Id *newId = vEdge->splittingId(); + if (newId == 0) { + newId = new Id(vEdge->getId()); + vEdge->setSplittingId(newId); + } + newId->setSecond(newId->getSecond() + 1); + newVEdge->setId(*newId); + newVEdge->setSplittingId(newId); #if 0 - Id id(vEdge->getId().getFirst(), vEdge->getId().getSecond() + 1); - newVEdge->setId(vEdge->getId()); - vEdge->setId(id); + Id id(vEdge->getId().getFirst(), vEdge->getId().getSecond() + 1); + newVEdge->setId(vEdge->getId()); + vEdge->setId(id); #endif - AddEdge(newVEdge); // here this shape is set as the edge's shape - - // add new edge to the list of new edges passed as argument: - ioNewViewEdges.push_back(newVEdge); - - if (0 != vvb) - vvb->Replace((vEdge), newVEdge); - - // we split the view edge: - vEdge->setB((*vv)); - vEdge->setFEdgeB(fe); //MODIF - - // Update fedges so that they point to the new viewedge: - newVEdge->UpdateFEdges(); - } - // check whether this vertex is a front vertex or a back one - if (sv == (*vv)->frontSVertex()) { - // -- View Vertex A' -- - (*vv)->setFrontEdgeA(vEdge, true); - (*vv)->setFrontEdgeB(newVEdge, false); - } - else { - // -- View Vertex A' -- - (*vv)->setBackEdgeA(vEdge, true); - (*vv)->setBackEdgeB(newVEdge, false); - } - } + AddEdge(newVEdge); // here this shape is set as the edge's shape + + // add new edge to the list of new edges passed as argument: + ioNewViewEdges.push_back(newVEdge); + + if (0 != vvb) + vvb->Replace((vEdge), newVEdge); + + // we split the view edge: + vEdge->setB((*vv)); + vEdge->setFEdgeB(fe); //MODIF + + // Update fedges so that they point to the new viewedge: + newVEdge->UpdateFEdges(); + } + // check whether this vertex is a front vertex or a back one + if (sv == (*vv)->frontSVertex()) { + // -- View Vertex A' -- + (*vv)->setFrontEdgeA(vEdge, true); + (*vv)->setFrontEdgeB(newVEdge, false); + } + else { + // -- View Vertex A' -- + (*vv)->setBackEdgeA(vEdge, true); + (*vv)->setBackEdgeB(newVEdge, false); + } + } } /**********************************/ @@ -1754,54 +1758,54 @@ void ViewShape::SplitEdge(FEdge *fe, const vector& iViewVertices, vect #if 0 inline Vec3r ViewEdge::orientation2d(int iCombination) const { - return edge_orientation2d_function(*this, iCombination); + return edge_orientation2d_function(*this, iCombination); } inline Vec3r ViewEdge::orientation3d(int iCombination) const { - return edge_orientation3d_function(*this, iCombination); + return edge_orientation3d_function(*this, iCombination); } inline real ViewEdge::z_discontinuity(int iCombination) const { - return z_discontinuity_edge_function(*this, iCombination); + return z_discontinuity_edge_function(*this, iCombination); } inline float ViewEdge::local_average_depth(int iCombination ) const { - return local_average_depth_edge_function(*this, iCombination); + return local_average_depth_edge_function(*this, iCombination); } inline float ViewEdge::local_depth_variance(int iCombination) const { - return local_depth_variance_edge_function(*this, iCombination); + return local_depth_variance_edge_function(*this, iCombination); } inline real ViewEdge::local_average_density(float sigma, int iCombination) const { - return density_edge_function(*this, iCombination); + return density_edge_function(*this, iCombination); } #endif inline const SShape *ViewEdge::occluded_shape() const { - if (0 == _aShape) - return 0; - return _aShape->sshape(); + if (0 == _aShape) + return 0; + return _aShape->sshape(); } #if 0 inline Vec3r ViewEdge::curvature2d_as_vector(int iCombination) const { - return curvature2d_as_vector_edge_function(*this, iCombination); + return curvature2d_as_vector_edge_function(*this, iCombination); } inline real ViewEdge::curvature2d_as_angle(int iCombination) const { - return curvature2d_as_angle_edge_function(*this, iCombination); + return curvature2d_as_angle_edge_function(*this, iCombination); } #endif } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_H__ +#endif // __FREESTYLE_VIEW_MAP_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h b/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h index 1b4a98498dd..2c09bde487b 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h +++ b/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h @@ -25,7 +25,7 @@ #include "ViewMap.h" -#include "../system/Iterator.h" //soc +#include "../system/Iterator.h" //soc namespace Freestyle { @@ -47,290 +47,295 @@ namespace Freestyle { namespace ViewVertexInternal { -class edge_const_traits : public Const_traits -{ -public: - typedef vector edges_container; - typedef edges_container::const_iterator edges_container_iterator; - typedef vector edge_pointers_container; - typedef edge_pointers_container::const_iterator edge_pointers_container_iterator; +class edge_const_traits : public Const_traits { + public: + typedef vector edges_container; + typedef edges_container::const_iterator edges_container_iterator; + typedef vector edge_pointers_container; + typedef edge_pointers_container::const_iterator edge_pointers_container_iterator; }; -class edge_nonconst_traits : public Nonconst_traits -{ -public: - typedef vector edges_container; - typedef edges_container::iterator edges_container_iterator; - typedef vector edge_pointers_container; - typedef edge_pointers_container::iterator edge_pointers_container_iterator; +class edge_nonconst_traits : public Nonconst_traits { + public: + typedef vector edges_container; + typedef edges_container::iterator edges_container_iterator; + typedef vector edge_pointers_container; + typedef edge_pointers_container::iterator edge_pointers_container_iterator; }; template -class edge_iterator_base : public IteratorBase -{ -public: - typedef typename Traits::value_type value_type; - typedef typename Traits::difference_type difference_type; - typedef typename Traits::pointer pointer; - typedef typename Traits::reference reference; - typedef edge_iterator_base Self; - typedef typename Traits::edges_container_iterator edges_container_iterator; - typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator; - typedef edge_iterator_base iterator; - typedef edge_iterator_base const_iterator; - -public: - friend class ViewVertex; - friend class TVertex; - friend class NonTVertex; - friend class ViewEdge; - friend class edge_iterator; - -protected: - Nature::VertexNature _Nature; // the nature of the underlying vertex - // T vertex attributes - edge_pointers_container_iterator _tbegin; - edge_pointers_container_iterator _tend; - edge_pointers_container_iterator _tvertex_iter; +class edge_iterator_base : public IteratorBase { + public: + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + typedef edge_iterator_base Self; + typedef typename Traits::edges_container_iterator edges_container_iterator; + typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator; + typedef edge_iterator_base iterator; + typedef edge_iterator_base const_iterator; + + public: + friend class ViewVertex; + friend class TVertex; + friend class NonTVertex; + friend class ViewEdge; + friend class edge_iterator; + + protected: + Nature::VertexNature _Nature; // the nature of the underlying vertex + // T vertex attributes + edge_pointers_container_iterator _tbegin; + edge_pointers_container_iterator _tend; + edge_pointers_container_iterator _tvertex_iter; #if 0 - mutable value_type _tvertex_iter; - value_type _feA; - value_type _feB; - value_type _beA; - value_type _beB; + mutable value_type _tvertex_iter; + value_type _feA; + value_type _feB; + value_type _beA; + value_type _beB; #endif - // Non TVertex attributes - edges_container_iterator _begin; - edges_container_iterator _end; - edges_container_iterator _nontvertex_iter; + // Non TVertex attributes + edges_container_iterator _begin; + edges_container_iterator _end; + edges_container_iterator _nontvertex_iter; - typedef IteratorBase parent_class; + typedef IteratorBase parent_class; -public: - inline edge_iterator_base() : parent_class() {} + public: + inline edge_iterator_base() : parent_class() + { + } - inline edge_iterator_base(Nature::VertexNature iNature) : parent_class() - { - _Nature = iNature; - } + inline edge_iterator_base(Nature::VertexNature iNature) : parent_class() + { + _Nature = iNature; + } - edge_iterator_base(const edge_iterator_base& iBrother) : parent_class(iBrother) - { - _Nature = iBrother._Nature; - if (_Nature & Nature::T_VERTEX) { + edge_iterator_base(const edge_iterator_base &iBrother) + : parent_class(iBrother) + { + _Nature = iBrother._Nature; + if (_Nature & Nature::T_VERTEX) { #if 0 - _feA = iBrother._feA; - _feB = iBrother._feB; - _beA = iBrother._beA; - _beB = iBrother._beB; - _tvertex_iter = iBrother._tvertex_iter; + _feA = iBrother._feA; + _feB = iBrother._feB; + _beA = iBrother._beA; + _beB = iBrother._beB; + _tvertex_iter = iBrother._tvertex_iter; #endif - _tbegin = iBrother._tbegin; - _tend = iBrother._tend; - _tvertex_iter = iBrother._tvertex_iter; - } - else { - _begin = iBrother._begin; - _end = iBrother._end; - _nontvertex_iter = iBrother._nontvertex_iter; - } - } - - edge_iterator_base(const edge_iterator_base& iBrother) : parent_class(iBrother) - { - _Nature = iBrother._Nature; - if (_Nature & Nature::T_VERTEX) { + _tbegin = iBrother._tbegin; + _tend = iBrother._tend; + _tvertex_iter = iBrother._tvertex_iter; + } + else { + _begin = iBrother._begin; + _end = iBrother._end; + _nontvertex_iter = iBrother._nontvertex_iter; + } + } + + edge_iterator_base(const edge_iterator_base &iBrother) + : parent_class(iBrother) + { + _Nature = iBrother._Nature; + if (_Nature & Nature::T_VERTEX) { #if 0 - _feA = iBrother._feA; - _feB = iBrother._feB; - _beA = iBrother._beA; - _beB = iBrother._beB; - _tvertex_iter = iBrother._tvertex_iter; + _feA = iBrother._feA; + _feB = iBrother._feB; + _beA = iBrother._beA; + _beB = iBrother._beB; + _tvertex_iter = iBrother._tvertex_iter; #endif - _tbegin = iBrother._tbegin; - _tend = iBrother._tend; - _tvertex_iter = iBrother._tvertex_iter; - } - else { - _begin = iBrother._begin; - _end = iBrother._end; - _nontvertex_iter = iBrother._nontvertex_iter; - } - } - - virtual ~edge_iterator_base() {} - -//protected://FIXME -public: + _tbegin = iBrother._tbegin; + _tend = iBrother._tend; + _tvertex_iter = iBrother._tvertex_iter; + } + else { + _begin = iBrother._begin; + _end = iBrother._end; + _nontvertex_iter = iBrother._nontvertex_iter; + } + } + + virtual ~edge_iterator_base() + { + } + + //protected://FIXME + public: #if 0 - inline edge_iterator_base(value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter) - : parent_class() - { - _Nature = Nature::T_VERTEX; - _feA = ifeA; - _feB = ifeB; - _beA = ibeA; - _beB = ibeB; - _tvertex_iter = iter; - } + inline edge_iterator_base(value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter) + : parent_class() + { + _Nature = Nature::T_VERTEX; + _feA = ifeA; + _feB = ifeB; + _beA = ibeA; + _beB = ibeB; + _tvertex_iter = iter; + } #endif - inline edge_iterator_base(edge_pointers_container_iterator begin, edge_pointers_container_iterator end, - edge_pointers_container_iterator iter) - : parent_class() - { - _Nature = Nature::T_VERTEX; - _tbegin = begin; - _tend = end; - _tvertex_iter = iter; - } - - inline edge_iterator_base(edges_container_iterator begin, edges_container_iterator end, - edges_container_iterator iter) - : parent_class() - { - _Nature = Nature::NON_T_VERTEX; - _begin = begin; - _end = end; - _nontvertex_iter = iter; - } - -public: - virtual bool begin() const - { - if (_Nature & Nature::T_VERTEX) - return (_tvertex_iter == _tbegin); - //return (_tvertex_iter == _feA); - else - return (_nontvertex_iter == _begin); - } - - virtual bool end() const - { - if (_Nature & Nature::T_VERTEX) - //return (_tvertex_iter.first == 0); - return (_tvertex_iter == _tend); - else - return (_nontvertex_iter == _end); - } - - // operators - // operator corresponding to ++i - virtual Self& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - virtual Self operator++(int) - { - Self tmp = *this; - increment(); - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - if (_Nature & Nature::T_VERTEX) - return (_tvertex_iter != b._tvertex_iter); - else - return (_nontvertex_iter != b._nontvertex_iter); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual reference operator*() const - { - if (_Nature & Nature::T_VERTEX) - //return _tvertex_iter; - return **_tvertex_iter; - else - return (*_nontvertex_iter); - } - - virtual pointer operator->() const - { - return &(operator*()); - } - -protected: - inline void increment() - { - if (_Nature & Nature::T_VERTEX) { - value_type tmp = (**_tvertex_iter); - ++_tvertex_iter; - value_type tmp2 = (**_tvertex_iter); - if (tmp2.first == tmp.first) - ++_tvertex_iter; + inline edge_iterator_base(edge_pointers_container_iterator begin, + edge_pointers_container_iterator end, + edge_pointers_container_iterator iter) + : parent_class() + { + _Nature = Nature::T_VERTEX; + _tbegin = begin; + _tend = end; + _tvertex_iter = iter; + } + + inline edge_iterator_base(edges_container_iterator begin, + edges_container_iterator end, + edges_container_iterator iter) + : parent_class() + { + _Nature = Nature::NON_T_VERTEX; + _begin = begin; + _end = end; + _nontvertex_iter = iter; + } + + public: + virtual bool begin() const + { + if (_Nature & Nature::T_VERTEX) + return (_tvertex_iter == _tbegin); + //return (_tvertex_iter == _feA); + else + return (_nontvertex_iter == _begin); + } + + virtual bool end() const + { + if (_Nature & Nature::T_VERTEX) + //return (_tvertex_iter.first == 0); + return (_tvertex_iter == _tend); + else + return (_nontvertex_iter == _end); + } + + // operators + // operator corresponding to ++i + virtual Self &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + virtual Self operator++(int) + { + Self tmp = *this; + increment(); + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + if (_Nature & Nature::T_VERTEX) + return (_tvertex_iter != b._tvertex_iter); + else + return (_nontvertex_iter != b._nontvertex_iter); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual reference operator*() const + { + if (_Nature & Nature::T_VERTEX) + //return _tvertex_iter; + return **_tvertex_iter; + else + return (*_nontvertex_iter); + } + + virtual pointer operator->() const + { + return &(operator*()); + } + + protected: + inline void increment() + { + if (_Nature & Nature::T_VERTEX) { + value_type tmp = (**_tvertex_iter); + ++_tvertex_iter; + value_type tmp2 = (**_tvertex_iter); + if (tmp2.first == tmp.first) + ++_tvertex_iter; #if 0 - // Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges. - // In order to iterate properly, we chose to skip these last ones. - if (_feB.first == _beA.first) { - if (_feA.first == _beB.first) { - _tvertex_iter.first = 0; - return; - } - - if (_tvertex_iter.first == _feA.first) - _tvertex_iter.first = _beB.first; - else if (_tvertex_iter.first == _beB.first) - _tvertex_iter.first = 0; - else - _tvertex_iter.first = _feA.first; - return; - } - if (_feA.first == _beB.first) { - if (_feB.first == _beA.first) { - _tvertex_iter.first = 0; - return; - } - - if (_tvertex_iter.first == _feB.first) - _tvertex_iter.first = _beA.first; - else if (_tvertex_iter.first == _beA.first) - _tvertex_iter.first = 0; - else - _tvertex_iter.first = _feB.first; - return; - } - // End of hack - - if (_tvertex_iter.first == _feA.first) { - // we return bea or beb - // choose one of them - _tvertex_iter.first = _feB.first; - return; - } - if (_tvertex_iter.first == _feB.first) { - _tvertex_iter.first = _beA.first; - return; - } - if (_tvertex_iter.first == _beA.first) { - _tvertex_iter.first = _beB.first; - return; - } - if (_tvertex_iter.first == _beB.first) { - _tvertex_iter.first = 0; - return; - } + // Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges. + // In order to iterate properly, we chose to skip these last ones. + if (_feB.first == _beA.first) { + if (_feA.first == _beB.first) { + _tvertex_iter.first = 0; + return; + } + + if (_tvertex_iter.first == _feA.first) + _tvertex_iter.first = _beB.first; + else if (_tvertex_iter.first == _beB.first) + _tvertex_iter.first = 0; + else + _tvertex_iter.first = _feA.first; + return; + } + if (_feA.first == _beB.first) { + if (_feB.first == _beA.first) { + _tvertex_iter.first = 0; + return; + } + + if (_tvertex_iter.first == _feB.first) + _tvertex_iter.first = _beA.first; + else if (_tvertex_iter.first == _beA.first) + _tvertex_iter.first = 0; + else + _tvertex_iter.first = _feB.first; + return; + } + // End of hack + + if (_tvertex_iter.first == _feA.first) { + // we return bea or beb + // choose one of them + _tvertex_iter.first = _feB.first; + return; + } + if (_tvertex_iter.first == _feB.first) { + _tvertex_iter.first = _beA.first; + return; + } + if (_tvertex_iter.first == _beA.first) { + _tvertex_iter.first = _beB.first; + return; + } + if (_tvertex_iter.first == _beB.first) { + _tvertex_iter.first = 0; + return; + } #endif - } - else { - ++_nontvertex_iter; - } - } + } + else { + ++_nontvertex_iter; + } + } }; -} // ViewVertexInternal namespace +} // namespace ViewVertexInternal /**********************************/ /* */ @@ -346,435 +351,453 @@ namespace ViewEdgeInternal { /*! Iterators definition */ /*!----------------------*/ template -class edge_iterator_base : public IteratorBase -{ -public: - typedef typename Traits::value_type value_type; - typedef typename Traits::difference_type difference_type; - typedef typename Traits::pointer pointer; - typedef typename Traits::reference reference; - typedef edge_iterator_base Self; - -public: - mutable value_type _ViewEdge; - //friend class edge_iterator_base >; - //friend class edge_iterator_base >; - value_type _first; - bool _orientation; - typedef IteratorBase parent_class; - -public: - friend class ViewEdge; - inline edge_iterator_base() : parent_class() - { - _orientation = true; - _first = 0; - } - - inline edge_iterator_base(const edge_iterator_base >& iBrother) : parent_class() - { - _ViewEdge = iBrother._ViewEdge; - _first = iBrother._first; - _orientation = iBrother._orientation; - } - - inline edge_iterator_base(const edge_iterator_base >& iBrother) : parent_class() - { - _ViewEdge = iBrother._ViewEdge; - _first = iBrother._first; - _orientation = iBrother._orientation; - } - -//protected://FIXME -public: - inline edge_iterator_base(value_type iEdge, bool orientation = true) : parent_class() - { - _ViewEdge = iEdge; - _first = iEdge; - _orientation = orientation; - } - -public: - virtual Self *clone() const - { - return new edge_iterator_base(*this); - } - - virtual ~edge_iterator_base() {} - -public: - virtual bool orientation() - { - return _orientation; - } - - virtual void set_edge(value_type iVE) - { - _ViewEdge = iVE; - } - - virtual void set_orientation(bool iOrientation) - { - _orientation = iOrientation; - } - - virtual void change_orientation() - { - _orientation = !_orientation; - } - - // operators - // operator corresponding to ++i - inline Self& operator++() - { - //++_ViewEdge->getTimeStamp(); - increment(); - return *this; - } - - // operator corresponding to i++, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator++(int) - { - //++_ViewEdge->getTimeStamp(); - Self tmp = *this; - increment(); - return tmp; - } - - // operator corresponding to --i - inline Self& operator--() - { - //++_ViewEdge->getTimeStamp(); - decrement(); - return *this; - } - - // operator corresponding to i--, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator--(int) - { - //++_ViewEdge->getTimeStamp(); - Self tmp = *this; - decrement(); - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - return (_ViewEdge != b._ViewEdge); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual reference operator*() const - { - return (_ViewEdge); - } - - virtual pointer operator->() const - { - return &(operator*()); - } - -public: - virtual bool begin() const - { - return (_ViewEdge == _first) ? true : false; - } - - virtual bool end() const - { - return (_ViewEdge == 0) ? true : false; - } - -protected: - virtual void increment() {} - virtual void decrement() {} +class edge_iterator_base : public IteratorBase { + public: + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + typedef edge_iterator_base Self; + + public: + mutable value_type _ViewEdge; + //friend class edge_iterator_base >; + //friend class edge_iterator_base >; + value_type _first; + bool _orientation; + typedef IteratorBase parent_class; + + public: + friend class ViewEdge; + inline edge_iterator_base() : parent_class() + { + _orientation = true; + _first = 0; + } + + inline edge_iterator_base(const edge_iterator_base> &iBrother) + : parent_class() + { + _ViewEdge = iBrother._ViewEdge; + _first = iBrother._first; + _orientation = iBrother._orientation; + } + + inline edge_iterator_base(const edge_iterator_base> &iBrother) + : parent_class() + { + _ViewEdge = iBrother._ViewEdge; + _first = iBrother._first; + _orientation = iBrother._orientation; + } + + //protected://FIXME + public: + inline edge_iterator_base(value_type iEdge, bool orientation = true) : parent_class() + { + _ViewEdge = iEdge; + _first = iEdge; + _orientation = orientation; + } + + public: + virtual Self *clone() const + { + return new edge_iterator_base(*this); + } + + virtual ~edge_iterator_base() + { + } + + public: + virtual bool orientation() + { + return _orientation; + } + + virtual void set_edge(value_type iVE) + { + _ViewEdge = iVE; + } + + virtual void set_orientation(bool iOrientation) + { + _orientation = iOrientation; + } + + virtual void change_orientation() + { + _orientation = !_orientation; + } + + // operators + // operator corresponding to ++i + inline Self &operator++() + { + //++_ViewEdge->getTimeStamp(); + increment(); + return *this; + } + + // operator corresponding to i++, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator++(int) + { + //++_ViewEdge->getTimeStamp(); + Self tmp = *this; + increment(); + return tmp; + } + + // operator corresponding to --i + inline Self &operator--() + { + //++_ViewEdge->getTimeStamp(); + decrement(); + return *this; + } + + // operator corresponding to i--, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator--(int) + { + //++_ViewEdge->getTimeStamp(); + Self tmp = *this; + decrement(); + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + return (_ViewEdge != b._ViewEdge); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual reference operator*() const + { + return (_ViewEdge); + } + + virtual pointer operator->() const + { + return &(operator*()); + } + + public: + virtual bool begin() const + { + return (_ViewEdge == _first) ? true : false; + } + + virtual bool end() const + { + return (_ViewEdge == 0) ? true : false; + } + + protected: + virtual void increment() + { + } + virtual void decrement() + { + } }; template -class fedge_iterator_base : public IteratorBase -{ -public: - typedef typename Traits::value_type value_type; - typedef typename Traits::difference_type difference_type; - typedef typename Traits::pointer pointer; - typedef typename Traits::reference reference; - typedef fedge_iterator_base Self; - -public: - typedef IteratorBase parent_class; - mutable value_type _FEdge; - value_type _first; - value_type _FEdgeB; // last fedge of the view edge - -public: - friend class ViewEdge; - friend class fedge_iterator; - - inline fedge_iterator_base() : parent_class() {} - - inline fedge_iterator_base(const fedge_iterator_base >& iBrother) : parent_class() - { - _FEdge = iBrother._FEdge; - _first = iBrother._first; - _FEdgeB = iBrother._FEdgeB; - } - - inline fedge_iterator_base(const fedge_iterator_base >& iBrother) : parent_class() - { - _FEdge = iBrother._FEdge; - _first = iBrother._first; - _FEdgeB = iBrother._FEdgeB; - } - -//protected://FIXME -public: - inline fedge_iterator_base(value_type iEdge, value_type iFEdgeB) : parent_class() - { - _FEdge = iEdge; - _first = iEdge; - _FEdgeB = iFEdgeB; - } - -public: - virtual ~fedge_iterator_base() {} - - // operators - // operator corresponding to ++i. - inline Self& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator++(int) - { - Self tmp = *this; - increment(); - return tmp; - } - - // operator corresponding to --i - inline Self& operator--() - { - decrement(); - return *this; - } - - // operator corresponding to i--, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator--(int) - { - Self tmp = *this; - decrement(); - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - return (_FEdge != b._FEdge); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual reference operator*() const - { - return (_FEdge); - } - - virtual pointer operator->() const - { - return &(operator*()); - } - -public: - virtual bool begin() const - { - return (_FEdge == _first) ? true : false; - } - - virtual bool end() const - { - return (_FEdge == 0) ? true : false; - } - -protected: - virtual void increment() - { - _FEdge = _FEdge->nextEdge(); // we don't change or - } - - virtual void decrement() - { - if (0 == _FEdge) { - _FEdge = _FEdgeB; - return; - } - _FEdge = _FEdge->previousEdge(); // we don't change or - } +class fedge_iterator_base : public IteratorBase { + public: + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + typedef fedge_iterator_base Self; + + public: + typedef IteratorBase parent_class; + mutable value_type _FEdge; + value_type _first; + value_type _FEdgeB; // last fedge of the view edge + + public: + friend class ViewEdge; + friend class fedge_iterator; + + inline fedge_iterator_base() : parent_class() + { + } + + inline fedge_iterator_base(const fedge_iterator_base> &iBrother) + : parent_class() + { + _FEdge = iBrother._FEdge; + _first = iBrother._first; + _FEdgeB = iBrother._FEdgeB; + } + + inline fedge_iterator_base(const fedge_iterator_base> &iBrother) + : parent_class() + { + _FEdge = iBrother._FEdge; + _first = iBrother._first; + _FEdgeB = iBrother._FEdgeB; + } + + //protected://FIXME + public: + inline fedge_iterator_base(value_type iEdge, value_type iFEdgeB) : parent_class() + { + _FEdge = iEdge; + _first = iEdge; + _FEdgeB = iFEdgeB; + } + + public: + virtual ~fedge_iterator_base() + { + } + + // operators + // operator corresponding to ++i. + inline Self &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator++(int) + { + Self tmp = *this; + increment(); + return tmp; + } + + // operator corresponding to --i + inline Self &operator--() + { + decrement(); + return *this; + } + + // operator corresponding to i--, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator--(int) + { + Self tmp = *this; + decrement(); + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + return (_FEdge != b._FEdge); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual reference operator*() const + { + return (_FEdge); + } + + virtual pointer operator->() const + { + return &(operator*()); + } + + public: + virtual bool begin() const + { + return (_FEdge == _first) ? true : false; + } + + virtual bool end() const + { + return (_FEdge == 0) ? true : false; + } + + protected: + virtual void increment() + { + _FEdge = _FEdge->nextEdge(); // we don't change or + } + + virtual void decrement() + { + if (0 == _FEdge) { + _FEdge = _FEdgeB; + return; + } + _FEdge = _FEdge->previousEdge(); // we don't change or + } }; template -class vertex_iterator_base : public IteratorBase -{ -public: - typedef typename Traits::value_type value_type; - typedef typename Traits::difference_type difference_type; - typedef typename Traits::pointer pointer; - typedef typename Traits::reference reference; - typedef vertex_iterator_base Self; - -protected: - typedef IteratorBase parent_class; - -public: - mutable value_type _SVertex; - FEdge *_NextFEdge; - FEdge *_PreviousFEdge; - -public: - friend class ViewEdge; - friend class vertex_iterator; - - inline vertex_iterator_base() : parent_class() {} - - inline vertex_iterator_base(const vertex_iterator_base >& iBrother) : parent_class() - { - _SVertex = iBrother._SVertex; - _NextFEdge = iBrother._NextFEdge; - _PreviousFEdge = iBrother._PreviousFEdge; - } - - inline vertex_iterator_base(const vertex_iterator_base >& iBrother) : parent_class() - { - _SVertex = iBrother._SVertex; - _NextFEdge = iBrother._NextFEdge; - _PreviousFEdge = iBrother._PreviousFEdge; - } - -//protected://FIXME -public: - inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge) : parent_class() - { - _SVertex = iVertex; - _NextFEdge = iNextFEdge; - _PreviousFEdge = iPreviousFEdge; - } - -public: - virtual ~vertex_iterator_base() {} - - virtual bool begin() const - { - return (_PreviousFEdge == 0) ? true : false; - } - - virtual bool end() const - { - return (_SVertex == 0) ? true : false; - } - - // operators - // operator corresponding to ++i - inline Self& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator++(int) - { - Self tmp = *this; - increment(); - return tmp; - } - - // operator corresponding to --i - inline Self& operator--() - { - decrement(); - return *this; - } - - // operator corresponding to --i, i.e. which returns the value *and then* increments it. - // That's why we store the value in a temp. - inline Self operator--(int) - { - Self tmp = *this; - decrement(); - return tmp; - } - - // comparibility - virtual bool operator!=(const Self& b) const - { - return (_SVertex != b._SVertex); - } - - virtual bool operator==(const Self& b) const - { - return !(*this != b); - } - - // dereferencing - virtual reference operator*() const - { - return (_SVertex); - } - - virtual pointer operator->() const - { - return &(operator*()); - } - -protected: - virtual void increment() - { - if (!_NextFEdge) { - _SVertex = NULL; - return; - } - _SVertex = _NextFEdge->vertexB(); - _PreviousFEdge = _NextFEdge; - _NextFEdge = _NextFEdge->nextEdge(); - } - - virtual void decrement() - { +class vertex_iterator_base : public IteratorBase { + public: + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + typedef vertex_iterator_base Self; + + protected: + typedef IteratorBase parent_class; + + public: + mutable value_type _SVertex; + FEdge *_NextFEdge; + FEdge *_PreviousFEdge; + + public: + friend class ViewEdge; + friend class vertex_iterator; + + inline vertex_iterator_base() : parent_class() + { + } + + inline vertex_iterator_base(const vertex_iterator_base> &iBrother) + : parent_class() + { + _SVertex = iBrother._SVertex; + _NextFEdge = iBrother._NextFEdge; + _PreviousFEdge = iBrother._PreviousFEdge; + } + + inline vertex_iterator_base(const vertex_iterator_base> &iBrother) + : parent_class() + { + _SVertex = iBrother._SVertex; + _NextFEdge = iBrother._NextFEdge; + _PreviousFEdge = iBrother._PreviousFEdge; + } + + //protected://FIXME + public: + inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge) + : parent_class() + { + _SVertex = iVertex; + _NextFEdge = iNextFEdge; + _PreviousFEdge = iPreviousFEdge; + } + + public: + virtual ~vertex_iterator_base() + { + } + + virtual bool begin() const + { + return (_PreviousFEdge == 0) ? true : false; + } + + virtual bool end() const + { + return (_SVertex == 0) ? true : false; + } + + // operators + // operator corresponding to ++i + inline Self &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator++(int) + { + Self tmp = *this; + increment(); + return tmp; + } + + // operator corresponding to --i + inline Self &operator--() + { + decrement(); + return *this; + } + + // operator corresponding to --i, i.e. which returns the value *and then* increments it. + // That's why we store the value in a temp. + inline Self operator--(int) + { + Self tmp = *this; + decrement(); + return tmp; + } + + // comparibility + virtual bool operator!=(const Self &b) const + { + return (_SVertex != b._SVertex); + } + + virtual bool operator==(const Self &b) const + { + return !(*this != b); + } + + // dereferencing + virtual reference operator*() const + { + return (_SVertex); + } + + virtual pointer operator->() const + { + return &(operator*()); + } + + protected: + virtual void increment() + { + if (!_NextFEdge) { + _SVertex = NULL; + return; + } + _SVertex = _NextFEdge->vertexB(); + _PreviousFEdge = _NextFEdge; + _NextFEdge = _NextFEdge->nextEdge(); + } + + virtual void decrement() + { #if 0 - if (!_SVertex) { - _SVertex = _PreviousFEdge->vertexB(); - return; - } + if (!_SVertex) { + _SVertex = _PreviousFEdge->vertexB(); + return; + } #endif - if (!_PreviousFEdge) { - _SVertex = NULL; - return; - } - _SVertex = _PreviousFEdge->vertexA(); - _NextFEdge = _PreviousFEdge; - _PreviousFEdge = _PreviousFEdge->previousEdge(); - } + if (!_PreviousFEdge) { + _SVertex = NULL; + return; + } + _SVertex = _PreviousFEdge->vertexA(); + _NextFEdge = _PreviousFEdge; + _PreviousFEdge = _PreviousFEdge->previousEdge(); + } }; -} // end of namespace ViewEdgeInternal +} // end of namespace ViewEdgeInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__ +#endif // __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp index e2bc45fc03f..ed0f5c9b0bd 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp @@ -49,347 +49,365 @@ static const Global &_global = G; using namespace std; -template -static void findOccludee(FEdge *fe, G& /*grid*/, I& occluders, real epsilon, WFace **oaWFace, - Vec3r& u, Vec3r& A, Vec3r& origin, Vec3r& edgeDir, vector& faceVertices) +template +static void findOccludee(FEdge *fe, + G & /*grid*/, + I &occluders, + real epsilon, + WFace **oaWFace, + Vec3r &u, + Vec3r &A, + Vec3r &origin, + Vec3r &edgeDir, + vector &faceVertices) { - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - WFace *oface; - bool skipFace; - - WVertex::incoming_edge_iterator ie; - - *oaWFace = NULL; - if (((fe)->getNature() & Nature::SILHOUETTE) || ((fe)->getNature() & Nature::BORDER)) { - // we cast a ray from A in the same direction but looking behind - Vec3r v(-u[0], -u[1], -u[2]); - bool noIntersection = true; - real mint = FLT_MAX; - - for (occluders.initAfterTarget(); occluders.validAfterTarget(); occluders.nextOccludee()) { + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + WFace *oface; + bool skipFace; + + WVertex::incoming_edge_iterator ie; + + *oaWFace = NULL; + if (((fe)->getNature() & Nature::SILHOUETTE) || ((fe)->getNature() & Nature::BORDER)) { + // we cast a ray from A in the same direction but looking behind + Vec3r v(-u[0], -u[1], -u[2]); + bool noIntersection = true; + real mint = FLT_MAX; + + for (occluders.initAfterTarget(); occluders.validAfterTarget(); occluders.nextOccludee()) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tEvaluating intersection for occludee " << occluders.getWFace() << " and ray " << A << - " * " << u << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tEvaluating intersection for occludee " << occluders.getWFace() << " and ray " + << A << " * " << u << endl; + } #endif - oface = occluders.getWFace(); - Polygon3r *p = occluders.getCameraSpacePolygon(); - real d = -((p->getVertices())[0] * p->getNormal()); - real t, t_u, t_v; - - if (0 != face) { - skipFace = false; - - if (face == oface) - continue; - - if (faceVertices.empty()) - continue; - - for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); - fv != fvend; - ++fv) - { - if ((*fv)->isBoundary()) - continue; - WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); - WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); - for (ie = iebegin; ie != ieend; ++ie) { - if ((*ie) == 0) - continue; - - WFace *sface = (*ie)->GetbFace(); - if (sface == oface) { - skipFace = true; - break; - } - } - if (skipFace) - break; - } - if (skipFace) - continue; - } - else { - // check whether the edge and the polygon plane are coincident: - //------------------------------------------------------------- - //first let us compute the plane equation. - if (GeomUtils::COINCIDENT == GeomUtils::intersectRayPlane(origin, edgeDir, p->getNormal(), d, t, epsilon)) - { + oface = occluders.getWFace(); + Polygon3r *p = occluders.getCameraSpacePolygon(); + real d = -((p->getVertices())[0] * p->getNormal()); + real t, t_u, t_v; + + if (0 != face) { + skipFace = false; + + if (face == oface) + continue; + + if (faceVertices.empty()) + continue; + + for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); + fv != fvend; + ++fv) { + if ((*fv)->isBoundary()) + continue; + WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); + WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); + for (ie = iebegin; ie != ieend; ++ie) { + if ((*ie) == 0) + continue; + + WFace *sface = (*ie)->GetbFace(); + if (sface == oface) { + skipFace = true; + break; + } + } + if (skipFace) + break; + } + if (skipFace) + continue; + } + else { + // check whether the edge and the polygon plane are coincident: + //------------------------------------------------------------- + //first let us compute the plane equation. + if (GeomUtils::COINCIDENT == + GeomUtils::intersectRayPlane(origin, edgeDir, p->getNormal(), d, t, epsilon)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRejecting occluder for target coincidence." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRejecting occluder for target coincidence." << endl; + } #endif - continue; - } - } + continue; + } + } - if (p->rayIntersect(A, v, t, t_u, t_v)) { + if (p->rayIntersect(A, v, t, t_u, t_v)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRay " << A << " * " << v << " intersects at time " << t << endl; - cout << "\t\t(v * normal) == " << (v * p->getNormal()) << " for normal " << p->getNormal() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRay " << A << " * " << v << " intersects at time " << t << endl; + cout << "\t\t(v * normal) == " << (v * p->getNormal()) << " for normal " + << p->getNormal() << endl; + } #endif - if (fabs(v * p->getNormal()) > 0.0001) { - if ((t > 0.0)) { // && (t<1.0)) - if (t < mint) { - *oaWFace = oface; - mint = t; - noIntersection = false; - fe->setOccludeeIntersection(Vec3r(A + t * v)); + if (fabs(v * p->getNormal()) > 0.0001) { + if ((t > 0.0)) { // && (t<1.0)) + if (t < mint) { + *oaWFace = oface; + mint = t; + noIntersection = false; + fe->setOccludeeIntersection(Vec3r(A + t * v)); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tIs occludee" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tIs occludee" << endl; + } #endif - } - } - } + } + } + } - occluders.reportDepth(A, v, t); - } - } + occluders.reportDepth(A, v, t); + } + } - if (noIntersection) - *oaWFace = NULL; - } + if (noIntersection) + *oaWFace = NULL; + } } -template -static void findOccludee(FEdge *fe, G& grid, real epsilon, ViewEdge * /*ve*/, WFace **oaFace) +template +static void findOccludee(FEdge *fe, G &grid, real epsilon, ViewEdge * /*ve*/, WFace **oaFace) { - Vec3r A; - Vec3r edgeDir; - Vec3r origin; - A = Vec3r(((fe)->vertexA()->point3D() + (fe)->vertexB()->point3D()) / 2.0); - edgeDir = Vec3r((fe)->vertexB()->point3D() - (fe)->vertexA()->point3D()); - edgeDir.normalize(); - origin = Vec3r((fe)->vertexA()->point3D()); - Vec3r u; - if (grid.orthographicProjection()) { - u = Vec3r(0.0, 0.0, grid.viewpoint().z() - A.z()); - } - else { - u = Vec3r(grid.viewpoint() - A); - } - u.normalize(); - - vector faceVertices; - - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - - if (face) { - face->RetrieveVertexList(faceVertices); - } - - I occluders(grid, A, epsilon); - findOccludee(fe, grid, occluders, epsilon, oaFace, u, A, origin, edgeDir, faceVertices); + Vec3r A; + Vec3r edgeDir; + Vec3r origin; + A = Vec3r(((fe)->vertexA()->point3D() + (fe)->vertexB()->point3D()) / 2.0); + edgeDir = Vec3r((fe)->vertexB()->point3D() - (fe)->vertexA()->point3D()); + edgeDir.normalize(); + origin = Vec3r((fe)->vertexA()->point3D()); + Vec3r u; + if (grid.orthographicProjection()) { + u = Vec3r(0.0, 0.0, grid.viewpoint().z() - A.z()); + } + else { + u = Vec3r(grid.viewpoint() - A); + } + u.normalize(); + + vector faceVertices; + + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + + if (face) { + face->RetrieveVertexList(faceVertices); + } + + I occluders(grid, A, epsilon); + findOccludee(fe, grid, occluders, epsilon, oaFace, u, A, origin, edgeDir, faceVertices); } // computeVisibility takes a pointer to foundOccluders, instead of using a reference, // so that computeVeryFastVisibility can skip the AddOccluders step with minimal overhead. -template -static int computeVisibility(ViewMap *viewMap, FEdge *fe, G& grid, real epsilon, ViewEdge * /*ve*/, WFace **oaWFace, - set *foundOccluders) +template +static int computeVisibility(ViewMap *viewMap, + FEdge *fe, + G &grid, + real epsilon, + ViewEdge * /*ve*/, + WFace **oaWFace, + set *foundOccluders) { - int qi = 0; - - Vec3r center; - Vec3r edgeDir; - Vec3r origin; - - center = fe->center3d(); - edgeDir = Vec3r(fe->vertexB()->point3D() - fe->vertexA()->point3D()); - edgeDir.normalize(); - origin = Vec3r(fe->vertexA()->point3D()); - - Vec3r vp; - if (grid.orthographicProjection()) { - vp = Vec3r(center.x(), center.y(), grid.viewpoint().z()); - } - else { - vp = Vec3r(grid.viewpoint()); - } - Vec3r u(vp - center); - real raylength = u.norm(); - u.normalize(); - - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - vector faceVertices; - WVertex::incoming_edge_iterator ie; - - WFace *oface; - bool skipFace; - - if (face) - face->RetrieveVertexList(faceVertices); - - I occluders(grid, center, epsilon); - - for (occluders.initBeforeTarget(); occluders.validBeforeTarget(); occluders.nextOccluder()) { - // If we're dealing with an exact silhouette, check whether we must take care of this occluder of not. - // (Indeed, we don't consider the occluders that share at least one vertex with the face containing this edge). - //----------- - oface = occluders.getWFace(); - Polygon3r *p = occluders.getCameraSpacePolygon(); - real t, t_u, t_v; + int qi = 0; + + Vec3r center; + Vec3r edgeDir; + Vec3r origin; + + center = fe->center3d(); + edgeDir = Vec3r(fe->vertexB()->point3D() - fe->vertexA()->point3D()); + edgeDir.normalize(); + origin = Vec3r(fe->vertexA()->point3D()); + + Vec3r vp; + if (grid.orthographicProjection()) { + vp = Vec3r(center.x(), center.y(), grid.viewpoint().z()); + } + else { + vp = Vec3r(grid.viewpoint()); + } + Vec3r u(vp - center); + real raylength = u.norm(); + u.normalize(); + + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + vector faceVertices; + WVertex::incoming_edge_iterator ie; + + WFace *oface; + bool skipFace; + + if (face) + face->RetrieveVertexList(faceVertices); + + I occluders(grid, center, epsilon); + + for (occluders.initBeforeTarget(); occluders.validBeforeTarget(); occluders.nextOccluder()) { + // If we're dealing with an exact silhouette, check whether we must take care of this occluder of not. + // (Indeed, we don't consider the occluders that share at least one vertex with the face containing this edge). + //----------- + oface = occluders.getWFace(); + Polygon3r *p = occluders.getCameraSpacePolygon(); + real t, t_u, t_v; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tEvaluating intersection for occluder " << (p->getVertices())[0] << (p->getVertices())[1] << - (p->getVertices())[2] << endl << "\t\t\tand ray " << vp << " * " << u << " (center " << center << - ")" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tEvaluating intersection for occluder " << (p->getVertices())[0] + << (p->getVertices())[1] << (p->getVertices())[2] << endl + << "\t\t\tand ray " << vp << " * " << u << " (center " << center << ")" << endl; + } #endif #if LOGGING - Vec3r v(vp - center); - real rl = v.norm(); - v.normalize(); - vector points; - // Iterate over vertices, storing projections in points - for (vector::const_iterator woe = oface->getEdgeList().begin(), woend = oface->getEdgeList().end(); - woe != woend; - woe++) - { - points.push_back(Vec3r((*woe)->GetaVertex()->GetVertex())); - } - Polygon3r p1(points, oface->GetNormal()); - Vec3r v1((p1.getVertices())[0]); - real d = -(v1 * p->getNormal()); - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tp: " << (p->getVertices())[0] << (p->getVertices())[1] << (p->getVertices())[2] << ", norm: " << - p->getNormal() << endl; - cout << "\t\tp1: " << (p1.getVertices())[0] << (p1.getVertices())[1] << (p1.getVertices())[2] << ", norm: " << - p1.getNormal() << endl; - } + Vec3r v(vp - center); + real rl = v.norm(); + v.normalize(); + vector points; + // Iterate over vertices, storing projections in points + for (vector::const_iterator woe = oface->getEdgeList().begin(), + woend = oface->getEdgeList().end(); + woe != woend; + woe++) { + points.push_back(Vec3r((*woe)->GetaVertex()->GetVertex())); + } + Polygon3r p1(points, oface->GetNormal()); + Vec3r v1((p1.getVertices())[0]); + real d = -(v1 * p->getNormal()); + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tp: " << (p->getVertices())[0] << (p->getVertices())[1] << (p->getVertices())[2] + << ", norm: " << p->getNormal() << endl; + cout << "\t\tp1: " << (p1.getVertices())[0] << (p1.getVertices())[1] << (p1.getVertices())[2] + << ", norm: " << p1.getNormal() << endl; + } #else - real d = -((p->getVertices())[0] * p->getNormal()); + real d = -((p->getVertices())[0] * p->getNormal()); #endif - if (face) { + if (face) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tDetermining face adjacency..."; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tDetermining face adjacency..."; + } #endif - skipFace = false; + skipFace = false; - if (face == oface) { + if (face == oface) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << " Rejecting occluder for face concurrency." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << " Rejecting occluder for face concurrency." << endl; + } #endif - continue; - } - - - for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); fv != fvend; ++fv) { - if ((*fv)->isBoundary()) - continue; - - WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); - WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); - for (ie = iebegin; ie != ieend; ++ie) { - if ((*ie) == 0) - continue; - - WFace *sface = (*ie)->GetbFace(); - //WFace *sfacea = (*ie)->GetaFace(); - //if ((sface == oface) || (sfacea == oface)) - if (sface == oface) { - skipFace = true; - break; - } - } - if (skipFace) - break; - } - if (skipFace) { + continue; + } + + for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); + fv != fvend; + ++fv) { + if ((*fv)->isBoundary()) + continue; + + WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); + WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); + for (ie = iebegin; ie != ieend; ++ie) { + if ((*ie) == 0) + continue; + + WFace *sface = (*ie)->GetbFace(); + //WFace *sfacea = (*ie)->GetaFace(); + //if ((sface == oface) || (sfacea == oface)) + if (sface == oface) { + skipFace = true; + break; + } + } + if (skipFace) + break; + } + if (skipFace) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << " Rejecting occluder for face adjacency." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << " Rejecting occluder for face adjacency." << endl; + } #endif - continue; - } - } - else { - // check whether the edge and the polygon plane are coincident: - //------------------------------------------------------------- - //first let us compute the plane equation. - if (GeomUtils::COINCIDENT == GeomUtils::intersectRayPlane(origin, edgeDir, p->getNormal(), d, t, epsilon)) { + continue; + } + } + else { + // check whether the edge and the polygon plane are coincident: + //------------------------------------------------------------- + //first let us compute the plane equation. + if (GeomUtils::COINCIDENT == + GeomUtils::intersectRayPlane(origin, edgeDir, p->getNormal(), d, t, epsilon)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRejecting occluder for target coincidence." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRejecting occluder for target coincidence." << endl; + } #endif - continue; - } - } + continue; + } + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - real x; - if (p1.rayIntersect(center, v, x, t_u, t_v)) { - cout << "\t\tRay should intersect at time " << (rl - x) << ". Center: " << center << ", V: " << v << - ", RL: " << rl << ", T:" << x << endl; - } - else { - cout << "\t\tRay should not intersect. Center: " << center << ", V: " << v << ", RL: " << rl << endl; - } - } + if (_global.debug & G_DEBUG_FREESTYLE) { + real x; + if (p1.rayIntersect(center, v, x, t_u, t_v)) { + cout << "\t\tRay should intersect at time " << (rl - x) << ". Center: " << center + << ", V: " << v << ", RL: " << rl << ", T:" << x << endl; + } + else { + cout << "\t\tRay should not intersect. Center: " << center << ", V: " << v + << ", RL: " << rl << endl; + } + } #endif - if (p->rayIntersect(center, u, t, t_u, t_v)) { + if (p->rayIntersect(center, u, t, t_u, t_v)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRay " << center << " * " << u << " intersects at time " << t << " (raylength is " << - raylength << ")" << endl; - cout << "\t\t(u * normal) == " << (u * p->getNormal()) << " for normal " << p->getNormal() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRay " << center << " * " << u << " intersects at time " << t + << " (raylength is " << raylength << ")" << endl; + cout << "\t\t(u * normal) == " << (u * p->getNormal()) << " for normal " << p->getNormal() + << endl; + } #endif - if (fabs(u * p->getNormal()) > 0.0001) { - if ((t > 0.0) && (t < raylength)) { + if (fabs(u * p->getNormal()) > 0.0001) { + if ((t > 0.0) && (t < raylength)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tIs occluder" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tIs occluder" << endl; + } #endif - if ( foundOccluders != NULL ) { - ViewShape *vshape = viewMap->viewShape(oface->GetVertex(0)->shape()->GetId()); - foundOccluders->insert(vshape); - } - ++qi; - - if (! grid.enableQI()) - break; - } - - occluders.reportDepth(center, u, t); - } - } - } - - // Find occludee - findOccludee(fe, grid, occluders, epsilon, oaWFace, u, center, origin, edgeDir, faceVertices); - - return qi; + if (foundOccluders != NULL) { + ViewShape *vshape = viewMap->viewShape(oface->GetVertex(0)->shape()->GetId()); + foundOccluders->insert(vshape); + } + ++qi; + + if (!grid.enableQI()) + break; + } + + occluders.reportDepth(center, u, t); + } + } + } + + // Find occludee + findOccludee( + fe, grid, occluders, epsilon, oaWFace, u, center, origin, edgeDir, faceVertices); + + return qi; } // computeCumulativeVisibility returns the lowest x such that the majority of FEdges have QI <= x @@ -400,1052 +418,1108 @@ static int computeVisibility(ViewMap *viewMap, FEdge *fe, G& grid, real epsilon, // FEdges are heavily occluded. computeCumulativeVisibility will treat this case as a QI of 22 because 3 out of // 6 occluders have QI <= 22. -template -static void computeCumulativeVisibility(ViewMap *ioViewMap, G& grid, real epsilon, RenderMonitor *iRenderMonitor) +template +static void computeCumulativeVisibility(ViewMap *ioViewMap, + G &grid, + real epsilon, + RenderMonitor *iRenderMonitor) { - vector& vedges = ioViewMap->ViewEdges(); - - FEdge *fe, *festart; - int nSamples = 0; - vector wFaces; - WFace *wFace = NULL; - unsigned cnt = 0; - unsigned cntStep = (unsigned)ceil(0.01f * vedges.size()); - unsigned tmpQI = 0; - unsigned qiClasses[256]; - unsigned maxIndex, maxCard; - unsigned qiMajority; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - if (iRenderMonitor) { - if (iRenderMonitor->testBreak()) - break; - if (cnt % cntStep == 0) { - stringstream ss; - ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%"; - iRenderMonitor->setInfo(ss.str()); - iRenderMonitor->progress((float)cnt / vedges.size()); - } - cnt++; - } + vector &vedges = ioViewMap->ViewEdges(); + + FEdge *fe, *festart; + int nSamples = 0; + vector wFaces; + WFace *wFace = NULL; + unsigned cnt = 0; + unsigned cntStep = (unsigned)ceil(0.01f * vedges.size()); + unsigned tmpQI = 0; + unsigned qiClasses[256]; + unsigned maxIndex, maxCard; + unsigned qiMajority; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + if (iRenderMonitor) { + if (iRenderMonitor->testBreak()) + break; + if (cnt % cntStep == 0) { + stringstream ss; + ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%"; + iRenderMonitor->setInfo(ss.str()); + iRenderMonitor->progress((float)cnt / vedges.size()); + } + cnt++; + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Processing ViewEdge " << (*ve)->getId() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Processing ViewEdge " << (*ve)->getId() << endl; + } #endif - // Find an edge to test - if (!(*ve)->isInImage()) { - // This view edge has been proscenium culled - (*ve)->setQI(255); - (*ve)->setaShape(0); + // Find an edge to test + if (!(*ve)->isInImage()) { + // This view edge has been proscenium culled + (*ve)->setQI(255); + (*ve)->setaShape(0); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tCulled." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tCulled." << endl; + } #endif - continue; - } - - // Test edge - festart = (*ve)->fedgeA(); - fe = (*ve)->fedgeA(); - qiMajority = 0; - do { - if (fe != NULL && fe->isInImage()) { - qiMajority++; - } - fe = fe->nextEdge(); - } while (fe && fe != festart); - - if (qiMajority == 0) { - // There are no occludable FEdges on this ViewEdge - // This should be impossible. - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; - } - // We can recover from this error: - // Treat this edge as fully visible with no occludee - (*ve)->setQI(0); - (*ve)->setaShape(0); - continue; - } - else { - ++qiMajority; - qiMajority >>= 1; - } + continue; + } + + // Test edge + festart = (*ve)->fedgeA(); + fe = (*ve)->fedgeA(); + qiMajority = 0; + do { + if (fe != NULL && fe->isInImage()) { + qiMajority++; + } + fe = fe->nextEdge(); + } while (fe && fe != festart); + + if (qiMajority == 0) { + // There are no occludable FEdges on this ViewEdge + // This should be impossible. + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; + } + // We can recover from this error: + // Treat this edge as fully visible with no occludee + (*ve)->setQI(0); + (*ve)->setaShape(0); + continue; + } + else { + ++qiMajority; + qiMajority >>= 1; + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tqiMajority: " << qiMajority << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tqiMajority: " << qiMajority << endl; + } #endif - tmpQI = 0; - maxIndex = 0; - maxCard = 0; - nSamples = 0; - memset(qiClasses, 0, 256 * sizeof(*qiClasses)); - set foundOccluders; - - fe = (*ve)->fedgeA(); - do { - if (!fe || !fe->isInImage()) { - fe = fe->nextEdge(); - continue; - } - if ((maxCard < qiMajority)) { - //ARB: change &wFace to wFace and use reference in called function - tmpQI = computeVisibility(ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); + tmpQI = 0; + maxIndex = 0; + maxCard = 0; + nSamples = 0; + memset(qiClasses, 0, 256 * sizeof(*qiClasses)); + set foundOccluders; + + fe = (*ve)->fedgeA(); + do { + if (!fe || !fe->isInImage()) { + fe = fe->nextEdge(); + continue; + } + if ((maxCard < qiMajority)) { + //ARB: change &wFace to wFace and use reference in called function + tmpQI = computeVisibility( + ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: visibility " << tmpQI << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: visibility " << tmpQI << endl; + } #endif - //ARB: This is an error condition, not an alert condition. - // Some sort of recovery or abort is necessary. - if (tmpQI >= 256) { - cerr << "Warning: too many occluding levels" << endl; - //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 - tmpQI = 255; - } - - if (++qiClasses[tmpQI] > maxCard) { - maxCard = qiClasses[tmpQI]; - maxIndex = tmpQI; - } - } - else { - //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called - //ARB: change &wFace to wFace and use reference in called function - findOccludee(fe, grid, epsilon, *ve, &wFace); + //ARB: This is an error condition, not an alert condition. + // Some sort of recovery or abort is necessary. + if (tmpQI >= 256) { + cerr << "Warning: too many occluding levels" << endl; + //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 + tmpQI = 255; + } + + if (++qiClasses[tmpQI] > maxCard) { + maxCard = qiClasses[tmpQI]; + maxIndex = tmpQI; + } + } + else { + //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called + //ARB: change &wFace to wFace and use reference in called function + findOccludee(fe, grid, epsilon, *ve, &wFace); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: occludee only (" << (wFace != NULL ? "found" : "not found") << ")" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: occludee only (" << (wFace != NULL ? "found" : "not found") << ")" + << endl; + } #endif - } - - // Store test results - if (wFace) { - vector vertices; - for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { - vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); - } - Polygon3r poly(vertices, wFace->GetNormal()); - poly.userdata = (void *)wFace; - fe->setaFace(poly); - wFaces.push_back(wFace); - fe->setOccludeeEmpty(false); + } + + // Store test results + if (wFace) { + vector vertices; + for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { + vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); + } + Polygon3r poly(vertices, wFace->GetNormal()); + poly.userdata = (void *)wFace; + fe->setaFace(poly); + wFaces.push_back(wFace); + fe->setOccludeeEmpty(false); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFound occludee" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFound occludee" << endl; + } #endif - } - else { - fe->setOccludeeEmpty(true); - } + } + else { + fe->setOccludeeEmpty(true); + } - ++nSamples; - fe = fe->nextEdge(); - } while ((maxCard < qiMajority) && (fe) && (fe != festart)); + ++nSamples; + fe = fe->nextEdge(); + } while ((maxCard < qiMajority) && (fe) && (fe != festart)); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; + } #endif - // ViewEdge - // qi -- - // Find the minimum value that is >= the majority of the QI - for (unsigned count = 0, i = 0; i < 256; ++i) { - count += qiClasses[i]; - if (count >= qiMajority) { - (*ve)->setQI(i); - break; - } - } - // occluders -- - // I would rather not have to go through the effort of creating this set and then copying out its contents. - // Is there a reason why ViewEdge::_Occluders cannot be converted to a set<>? - for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); o != oend; ++o) { - (*ve)->AddOccluder((*o)); - } + // ViewEdge + // qi -- + // Find the minimum value that is >= the majority of the QI + for (unsigned count = 0, i = 0; i < 256; ++i) { + count += qiClasses[i]; + if (count >= qiMajority) { + (*ve)->setQI(i); + break; + } + } + // occluders -- + // I would rather not have to go through the effort of creating this set and then copying out its contents. + // Is there a reason why ViewEdge::_Occluders cannot be converted to a set<>? + for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); + o != oend; + ++o) { + (*ve)->AddOccluder((*o)); + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." + << endl; + } #else - (void)maxIndex; + (void)maxIndex; #endif - // occludee -- - if (!wFaces.empty()) { - if (wFaces.size() <= (float)nSamples / 2.0f) { - (*ve)->setaShape(0); - } - else { - ViewShape *vshape = ioViewMap->viewShape((*wFaces.begin())->GetVertex(0)->shape()->GetId()); - (*ve)->setaShape(vshape); - } - } - - wFaces.clear(); - } - if (iRenderMonitor && vedges.size()) { - stringstream ss; - ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%"; - iRenderMonitor->setInfo(ss.str()); - iRenderMonitor->progress((float)cnt / vedges.size()); - } + // occludee -- + if (!wFaces.empty()) { + if (wFaces.size() <= (float)nSamples / 2.0f) { + (*ve)->setaShape(0); + } + else { + ViewShape *vshape = ioViewMap->viewShape( + (*wFaces.begin())->GetVertex(0)->shape()->GetId()); + (*ve)->setaShape(vshape); + } + } + + wFaces.clear(); + } + if (iRenderMonitor && vedges.size()) { + stringstream ss; + ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%"; + iRenderMonitor->setInfo(ss.str()); + iRenderMonitor->progress((float)cnt / vedges.size()); + } } -template -static void computeDetailedVisibility(ViewMap *ioViewMap, G& grid, real epsilon, RenderMonitor *iRenderMonitor) +template +static void computeDetailedVisibility(ViewMap *ioViewMap, + G &grid, + real epsilon, + RenderMonitor *iRenderMonitor) { - vector& vedges = ioViewMap->ViewEdges(); - - FEdge *fe, *festart; - int nSamples = 0; - vector wFaces; - WFace *wFace = NULL; - unsigned tmpQI = 0; - unsigned qiClasses[256]; - unsigned maxIndex, maxCard; - unsigned qiMajority; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - if (iRenderMonitor && iRenderMonitor->testBreak()) - break; + vector &vedges = ioViewMap->ViewEdges(); + + FEdge *fe, *festart; + int nSamples = 0; + vector wFaces; + WFace *wFace = NULL; + unsigned tmpQI = 0; + unsigned qiClasses[256]; + unsigned maxIndex, maxCard; + unsigned qiMajority; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + if (iRenderMonitor && iRenderMonitor->testBreak()) + break; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Processing ViewEdge " << (*ve)->getId() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Processing ViewEdge " << (*ve)->getId() << endl; + } #endif - // Find an edge to test - if (!(*ve)->isInImage()) { - // This view edge has been proscenium culled - (*ve)->setQI(255); - (*ve)->setaShape(0); + // Find an edge to test + if (!(*ve)->isInImage()) { + // This view edge has been proscenium culled + (*ve)->setQI(255); + (*ve)->setaShape(0); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tCulled." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tCulled." << endl; + } #endif - continue; - } - - // Test edge - festart = (*ve)->fedgeA(); - fe = (*ve)->fedgeA(); - qiMajority = 0; - do { - if (fe != NULL && fe->isInImage()) { - qiMajority++; - } - fe = fe->nextEdge(); - } while (fe && fe != festart); - - if (qiMajority == 0) { - // There are no occludable FEdges on this ViewEdge - // This should be impossible. - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; - } - // We can recover from this error: - // Treat this edge as fully visible with no occludee - (*ve)->setQI(0); - (*ve)->setaShape(0); - continue; - } - else { - ++qiMajority; - qiMajority >>= 1; - } + continue; + } + + // Test edge + festart = (*ve)->fedgeA(); + fe = (*ve)->fedgeA(); + qiMajority = 0; + do { + if (fe != NULL && fe->isInImage()) { + qiMajority++; + } + fe = fe->nextEdge(); + } while (fe && fe != festart); + + if (qiMajority == 0) { + // There are no occludable FEdges on this ViewEdge + // This should be impossible. + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; + } + // We can recover from this error: + // Treat this edge as fully visible with no occludee + (*ve)->setQI(0); + (*ve)->setaShape(0); + continue; + } + else { + ++qiMajority; + qiMajority >>= 1; + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tqiMajority: " << qiMajority << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tqiMajority: " << qiMajority << endl; + } #endif - tmpQI = 0; - maxIndex = 0; - maxCard = 0; - nSamples = 0; - memset(qiClasses, 0, 256 * sizeof(*qiClasses)); - set foundOccluders; - - fe = (*ve)->fedgeA(); - do { - if (fe == NULL || ! fe->isInImage()) { - fe = fe->nextEdge(); - continue; - } - if ((maxCard < qiMajority)) { - //ARB: change &wFace to wFace and use reference in called function - tmpQI = computeVisibility(ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); + tmpQI = 0; + maxIndex = 0; + maxCard = 0; + nSamples = 0; + memset(qiClasses, 0, 256 * sizeof(*qiClasses)); + set foundOccluders; + + fe = (*ve)->fedgeA(); + do { + if (fe == NULL || !fe->isInImage()) { + fe = fe->nextEdge(); + continue; + } + if ((maxCard < qiMajority)) { + //ARB: change &wFace to wFace and use reference in called function + tmpQI = computeVisibility( + ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: visibility " << tmpQI << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: visibility " << tmpQI << endl; + } #endif - //ARB: This is an error condition, not an alert condition. - // Some sort of recovery or abort is necessary. - if (tmpQI >= 256) { - cerr << "Warning: too many occluding levels" << endl; - //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 - tmpQI = 255; - } - - if (++qiClasses[tmpQI] > maxCard) { - maxCard = qiClasses[tmpQI]; - maxIndex = tmpQI; - } - } - else { - //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called - //ARB: change &wFace to wFace and use reference in called function - findOccludee(fe, grid, epsilon, *ve, &wFace); + //ARB: This is an error condition, not an alert condition. + // Some sort of recovery or abort is necessary. + if (tmpQI >= 256) { + cerr << "Warning: too many occluding levels" << endl; + //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 + tmpQI = 255; + } + + if (++qiClasses[tmpQI] > maxCard) { + maxCard = qiClasses[tmpQI]; + maxIndex = tmpQI; + } + } + else { + //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called + //ARB: change &wFace to wFace and use reference in called function + findOccludee(fe, grid, epsilon, *ve, &wFace); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: occludee only (" << (wFace != NULL ? "found" : "not found") << ")" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: occludee only (" << (wFace != NULL ? "found" : "not found") << ")" + << endl; + } #endif - } - - // Store test results - if (wFace) { - vector vertices; - for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { - vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); - } - Polygon3r poly(vertices, wFace->GetNormal()); - poly.userdata = (void *)wFace; - fe->setaFace(poly); - wFaces.push_back(wFace); - fe->setOccludeeEmpty(false); + } + + // Store test results + if (wFace) { + vector vertices; + for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { + vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); + } + Polygon3r poly(vertices, wFace->GetNormal()); + poly.userdata = (void *)wFace; + fe->setaFace(poly); + wFaces.push_back(wFace); + fe->setOccludeeEmpty(false); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFound occludee" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFound occludee" << endl; + } #endif - } - else { - fe->setOccludeeEmpty(true); - } + } + else { + fe->setOccludeeEmpty(true); + } - ++nSamples; - fe = fe->nextEdge(); - } while ((maxCard < qiMajority) && (fe) && (fe != festart)); + ++nSamples; + fe = fe->nextEdge(); + } while ((maxCard < qiMajority) && (fe) && (fe != festart)); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; + } #endif - // ViewEdge - // qi -- - (*ve)->setQI(maxIndex); - // occluders -- - // I would rather not have to go through the effort of creating this this set and then copying out its contents. - // Is there a reason why ViewEdge::_Occluders cannot be converted to a set<>? - for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); o != oend; ++o) { - (*ve)->AddOccluder((*o)); - } + // ViewEdge + // qi -- + (*ve)->setQI(maxIndex); + // occluders -- + // I would rather not have to go through the effort of creating this this set and then copying out its contents. + // Is there a reason why ViewEdge::_Occluders cannot be converted to a set<>? + for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); + o != oend; + ++o) { + (*ve)->AddOccluder((*o)); + } #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." + << endl; + } #endif - // occludee -- - if (!wFaces.empty()) { - if (wFaces.size() <= (float)nSamples / 2.0f) { - (*ve)->setaShape(0); - } - else { - ViewShape *vshape = ioViewMap->viewShape((*wFaces.begin())->GetVertex(0)->shape()->GetId()); - (*ve)->setaShape(vshape); - } - } - - wFaces.clear(); - } + // occludee -- + if (!wFaces.empty()) { + if (wFaces.size() <= (float)nSamples / 2.0f) { + (*ve)->setaShape(0); + } + else { + ViewShape *vshape = ioViewMap->viewShape( + (*wFaces.begin())->GetVertex(0)->shape()->GetId()); + (*ve)->setaShape(vshape); + } + } + + wFaces.clear(); + } } -template -static void computeFastVisibility(ViewMap *ioViewMap, G& grid, real epsilon) +template +static void computeFastVisibility(ViewMap *ioViewMap, G &grid, real epsilon) { - vector& vedges = ioViewMap->ViewEdges(); - - FEdge *fe, *festart; - unsigned nSamples = 0; - vector wFaces; - WFace *wFace = NULL; - unsigned tmpQI = 0; - unsigned qiClasses[256]; - unsigned maxIndex, maxCard; - unsigned qiMajority; - bool even_test; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - // Find an edge to test - if (!(*ve)->isInImage()) { - // This view edge has been proscenium culled - (*ve)->setQI(255); - (*ve)->setaShape(0); - continue; - } - - // Test edge - festart = (*ve)->fedgeA(); - fe = (*ve)->fedgeA(); - - even_test = true; - qiMajority = 0; - do { - if (even_test && fe && fe->isInImage()) { - qiMajority++; - even_test = !even_test; - } - fe = fe->nextEdge(); - } while (fe && fe != festart); - - if (qiMajority == 0 ) { - // There are no occludable FEdges on this ViewEdge - // This should be impossible. - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; - } - // We can recover from this error: - // Treat this edge as fully visible with no occludee - (*ve)->setQI(0); - (*ve)->setaShape(0); - continue; - } - else { - ++qiMajority; - qiMajority >>= 1; - } - - even_test = true; - maxIndex = 0; - maxCard = 0; - nSamples = 0; - memset(qiClasses, 0, 256 * sizeof(*qiClasses)); - set foundOccluders; - - fe = (*ve)->fedgeA(); - do { - if (!fe || !fe->isInImage()) { - fe = fe->nextEdge(); - continue; - } - if (even_test) { - if ((maxCard < qiMajority)) { - //ARB: change &wFace to wFace and use reference in called function - tmpQI = computeVisibility(ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); - - //ARB: This is an error condition, not an alert condition. - // Some sort of recovery or abort is necessary. - if (tmpQI >= 256) { - cerr << "Warning: too many occluding levels" << endl; - //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 - tmpQI = 255; - } - - if (++qiClasses[tmpQI] > maxCard) { - maxCard = qiClasses[tmpQI]; - maxIndex = tmpQI; - } - } - else { - //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called - //ARB: change &wFace to wFace and use reference in called function - findOccludee(fe, grid, epsilon, *ve, &wFace); - } - - if (wFace) { - vector vertices; - for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { - vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); - } - Polygon3r poly(vertices, wFace->GetNormal()); - poly.userdata = (void *)wFace; - fe->setaFace(poly); - wFaces.push_back(wFace); - } - ++nSamples; - } - - even_test = ! even_test; - fe = fe->nextEdge(); - } while ((maxCard < qiMajority) && (fe) && (fe != festart)); - - // qi -- - (*ve)->setQI(maxIndex); - - // occluders -- - for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); o != oend; ++o) { - (*ve)->AddOccluder((*o)); - } - - // occludee -- - if (!wFaces.empty()) { - if (wFaces.size() < nSamples / 2) { - (*ve)->setaShape(0); - } - else { - ViewShape *vshape = ioViewMap->viewShape((*wFaces.begin())->GetVertex(0)->shape()->GetId()); - (*ve)->setaShape(vshape); - } - } - - wFaces.clear(); - } + vector &vedges = ioViewMap->ViewEdges(); + + FEdge *fe, *festart; + unsigned nSamples = 0; + vector wFaces; + WFace *wFace = NULL; + unsigned tmpQI = 0; + unsigned qiClasses[256]; + unsigned maxIndex, maxCard; + unsigned qiMajority; + bool even_test; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + // Find an edge to test + if (!(*ve)->isInImage()) { + // This view edge has been proscenium culled + (*ve)->setQI(255); + (*ve)->setaShape(0); + continue; + } + + // Test edge + festart = (*ve)->fedgeA(); + fe = (*ve)->fedgeA(); + + even_test = true; + qiMajority = 0; + do { + if (even_test && fe && fe->isInImage()) { + qiMajority++; + even_test = !even_test; + } + fe = fe->nextEdge(); + } while (fe && fe != festart); + + if (qiMajority == 0) { + // There are no occludable FEdges on this ViewEdge + // This should be impossible. + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; + } + // We can recover from this error: + // Treat this edge as fully visible with no occludee + (*ve)->setQI(0); + (*ve)->setaShape(0); + continue; + } + else { + ++qiMajority; + qiMajority >>= 1; + } + + even_test = true; + maxIndex = 0; + maxCard = 0; + nSamples = 0; + memset(qiClasses, 0, 256 * sizeof(*qiClasses)); + set foundOccluders; + + fe = (*ve)->fedgeA(); + do { + if (!fe || !fe->isInImage()) { + fe = fe->nextEdge(); + continue; + } + if (even_test) { + if ((maxCard < qiMajority)) { + //ARB: change &wFace to wFace and use reference in called function + tmpQI = computeVisibility( + ioViewMap, fe, grid, epsilon, *ve, &wFace, &foundOccluders); + + //ARB: This is an error condition, not an alert condition. + // Some sort of recovery or abort is necessary. + if (tmpQI >= 256) { + cerr << "Warning: too many occluding levels" << endl; + //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 + tmpQI = 255; + } + + if (++qiClasses[tmpQI] > maxCard) { + maxCard = qiClasses[tmpQI]; + maxIndex = tmpQI; + } + } + else { + //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called + //ARB: change &wFace to wFace and use reference in called function + findOccludee(fe, grid, epsilon, *ve, &wFace); + } + + if (wFace) { + vector vertices; + for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { + vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); + } + Polygon3r poly(vertices, wFace->GetNormal()); + poly.userdata = (void *)wFace; + fe->setaFace(poly); + wFaces.push_back(wFace); + } + ++nSamples; + } + + even_test = !even_test; + fe = fe->nextEdge(); + } while ((maxCard < qiMajority) && (fe) && (fe != festart)); + + // qi -- + (*ve)->setQI(maxIndex); + + // occluders -- + for (set::iterator o = foundOccluders.begin(), oend = foundOccluders.end(); + o != oend; + ++o) { + (*ve)->AddOccluder((*o)); + } + + // occludee -- + if (!wFaces.empty()) { + if (wFaces.size() < nSamples / 2) { + (*ve)->setaShape(0); + } + else { + ViewShape *vshape = ioViewMap->viewShape( + (*wFaces.begin())->GetVertex(0)->shape()->GetId()); + (*ve)->setaShape(vshape); + } + } + + wFaces.clear(); + } } -template -static void computeVeryFastVisibility(ViewMap *ioViewMap, G& grid, real epsilon) +template +static void computeVeryFastVisibility(ViewMap *ioViewMap, G &grid, real epsilon) { - vector& vedges = ioViewMap->ViewEdges(); - - FEdge *fe; - unsigned qi = 0; - WFace *wFace = 0; - - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - // Find an edge to test - if (!(*ve)->isInImage()) { - // This view edge has been proscenium culled - (*ve)->setQI(255); - (*ve)->setaShape(0); - continue; - } - fe = (*ve)->fedgeA(); - // Find a FEdge inside the occluder proscenium to test for visibility - FEdge *festart = fe; - while (fe && !fe->isInImage() && fe != festart) { - fe = fe->nextEdge(); - } - - // Test edge - if (!fe || !fe->isInImage()) { - // There are no occludable FEdges on this ViewEdge - // This should be impossible. - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; - } - // We can recover from this error: - // Treat this edge as fully visible with no occludee - qi = 0; - wFace = NULL; - } - else { - qi = computeVisibility(ioViewMap, fe, grid, epsilon, *ve, &wFace, NULL); - } - - // Store test results - if (wFace) { - vector vertices; - for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { - vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); - } - Polygon3r poly(vertices, wFace->GetNormal()); - poly.userdata = (void *)wFace; - fe->setaFace(poly); // This works because setaFace *copies* the polygon - ViewShape *vshape = ioViewMap->viewShape(wFace->GetVertex(0)->shape()->GetId()); - (*ve)->setaShape(vshape); - } - else { - (*ve)->setaShape(0); - } - (*ve)->setQI(qi); - } + vector &vedges = ioViewMap->ViewEdges(); + + FEdge *fe; + unsigned qi = 0; + WFace *wFace = 0; + + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + // Find an edge to test + if (!(*ve)->isInImage()) { + // This view edge has been proscenium culled + (*ve)->setQI(255); + (*ve)->setaShape(0); + continue; + } + fe = (*ve)->fedgeA(); + // Find a FEdge inside the occluder proscenium to test for visibility + FEdge *festart = fe; + while (fe && !fe->isInImage() && fe != festart) { + fe = fe->nextEdge(); + } + + // Test edge + if (!fe || !fe->isInImage()) { + // There are no occludable FEdges on this ViewEdge + // This should be impossible. + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "View Edge in viewport without occludable FEdges: " << (*ve)->getId() << endl; + } + // We can recover from this error: + // Treat this edge as fully visible with no occludee + qi = 0; + wFace = NULL; + } + else { + qi = computeVisibility(ioViewMap, fe, grid, epsilon, *ve, &wFace, NULL); + } + + // Store test results + if (wFace) { + vector vertices; + for (int i = 0, numEdges = wFace->numberOfEdges(); i < numEdges; ++i) { + vertices.push_back(Vec3r(wFace->GetVertex(i)->GetVertex())); + } + Polygon3r poly(vertices, wFace->GetNormal()); + poly.userdata = (void *)wFace; + fe->setaFace(poly); // This works because setaFace *copies* the polygon + ViewShape *vshape = ioViewMap->viewShape(wFace->GetVertex(0)->shape()->GetId()); + (*ve)->setaShape(vshape); + } + else { + (*ve)->setaShape(0); + } + (*ve)->setQI(qi); + } } -void ViewMapBuilder::BuildGrid(WingedEdge& we, const BBox& bbox, unsigned int sceneNumFaces) +void ViewMapBuilder::BuildGrid(WingedEdge &we, const BBox &bbox, unsigned int sceneNumFaces) { - _Grid->clear(); - Vec3r size; - for (unsigned int i = 0; i < 3; i++) { - size[i] = fabs(bbox.getMax()[i] - bbox.getMin()[i]); - // let make the grid 1/10 bigger to avoid numerical errors while computing triangles/cells intersections. - size[i] += size[i] / 10.0; - if (size[i] == 0) { - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Warning: the bbox size is 0 in dimension " << i << endl; - } - } - } - _Grid->configure(Vec3r(bbox.getMin() - size / 20.0), size, sceneNumFaces); - - // Fill in the grid: - WFillGrid fillGridRenderer(_Grid, &we); - fillGridRenderer.fillGrid(); - - // DEBUG - _Grid->displayDebug(); + _Grid->clear(); + Vec3r size; + for (unsigned int i = 0; i < 3; i++) { + size[i] = fabs(bbox.getMax()[i] - bbox.getMin()[i]); + // let make the grid 1/10 bigger to avoid numerical errors while computing triangles/cells intersections. + size[i] += size[i] / 10.0; + if (size[i] == 0) { + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Warning: the bbox size is 0 in dimension " << i << endl; + } + } + } + _Grid->configure(Vec3r(bbox.getMin() - size / 20.0), size, sceneNumFaces); + + // Fill in the grid: + WFillGrid fillGridRenderer(_Grid, &we); + fillGridRenderer.fillGrid(); + + // DEBUG + _Grid->displayDebug(); } -ViewMap *ViewMapBuilder::BuildViewMap(WingedEdge& we, visibility_algo iAlgo, real epsilon, - const BBox& bbox, unsigned int sceneNumFaces) +ViewMap *ViewMapBuilder::BuildViewMap(WingedEdge &we, + visibility_algo iAlgo, + real epsilon, + const BBox &bbox, + unsigned int sceneNumFaces) { - _ViewMap = new ViewMap; - _currentId = 1; - _currentFId = 0; - _currentSVertexId = 0; + _ViewMap = new ViewMap; + _currentId = 1; + _currentFId = 0; + _currentSVertexId = 0; - // Builds initial view edges - computeInitialViewEdges(we); + // Builds initial view edges + computeInitialViewEdges(we); - // Detects cusps - computeCusps(_ViewMap); + // Detects cusps + computeCusps(_ViewMap); - // Compute intersections - ComputeIntersections(_ViewMap, sweep_line, epsilon); + // Compute intersections + ComputeIntersections(_ViewMap, sweep_line, epsilon); - // Compute visibility - ComputeEdgesVisibility(_ViewMap, we, bbox, sceneNumFaces, iAlgo, epsilon); + // Compute visibility + ComputeEdgesVisibility(_ViewMap, we, bbox, sceneNumFaces, iAlgo, epsilon); - return _ViewMap; + return _ViewMap; } -static inline real distance2D(const Vec3r & point, const real origin[2]) +static inline real distance2D(const Vec3r &point, const real origin[2]) { - return ::hypot((point[0] - origin[0]), (point[1] - origin[1])); + return ::hypot((point[0] - origin[0]), (point[1] - origin[1])); } static inline bool crossesProscenium(real proscenium[4], FEdge *fe) { - Vec2r min(proscenium[0], proscenium[2]); - Vec2r max(proscenium[1], proscenium[3]); - Vec2r A(fe->vertexA()->getProjectedX(), fe->vertexA()->getProjectedY()); - Vec2r B(fe->vertexB()->getProjectedX(), fe->vertexB()->getProjectedY()); + Vec2r min(proscenium[0], proscenium[2]); + Vec2r max(proscenium[1], proscenium[3]); + Vec2r A(fe->vertexA()->getProjectedX(), fe->vertexA()->getProjectedY()); + Vec2r B(fe->vertexB()->getProjectedX(), fe->vertexB()->getProjectedY()); - return GeomUtils::intersect2dSeg2dArea (min, max, A, B); + return GeomUtils::intersect2dSeg2dArea(min, max, A, B); } -static inline bool insideProscenium(real proscenium[4], const Vec3r& point) +static inline bool insideProscenium(real proscenium[4], const Vec3r &point) { - return !(point[0] < proscenium[0] || point[0] > proscenium[1] || - point[1] < proscenium[2] || point[1] > proscenium[3]); + return !(point[0] < proscenium[0] || point[0] > proscenium[1] || point[1] < proscenium[2] || + point[1] > proscenium[3]); } -void ViewMapBuilder::CullViewEdges(ViewMap *ioViewMap, real viewProscenium[4], real occluderProscenium[4], +void ViewMapBuilder::CullViewEdges(ViewMap *ioViewMap, + real viewProscenium[4], + real occluderProscenium[4], bool extensiveFEdgeSearch) { - // Cull view edges by marking them as non-displayable. - // This avoids the complications of trying to delete edges from the ViewMap. - - // Non-displayable view edges will be skipped over during visibility calculation. - - // View edges will be culled according to their position w.r.t. the viewport proscenium (viewport + 5% border, - // or some such). - - // Get proscenium boundary for culling - GridHelpers::getDefaultViewProscenium(viewProscenium); - real prosceniumOrigin[2]; - prosceniumOrigin[0] = (viewProscenium[1] - viewProscenium[0]) / 2.0; - prosceniumOrigin[1] = (viewProscenium[3] - viewProscenium[2]) / 2.0; - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Proscenium culling:" << endl; - cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " << viewProscenium[2] << - ", " << viewProscenium[3] << "]"<< endl; - cout << "Origin: [" << prosceniumOrigin[0] << ", " << prosceniumOrigin[1] << "]"<< endl; - } - - // A separate occluder proscenium will also be maintained, starting out the same as the viewport proscenium, and - // expanding as necessary so that it encompasses the center point of at least one feature edge in each retained view - // edge. - // The occluder proscenium will be used later to cull occluding triangles before they are inserted into the Grid. - // The occluder proscenium starts out the same size as the view proscenium - GridHelpers::getDefaultViewProscenium(occluderProscenium); - - // N.B. Freestyle is inconsistent in its use of ViewMap::viewedges_container and vector::iterator. - // Probably all occurences of vector::iterator should be replaced ViewMap::viewedges_container - // throughout the code. - // For each view edge - ViewMap::viewedges_container::iterator ve, veend; - - for (ve = ioViewMap->ViewEdges().begin(), veend = ioViewMap->ViewEdges().end(); ve != veend; ve++) { - // Overview: - // Search for a visible feature edge - // If none: mark view edge as non-displayable - // Otherwise: - // Find a feature edge with center point inside occluder proscenium. - // If none exists, find the feature edge with center point closest to viewport origin. - // Expand occluder proscenium to enclose center point. - - // For each feature edge, while bestOccluderTarget not found and view edge not visibile - bool bestOccluderTargetFound = false; - FEdge *bestOccluderTarget = NULL; - real bestOccluderDistance = 0.0; - FEdge *festart = (*ve)->fedgeA(); - FEdge *fe = festart; - // All ViewEdges start culled - (*ve)->setIsInImage(false); - - // For simple visibility calculation: mark a feature edge that is known to have a center point inside the - // occluder proscenium. Cull all other feature edges. - do { - // All FEdges start culled - fe->setIsInImage(false); - - // Look for the visible edge that can most easily be included in the occluder proscenium. - if (!bestOccluderTargetFound) { - // If center point is inside occluder proscenium, - if (insideProscenium(occluderProscenium, fe->center2d())) { - // Use this feature edge for visibility deterimination - fe->setIsInImage(true); - // Mark bestOccluderTarget as found - bestOccluderTargetFound = true; - bestOccluderTarget = fe; - } - else { - real d = distance2D(fe->center2d(), prosceniumOrigin); - // If center point is closer to viewport origin than current target - if (bestOccluderTarget == NULL || d < bestOccluderDistance) { - // Then store as bestOccluderTarget - bestOccluderDistance = d; - bestOccluderTarget = fe; - } - } - } - - // If feature edge crosses the view proscenium - if (!(*ve)->isInImage() && crossesProscenium(viewProscenium, fe)) { - // Then the view edge will be included in the image - (*ve)->setIsInImage(true); - } - fe = fe->nextEdge(); - } while (fe && fe != festart && !(bestOccluderTargetFound && (*ve)->isInImage())); - - // Either we have run out of FEdges, or we already have the one edge we need to determine visibility - // Cull all remaining edges. - while (fe && fe != festart) { - fe->setIsInImage(false); - fe = fe->nextEdge(); - } - - // If bestOccluderTarget was not found inside the occluder proscenium, we need to expand the occluder - // proscenium to include it. - if ((*ve)->isInImage() && bestOccluderTarget != NULL && !bestOccluderTargetFound) { - // Expand occluder proscenium to enclose bestOccluderTarget - Vec3r point = bestOccluderTarget->center2d(); - if (point[0] < occluderProscenium[0]) { - occluderProscenium[0] = point[0]; - } - else if (point[0] > occluderProscenium[1]) { - occluderProscenium[1] = point[0]; - } - if (point[1] < occluderProscenium[2]) { - occluderProscenium[2] = point[1]; - } - else if (point[1] > occluderProscenium[3]) { - occluderProscenium[3] = point[1]; - } - // Use bestOccluderTarget for visibility determination - bestOccluderTarget->setIsInImage(true); - } - } - - // We are done calculating the occluder proscenium. - // Expand the occluder proscenium by an epsilon to avoid rounding errors. - const real epsilon = 1.0e-6; - occluderProscenium[0] -= epsilon; - occluderProscenium[1] += epsilon; - occluderProscenium[2] -= epsilon; - occluderProscenium[3] += epsilon; - - // For "Normal" or "Fast" style visibility computation only: - - // For more detailed visibility calculation, make a second pass through the view map, marking all feature edges - // with center points inside the final occluder proscenium. All of these feature edges can be considered during - // visibility calculation. - - // So far we have only found one FEdge per ViewEdge. The "Normal" and "Fast" styles of visibility computation - // want to consider many FEdges for each ViewEdge. - // Here we re-scan the view map to find any usable FEdges that we skipped on the first pass, or that have become - // usable because the occluder proscenium has been expanded since the edge was visited on the first pass. - if (extensiveFEdgeSearch) { - // For each view edge, - for (ve = ioViewMap->ViewEdges().begin(), veend = ioViewMap->ViewEdges().end(); ve != veend; ve++) { - if (!(*ve)->isInImage()) { - continue; - } - // For each feature edge, - FEdge *festart = (*ve)->fedgeA(); - FEdge *fe = festart; - do { - // If not (already) visible and center point inside occluder proscenium, - if (!fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d())) { - // Use the feature edge for visibility determination - fe->setIsInImage(true); - } - fe = fe->nextEdge(); - } while (fe && fe != festart); - } - } + // Cull view edges by marking them as non-displayable. + // This avoids the complications of trying to delete edges from the ViewMap. + + // Non-displayable view edges will be skipped over during visibility calculation. + + // View edges will be culled according to their position w.r.t. the viewport proscenium (viewport + 5% border, + // or some such). + + // Get proscenium boundary for culling + GridHelpers::getDefaultViewProscenium(viewProscenium); + real prosceniumOrigin[2]; + prosceniumOrigin[0] = (viewProscenium[1] - viewProscenium[0]) / 2.0; + prosceniumOrigin[1] = (viewProscenium[3] - viewProscenium[2]) / 2.0; + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Proscenium culling:" << endl; + cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " + << viewProscenium[2] << ", " << viewProscenium[3] << "]" << endl; + cout << "Origin: [" << prosceniumOrigin[0] << ", " << prosceniumOrigin[1] << "]" << endl; + } + + // A separate occluder proscenium will also be maintained, starting out the same as the viewport proscenium, and + // expanding as necessary so that it encompasses the center point of at least one feature edge in each retained view + // edge. + // The occluder proscenium will be used later to cull occluding triangles before they are inserted into the Grid. + // The occluder proscenium starts out the same size as the view proscenium + GridHelpers::getDefaultViewProscenium(occluderProscenium); + + // N.B. Freestyle is inconsistent in its use of ViewMap::viewedges_container and vector::iterator. + // Probably all occurences of vector::iterator should be replaced ViewMap::viewedges_container + // throughout the code. + // For each view edge + ViewMap::viewedges_container::iterator ve, veend; + + for (ve = ioViewMap->ViewEdges().begin(), veend = ioViewMap->ViewEdges().end(); ve != veend; + ve++) { + // Overview: + // Search for a visible feature edge + // If none: mark view edge as non-displayable + // Otherwise: + // Find a feature edge with center point inside occluder proscenium. + // If none exists, find the feature edge with center point closest to viewport origin. + // Expand occluder proscenium to enclose center point. + + // For each feature edge, while bestOccluderTarget not found and view edge not visibile + bool bestOccluderTargetFound = false; + FEdge *bestOccluderTarget = NULL; + real bestOccluderDistance = 0.0; + FEdge *festart = (*ve)->fedgeA(); + FEdge *fe = festart; + // All ViewEdges start culled + (*ve)->setIsInImage(false); + + // For simple visibility calculation: mark a feature edge that is known to have a center point inside the + // occluder proscenium. Cull all other feature edges. + do { + // All FEdges start culled + fe->setIsInImage(false); + + // Look for the visible edge that can most easily be included in the occluder proscenium. + if (!bestOccluderTargetFound) { + // If center point is inside occluder proscenium, + if (insideProscenium(occluderProscenium, fe->center2d())) { + // Use this feature edge for visibility deterimination + fe->setIsInImage(true); + // Mark bestOccluderTarget as found + bestOccluderTargetFound = true; + bestOccluderTarget = fe; + } + else { + real d = distance2D(fe->center2d(), prosceniumOrigin); + // If center point is closer to viewport origin than current target + if (bestOccluderTarget == NULL || d < bestOccluderDistance) { + // Then store as bestOccluderTarget + bestOccluderDistance = d; + bestOccluderTarget = fe; + } + } + } + + // If feature edge crosses the view proscenium + if (!(*ve)->isInImage() && crossesProscenium(viewProscenium, fe)) { + // Then the view edge will be included in the image + (*ve)->setIsInImage(true); + } + fe = fe->nextEdge(); + } while (fe && fe != festart && !(bestOccluderTargetFound && (*ve)->isInImage())); + + // Either we have run out of FEdges, or we already have the one edge we need to determine visibility + // Cull all remaining edges. + while (fe && fe != festart) { + fe->setIsInImage(false); + fe = fe->nextEdge(); + } + + // If bestOccluderTarget was not found inside the occluder proscenium, we need to expand the occluder + // proscenium to include it. + if ((*ve)->isInImage() && bestOccluderTarget != NULL && !bestOccluderTargetFound) { + // Expand occluder proscenium to enclose bestOccluderTarget + Vec3r point = bestOccluderTarget->center2d(); + if (point[0] < occluderProscenium[0]) { + occluderProscenium[0] = point[0]; + } + else if (point[0] > occluderProscenium[1]) { + occluderProscenium[1] = point[0]; + } + if (point[1] < occluderProscenium[2]) { + occluderProscenium[2] = point[1]; + } + else if (point[1] > occluderProscenium[3]) { + occluderProscenium[3] = point[1]; + } + // Use bestOccluderTarget for visibility determination + bestOccluderTarget->setIsInImage(true); + } + } + + // We are done calculating the occluder proscenium. + // Expand the occluder proscenium by an epsilon to avoid rounding errors. + const real epsilon = 1.0e-6; + occluderProscenium[0] -= epsilon; + occluderProscenium[1] += epsilon; + occluderProscenium[2] -= epsilon; + occluderProscenium[3] += epsilon; + + // For "Normal" or "Fast" style visibility computation only: + + // For more detailed visibility calculation, make a second pass through the view map, marking all feature edges + // with center points inside the final occluder proscenium. All of these feature edges can be considered during + // visibility calculation. + + // So far we have only found one FEdge per ViewEdge. The "Normal" and "Fast" styles of visibility computation + // want to consider many FEdges for each ViewEdge. + // Here we re-scan the view map to find any usable FEdges that we skipped on the first pass, or that have become + // usable because the occluder proscenium has been expanded since the edge was visited on the first pass. + if (extensiveFEdgeSearch) { + // For each view edge, + for (ve = ioViewMap->ViewEdges().begin(), veend = ioViewMap->ViewEdges().end(); ve != veend; + ve++) { + if (!(*ve)->isInImage()) { + continue; + } + // For each feature edge, + FEdge *festart = (*ve)->fedgeA(); + FEdge *fe = festart; + do { + // If not (already) visible and center point inside occluder proscenium, + if (!fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d())) { + // Use the feature edge for visibility determination + fe->setIsInImage(true); + } + fe = fe->nextEdge(); + } while (fe && fe != festart); + } + } } -void ViewMapBuilder::computeInitialViewEdges(WingedEdge& we) +void ViewMapBuilder::computeInitialViewEdges(WingedEdge &we) { - vector wshapes = we.getWShapes(); - SShape *psShape; - - for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); it++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - - // create the embedding - psShape = new SShape; - psShape->setId((*it)->GetId()); - psShape->setName((*it)->getName()); - psShape->setLibraryPath((*it)->getLibraryPath()); - psShape->setFrsMaterials((*it)->frs_materials()); // FIXME - - // create the view shape - ViewShape *vshape = new ViewShape(psShape); - // add this view shape to the view map: - _ViewMap->AddViewShape(vshape); - - // we want to number the view edges in a unique way for the while scene. - _pViewEdgeBuilder->setCurrentViewId(_currentId); - // we want to number the feature edges in a unique way for the while scene. - _pViewEdgeBuilder->setCurrentFId(_currentFId); - // we want to number the SVertex in a unique way for the while scene. - _pViewEdgeBuilder->setCurrentSVertexId(_currentFId); - _pViewEdgeBuilder->BuildViewEdges(dynamic_cast(*it), vshape, _ViewMap->ViewEdges(), - _ViewMap->ViewVertices(), _ViewMap->FEdges(), _ViewMap->SVertices()); - - _currentId = _pViewEdgeBuilder->currentViewId() + 1; - _currentFId = _pViewEdgeBuilder->currentFId() + 1; - _currentSVertexId = _pViewEdgeBuilder->currentSVertexId() + 1; - - psShape->ComputeBBox(); - } + vector wshapes = we.getWShapes(); + SShape *psShape; + + for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); it++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + + // create the embedding + psShape = new SShape; + psShape->setId((*it)->GetId()); + psShape->setName((*it)->getName()); + psShape->setLibraryPath((*it)->getLibraryPath()); + psShape->setFrsMaterials((*it)->frs_materials()); // FIXME + + // create the view shape + ViewShape *vshape = new ViewShape(psShape); + // add this view shape to the view map: + _ViewMap->AddViewShape(vshape); + + // we want to number the view edges in a unique way for the while scene. + _pViewEdgeBuilder->setCurrentViewId(_currentId); + // we want to number the feature edges in a unique way for the while scene. + _pViewEdgeBuilder->setCurrentFId(_currentFId); + // we want to number the SVertex in a unique way for the while scene. + _pViewEdgeBuilder->setCurrentSVertexId(_currentFId); + _pViewEdgeBuilder->BuildViewEdges(dynamic_cast(*it), + vshape, + _ViewMap->ViewEdges(), + _ViewMap->ViewVertices(), + _ViewMap->FEdges(), + _ViewMap->SVertices()); + + _currentId = _pViewEdgeBuilder->currentViewId() + 1; + _currentFId = _pViewEdgeBuilder->currentFId() + 1; + _currentSVertexId = _pViewEdgeBuilder->currentSVertexId() + 1; + + psShape->ComputeBBox(); + } } void ViewMapBuilder::computeCusps(ViewMap *ioViewMap) { - vector newVVertices; - vector newVEdges; - ViewMap::viewedges_container& vedges = ioViewMap->ViewEdges(); - ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); - for (; ve != veend; ++ve) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - if ((!((*ve)->getNature() & Nature::SILHOUETTE)) || (!((*ve)->fedgeA()->isSmooth()))) - continue; - FEdge *fe = (*ve)->fedgeA(); - FEdge *fefirst = fe; - bool first = true; - bool positive = true; - do { - FEdgeSmooth *fes = dynamic_cast(fe); - Vec3r A((fes)->vertexA()->point3d()); - Vec3r B((fes)->vertexB()->point3d()); - Vec3r AB(B - A); - AB.normalize(); - Vec3r m((A + B) / 2.0); - Vec3r crossP(AB ^ (fes)->normal()); - crossP.normalize(); - Vec3r viewvector; - if (_orthographicProjection) { - viewvector = Vec3r(0.0, 0.0, m.z() - _viewpoint.z()); - } - else { - viewvector = Vec3r(m - _viewpoint); - } - viewvector.normalize(); - if (first) { - if (((crossP) * (viewvector)) > 0) - positive = true; - else - positive = false; - first = false; - } - // If we're in a positive part, we need a stronger negative value to change - NonTVertex *cusp = NULL; - if (positive) { - if (((crossP) * (viewvector)) < -0.1) { - // state changes - positive = false; - // creates and insert cusp - cusp = dynamic_cast(ioViewMap->InsertViewVertex(fes->vertexA(), newVEdges)); - if (cusp) - cusp->setNature(cusp->getNature() | Nature::CUSP); - } - } - else { - // If we're in a negative part, we need a stronger negative value to change - if (((crossP) * (viewvector)) > 0.1) { - positive = true; - cusp = dynamic_cast(ioViewMap->InsertViewVertex(fes->vertexA(), newVEdges)); - if (cusp) - cusp->setNature(cusp->getNature() | Nature::CUSP); - } - } - fe = fe->nextEdge(); - } while (fe && fe != fefirst); - } - for (ve = newVEdges.begin(), veend = newVEdges.end(); ve != veend; ++ve) { - (*ve)->viewShape()->AddEdge(*ve); - vedges.push_back(*ve); - } + vector newVVertices; + vector newVEdges; + ViewMap::viewedges_container &vedges = ioViewMap->ViewEdges(); + ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); + for (; ve != veend; ++ve) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + if ((!((*ve)->getNature() & Nature::SILHOUETTE)) || (!((*ve)->fedgeA()->isSmooth()))) + continue; + FEdge *fe = (*ve)->fedgeA(); + FEdge *fefirst = fe; + bool first = true; + bool positive = true; + do { + FEdgeSmooth *fes = dynamic_cast(fe); + Vec3r A((fes)->vertexA()->point3d()); + Vec3r B((fes)->vertexB()->point3d()); + Vec3r AB(B - A); + AB.normalize(); + Vec3r m((A + B) / 2.0); + Vec3r crossP(AB ^ (fes)->normal()); + crossP.normalize(); + Vec3r viewvector; + if (_orthographicProjection) { + viewvector = Vec3r(0.0, 0.0, m.z() - _viewpoint.z()); + } + else { + viewvector = Vec3r(m - _viewpoint); + } + viewvector.normalize(); + if (first) { + if (((crossP) * (viewvector)) > 0) + positive = true; + else + positive = false; + first = false; + } + // If we're in a positive part, we need a stronger negative value to change + NonTVertex *cusp = NULL; + if (positive) { + if (((crossP) * (viewvector)) < -0.1) { + // state changes + positive = false; + // creates and insert cusp + cusp = dynamic_cast( + ioViewMap->InsertViewVertex(fes->vertexA(), newVEdges)); + if (cusp) + cusp->setNature(cusp->getNature() | Nature::CUSP); + } + } + else { + // If we're in a negative part, we need a stronger negative value to change + if (((crossP) * (viewvector)) > 0.1) { + positive = true; + cusp = dynamic_cast( + ioViewMap->InsertViewVertex(fes->vertexA(), newVEdges)); + if (cusp) + cusp->setNature(cusp->getNature() | Nature::CUSP); + } + } + fe = fe->nextEdge(); + } while (fe && fe != fefirst); + } + for (ve = newVEdges.begin(), veend = newVEdges.end(); ve != veend; ++ve) { + (*ve)->viewShape()->AddEdge(*ve); + vedges.push_back(*ve); + } } -void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, - real epsilon, bool cull, GridDensityProviderFactory& factory) +void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + real epsilon, + bool cull, + GridDensityProviderFactory &factory) { - AutoPtr transform; - AutoPtr source; - - if (_orthographicProjection) { - transform.reset(new BoxGrid::Transform); - } - else { - transform.reset(new SphericalGrid::Transform); - } - - if (cull) { - source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); - } - else { - source.reset(new OccluderSource(*transform, we)); - } - - AutoPtr density(factory.newGridDensityProvider(*source, bbox, *transform)); - - if (_orthographicProjection) { - BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); - computeCumulativeVisibility(ioViewMap, grid, epsilon, _pRenderMonitor); - } - else { - SphericalGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); - computeCumulativeVisibility(ioViewMap, grid, epsilon, _pRenderMonitor); - } + AutoPtr transform; + AutoPtr source; + + if (_orthographicProjection) { + transform.reset(new BoxGrid::Transform); + } + else { + transform.reset(new SphericalGrid::Transform); + } + + if (cull) { + source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); + } + else { + source.reset(new OccluderSource(*transform, we)); + } + + AutoPtr density(factory.newGridDensityProvider(*source, bbox, *transform)); + + if (_orthographicProjection) { + BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); + computeCumulativeVisibility( + ioViewMap, grid, epsilon, _pRenderMonitor); + } + else { + SphericalGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); + computeCumulativeVisibility( + ioViewMap, grid, epsilon, _pRenderMonitor); + } } -void ViewMapBuilder::ComputeDetailedVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, - real epsilon, bool cull, GridDensityProviderFactory& factory) +void ViewMapBuilder::ComputeDetailedVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + real epsilon, + bool cull, + GridDensityProviderFactory &factory) { - AutoPtr transform; - AutoPtr source; - - if (_orthographicProjection) { - transform.reset(new BoxGrid::Transform); - } - else { - transform.reset(new SphericalGrid::Transform); - } - - if (cull) { - source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); - } - else { - source.reset(new OccluderSource(*transform, we)); - } - - AutoPtr density(factory.newGridDensityProvider(*source, bbox, *transform)); - - if (_orthographicProjection) { - BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); - computeDetailedVisibility(ioViewMap, grid, epsilon, _pRenderMonitor); - } - else { - SphericalGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); - computeDetailedVisibility(ioViewMap, grid, epsilon, _pRenderMonitor); - } + AutoPtr transform; + AutoPtr source; + + if (_orthographicProjection) { + transform.reset(new BoxGrid::Transform); + } + else { + transform.reset(new SphericalGrid::Transform); + } + + if (cull) { + source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); + } + else { + source.reset(new OccluderSource(*transform, we)); + } + + AutoPtr density(factory.newGridDensityProvider(*source, bbox, *transform)); + + if (_orthographicProjection) { + BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); + computeDetailedVisibility( + ioViewMap, grid, epsilon, _pRenderMonitor); + } + else { + SphericalGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); + computeDetailedVisibility( + ioViewMap, grid, epsilon, _pRenderMonitor); + } } -void ViewMapBuilder::ComputeEdgesVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, - unsigned int sceneNumFaces, visibility_algo iAlgo, real epsilon) +void ViewMapBuilder::ComputeEdgesVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + unsigned int sceneNumFaces, + visibility_algo iAlgo, + real epsilon) { #if 0 - iAlgo = ray_casting; // for testing algorithms equivalence + iAlgo = ray_casting; // for testing algorithms equivalence #endif - switch (iAlgo) { - case ray_casting: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using ordinary ray casting" << endl; - } - BuildGrid(we, bbox, sceneNumFaces); - ComputeRayCastingVisibility(ioViewMap, epsilon); - break; - case ray_casting_fast: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using fast ray casting" << endl; - } - BuildGrid(we, bbox, sceneNumFaces); - ComputeFastRayCastingVisibility(ioViewMap, epsilon); - break; - case ray_casting_very_fast: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using very fast ray casting" << endl; - } - BuildGrid(we, bbox, sceneNumFaces); - ComputeVeryFastRayCastingVisibility(ioViewMap, epsilon); - break; - case ray_casting_culled_adaptive_traditional: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using culled adaptive grid with heuristic density and traditional QI calculation" << endl; - } - try { - HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); - ComputeDetailedVisibility(ioViewMap, we, bbox, epsilon, true, factory); - } - catch (...) { - // Last resort catch to make sure RAII semantics hold for OptimizedGrid. Can be replaced with - // try...catch block around main() if the program as a whole is converted to RAII - - // This is the little-mentioned caveat of RAII: RAII does not work unless destructors are always - // called, but destructors are only called if all exceptions are caught (or std::terminate() is - // replaced). - - // We don't actually handle the exception here, so re-throw it now that our destructors have had a - // chance to run. - throw; - } - break; - case ray_casting_adaptive_traditional: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using unculled adaptive grid with heuristic density and traditional QI calculation" << endl; - } - try { - HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); - ComputeDetailedVisibility(ioViewMap, we, bbox, epsilon, false, factory); - } - catch (...) { - throw; - } - break; - case ray_casting_culled_adaptive_cumulative: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using culled adaptive grid with heuristic density and cumulative QI calculation" << endl; - } - try { - HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); - ComputeCumulativeVisibility(ioViewMap, we, bbox, epsilon, true, factory); - } - catch (...) { - throw; - } - break; - case ray_casting_adaptive_cumulative: - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Using unculled adaptive grid with heuristic density and cumulative QI calculation" << endl; - } - try { - HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); - ComputeCumulativeVisibility(ioViewMap, we, bbox, epsilon, false, factory); - } - catch (...) { - throw; - } - break; - default: - break; - } + switch (iAlgo) { + case ray_casting: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using ordinary ray casting" << endl; + } + BuildGrid(we, bbox, sceneNumFaces); + ComputeRayCastingVisibility(ioViewMap, epsilon); + break; + case ray_casting_fast: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using fast ray casting" << endl; + } + BuildGrid(we, bbox, sceneNumFaces); + ComputeFastRayCastingVisibility(ioViewMap, epsilon); + break; + case ray_casting_very_fast: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using very fast ray casting" << endl; + } + BuildGrid(we, bbox, sceneNumFaces); + ComputeVeryFastRayCastingVisibility(ioViewMap, epsilon); + break; + case ray_casting_culled_adaptive_traditional: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using culled adaptive grid with heuristic density and traditional QI calculation" + << endl; + } + try { + HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); + ComputeDetailedVisibility(ioViewMap, we, bbox, epsilon, true, factory); + } + catch (...) { + // Last resort catch to make sure RAII semantics hold for OptimizedGrid. Can be replaced with + // try...catch block around main() if the program as a whole is converted to RAII + + // This is the little-mentioned caveat of RAII: RAII does not work unless destructors are always + // called, but destructors are only called if all exceptions are caught (or std::terminate() is + // replaced). + + // We don't actually handle the exception here, so re-throw it now that our destructors have had a + // chance to run. + throw; + } + break; + case ray_casting_adaptive_traditional: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout + << "Using unculled adaptive grid with heuristic density and traditional QI calculation" + << endl; + } + try { + HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); + ComputeDetailedVisibility(ioViewMap, we, bbox, epsilon, false, factory); + } + catch (...) { + throw; + } + break; + case ray_casting_culled_adaptive_cumulative: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using culled adaptive grid with heuristic density and cumulative QI calculation" + << endl; + } + try { + HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); + ComputeCumulativeVisibility(ioViewMap, we, bbox, epsilon, true, factory); + } + catch (...) { + throw; + } + break; + case ray_casting_adaptive_cumulative: + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Using unculled adaptive grid with heuristic density and cumulative QI calculation" + << endl; + } + try { + HeuristicGridDensityProviderFactory factory(0.5f, sceneNumFaces); + ComputeCumulativeVisibility(ioViewMap, we, bbox, epsilon, false, factory); + } + catch (...) { + throw; + } + break; + default: + break; + } } static const unsigned gProgressBarMaxSteps = 10; @@ -1453,960 +1527,984 @@ static const unsigned gProgressBarMinSize = 2000; void ViewMapBuilder::ComputeRayCastingVisibility(ViewMap *ioViewMap, real epsilon) { - vector& vedges = ioViewMap->ViewEdges(); - bool progressBarDisplay = false; - unsigned progressBarStep = 0; - unsigned vEdgesSize = vedges.size(); - unsigned fEdgesSize = ioViewMap->FEdges().size(); - - if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { - unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); - progressBarStep = vEdgesSize / progressBarSteps; - _pProgressBar->reset(); - _pProgressBar->setLabelText("Computing Ray casting Visibility"); - _pProgressBar->setTotalSteps(progressBarSteps); - _pProgressBar->setProgress(0); - progressBarDisplay = true; - } - - unsigned counter = progressBarStep; - FEdge *fe, *festart; - int nSamples = 0; - vector aFaces; - Polygon3r *aFace = NULL; - unsigned tmpQI = 0; - unsigned qiClasses[256]; - unsigned maxIndex, maxCard; - unsigned qiMajority; - static unsigned timestamp = 1; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; + vector &vedges = ioViewMap->ViewEdges(); + bool progressBarDisplay = false; + unsigned progressBarStep = 0; + unsigned vEdgesSize = vedges.size(); + unsigned fEdgesSize = ioViewMap->FEdges().size(); + + if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { + unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); + progressBarStep = vEdgesSize / progressBarSteps; + _pProgressBar->reset(); + _pProgressBar->setLabelText("Computing Ray casting Visibility"); + _pProgressBar->setTotalSteps(progressBarSteps); + _pProgressBar->setProgress(0); + progressBarDisplay = true; + } + + unsigned counter = progressBarStep; + FEdge *fe, *festart; + int nSamples = 0; + vector aFaces; + Polygon3r *aFace = NULL; + unsigned tmpQI = 0; + unsigned qiClasses[256]; + unsigned maxIndex, maxCard; + unsigned qiMajority; + static unsigned timestamp = 1; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "Processing ViewEdge " << (*ve)->getId() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "Processing ViewEdge " << (*ve)->getId() << endl; + } #endif - festart = (*ve)->fedgeA(); - fe = (*ve)->fedgeA(); - qiMajority = 1; - do { - qiMajority++; - fe = fe->nextEdge(); - } while (fe && fe != festart); - qiMajority >>= 1; + festart = (*ve)->fedgeA(); + fe = (*ve)->fedgeA(); + qiMajority = 1; + do { + qiMajority++; + fe = fe->nextEdge(); + } while (fe && fe != festart); + qiMajority >>= 1; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tqiMajority: " << qiMajority << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tqiMajority: " << qiMajority << endl; + } #endif - tmpQI = 0; - maxIndex = 0; - maxCard = 0; - nSamples = 0; - fe = (*ve)->fedgeA(); - memset(qiClasses, 0, 256 * sizeof(*qiClasses)); - set occluders; - do { - if ((maxCard < qiMajority)) { - tmpQI = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); + tmpQI = 0; + maxIndex = 0; + maxCard = 0; + nSamples = 0; + fe = (*ve)->fedgeA(); + memset(qiClasses, 0, 256 * sizeof(*qiClasses)); + set occluders; + do { + if ((maxCard < qiMajority)) { + tmpQI = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: visibility " << tmpQI << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: visibility " << tmpQI << endl; + } #endif - //ARB: This is an error condition, not an alert condition. - // Some sort of recovery or abort is necessary. - if (tmpQI >= 256) { - cerr << "Warning: too many occluding levels" << endl; - //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 - tmpQI = 255; - } - - if (++qiClasses[tmpQI] > maxCard) { - maxCard = qiClasses[tmpQI]; - maxIndex = tmpQI; - } - } - else { - //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called - FindOccludee(fe, _Grid, epsilon, &aFace, timestamp++); + //ARB: This is an error condition, not an alert condition. + // Some sort of recovery or abort is necessary. + if (tmpQI >= 256) { + cerr << "Warning: too many occluding levels" << endl; + //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 + tmpQI = 255; + } + + if (++qiClasses[tmpQI] > maxCard) { + maxCard = qiClasses[tmpQI]; + maxIndex = tmpQI; + } + } + else { + //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called + FindOccludee(fe, _Grid, epsilon, &aFace, timestamp++); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFEdge: occludee only (" << (aFace != NULL ? "found" : "not found") << ")" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFEdge: occludee only (" << (aFace != NULL ? "found" : "not found") << ")" + << endl; + } #endif - } + } - if (aFace) { - fe->setaFace(*aFace); - aFaces.push_back(aFace); - fe->setOccludeeEmpty(false); + if (aFace) { + fe->setaFace(*aFace); + aFaces.push_back(aFace); + fe->setOccludeeEmpty(false); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFound occludee" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFound occludee" << endl; + } #endif - } - else { - //ARB: We are arbitrarily using the last observed value for occludee (almost always the value observed - // for the edge before festart). Is that meaningful? - // ...in fact, _occludeeEmpty seems to be unused. - fe->setOccludeeEmpty(true); - } - - ++nSamples; - fe = fe->nextEdge(); - } while ((maxCard < qiMajority) && (fe) && (fe != festart)); + } + else { + //ARB: We are arbitrarily using the last observed value for occludee (almost always the value observed + // for the edge before festart). Is that meaningful? + // ...in fact, _occludeeEmpty seems to be unused. + fe->setOccludeeEmpty(true); + } + + ++nSamples; + fe = fe->nextEdge(); + } while ((maxCard < qiMajority) && (fe) && (fe != festart)); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tFinished with " << nSamples << " samples, maxCard = " << maxCard << endl; + } #endif - // ViewEdge - // qi -- - (*ve)->setQI(maxIndex); - // occluders -- - for (set::iterator o = occluders.begin(), oend = occluders.end(); o != oend; ++o) - (*ve)->AddOccluder((*o)); + // ViewEdge + // qi -- + (*ve)->setQI(maxIndex); + // occluders -- + for (set::iterator o = occluders.begin(), oend = occluders.end(); o != oend; ++o) + (*ve)->AddOccluder((*o)); #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\tConclusion: QI = " << maxIndex << ", " << (*ve)->occluders_size() << " occluders." + << endl; + } #endif - // occludee -- - if (!aFaces.empty()) { - if (aFaces.size() <= (float)nSamples / 2.0f) { - (*ve)->setaShape(0); - } - else { - vector::iterator p = aFaces.begin(); - WFace *wface = (WFace *)((*p)->userdata); - ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); - ++p; - (*ve)->setaShape(vshape); - } - } - - if (progressBarDisplay) { - counter--; - if (counter <= 0) { - counter = progressBarStep; - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - } - } - aFaces.clear(); - } + // occludee -- + if (!aFaces.empty()) { + if (aFaces.size() <= (float)nSamples / 2.0f) { + (*ve)->setaShape(0); + } + else { + vector::iterator p = aFaces.begin(); + WFace *wface = (WFace *)((*p)->userdata); + ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); + ++p; + (*ve)->setaShape(vshape); + } + } + + if (progressBarDisplay) { + counter--; + if (counter <= 0) { + counter = progressBarStep; + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + } + } + aFaces.clear(); + } } void ViewMapBuilder::ComputeFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon) { - vector& vedges = ioViewMap->ViewEdges(); - bool progressBarDisplay = false; - unsigned progressBarStep = 0; - unsigned vEdgesSize = vedges.size(); - unsigned fEdgesSize = ioViewMap->FEdges().size(); - - if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { - unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); - progressBarStep = vEdgesSize / progressBarSteps; - _pProgressBar->reset(); - _pProgressBar->setLabelText("Computing Ray casting Visibility"); - _pProgressBar->setTotalSteps(progressBarSteps); - _pProgressBar->setProgress(0); - progressBarDisplay = true; - } - - unsigned counter = progressBarStep; - FEdge *fe, *festart; - unsigned nSamples = 0; - vector aFaces; - Polygon3r *aFace = NULL; - unsigned tmpQI = 0; - unsigned qiClasses[256]; - unsigned maxIndex, maxCard; - unsigned qiMajority; - static unsigned timestamp = 1; - bool even_test; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - - festart = (*ve)->fedgeA(); - fe = (*ve)->fedgeA(); - qiMajority = 1; - do { - qiMajority++; - fe = fe->nextEdge(); - } while (fe && fe != festart); - if (qiMajority >= 4) - qiMajority >>= 2; - else - qiMajority = 1; - - set occluders; - - even_test = true; - maxIndex = 0; - maxCard = 0; - nSamples = 0; - memset(qiClasses, 0, 256 * sizeof(*qiClasses)); - fe = (*ve)->fedgeA(); - do { - if (even_test) { - if ((maxCard < qiMajority)) { - tmpQI = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); - - //ARB: This is an error condition, not an alert condition. - // Some sort of recovery or abort is necessary. - if (tmpQI >= 256) { - cerr << "Warning: too many occluding levels" << endl; - //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 - tmpQI = 255; - } - - if (++qiClasses[tmpQI] > maxCard) { - maxCard = qiClasses[tmpQI]; - maxIndex = tmpQI; - } - } - else { - //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called - FindOccludee(fe, _Grid, epsilon, &aFace, timestamp++); - } - - if (aFace) { - fe->setaFace(*aFace); - aFaces.push_back(aFace); - } - ++nSamples; - even_test = false; - } - else { - even_test = true; - } - fe = fe->nextEdge(); - } while ((maxCard < qiMajority) && (fe) && (fe != festart)); - - (*ve)->setQI(maxIndex); - - if (!aFaces.empty()) { - if (aFaces.size() < nSamples / 2) { - (*ve)->setaShape(0); - } - else { - vector::iterator p = aFaces.begin(); - WFace *wface = (WFace *)((*p)->userdata); - ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); - ++p; + vector &vedges = ioViewMap->ViewEdges(); + bool progressBarDisplay = false; + unsigned progressBarStep = 0; + unsigned vEdgesSize = vedges.size(); + unsigned fEdgesSize = ioViewMap->FEdges().size(); + + if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { + unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); + progressBarStep = vEdgesSize / progressBarSteps; + _pProgressBar->reset(); + _pProgressBar->setLabelText("Computing Ray casting Visibility"); + _pProgressBar->setTotalSteps(progressBarSteps); + _pProgressBar->setProgress(0); + progressBarDisplay = true; + } + + unsigned counter = progressBarStep; + FEdge *fe, *festart; + unsigned nSamples = 0; + vector aFaces; + Polygon3r *aFace = NULL; + unsigned tmpQI = 0; + unsigned qiClasses[256]; + unsigned maxIndex, maxCard; + unsigned qiMajority; + static unsigned timestamp = 1; + bool even_test; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + + festart = (*ve)->fedgeA(); + fe = (*ve)->fedgeA(); + qiMajority = 1; + do { + qiMajority++; + fe = fe->nextEdge(); + } while (fe && fe != festart); + if (qiMajority >= 4) + qiMajority >>= 2; + else + qiMajority = 1; + + set occluders; + + even_test = true; + maxIndex = 0; + maxCard = 0; + nSamples = 0; + memset(qiClasses, 0, 256 * sizeof(*qiClasses)); + fe = (*ve)->fedgeA(); + do { + if (even_test) { + if ((maxCard < qiMajority)) { + tmpQI = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); + + //ARB: This is an error condition, not an alert condition. + // Some sort of recovery or abort is necessary. + if (tmpQI >= 256) { + cerr << "Warning: too many occluding levels" << endl; + //ARB: Wild guess: instead of aborting or corrupting memory, treat as tmpQI == 255 + tmpQI = 255; + } + + if (++qiClasses[tmpQI] > maxCard) { + maxCard = qiClasses[tmpQI]; + maxIndex = tmpQI; + } + } + else { + //ARB: FindOccludee is redundant if ComputeRayCastingVisibility has been called + FindOccludee(fe, _Grid, epsilon, &aFace, timestamp++); + } + + if (aFace) { + fe->setaFace(*aFace); + aFaces.push_back(aFace); + } + ++nSamples; + even_test = false; + } + else { + even_test = true; + } + fe = fe->nextEdge(); + } while ((maxCard < qiMajority) && (fe) && (fe != festart)); + + (*ve)->setQI(maxIndex); + + if (!aFaces.empty()) { + if (aFaces.size() < nSamples / 2) { + (*ve)->setaShape(0); + } + else { + vector::iterator p = aFaces.begin(); + WFace *wface = (WFace *)((*p)->userdata); + ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); + ++p; #if 0 - for (; p != pend; ++p) { - WFace *f = (WFace*)((*p)->userdata); - ViewShape *vs = ioViewMap->viewShape(f->GetVertex(0)->shape()->GetId()); - if (vs != vshape) { - sameShape = false; - break; - } - } - if (sameShape) + for (; p != pend; ++p) { + WFace *f = (WFace*)((*p)->userdata); + ViewShape *vs = ioViewMap->viewShape(f->GetVertex(0)->shape()->GetId()); + if (vs != vshape) { + sameShape = false; + break; + } + } + if (sameShape) #endif - (*ve)->setaShape(vshape); - } - } - - //(*ve)->setaFace(aFace); - - if (progressBarDisplay) { - counter--; - if (counter <= 0) { - counter = progressBarStep; - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - } - } - aFaces.clear(); - } + (*ve)->setaShape(vshape); + } + } + + //(*ve)->setaFace(aFace); + + if (progressBarDisplay) { + counter--; + if (counter <= 0) { + counter = progressBarStep; + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + } + } + aFaces.clear(); + } } void ViewMapBuilder::ComputeVeryFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon) { - vector& vedges = ioViewMap->ViewEdges(); - bool progressBarDisplay = false; - unsigned progressBarStep = 0; - unsigned vEdgesSize = vedges.size(); - unsigned fEdgesSize = ioViewMap->FEdges().size(); - - if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { - unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); - progressBarStep = vEdgesSize / progressBarSteps; - _pProgressBar->reset(); - _pProgressBar->setLabelText("Computing Ray casting Visibility"); - _pProgressBar->setTotalSteps(progressBarSteps); - _pProgressBar->setProgress(0); - progressBarDisplay = true; - } - - unsigned counter = progressBarStep; - FEdge *fe; - unsigned qi = 0; - Polygon3r *aFace = NULL; - static unsigned timestamp = 1; - for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - - set occluders; - - fe = (*ve)->fedgeA(); - qi = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); - if (aFace) { - fe->setaFace(*aFace); - WFace *wface = (WFace *)(aFace->userdata); - ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); - (*ve)->setaShape(vshape); - } - else { - (*ve)->setaShape(0); - } - - (*ve)->setQI(qi); - - if (progressBarDisplay) { - counter--; - if (counter <= 0) { - counter = progressBarStep; - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - } - } - } + vector &vedges = ioViewMap->ViewEdges(); + bool progressBarDisplay = false; + unsigned progressBarStep = 0; + unsigned vEdgesSize = vedges.size(); + unsigned fEdgesSize = ioViewMap->FEdges().size(); + + if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { + unsigned progressBarSteps = min(gProgressBarMaxSteps, vEdgesSize); + progressBarStep = vEdgesSize / progressBarSteps; + _pProgressBar->reset(); + _pProgressBar->setLabelText("Computing Ray casting Visibility"); + _pProgressBar->setTotalSteps(progressBarSteps); + _pProgressBar->setProgress(0); + progressBarDisplay = true; + } + + unsigned counter = progressBarStep; + FEdge *fe; + unsigned qi = 0; + Polygon3r *aFace = NULL; + static unsigned timestamp = 1; + for (vector::iterator ve = vedges.begin(), veend = vedges.end(); ve != veend; ve++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + + set occluders; + + fe = (*ve)->fedgeA(); + qi = ComputeRayCastingVisibility(fe, _Grid, epsilon, occluders, &aFace, timestamp++); + if (aFace) { + fe->setaFace(*aFace); + WFace *wface = (WFace *)(aFace->userdata); + ViewShape *vshape = ioViewMap->viewShape(wface->GetVertex(0)->shape()->GetId()); + (*ve)->setaShape(vshape); + } + else { + (*ve)->setaShape(0); + } + + (*ve)->setQI(qi); + + if (progressBarDisplay) { + counter--; + if (counter <= 0) { + counter = progressBarStep; + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + } + } + } } -void ViewMapBuilder::FindOccludee(FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp, - Vec3r& u, Vec3r& A, Vec3r& origin, Vec3r& edgeDir, vector& faceVertices) +void ViewMapBuilder::FindOccludee(FEdge *fe, + Grid *iGrid, + real epsilon, + Polygon3r **oaPolygon, + unsigned timestamp, + Vec3r &u, + Vec3r &A, + Vec3r &origin, + Vec3r &edgeDir, + vector &faceVertices) { - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - OccludersSet occluders; - WFace *oface; - bool skipFace; - - WVertex::incoming_edge_iterator ie; - OccludersSet::iterator p, pend; - - *oaPolygon = NULL; - if (((fe)->getNature() & Nature::SILHOUETTE) || ((fe)->getNature() & Nature::BORDER)) { - occluders.clear(); - // we cast a ray from A in the same direction but looking behind - Vec3r v(-u[0], -u[1], -u[2]); - iGrid->castInfiniteRay(A, v, occluders, timestamp); - - bool noIntersection = true; - real mint = FLT_MAX; - // we met some occluders, let us fill the aShape field with the first intersected occluder - for (p = occluders.begin(), pend = occluders.end(); p != pend; p++) { - // check whether the edge and the polygon plane are coincident: - //------------------------------------------------------------- - //first let us compute the plane equation. - oface = (WFace *)(*p)->userdata; - Vec3r v1(((*p)->getVertices())[0]); - Vec3r normal((*p)->getNormal()); - real d = -(v1 * normal); - real t, t_u, t_v; - - if (face) { - skipFace = false; - - if (face == oface) - continue; - - if (faceVertices.empty()) - continue; - - for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); - fv != fvend; - ++fv) - { - if ((*fv)->isBoundary()) - continue; - WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); - WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); - for (ie = iebegin; ie != ieend; ++ie) { - if ((*ie) == 0) - continue; - - WFace *sface = (*ie)->GetbFace(); - if (sface == oface) { - skipFace = true; - break; - } - } - if (skipFace) - break; - } - if (skipFace) - continue; - } - else { - if (GeomUtils::COINCIDENT == GeomUtils::intersectRayPlane(origin, edgeDir, normal, d, t, epsilon)) - continue; - } - if ((*p)->rayIntersect(A, v, t, t_u, t_v)) { - if (fabs(v * normal) > 0.0001) { - if (t > 0.0) { // && t < 1.0) { - if (t < mint) { - *oaPolygon = (*p); - mint = t; - noIntersection = false; - fe->setOccludeeIntersection(Vec3r(A + t * v)); - } - } - } - } - } - - if (noIntersection) - *oaPolygon = NULL; - } + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + OccludersSet occluders; + WFace *oface; + bool skipFace; + + WVertex::incoming_edge_iterator ie; + OccludersSet::iterator p, pend; + + *oaPolygon = NULL; + if (((fe)->getNature() & Nature::SILHOUETTE) || ((fe)->getNature() & Nature::BORDER)) { + occluders.clear(); + // we cast a ray from A in the same direction but looking behind + Vec3r v(-u[0], -u[1], -u[2]); + iGrid->castInfiniteRay(A, v, occluders, timestamp); + + bool noIntersection = true; + real mint = FLT_MAX; + // we met some occluders, let us fill the aShape field with the first intersected occluder + for (p = occluders.begin(), pend = occluders.end(); p != pend; p++) { + // check whether the edge and the polygon plane are coincident: + //------------------------------------------------------------- + //first let us compute the plane equation. + oface = (WFace *)(*p)->userdata; + Vec3r v1(((*p)->getVertices())[0]); + Vec3r normal((*p)->getNormal()); + real d = -(v1 * normal); + real t, t_u, t_v; + + if (face) { + skipFace = false; + + if (face == oface) + continue; + + if (faceVertices.empty()) + continue; + + for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); + fv != fvend; + ++fv) { + if ((*fv)->isBoundary()) + continue; + WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); + WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); + for (ie = iebegin; ie != ieend; ++ie) { + if ((*ie) == 0) + continue; + + WFace *sface = (*ie)->GetbFace(); + if (sface == oface) { + skipFace = true; + break; + } + } + if (skipFace) + break; + } + if (skipFace) + continue; + } + else { + if (GeomUtils::COINCIDENT == + GeomUtils::intersectRayPlane(origin, edgeDir, normal, d, t, epsilon)) + continue; + } + if ((*p)->rayIntersect(A, v, t, t_u, t_v)) { + if (fabs(v * normal) > 0.0001) { + if (t > 0.0) { // && t < 1.0) { + if (t < mint) { + *oaPolygon = (*p); + mint = t; + noIntersection = false; + fe->setOccludeeIntersection(Vec3r(A + t * v)); + } + } + } + } + } + + if (noIntersection) + *oaPolygon = NULL; + } } -void ViewMapBuilder::FindOccludee(FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp) +void ViewMapBuilder::FindOccludee( + FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp) { - OccludersSet occluders; - - Vec3r A; - Vec3r edgeDir; - Vec3r origin; - A = Vec3r(((fe)->vertexA()->point3D() + (fe)->vertexB()->point3D()) / 2.0); - edgeDir = Vec3r((fe)->vertexB()->point3D() - (fe)->vertexA()->point3D()); - edgeDir.normalize(); - origin = Vec3r((fe)->vertexA()->point3D()); - Vec3r u; - if (_orthographicProjection) { - u = Vec3r(0.0, 0.0, _viewpoint.z() - A.z()); - } - else { - u = Vec3r(_viewpoint - A); - } - u.normalize(); - if (A < iGrid->getOrigin()) - cerr << "Warning: point is out of the grid for fedge " << fe->getId().getFirst() << "-" << - fe->getId().getSecond() << endl; - - vector faceVertices; - - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - if (face) - face->RetrieveVertexList(faceVertices); - - return FindOccludee(fe, iGrid, epsilon, oaPolygon, timestamp, u, A, origin, edgeDir, faceVertices); + OccludersSet occluders; + + Vec3r A; + Vec3r edgeDir; + Vec3r origin; + A = Vec3r(((fe)->vertexA()->point3D() + (fe)->vertexB()->point3D()) / 2.0); + edgeDir = Vec3r((fe)->vertexB()->point3D() - (fe)->vertexA()->point3D()); + edgeDir.normalize(); + origin = Vec3r((fe)->vertexA()->point3D()); + Vec3r u; + if (_orthographicProjection) { + u = Vec3r(0.0, 0.0, _viewpoint.z() - A.z()); + } + else { + u = Vec3r(_viewpoint - A); + } + u.normalize(); + if (A < iGrid->getOrigin()) + cerr << "Warning: point is out of the grid for fedge " << fe->getId().getFirst() << "-" + << fe->getId().getSecond() << endl; + + vector faceVertices; + + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + if (face) + face->RetrieveVertexList(faceVertices); + + return FindOccludee( + fe, iGrid, epsilon, oaPolygon, timestamp, u, A, origin, edgeDir, faceVertices); } -int ViewMapBuilder::ComputeRayCastingVisibility(FEdge *fe, Grid *iGrid, real epsilon, set& oOccluders, - Polygon3r **oaPolygon, unsigned timestamp) +int ViewMapBuilder::ComputeRayCastingVisibility(FEdge *fe, + Grid *iGrid, + real epsilon, + set &oOccluders, + Polygon3r **oaPolygon, + unsigned timestamp) { - OccludersSet occluders; - int qi = 0; - - Vec3r center; - Vec3r edgeDir; - Vec3r origin; - - center = fe->center3d(); - edgeDir = Vec3r(fe->vertexB()->point3D() - fe->vertexA()->point3D()); - edgeDir.normalize(); - origin = Vec3r(fe->vertexA()->point3D()); - // Is the edge outside the view frustum ? - Vec3r gridOrigin(iGrid->getOrigin()); - Vec3r gridExtremity(iGrid->getOrigin() + iGrid->gridSize()); - - if ((center.x() < gridOrigin.x()) || (center.y() < gridOrigin.y()) || (center.z() < gridOrigin.z()) || - (center.x() > gridExtremity.x()) || (center.y() > gridExtremity.y()) || (center.z() > gridExtremity.z())) - { - cerr << "Warning: point is out of the grid for fedge " << fe->getId() << endl; - //return 0; - } + OccludersSet occluders; + int qi = 0; + + Vec3r center; + Vec3r edgeDir; + Vec3r origin; + + center = fe->center3d(); + edgeDir = Vec3r(fe->vertexB()->point3D() - fe->vertexA()->point3D()); + edgeDir.normalize(); + origin = Vec3r(fe->vertexA()->point3D()); + // Is the edge outside the view frustum ? + Vec3r gridOrigin(iGrid->getOrigin()); + Vec3r gridExtremity(iGrid->getOrigin() + iGrid->gridSize()); + + if ((center.x() < gridOrigin.x()) || (center.y() < gridOrigin.y()) || + (center.z() < gridOrigin.z()) || (center.x() > gridExtremity.x()) || + (center.y() > gridExtremity.y()) || (center.z() > gridExtremity.z())) { + cerr << "Warning: point is out of the grid for fedge " << fe->getId() << endl; + //return 0; + } #if 0 - Vec3r A(fe->vertexA()->point2d()); - Vec3r B(fe->vertexB()->point2d()); - int viewport[4]; - SilhouetteGeomEngine::retrieveViewport(viewport); - if ((A.x() < viewport[0]) || (A.x() > viewport[2]) || (A.y() < viewport[1]) || (A.y() > viewport[3]) || - (B.x() < viewport[0]) || (B.x() > viewport[2]) || (B.y() < viewport[1]) || (B.y() > viewport[3])) - { - cerr << "Warning: point is out of the grid for fedge " << fe->getId() << endl; - //return 0; - } + Vec3r A(fe->vertexA()->point2d()); + Vec3r B(fe->vertexB()->point2d()); + int viewport[4]; + SilhouetteGeomEngine::retrieveViewport(viewport); + if ((A.x() < viewport[0]) || (A.x() > viewport[2]) || (A.y() < viewport[1]) || (A.y() > viewport[3]) || + (B.x() < viewport[0]) || (B.x() > viewport[2]) || (B.y() < viewport[1]) || (B.y() > viewport[3])) + { + cerr << "Warning: point is out of the grid for fedge " << fe->getId() << endl; + //return 0; + } #endif - Vec3r vp; - if (_orthographicProjection) { - vp = Vec3r(center.x(), center.y(), _viewpoint.z()); - } - else { - vp = Vec3r(_viewpoint); - } - Vec3r u(vp - center); - real raylength = u.norm(); - u.normalize(); + Vec3r vp; + if (_orthographicProjection) { + vp = Vec3r(center.x(), center.y(), _viewpoint.z()); + } + else { + vp = Vec3r(_viewpoint); + } + Vec3r u(vp - center); + real raylength = u.norm(); + u.normalize(); #if 0 - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "grid origin " << iGrid->getOrigin().x() << "," << iGrid->getOrigin().y() << "," - << iGrid->getOrigin().z() << endl; - cout << "center " << center.x() << "," << center.y() << "," << center.z() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "grid origin " << iGrid->getOrigin().x() << "," << iGrid->getOrigin().y() << "," + << iGrid->getOrigin().z() << endl; + cout << "center " << center.x() << "," << center.y() << "," << center.z() << endl; + } #endif - iGrid->castRay(center, vp, occluders, timestamp); - - WFace *face = NULL; - if (fe->isSmooth()) { - FEdgeSmooth *fes = dynamic_cast(fe); - face = (WFace *)fes->face(); - } - vector faceVertices; - WVertex::incoming_edge_iterator ie; - - WFace *oface; - bool skipFace; - OccludersSet::iterator p, pend; - if (face) - face->RetrieveVertexList(faceVertices); - - for (p = occluders.begin(), pend = occluders.end(); p != pend; p++) { - // If we're dealing with an exact silhouette, check whether we must take care of this occluder of not. - // (Indeed, we don't consider the occluders that share at least one vertex with the face containing this edge). - //----------- - oface = (WFace *)(*p)->userdata; + iGrid->castRay(center, vp, occluders, timestamp); + + WFace *face = NULL; + if (fe->isSmooth()) { + FEdgeSmooth *fes = dynamic_cast(fe); + face = (WFace *)fes->face(); + } + vector faceVertices; + WVertex::incoming_edge_iterator ie; + + WFace *oface; + bool skipFace; + OccludersSet::iterator p, pend; + if (face) + face->RetrieveVertexList(faceVertices); + + for (p = occluders.begin(), pend = occluders.end(); p != pend; p++) { + // If we're dealing with an exact silhouette, check whether we must take care of this occluder of not. + // (Indeed, we don't consider the occluders that share at least one vertex with the face containing this edge). + //----------- + oface = (WFace *)(*p)->userdata; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tEvaluating intersection for occluder " << ((*p)->getVertices())[0] << - ((*p)->getVertices())[1] << ((*p)->getVertices())[2] << endl << "\t\t\tand ray " << vp << - " * " << u << " (center " << center << ")" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tEvaluating intersection for occluder " << ((*p)->getVertices())[0] + << ((*p)->getVertices())[1] << ((*p)->getVertices())[2] << endl + << "\t\t\tand ray " << vp << " * " << u << " (center " << center << ")" << endl; + } #endif - Vec3r v1(((*p)->getVertices())[0]); - Vec3r normal((*p)->getNormal()); - real d = -(v1 * normal); - real t, t_u, t_v; + Vec3r v1(((*p)->getVertices())[0]); + Vec3r normal((*p)->getNormal()); + real d = -(v1 * normal); + real t, t_u, t_v; #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tp: " << ((*p)->getVertices())[0] << ((*p)->getVertices())[1] << ((*p)->getVertices())[2] << - ", norm: " << (*p)->getNormal() << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tp: " << ((*p)->getVertices())[0] << ((*p)->getVertices())[1] + << ((*p)->getVertices())[2] << ", norm: " << (*p)->getNormal() << endl; + } #endif - if (face) { + if (face) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tDetermining face adjacency..."; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tDetermining face adjacency..."; + } #endif - skipFace = false; + skipFace = false; - if (face == oface) { + if (face == oface) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << " Rejecting occluder for face concurrency." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << " Rejecting occluder for face concurrency." << endl; + } #endif - continue; - } - - for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); - fv != fvend; - ++fv) - { - if ((*fv)->isBoundary()) - continue; - - WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); - WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); - for (ie = iebegin; ie != ieend; ++ie) { - if ((*ie) == 0) - continue; - - WFace *sface = (*ie)->GetbFace(); - //WFace *sfacea = (*ie)->GetaFace(); - //if ((sface == oface) || (sfacea == oface)) { - if (sface == oface) { - skipFace = true; - break; - } - } - if (skipFace) - break; - } - if (skipFace) { + continue; + } + + for (vector::iterator fv = faceVertices.begin(), fvend = faceVertices.end(); + fv != fvend; + ++fv) { + if ((*fv)->isBoundary()) + continue; + + WVertex::incoming_edge_iterator iebegin = (*fv)->incoming_edges_begin(); + WVertex::incoming_edge_iterator ieend = (*fv)->incoming_edges_end(); + for (ie = iebegin; ie != ieend; ++ie) { + if ((*ie) == 0) + continue; + + WFace *sface = (*ie)->GetbFace(); + //WFace *sfacea = (*ie)->GetaFace(); + //if ((sface == oface) || (sfacea == oface)) { + if (sface == oface) { + skipFace = true; + break; + } + } + if (skipFace) + break; + } + if (skipFace) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << " Rejecting occluder for face adjacency." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << " Rejecting occluder for face adjacency." << endl; + } #endif - continue; - } - } - else { - // check whether the edge and the polygon plane are coincident: - //------------------------------------------------------------- - //first let us compute the plane equation. - - if (GeomUtils::COINCIDENT == GeomUtils::intersectRayPlane(origin, edgeDir, normal, d, t, epsilon)) { + continue; + } + } + else { + // check whether the edge and the polygon plane are coincident: + //------------------------------------------------------------- + //first let us compute the plane equation. + + if (GeomUtils::COINCIDENT == + GeomUtils::intersectRayPlane(origin, edgeDir, normal, d, t, epsilon)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRejecting occluder for target coincidence." << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRejecting occluder for target coincidence." << endl; + } #endif - continue; - } - } + continue; + } + } - if ((*p)->rayIntersect(center, u, t, t_u, t_v)) { + if ((*p)->rayIntersect(center, u, t, t_u, t_v)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tRay " << vp << " * " << u << " intersects at time " << t << " (raylength is " << - raylength << ")" << endl; - cout << "\t\t(u * normal) == " << (u * normal) << " for normal " << normal << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tRay " << vp << " * " << u << " intersects at time " << t << " (raylength is " + << raylength << ")" << endl; + cout << "\t\t(u * normal) == " << (u * normal) << " for normal " << normal << endl; + } #endif - if (fabs(u * normal) > 0.0001) { - if ((t>0.0) && (t 0.0001) { + if ((t > 0.0) && (t < raylength)) { #if LOGGING - if (_global.debug & G_DEBUG_FREESTYLE) { - cout << "\t\tIs occluder" << endl; - } + if (_global.debug & G_DEBUG_FREESTYLE) { + cout << "\t\tIs occluder" << endl; + } #endif - WFace *f = (WFace *)((*p)->userdata); - ViewShape *vshape = _ViewMap->viewShape(f->GetVertex(0)->shape()->GetId()); - oOccluders.insert(vshape); - ++qi; - if (!_EnableQI) - break; - } - } - } - } - - // Find occludee - FindOccludee(fe, iGrid, epsilon, oaPolygon, timestamp, u, center, origin, edgeDir, faceVertices); - - return qi; + WFace *f = (WFace *)((*p)->userdata); + ViewShape *vshape = _ViewMap->viewShape(f->GetVertex(0)->shape()->GetId()); + oOccluders.insert(vshape); + ++qi; + if (!_EnableQI) + break; + } + } + } + } + + // Find occludee + FindOccludee(fe, iGrid, epsilon, oaPolygon, timestamp, u, center, origin, edgeDir, faceVertices); + + return qi; } -void ViewMapBuilder::ComputeIntersections(ViewMap *ioViewMap, intersection_algo iAlgo, real epsilon) +void ViewMapBuilder::ComputeIntersections(ViewMap *ioViewMap, + intersection_algo iAlgo, + real epsilon) { - switch (iAlgo) { - case sweep_line: - ComputeSweepLineIntersections(ioViewMap, epsilon); - break; - default: - break; - } + switch (iAlgo) { + case sweep_line: + ComputeSweepLineIntersections(ioViewMap, epsilon); + break; + default: + break; + } #if 0 - if (_global.debug & G_DEBUG_FREESTYLE) { - ViewMap::viewvertices_container& vvertices = ioViewMap->ViewVertices(); - for (ViewMap::viewvertices_container::iterator vv = vvertices.begin(), vvend = vvertices.end(); - vv != vvend; ++vv) - { - if ((*vv)->getNature() == Nature::T_VERTEX) { - TVertex *tvertex = (TVertex *)(*vv); - cout << "TVertex " << tvertex->getId() << " has :" << endl; - cout << "FrontEdgeA: " << tvertex->frontEdgeA().first << endl; - cout << "FrontEdgeB: " << tvertex->frontEdgeB().first << endl; - cout << "BackEdgeA: " << tvertex->backEdgeA().first << endl; - cout << "BackEdgeB: " << tvertex->backEdgeB().first << endl << endl; - } - } - } + if (_global.debug & G_DEBUG_FREESTYLE) { + ViewMap::viewvertices_container& vvertices = ioViewMap->ViewVertices(); + for (ViewMap::viewvertices_container::iterator vv = vvertices.begin(), vvend = vvertices.end(); + vv != vvend; ++vv) + { + if ((*vv)->getNature() == Nature::T_VERTEX) { + TVertex *tvertex = (TVertex *)(*vv); + cout << "TVertex " << tvertex->getId() << " has :" << endl; + cout << "FrontEdgeA: " << tvertex->frontEdgeA().first << endl; + cout << "FrontEdgeB: " << tvertex->frontEdgeB().first << endl; + cout << "BackEdgeA: " << tvertex->backEdgeA().first << endl; + cout << "BackEdgeB: " << tvertex->backEdgeB().first << endl << endl; + } + } + } #endif } -struct less_SVertex2D : public binary_function -{ - real epsilon; - - less_SVertex2D(real eps) : binary_function() - { - epsilon = eps; - } - - bool operator()(SVertex *x, SVertex *y) - { - Vec3r A = x->point2D(); - Vec3r B = y->point2D(); - for (unsigned int i = 0; i < 3; i++) { - if ((fabs(A[i] - B[i])) < epsilon) - continue; - if (A[i] < B[i]) - return true; - if (A[i] > B[i]) - return false; - } - return false; - } +struct less_SVertex2D : public binary_function { + real epsilon; + + less_SVertex2D(real eps) : binary_function() + { + epsilon = eps; + } + + bool operator()(SVertex *x, SVertex *y) + { + Vec3r A = x->point2D(); + Vec3r B = y->point2D(); + for (unsigned int i = 0; i < 3; i++) { + if ((fabs(A[i] - B[i])) < epsilon) + continue; + if (A[i] < B[i]) + return true; + if (A[i] > B[i]) + return false; + } + return false; + } }; typedef Segment segment; typedef Intersection intersection; -struct less_Intersection : public binary_function -{ - segment *edge; - - less_Intersection(segment *iEdge) : binary_function() - { - edge = iEdge; - } - - bool operator()(intersection *x, intersection *y) - { - real tx = x->getParameter(edge); - real ty = y->getParameter(edge); - if (tx > ty) - return true; - return false; - } +struct less_Intersection : public binary_function { + segment *edge; + + less_Intersection(segment *iEdge) : binary_function() + { + edge = iEdge; + } + + bool operator()(intersection *x, intersection *y) + { + real tx = x->getParameter(edge); + real ty = y->getParameter(edge); + if (tx > ty) + return true; + return false; + } }; -struct silhouette_binary_rule : public binary_rule -{ - silhouette_binary_rule() : binary_rule() {} +struct silhouette_binary_rule : public binary_rule { + silhouette_binary_rule() : binary_rule() + { + } - virtual bool operator()(segment& s1, segment& s2) - { - FEdge *f1 = s1.edge(); - FEdge *f2 = s2.edge(); + virtual bool operator()(segment &s1, segment &s2) + { + FEdge *f1 = s1.edge(); + FEdge *f2 = s2.edge(); - if ((!(((f1)->getNature() & Nature::SILHOUETTE) || ((f1)->getNature() & Nature::BORDER))) && - (!(((f2)->getNature() & Nature::SILHOUETTE) || ((f2)->getNature() & Nature::BORDER)))) - { - return false; - } + if ((!(((f1)->getNature() & Nature::SILHOUETTE) || ((f1)->getNature() & Nature::BORDER))) && + (!(((f2)->getNature() & Nature::SILHOUETTE) || ((f2)->getNature() & Nature::BORDER)))) { + return false; + } - return true; - } + return true; + } }; void ViewMapBuilder::ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsilon) { - vector& svertices = ioViewMap->SVertices(); - bool progressBarDisplay = false; - unsigned sVerticesSize = svertices.size(); - unsigned fEdgesSize = ioViewMap->FEdges().size(); + vector &svertices = ioViewMap->SVertices(); + bool progressBarDisplay = false; + unsigned sVerticesSize = svertices.size(); + unsigned fEdgesSize = ioViewMap->FEdges().size(); #if 0 - if (_global.debug & G_DEBUG_FREESTYLE) { - ViewMap::fedges_container& fedges = ioViewMap->FEdges(); - for (ViewMap::fedges_container::const_iterator f = fedges.begin(), end = fedges.end(); f != end; ++f) { - cout << (*f)->aMaterialIndex() << "-" << (*f)->bMaterialIndex() << endl; - } - } + if (_global.debug & G_DEBUG_FREESTYLE) { + ViewMap::fedges_container& fedges = ioViewMap->FEdges(); + for (ViewMap::fedges_container::const_iterator f = fedges.begin(), end = fedges.end(); f != end; ++f) { + cout << (*f)->aMaterialIndex() << "-" << (*f)->bMaterialIndex() << endl; + } + } #endif - unsigned progressBarStep = 0; - - if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { - unsigned progressBarSteps = min(gProgressBarMaxSteps, sVerticesSize); - progressBarStep = sVerticesSize / progressBarSteps; - _pProgressBar->reset(); - _pProgressBar->setLabelText("Computing Sweep Line Intersections"); - _pProgressBar->setTotalSteps(progressBarSteps); - _pProgressBar->setProgress(0); - progressBarDisplay = true; - } - - unsigned counter = progressBarStep; - - sort(svertices.begin(), svertices.end(), less_SVertex2D(epsilon)); - - SweepLine SL; - - vector& ioEdges = ioViewMap->FEdges(); - - vector segments; - - vector::iterator fe, fend; - - for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) { - segment *s = new segment((*fe), (*fe)->vertexA()->point2D(), (*fe)->vertexB()->point2D()); - (*fe)->userdata = s; - segments.push_back(s); - } - - vector vsegments; - for (vector::iterator sv = svertices.begin(), svend = svertices.end(); sv != svend; sv++) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - break; - - const vector& vedges = (*sv)->fedges(); - - for (vector::const_iterator sve = vedges.begin(), sveend = vedges.end(); sve != sveend; sve++) { - vsegments.push_back((segment *)((*sve)->userdata)); - } - - Vec3r evt((*sv)->point2D()); - silhouette_binary_rule sbr; - SL.process(evt, vsegments, sbr, epsilon); - - if (progressBarDisplay) { - counter--; - if (counter <= 0) { - counter = progressBarStep; - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - } - } - vsegments.clear(); - } - - if (_pRenderMonitor && _pRenderMonitor->testBreak()) { - // delete segments - if (!segments.empty()) { - vector::iterator s, send; - for (s = segments.begin(), send = segments.end(); s != send; s++) { - delete *s; - } - } - return; - } - - // reset userdata: - for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) - (*fe)->userdata = NULL; - - // list containing the new edges resulting from splitting operations. - vector newEdges; - - // retrieve the intersected edges: - vector& iedges = SL.intersectedEdges(); - // retrieve the intersections: - vector& intersections = SL.intersections(); - - int id = 0; - // create a view vertex for each intersection and linked this one with the intersection object - vector::iterator i, iend; - for (i = intersections.begin(), iend = intersections.end(); i != iend; i++) { - FEdge *fA = (*i)->EdgeA->edge(); - FEdge *fB = (*i)->EdgeB->edge(); - - Vec3r A1 = fA->vertexA()->point3D(); - Vec3r A2 = fA->vertexB()->point3D(); - Vec3r B1 = fB->vertexA()->point3D(); - Vec3r B2 = fB->vertexB()->point3D(); - - Vec3r a1 = fA->vertexA()->point2D(); - Vec3r a2 = fA->vertexB()->point2D(); - Vec3r b1 = fB->vertexA()->point2D(); - Vec3r b2 = fB->vertexB()->point2D(); - - real ta = (*i)->tA; - real tb = (*i)->tB; - - if ((ta < -epsilon) || (ta > 1 + epsilon)) - cerr << "Warning: 2D intersection out of range for edge " << fA->vertexA()->getId() << " - " << - fA->vertexB()->getId() << endl; - - if ((tb < -epsilon) || (tb > 1 + epsilon)) - cerr << "Warning: 2D intersection out of range for edge " << fB->vertexA()->getId() << " - " << - fB->vertexB()->getId() << endl; - - real Ta = SilhouetteGeomEngine::ImageToWorldParameter(fA, ta); - real Tb = SilhouetteGeomEngine::ImageToWorldParameter(fB, tb); - - if ((Ta < -epsilon) || (Ta > 1 + epsilon)) - cerr << "Warning: 3D intersection out of range for edge " << fA->vertexA()->getId() << " - " << - fA->vertexB()->getId() << endl; - - if ((Tb < -epsilon) || (Tb > 1 + epsilon)) - cerr << "Warning: 3D intersection out of range for edge " << fB->vertexA()->getId() << " - " << - fB->vertexB()->getId() << endl; + unsigned progressBarStep = 0; + + if (_pProgressBar != NULL && fEdgesSize > gProgressBarMinSize) { + unsigned progressBarSteps = min(gProgressBarMaxSteps, sVerticesSize); + progressBarStep = sVerticesSize / progressBarSteps; + _pProgressBar->reset(); + _pProgressBar->setLabelText("Computing Sweep Line Intersections"); + _pProgressBar->setTotalSteps(progressBarSteps); + _pProgressBar->setProgress(0); + progressBarDisplay = true; + } + + unsigned counter = progressBarStep; + + sort(svertices.begin(), svertices.end(), less_SVertex2D(epsilon)); + + SweepLine SL; + + vector &ioEdges = ioViewMap->FEdges(); + + vector segments; + + vector::iterator fe, fend; + + for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) { + segment *s = new segment((*fe), (*fe)->vertexA()->point2D(), (*fe)->vertexB()->point2D()); + (*fe)->userdata = s; + segments.push_back(s); + } + + vector vsegments; + for (vector::iterator sv = svertices.begin(), svend = svertices.end(); sv != svend; + sv++) { + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + break; + + const vector &vedges = (*sv)->fedges(); + + for (vector::const_iterator sve = vedges.begin(), sveend = vedges.end(); + sve != sveend; + sve++) { + vsegments.push_back((segment *)((*sve)->userdata)); + } + + Vec3r evt((*sv)->point2D()); + silhouette_binary_rule sbr; + SL.process(evt, vsegments, sbr, epsilon); + + if (progressBarDisplay) { + counter--; + if (counter <= 0) { + counter = progressBarStep; + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + } + } + vsegments.clear(); + } + + if (_pRenderMonitor && _pRenderMonitor->testBreak()) { + // delete segments + if (!segments.empty()) { + vector::iterator s, send; + for (s = segments.begin(), send = segments.end(); s != send; s++) { + delete *s; + } + } + return; + } + + // reset userdata: + for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) + (*fe)->userdata = NULL; + + // list containing the new edges resulting from splitting operations. + vector newEdges; + + // retrieve the intersected edges: + vector &iedges = SL.intersectedEdges(); + // retrieve the intersections: + vector &intersections = SL.intersections(); + + int id = 0; + // create a view vertex for each intersection and linked this one with the intersection object + vector::iterator i, iend; + for (i = intersections.begin(), iend = intersections.end(); i != iend; i++) { + FEdge *fA = (*i)->EdgeA->edge(); + FEdge *fB = (*i)->EdgeB->edge(); + + Vec3r A1 = fA->vertexA()->point3D(); + Vec3r A2 = fA->vertexB()->point3D(); + Vec3r B1 = fB->vertexA()->point3D(); + Vec3r B2 = fB->vertexB()->point3D(); + + Vec3r a1 = fA->vertexA()->point2D(); + Vec3r a2 = fA->vertexB()->point2D(); + Vec3r b1 = fB->vertexA()->point2D(); + Vec3r b2 = fB->vertexB()->point2D(); + + real ta = (*i)->tA; + real tb = (*i)->tB; + + if ((ta < -epsilon) || (ta > 1 + epsilon)) + cerr << "Warning: 2D intersection out of range for edge " << fA->vertexA()->getId() << " - " + << fA->vertexB()->getId() << endl; + + if ((tb < -epsilon) || (tb > 1 + epsilon)) + cerr << "Warning: 2D intersection out of range for edge " << fB->vertexA()->getId() << " - " + << fB->vertexB()->getId() << endl; + + real Ta = SilhouetteGeomEngine::ImageToWorldParameter(fA, ta); + real Tb = SilhouetteGeomEngine::ImageToWorldParameter(fB, tb); + + if ((Ta < -epsilon) || (Ta > 1 + epsilon)) + cerr << "Warning: 3D intersection out of range for edge " << fA->vertexA()->getId() << " - " + << fA->vertexB()->getId() << endl; + + if ((Tb < -epsilon) || (Tb > 1 + epsilon)) + cerr << "Warning: 3D intersection out of range for edge " << fB->vertexA()->getId() << " - " + << fB->vertexB()->getId() << endl; #if 0 - if (_global.debug & G_DEBUG_FREESTYLE) { - if ((Ta < -epsilon) || (Ta > 1 + epsilon) || (Tb < -epsilon) || (Tb > 1 + epsilon)) { - printf("ta %.12e\n", ta); - printf("tb %.12e\n", tb); - printf("a1 %e, %e -- a2 %e, %e\n", a1[0], a1[1], a2[0], a2[1]); - printf("b1 %e, %e -- b2 %e, %e\n", b1[0], b1[1], b2[0], b2[1]); - //printf("line([%e, %e], [%e, %e]);\n", a1[0], a2[0], a1[1], a2[1]); - //printf("line([%e, %e], [%e, %e]);\n", b1[0], b2[0], b1[1], b2[1]); - if ((Ta < -epsilon) || (Ta > 1 + epsilon)) - printf("Ta %.12e\n", Ta); - if ((Tb < -epsilon) || (Tb > 1 + epsilon)) - printf("Tb %.12e\n", Tb); - printf("A1 %e, %e, %e -- A2 %e, %e, %e\n", A1[0], A1[1], A1[2], A2[0], A2[1], A2[2]); - printf("B1 %e, %e, %e -- B2 %e, %e, %e\n", B1[0], B1[1], B1[2], B2[0], B2[1], B2[2]); - } - } + if (_global.debug & G_DEBUG_FREESTYLE) { + if ((Ta < -epsilon) || (Ta > 1 + epsilon) || (Tb < -epsilon) || (Tb > 1 + epsilon)) { + printf("ta %.12e\n", ta); + printf("tb %.12e\n", tb); + printf("a1 %e, %e -- a2 %e, %e\n", a1[0], a1[1], a2[0], a2[1]); + printf("b1 %e, %e -- b2 %e, %e\n", b1[0], b1[1], b2[0], b2[1]); + //printf("line([%e, %e], [%e, %e]);\n", a1[0], a2[0], a1[1], a2[1]); + //printf("line([%e, %e], [%e, %e]);\n", b1[0], b2[0], b1[1], b2[1]); + if ((Ta < -epsilon) || (Ta > 1 + epsilon)) + printf("Ta %.12e\n", Ta); + if ((Tb < -epsilon) || (Tb > 1 + epsilon)) + printf("Tb %.12e\n", Tb); + printf("A1 %e, %e, %e -- A2 %e, %e, %e\n", A1[0], A1[1], A1[2], A2[0], A2[1], A2[2]); + printf("B1 %e, %e, %e -- B2 %e, %e, %e\n", B1[0], B1[1], B1[2], B2[0], B2[1], B2[2]); + } + } #endif - TVertex *tvertex = ioViewMap->CreateTVertex(Vec3r(A1 + Ta * (A2 - A1)), Vec3r(a1 + ta * (a2 - a1)), fA, - Vec3r(B1 + Tb * (B2 - B1)), Vec3r(b1 + tb * (b2 - b1)), fB, id); - - (*i)->userdata = tvertex; - ++id; - } - - progressBarStep = 0; - - if (progressBarDisplay) { - unsigned iEdgesSize = iedges.size(); - unsigned progressBarSteps = min(gProgressBarMaxSteps, iEdgesSize); - progressBarStep = iEdgesSize / progressBarSteps; - _pProgressBar->reset(); - _pProgressBar->setLabelText("Splitting intersected edges"); - _pProgressBar->setTotalSteps(progressBarSteps); - _pProgressBar->setProgress(0); - } - - counter = progressBarStep; - - vector edgeVVertices; - vector newVEdges; - vector::iterator s, send; - for (s = iedges.begin(), send = iedges.end(); s != send; s++) { - edgeVVertices.clear(); - newEdges.clear(); - newVEdges.clear(); - - FEdge *fedge = (*s)->edge(); - ViewEdge *vEdge = fedge->viewedge(); - ViewShape *shape = vEdge->viewShape(); - - vector& eIntersections = (*s)->intersections(); - // we first need to sort these intersections from farther to closer to A - sort(eIntersections.begin(), eIntersections.end(), less_Intersection(*s)); - for (i = eIntersections.begin(), iend = eIntersections.end(); i != iend; i++) - edgeVVertices.push_back((TVertex *)(*i)->userdata); - - shape->SplitEdge(fedge, edgeVVertices, ioViewMap->FEdges(), ioViewMap->ViewEdges()); - - if (progressBarDisplay) { - counter--; - if (counter <= 0) { - counter = progressBarStep; - _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - } - } - } - - // reset userdata: - for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) - (*fe)->userdata = NULL; - - // delete segments - if (!segments.empty()) { - for (s = segments.begin(), send = segments.end(); s != send; s++) { - delete *s; - } - } + TVertex *tvertex = ioViewMap->CreateTVertex(Vec3r(A1 + Ta * (A2 - A1)), + Vec3r(a1 + ta * (a2 - a1)), + fA, + Vec3r(B1 + Tb * (B2 - B1)), + Vec3r(b1 + tb * (b2 - b1)), + fB, + id); + + (*i)->userdata = tvertex; + ++id; + } + + progressBarStep = 0; + + if (progressBarDisplay) { + unsigned iEdgesSize = iedges.size(); + unsigned progressBarSteps = min(gProgressBarMaxSteps, iEdgesSize); + progressBarStep = iEdgesSize / progressBarSteps; + _pProgressBar->reset(); + _pProgressBar->setLabelText("Splitting intersected edges"); + _pProgressBar->setTotalSteps(progressBarSteps); + _pProgressBar->setProgress(0); + } + + counter = progressBarStep; + + vector edgeVVertices; + vector newVEdges; + vector::iterator s, send; + for (s = iedges.begin(), send = iedges.end(); s != send; s++) { + edgeVVertices.clear(); + newEdges.clear(); + newVEdges.clear(); + + FEdge *fedge = (*s)->edge(); + ViewEdge *vEdge = fedge->viewedge(); + ViewShape *shape = vEdge->viewShape(); + + vector &eIntersections = (*s)->intersections(); + // we first need to sort these intersections from farther to closer to A + sort(eIntersections.begin(), eIntersections.end(), less_Intersection(*s)); + for (i = eIntersections.begin(), iend = eIntersections.end(); i != iend; i++) + edgeVVertices.push_back((TVertex *)(*i)->userdata); + + shape->SplitEdge(fedge, edgeVVertices, ioViewMap->FEdges(), ioViewMap->ViewEdges()); + + if (progressBarDisplay) { + counter--; + if (counter <= 0) { + counter = progressBarStep; + _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); + } + } + } + + // reset userdata: + for (fe = ioEdges.begin(), fend = ioEdges.end(); fe != fend; fe++) + (*fe)->userdata = NULL; + + // delete segments + if (!segments.empty()) { + for (s = segments.begin(), send = segments.end(); s != send; s++) { + delete *s; + } + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.h b/source/blender/freestyle/intern/view_map/ViewMapBuilder.h index 4148ef5e436..0e3dbf9148e 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.h +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.h @@ -47,210 +47,246 @@ #include "../winged_edge/WXEdge.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { using namespace Geometry; -class ViewMapBuilder -{ -private: - ViewMap *_ViewMap; // result - //SilhouetteGeomEngine _GeomEngine; - ProgressBar *_pProgressBar; - RenderMonitor *_pRenderMonitor; - Vec3r _viewpoint; - bool _orthographicProjection; - Grid *_Grid; - ViewEdgeXBuilder *_pViewEdgeBuilder; - bool _EnableQI; - double _epsilon; - - // tmp values: - int _currentId; - int _currentFId; - int _currentSVertexId; - -public: - typedef enum { - sweep_line, - } intersection_algo; - - typedef enum { - ray_casting, - ray_casting_fast, - ray_casting_very_fast, - ray_casting_culled_adaptive_traditional, - ray_casting_adaptive_traditional, - ray_casting_culled_adaptive_cumulative, - ray_casting_adaptive_cumulative, - } visibility_algo; - - inline ViewMapBuilder() - { - _pProgressBar = NULL; - _pRenderMonitor = NULL; - _Grid = NULL; - _currentId = 1; - _currentFId = 0; - _currentSVertexId = 0; - _pViewEdgeBuilder = new ViewEdgeXBuilder; - _EnableQI = true; - } - - inline ~ViewMapBuilder() - { - if (_pViewEdgeBuilder) { - delete _pViewEdgeBuilder; - _pViewEdgeBuilder = NULL; - } - } - - /* Build Grid for ray casting */ - /*! Build non-culled Grid in camera space for ray casting */ - void BuildGrid(WingedEdge& we, const BBox& bbox, unsigned int sceneNumFaces); - - /*! Compute Shapes from a WingedEdge containing a list of WShapes */ - void computeInitialViewEdges(WingedEdge&); - - /*! Compute Cusps */ - void computeCusps(ViewMap *ioViewMap); - - /*! Detects cusps (for a single ViewEdge) among SVertices and builds a ViewVertex on top of each cusp SVertex - * We use a hysteresis approach to avoid noise. - */ - void DetectCusps(ViewEdge *ioEdge); - - /*! Sets the current viewpoint */ - inline void setViewpoint(const Vec3r& ivp) - { - _viewpoint = ivp; - SilhouetteGeomEngine::setViewpoint(ivp); - } - - /*! Sets the current transformation - * iModelViewMatrix - * The 4x4 model view matrix, in column major order (openGL like). - * iProjection matrix - * The 4x4 projection matrix, in column major order (openGL like). - * iViewport - * The viewport. 4 real array: origin.x, origin.y, width, length - */ - inline void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], - const int iViewport[4], real iFocalLength, real /*iAspect*/, real /*iFovy*/) - { - _orthographicProjection = (iProjectionMatrix[3][3] != 0.0); - SilhouetteGeomEngine::setTransform(iModelViewMatrix, iProjectionMatrix, iViewport, iFocalLength); - } - - inline void setFrustum(real iZnear, real iZfar) - { - SilhouetteGeomEngine::setFrustum(iZnear, iZfar); - } - - /*! Builds the scene view map returns the list the view map - * it is up to the caller to delete this ViewMap - * iWRoot - * The root group node containing the WEdge structured scene - */ - ViewMap *BuildViewMap(WingedEdge& we, visibility_algo iAlgo, real epsilon, const BBox& bbox, - unsigned int sceneNumFaces); - - void CullViewEdges(ViewMap *ioViewMap, real viewProscenium[4], real occluderProscenium[4], - bool extensiveFEdgeSearch = true); - - /*! computes the intersection between all 2D feature edges of the scene. - * ioViewMap - * The view map. It is modified by the method. - * The list of all features edges of the scene. - * Each time an intersection is found, the 2 intersecting edges are splitted (creating 2 new vertices) - * At the end, this list is updated with the adding of all new created edges (resulting from splitting). - * iAlgo - * The algo to use for computing the intersections - */ - void ComputeIntersections(ViewMap *ioViewMap, intersection_algo iAlgo = sweep_line, real epsilon = 1.0e-06); - - /*! Computes the 2D scene silhouette edges visibility - * iGrid - * For the Ray Casting algorithm. - */ - void ComputeEdgesVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, unsigned int sceneNumFaces, - visibility_algo iAlgo = ray_casting, real epsilon = 1.0e-6); - - void setGrid(Grid *iGrid) - { - _Grid = iGrid; - } - - /*! accessors */ - - /*! Modifiers */ - inline void setProgressBar(ProgressBar *iProgressBar) - { - _pProgressBar = iProgressBar; - } - - inline void setRenderMonitor(RenderMonitor *iRenderMonitor) - { - _pRenderMonitor = iRenderMonitor; - } - - inline void setEnableQI(bool iBool) - { - _EnableQI = iBool; - } - -protected: - /*! Computes intersections on all edges of the scene using a sweep line algorithm */ - void ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsilon = 1.0e-6); - - /*! Computes the 2D scene silhouette edges visibility using a ray casting. On each edge, a ray is cast - * to check its quantitative invisibility. The list of occluders are each time stored in the tested edge. - * ioViewMap - * The view map. - * The 2D scene silhouette edges as FEdges. - * These edges have already been splitted at their intersections points. - * Thus, these edges do not intersect anymore. - * The visibility corresponding to each edge of ioScene is set is this edge. - */ - void ComputeRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); - void ComputeFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); - void ComputeVeryFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); - - void ComputeCumulativeVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, real epsilon, - bool cull, GridDensityProviderFactory& factory); - void ComputeDetailedVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox& bbox, real epsilon, - bool cull, GridDensityProviderFactory& factory); - - /*! Compute the visibility for the FEdge fe. - * The occluders are added to fe occluders list. - * fe - * The FEdge - * iGrid - * The grid used to compute the ray casting visibility - * epsilon - * The epsilon used for computation - * oShapeId - * fe is the border (in 2D) between 2 2D spaces. - * if fe is a silhouette, One of these 2D spaces is occupied by the shape to which fe belongs (on its left) - * and the other one is either occupied by another shape or empty or occupied by the same shape. - * We use this ray csating operation to determine which shape lies on fe's right. - * The result is the shape id stored in oShapeId - */ - int ComputeRayCastingVisibility(FEdge *fe, Grid *iGrid, real epsilon, set& oOccluders, - Polygon3r **oaPolygon, unsigned timestamp); - // FIXME - void FindOccludee(FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp); - void FindOccludee(FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp, - Vec3r& u, Vec3r& A, Vec3r& origin, Vec3r& edgeDir, vector& faceVertices); +class ViewMapBuilder { + private: + ViewMap *_ViewMap; // result + //SilhouetteGeomEngine _GeomEngine; + ProgressBar *_pProgressBar; + RenderMonitor *_pRenderMonitor; + Vec3r _viewpoint; + bool _orthographicProjection; + Grid *_Grid; + ViewEdgeXBuilder *_pViewEdgeBuilder; + bool _EnableQI; + double _epsilon; + + // tmp values: + int _currentId; + int _currentFId; + int _currentSVertexId; + + public: + typedef enum { + sweep_line, + } intersection_algo; + + typedef enum { + ray_casting, + ray_casting_fast, + ray_casting_very_fast, + ray_casting_culled_adaptive_traditional, + ray_casting_adaptive_traditional, + ray_casting_culled_adaptive_cumulative, + ray_casting_adaptive_cumulative, + } visibility_algo; + + inline ViewMapBuilder() + { + _pProgressBar = NULL; + _pRenderMonitor = NULL; + _Grid = NULL; + _currentId = 1; + _currentFId = 0; + _currentSVertexId = 0; + _pViewEdgeBuilder = new ViewEdgeXBuilder; + _EnableQI = true; + } + + inline ~ViewMapBuilder() + { + if (_pViewEdgeBuilder) { + delete _pViewEdgeBuilder; + _pViewEdgeBuilder = NULL; + } + } + + /* Build Grid for ray casting */ + /*! Build non-culled Grid in camera space for ray casting */ + void BuildGrid(WingedEdge &we, const BBox &bbox, unsigned int sceneNumFaces); + + /*! Compute Shapes from a WingedEdge containing a list of WShapes */ + void computeInitialViewEdges(WingedEdge &); + + /*! Compute Cusps */ + void computeCusps(ViewMap *ioViewMap); + + /*! Detects cusps (for a single ViewEdge) among SVertices and builds a ViewVertex on top of each cusp SVertex + * We use a hysteresis approach to avoid noise. + */ + void DetectCusps(ViewEdge *ioEdge); + + /*! Sets the current viewpoint */ + inline void setViewpoint(const Vec3r &ivp) + { + _viewpoint = ivp; + SilhouetteGeomEngine::setViewpoint(ivp); + } + + /*! Sets the current transformation + * iModelViewMatrix + * The 4x4 model view matrix, in column major order (openGL like). + * iProjection matrix + * The 4x4 projection matrix, in column major order (openGL like). + * iViewport + * The viewport. 4 real array: origin.x, origin.y, width, length + */ + inline void setTransform(const real iModelViewMatrix[4][4], + const real iProjectionMatrix[4][4], + const int iViewport[4], + real iFocalLength, + real /*iAspect*/, + real /*iFovy*/) + { + _orthographicProjection = (iProjectionMatrix[3][3] != 0.0); + SilhouetteGeomEngine::setTransform( + iModelViewMatrix, iProjectionMatrix, iViewport, iFocalLength); + } + + inline void setFrustum(real iZnear, real iZfar) + { + SilhouetteGeomEngine::setFrustum(iZnear, iZfar); + } + + /*! Builds the scene view map returns the list the view map + * it is up to the caller to delete this ViewMap + * iWRoot + * The root group node containing the WEdge structured scene + */ + ViewMap *BuildViewMap(WingedEdge &we, + visibility_algo iAlgo, + real epsilon, + const BBox &bbox, + unsigned int sceneNumFaces); + + void CullViewEdges(ViewMap *ioViewMap, + real viewProscenium[4], + real occluderProscenium[4], + bool extensiveFEdgeSearch = true); + + /*! computes the intersection between all 2D feature edges of the scene. + * ioViewMap + * The view map. It is modified by the method. + * The list of all features edges of the scene. + * Each time an intersection is found, the 2 intersecting edges are splitted (creating 2 new vertices) + * At the end, this list is updated with the adding of all new created edges (resulting from splitting). + * iAlgo + * The algo to use for computing the intersections + */ + void ComputeIntersections(ViewMap *ioViewMap, + intersection_algo iAlgo = sweep_line, + real epsilon = 1.0e-06); + + /*! Computes the 2D scene silhouette edges visibility + * iGrid + * For the Ray Casting algorithm. + */ + void ComputeEdgesVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + unsigned int sceneNumFaces, + visibility_algo iAlgo = ray_casting, + real epsilon = 1.0e-6); + + void setGrid(Grid *iGrid) + { + _Grid = iGrid; + } + + /*! accessors */ + + /*! Modifiers */ + inline void setProgressBar(ProgressBar *iProgressBar) + { + _pProgressBar = iProgressBar; + } + + inline void setRenderMonitor(RenderMonitor *iRenderMonitor) + { + _pRenderMonitor = iRenderMonitor; + } + + inline void setEnableQI(bool iBool) + { + _EnableQI = iBool; + } + + protected: + /*! Computes intersections on all edges of the scene using a sweep line algorithm */ + void ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsilon = 1.0e-6); + + /*! Computes the 2D scene silhouette edges visibility using a ray casting. On each edge, a ray is cast + * to check its quantitative invisibility. The list of occluders are each time stored in the tested edge. + * ioViewMap + * The view map. + * The 2D scene silhouette edges as FEdges. + * These edges have already been splitted at their intersections points. + * Thus, these edges do not intersect anymore. + * The visibility corresponding to each edge of ioScene is set is this edge. + */ + void ComputeRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); + void ComputeFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); + void ComputeVeryFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6); + + void ComputeCumulativeVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + real epsilon, + bool cull, + GridDensityProviderFactory &factory); + void ComputeDetailedVisibility(ViewMap *ioViewMap, + WingedEdge &we, + const BBox &bbox, + real epsilon, + bool cull, + GridDensityProviderFactory &factory); + + /*! Compute the visibility for the FEdge fe. + * The occluders are added to fe occluders list. + * fe + * The FEdge + * iGrid + * The grid used to compute the ray casting visibility + * epsilon + * The epsilon used for computation + * oShapeId + * fe is the border (in 2D) between 2 2D spaces. + * if fe is a silhouette, One of these 2D spaces is occupied by the shape to which fe belongs (on its left) + * and the other one is either occupied by another shape or empty or occupied by the same shape. + * We use this ray csating operation to determine which shape lies on fe's right. + * The result is the shape id stored in oShapeId + */ + int ComputeRayCastingVisibility(FEdge *fe, + Grid *iGrid, + real epsilon, + set &oOccluders, + Polygon3r **oaPolygon, + unsigned timestamp); + // FIXME + void FindOccludee( + FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp); + void FindOccludee(FEdge *fe, + Grid *iGrid, + real epsilon, + Polygon3r **oaPolygon, + unsigned timestamp, + Vec3r &u, + Vec3r &A, + Vec3r &origin, + Vec3r &edgeDir, + vector &faceVertices); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapBuilder") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapBuilder") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_BUILDER_H__ +#endif // __FREESTYLE_VIEW_MAP_BUILDER_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewMapIO.cpp b/source/blender/freestyle/intern/view_map/ViewMapIO.cpp index 6a37467a867..65336f593c7 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapIO.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapIO.cpp @@ -31,22 +31,24 @@ # define READ(n) in.read((char *)(&(n)), sizeof((n))) #endif -#define WRITE_IF_NON_NULL(ptr) \ - if (ptr) { \ - WRITE((ptr)->userdata); \ - } \ - else { \ - WRITE(ZERO); \ - } (void)0 +#define WRITE_IF_NON_NULL(ptr) \ + if (ptr) { \ + WRITE((ptr)->userdata); \ + } \ + else { \ + WRITE(ZERO); \ + } \ + (void)0 #define READ_IF_NON_NULL(ptr, array) \ - READ(tmp); \ - if (tmp) { \ - (ptr) = (array)[tmp]; \ - } \ - else { \ - (ptr) = NULL; \ - } (void)0 + READ(tmp); \ + if (tmp) { \ + (ptr) = (array)[tmp]; \ + } \ + else { \ + (ptr) = NULL; \ + } \ + (void)0 namespace Freestyle { @@ -58,1155 +60,1170 @@ static ViewMap *g_vm; //////////////////// 'load' Functions //////////////////// -inline int load(istream& in, Vec3r& v) +inline int load(istream &in, Vec3r &v) { - if (Options::getFlags() & Options::FLOAT_VECTORS) { - float tmp; - READ(tmp); - v[0] = tmp; - READ(tmp); - v[1] = tmp; - READ(tmp); - v[2] = tmp; - } - else { - Vec3r::value_type tmp; - READ(tmp); - v[0] = tmp; - READ(tmp); - v[1] = tmp; - READ(tmp); - v[2] = tmp; - } - return 0; + if (Options::getFlags() & Options::FLOAT_VECTORS) { + float tmp; + READ(tmp); + v[0] = tmp; + READ(tmp); + v[1] = tmp; + READ(tmp); + v[2] = tmp; + } + else { + Vec3r::value_type tmp; + READ(tmp); + v[0] = tmp; + READ(tmp); + v[1] = tmp; + READ(tmp); + v[2] = tmp; + } + return 0; } -inline int load(istream& in, Polygon3r& p) +inline int load(istream &in, Polygon3r &p) { - unsigned tmp; - - // Id - READ(tmp); - p.setId(tmp); - - // vertices (List) - vector tmp_vec; - Vec3r v; - READ(tmp); - for (unsigned int i = 0; i < tmp; i++) { - load(in, v); - tmp_vec.push_back(v); - } - p.setVertices(tmp_vec); - - // min & max - // Already computed (in the SetVertices() method) - - return 0; + unsigned tmp; + + // Id + READ(tmp); + p.setId(tmp); + + // vertices (List) + vector tmp_vec; + Vec3r v; + READ(tmp); + for (unsigned int i = 0; i < tmp; i++) { + load(in, v); + tmp_vec.push_back(v); + } + p.setVertices(tmp_vec); + + // min & max + // Already computed (in the SetVertices() method) + + return 0; } -inline int load(istream& in, FrsMaterial& m) +inline int load(istream &in, FrsMaterial &m) { - float tmp_array[4]; - int i; - - // Diffuse - for (i = 0; i < 4; i++) - READ(tmp_array[i]); - m.setDiffuse(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); - - // Specular - for (i = 0; i < 4; i++) - READ(tmp_array[i]); - m.setSpecular(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); - - // Ambient - for (i = 0; i < 4; i++) - READ(tmp_array[i]); - m.setAmbient(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); - - // Emission - for (i = 0; i < 4; i++) - READ(tmp_array[i]); - m.setEmission(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); - - // Shininess - READ(tmp_array[0]); - m.setShininess(tmp_array[0]); - - return 0; + float tmp_array[4]; + int i; + + // Diffuse + for (i = 0; i < 4; i++) + READ(tmp_array[i]); + m.setDiffuse(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); + + // Specular + for (i = 0; i < 4; i++) + READ(tmp_array[i]); + m.setSpecular(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); + + // Ambient + for (i = 0; i < 4; i++) + READ(tmp_array[i]); + m.setAmbient(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); + + // Emission + for (i = 0; i < 4; i++) + READ(tmp_array[i]); + m.setEmission(tmp_array[0], tmp_array[1], tmp_array[2], tmp_array[3]); + + // Shininess + READ(tmp_array[0]); + m.setShininess(tmp_array[0]); + + return 0; } -static int load(istream& in, ViewShape *vs) +static int load(istream &in, ViewShape *vs) { - if (!vs || !vs->sshape()) - return 1; - - // SShape - - // -> Id - Id::id_type id1, id2; - READ(id1); - READ(id2); - vs->sshape()->setId(Id(id1, id2)); - - // -> Importance - float importance; - READ(importance); - vs->sshape()->setImportance(importance); - - // -> BBox - // Not necessary (only used during view map computatiom) - - unsigned i, size, tmp; - - // -> Material - READ(size); - vector frs_materials; - FrsMaterial m; - for (i = 0; i < size; ++i) { - load(in, m); - frs_materials.push_back(m); - } - vs->sshape()->setFrsMaterials(frs_materials); - - // -> VerticesList (List) - READ(size); - for (i = 0; i < size; i++) { - SVertex *sv; - READ_IF_NON_NULL(sv, g_vm->SVertices()); - vs->sshape()->AddNewVertex(sv); - } - - // -> Chains (List) - READ(size); - for (i = 0; i < size; i++) { - FEdge *fe; - READ_IF_NON_NULL(fe, g_vm->FEdges()); - vs->sshape()->AddChain(fe); - } - - // -> EdgesList (List) - READ(size); - for (i = 0; i < size; i++) { - FEdge *fe; - READ_IF_NON_NULL(fe, g_vm->FEdges()); - vs->sshape()->AddEdge(fe); - } - - // ViewEdges (List) - READ(size); - for (i = 0; i < size; i++) { - ViewEdge *ve; - READ_IF_NON_NULL(ve, g_vm->ViewEdges()); - vs->AddEdge(ve); - } - - // ViewVertices (List) - READ(size); - for (i = 0; i < size; i++) { - ViewVertex *vv; - READ_IF_NON_NULL(vv, g_vm->ViewVertices()); - vs->AddVertex(vv); - } - - return 0; + if (!vs || !vs->sshape()) + return 1; + + // SShape + + // -> Id + Id::id_type id1, id2; + READ(id1); + READ(id2); + vs->sshape()->setId(Id(id1, id2)); + + // -> Importance + float importance; + READ(importance); + vs->sshape()->setImportance(importance); + + // -> BBox + // Not necessary (only used during view map computatiom) + + unsigned i, size, tmp; + + // -> Material + READ(size); + vector frs_materials; + FrsMaterial m; + for (i = 0; i < size; ++i) { + load(in, m); + frs_materials.push_back(m); + } + vs->sshape()->setFrsMaterials(frs_materials); + + // -> VerticesList (List) + READ(size); + for (i = 0; i < size; i++) { + SVertex *sv; + READ_IF_NON_NULL(sv, g_vm->SVertices()); + vs->sshape()->AddNewVertex(sv); + } + + // -> Chains (List) + READ(size); + for (i = 0; i < size; i++) { + FEdge *fe; + READ_IF_NON_NULL(fe, g_vm->FEdges()); + vs->sshape()->AddChain(fe); + } + + // -> EdgesList (List) + READ(size); + for (i = 0; i < size; i++) { + FEdge *fe; + READ_IF_NON_NULL(fe, g_vm->FEdges()); + vs->sshape()->AddEdge(fe); + } + + // ViewEdges (List) + READ(size); + for (i = 0; i < size; i++) { + ViewEdge *ve; + READ_IF_NON_NULL(ve, g_vm->ViewEdges()); + vs->AddEdge(ve); + } + + // ViewVertices (List) + READ(size); + for (i = 0; i < size; i++) { + ViewVertex *vv; + READ_IF_NON_NULL(vv, g_vm->ViewVertices()); + vs->AddVertex(vv); + } + + return 0; } - -static int load(istream& in, FEdge *fe) +static int load(istream &in, FEdge *fe) { - if (!fe) - return 1; - - bool b; - - FEdgeSmooth *fesmooth = NULL; - FEdgeSharp *fesharp = NULL; - if (fe->isSmooth()) { - fesmooth = dynamic_cast(fe); - } - else { - fesharp = dynamic_cast(fe); - } - - // Id - Id::id_type id1, id2; - READ(id1); - READ(id2); - fe->setId(Id(id1, id2)); - - // Nature - Nature::EdgeNature nature; - READ(nature); - fe->setNature(nature); - -#if 0 // hasVisibilityPoint - bool b; - READ(b); - fe->setHasVisibilityPoint(b); + if (!fe) + return 1; + + bool b; + + FEdgeSmooth *fesmooth = NULL; + FEdgeSharp *fesharp = NULL; + if (fe->isSmooth()) { + fesmooth = dynamic_cast(fe); + } + else { + fesharp = dynamic_cast(fe); + } + + // Id + Id::id_type id1, id2; + READ(id1); + READ(id2); + fe->setId(Id(id1, id2)); + + // Nature + Nature::EdgeNature nature; + READ(nature); + fe->setNature(nature); + +#if 0 // hasVisibilityPoint + bool b; + READ(b); + fe->setHasVisibilityPoint(b); #endif - Vec3r v; - unsigned int matindex; + Vec3r v; + unsigned int matindex; #if 0 - // VisibilityPointA - load(in, v); - fe->setVisibilityPointA(v); + // VisibilityPointA + load(in, v); + fe->setVisibilityPointA(v); - // VisibilityPointB - load(in, v); - fe->setVisibilityPointB(v); + // VisibilityPointB + load(in, v); + fe->setVisibilityPointB(v); #endif - if (fe->isSmooth()) { - // Normal - load(in, v); - fesmooth->setNormal(v); - - // Material - READ(matindex); - fesmooth->setFrsMaterialIndex(matindex); - } - else { - // aNormal - load(in, v); - fesharp->setNormalA(v); - - // bNormal - load(in, v); - fesharp->setNormalB(v); - - // Materials - READ(matindex); - fesharp->setaFrsMaterialIndex(matindex); - READ(matindex); - fesharp->setbFrsMaterialIndex(matindex); - } - - unsigned tmp; - - // VertexA - SVertex *sva; - READ_IF_NON_NULL(sva, g_vm->SVertices()); - fe->setVertexA(sva); - - // VertexB - SVertex *svb; - READ_IF_NON_NULL(svb, g_vm->SVertices()); - fe->setVertexB(svb); - - // NextEdge - FEdge *nfe; - READ_IF_NON_NULL(nfe, g_vm->FEdges()); - fe->setNextEdge(nfe); - - // PreviousEdge - FEdge *pfe; - READ_IF_NON_NULL(pfe, g_vm->FEdges()); - fe->setPreviousEdge(pfe); - - // ViewEdge - ViewEdge *ve; - READ_IF_NON_NULL(ve, g_vm->ViewEdges()); - fe->setViewEdge(ve); - - // Face - // Not necessary (only used during view map computatiom) - - Polygon3r p; - - // aFace - load(in, p); - fe->setaFace(p); - - // occludeeEmpty - READ(b); - fe->setOccludeeEmpty(b); - - // occludeeIntersection - load(in, v); - fe->setOccludeeIntersection(v); - - return 0; + if (fe->isSmooth()) { + // Normal + load(in, v); + fesmooth->setNormal(v); + + // Material + READ(matindex); + fesmooth->setFrsMaterialIndex(matindex); + } + else { + // aNormal + load(in, v); + fesharp->setNormalA(v); + + // bNormal + load(in, v); + fesharp->setNormalB(v); + + // Materials + READ(matindex); + fesharp->setaFrsMaterialIndex(matindex); + READ(matindex); + fesharp->setbFrsMaterialIndex(matindex); + } + + unsigned tmp; + + // VertexA + SVertex *sva; + READ_IF_NON_NULL(sva, g_vm->SVertices()); + fe->setVertexA(sva); + + // VertexB + SVertex *svb; + READ_IF_NON_NULL(svb, g_vm->SVertices()); + fe->setVertexB(svb); + + // NextEdge + FEdge *nfe; + READ_IF_NON_NULL(nfe, g_vm->FEdges()); + fe->setNextEdge(nfe); + + // PreviousEdge + FEdge *pfe; + READ_IF_NON_NULL(pfe, g_vm->FEdges()); + fe->setPreviousEdge(pfe); + + // ViewEdge + ViewEdge *ve; + READ_IF_NON_NULL(ve, g_vm->ViewEdges()); + fe->setViewEdge(ve); + + // Face + // Not necessary (only used during view map computatiom) + + Polygon3r p; + + // aFace + load(in, p); + fe->setaFace(p); + + // occludeeEmpty + READ(b); + fe->setOccludeeEmpty(b); + + // occludeeIntersection + load(in, v); + fe->setOccludeeIntersection(v); + + return 0; } -static int load(istream& in, SVertex *sv) +static int load(istream &in, SVertex *sv) { - if (!sv) - return 1; - - // Id - Id::id_type id1, id2; - READ(id1); - READ(id2); - sv->setId(Id(id1, id2)); - - Vec3r v; - - // Point3D - load(in, v); - sv->setPoint3D(v); - - // Point2D - load(in, v); - sv->setPoint2D(v); - - unsigned tmp; - - // Shape - ViewShape *vs; - READ_IF_NON_NULL(vs, g_vm->ViewShapes()); - sv->setShape(vs->sshape()); - - // pViewVertex - ViewVertex *vv; - READ_IF_NON_NULL(vv, g_vm->ViewVertices()); - sv->setViewVertex(vv); - - unsigned i, size; - - // Normals (List) - READ(size); - for (i = 0; i < size; i++) { - load(in, v); - sv->AddNormal(v); - } - - // FEdges (List) - READ(size); - FEdge *fe; - for (i = 0; i < size; i++) { - READ_IF_NON_NULL(fe, g_vm->FEdges()); - sv->AddFEdge(fe); - } - - return 0; + if (!sv) + return 1; + + // Id + Id::id_type id1, id2; + READ(id1); + READ(id2); + sv->setId(Id(id1, id2)); + + Vec3r v; + + // Point3D + load(in, v); + sv->setPoint3D(v); + + // Point2D + load(in, v); + sv->setPoint2D(v); + + unsigned tmp; + + // Shape + ViewShape *vs; + READ_IF_NON_NULL(vs, g_vm->ViewShapes()); + sv->setShape(vs->sshape()); + + // pViewVertex + ViewVertex *vv; + READ_IF_NON_NULL(vv, g_vm->ViewVertices()); + sv->setViewVertex(vv); + + unsigned i, size; + + // Normals (List) + READ(size); + for (i = 0; i < size; i++) { + load(in, v); + sv->AddNormal(v); + } + + // FEdges (List) + READ(size); + FEdge *fe; + for (i = 0; i < size; i++) { + READ_IF_NON_NULL(fe, g_vm->FEdges()); + sv->AddFEdge(fe); + } + + return 0; } - -static int load(istream& in, ViewEdge *ve) +static int load(istream &in, ViewEdge *ve) { - if (!ve) - return 1; - - unsigned tmp; - - // Id - Id::id_type id1, id2; - READ(id1); - READ(id2); - ve->setId(Id(id1, id2)); - - // Nature - Nature::EdgeNature nature; - READ(nature); - ve->setNature(nature); - - // QI - READ(tmp); - ve->setQI(tmp); - - // Shape - ViewShape *vs; - READ_IF_NON_NULL(vs, g_vm->ViewShapes()); - ve->setShape(vs); - - // aShape - ViewShape *avs; - READ_IF_NON_NULL(avs, g_vm->ViewShapes()); - ve->setaShape(avs); - - // FEdgeA - FEdge *fea; - READ_IF_NON_NULL(fea, g_vm->FEdges()); - ve->setFEdgeA(fea); - - // FEdgeB - FEdge *feb; - READ_IF_NON_NULL(feb, g_vm->FEdges()); - ve->setFEdgeB(feb); - - // A - ViewVertex *vva; - READ_IF_NON_NULL(vva, g_vm->ViewVertices()); - ve->setA(vva); - - // B - ViewVertex *vvb; - READ_IF_NON_NULL(vvb, g_vm->ViewVertices()); - ve->setB(vvb); - - // Occluders (List) - if (!(Options::getFlags() & Options::NO_OCCLUDERS)) { - unsigned size; - READ(size); - ViewShape *vso; - for (unsigned int i = 0; i < size; i++) { - READ_IF_NON_NULL(vso, g_vm->ViewShapes()); - ve->AddOccluder(vso); - } - } - - return 0; + if (!ve) + return 1; + + unsigned tmp; + + // Id + Id::id_type id1, id2; + READ(id1); + READ(id2); + ve->setId(Id(id1, id2)); + + // Nature + Nature::EdgeNature nature; + READ(nature); + ve->setNature(nature); + + // QI + READ(tmp); + ve->setQI(tmp); + + // Shape + ViewShape *vs; + READ_IF_NON_NULL(vs, g_vm->ViewShapes()); + ve->setShape(vs); + + // aShape + ViewShape *avs; + READ_IF_NON_NULL(avs, g_vm->ViewShapes()); + ve->setaShape(avs); + + // FEdgeA + FEdge *fea; + READ_IF_NON_NULL(fea, g_vm->FEdges()); + ve->setFEdgeA(fea); + + // FEdgeB + FEdge *feb; + READ_IF_NON_NULL(feb, g_vm->FEdges()); + ve->setFEdgeB(feb); + + // A + ViewVertex *vva; + READ_IF_NON_NULL(vva, g_vm->ViewVertices()); + ve->setA(vva); + + // B + ViewVertex *vvb; + READ_IF_NON_NULL(vvb, g_vm->ViewVertices()); + ve->setB(vvb); + + // Occluders (List) + if (!(Options::getFlags() & Options::NO_OCCLUDERS)) { + unsigned size; + READ(size); + ViewShape *vso; + for (unsigned int i = 0; i < size; i++) { + READ_IF_NON_NULL(vso, g_vm->ViewShapes()); + ve->AddOccluder(vso); + } + } + + return 0; } - -static int load(istream& in, ViewVertex *vv) +static int load(istream &in, ViewVertex *vv) { - if (!vv) - return 1; - - unsigned tmp; - bool b; - - // Nature - Nature::VertexNature nature; - READ(nature); - vv->setNature(nature); - - if (vv->getNature() & Nature::T_VERTEX) { - TVertex *tv = dynamic_cast(vv); - - // Id - Id::id_type id1, id2; - READ(id1); - READ(id2); - tv->setId(Id(id1, id2)); - - // FrontSVertex - SVertex *fsv; - READ_IF_NON_NULL(fsv, g_vm->SVertices()); - tv->setFrontSVertex(fsv); - - // BackSVertex - SVertex *bsv; - READ_IF_NON_NULL(bsv, g_vm->SVertices()); - tv->setBackSVertex(bsv); - - // FrontEdgeA - ViewEdge *fea; - READ_IF_NON_NULL(fea, g_vm->ViewEdges()); - READ(b); - tv->setFrontEdgeA(fea, b); - - // FrontEdgeB - ViewEdge *feb; - READ_IF_NON_NULL(feb, g_vm->ViewEdges()); - READ(b); - tv->setFrontEdgeB(feb, b); - - // BackEdgeA - ViewEdge *bea; - READ_IF_NON_NULL(bea, g_vm->ViewEdges()); - READ(b); - tv->setBackEdgeA(bea, b); - - // BackEdgeB - ViewEdge *beb; - READ_IF_NON_NULL(beb, g_vm->ViewEdges()); - READ(b); - tv->setBackEdgeB(beb, b); - } - else if (vv->getNature() & Nature::NON_T_VERTEX) { - NonTVertex *ntv = dynamic_cast(vv); - - // SVertex - SVertex *sv; - READ_IF_NON_NULL(sv, g_vm->SVertices()); - ntv->setSVertex(sv); - - // ViewEdges (List) - unsigned size; - READ(size); - ViewEdge *ve; - for (unsigned int i = 0; i < size; i++) { - READ_IF_NON_NULL(ve, g_vm->ViewEdges()); - READ(b); - ntv->AddViewEdge(ve, b); - } - } - - return 0; + if (!vv) + return 1; + + unsigned tmp; + bool b; + + // Nature + Nature::VertexNature nature; + READ(nature); + vv->setNature(nature); + + if (vv->getNature() & Nature::T_VERTEX) { + TVertex *tv = dynamic_cast(vv); + + // Id + Id::id_type id1, id2; + READ(id1); + READ(id2); + tv->setId(Id(id1, id2)); + + // FrontSVertex + SVertex *fsv; + READ_IF_NON_NULL(fsv, g_vm->SVertices()); + tv->setFrontSVertex(fsv); + + // BackSVertex + SVertex *bsv; + READ_IF_NON_NULL(bsv, g_vm->SVertices()); + tv->setBackSVertex(bsv); + + // FrontEdgeA + ViewEdge *fea; + READ_IF_NON_NULL(fea, g_vm->ViewEdges()); + READ(b); + tv->setFrontEdgeA(fea, b); + + // FrontEdgeB + ViewEdge *feb; + READ_IF_NON_NULL(feb, g_vm->ViewEdges()); + READ(b); + tv->setFrontEdgeB(feb, b); + + // BackEdgeA + ViewEdge *bea; + READ_IF_NON_NULL(bea, g_vm->ViewEdges()); + READ(b); + tv->setBackEdgeA(bea, b); + + // BackEdgeB + ViewEdge *beb; + READ_IF_NON_NULL(beb, g_vm->ViewEdges()); + READ(b); + tv->setBackEdgeB(beb, b); + } + else if (vv->getNature() & Nature::NON_T_VERTEX) { + NonTVertex *ntv = dynamic_cast(vv); + + // SVertex + SVertex *sv; + READ_IF_NON_NULL(sv, g_vm->SVertices()); + ntv->setSVertex(sv); + + // ViewEdges (List) + unsigned size; + READ(size); + ViewEdge *ve; + for (unsigned int i = 0; i < size; i++) { + READ_IF_NON_NULL(ve, g_vm->ViewEdges()); + READ(b); + ntv->AddViewEdge(ve, b); + } + } + + return 0; } //////////////////// 'save' Functions //////////////////// -inline int save(ostream& out, const Vec3r& v) +inline int save(ostream &out, const Vec3r &v) { - if (Options::getFlags() & Options::FLOAT_VECTORS) { - float tmp; - - tmp = v[0]; - WRITE(tmp); - tmp = v[1]; - WRITE(tmp); - tmp = v[2]; - WRITE(tmp); - } - else { - Vec3r::value_type tmp; - - tmp = v[0]; - WRITE(tmp); - tmp = v[1]; - WRITE(tmp); - tmp = v[2]; - WRITE(tmp); - } - return 0; + if (Options::getFlags() & Options::FLOAT_VECTORS) { + float tmp; + + tmp = v[0]; + WRITE(tmp); + tmp = v[1]; + WRITE(tmp); + tmp = v[2]; + WRITE(tmp); + } + else { + Vec3r::value_type tmp; + + tmp = v[0]; + WRITE(tmp); + tmp = v[1]; + WRITE(tmp); + tmp = v[2]; + WRITE(tmp); + } + return 0; } - -inline int save(ostream& out, const Polygon3r& p) +inline int save(ostream &out, const Polygon3r &p) { - unsigned tmp; + unsigned tmp; - // Id - tmp = p.getId(); - WRITE(tmp); + // Id + tmp = p.getId(); + WRITE(tmp); - // vertices (List) - tmp = p.getVertices().size(); - WRITE(tmp); - for (vector::const_iterator i = p.getVertices().begin(); i != p.getVertices().end(); i++) { - save(out, *i); - } + // vertices (List) + tmp = p.getVertices().size(); + WRITE(tmp); + for (vector::const_iterator i = p.getVertices().begin(); i != p.getVertices().end(); + i++) { + save(out, *i); + } - // min & max - // Do not need to be saved + // min & max + // Do not need to be saved - return 0; + return 0; } -inline int save(ostream& out, const FrsMaterial& m) +inline int save(ostream &out, const FrsMaterial &m) { - unsigned i; + unsigned i; - // Diffuse - for (i = 0; i < 4; i++) - WRITE(m.diffuse()[i]); + // Diffuse + for (i = 0; i < 4; i++) + WRITE(m.diffuse()[i]); - // Specular - for (i = 0; i < 4; i++) - WRITE(m.specular()[i]); + // Specular + for (i = 0; i < 4; i++) + WRITE(m.specular()[i]); - // Ambient - for (i = 0; i < 4; i++) - WRITE(m.ambient()[i]); + // Ambient + for (i = 0; i < 4; i++) + WRITE(m.ambient()[i]); - // Emission - for (i = 0; i < 4; i++) - WRITE(m.emission()[i]); + // Emission + for (i = 0; i < 4; i++) + WRITE(m.emission()[i]); - // Shininess - float shininess = m.shininess(); - WRITE(shininess); + // Shininess + float shininess = m.shininess(); + WRITE(shininess); - return 0; + return 0; } -static int save(ostream& out, ViewShape *vs) +static int save(ostream &out, ViewShape *vs) { - if (!vs || !vs->sshape()) { - cerr << "Warning: null ViewShape" << endl; - return 1; - } - - unsigned tmp; - - // SShape - - // -> Id - Id::id_type id = vs->sshape()->getId().getFirst(); - WRITE(id); - id = vs->sshape()->getId().getSecond(); - WRITE(id); - - // -> Importance - float importance = vs->sshape()->importance(); - WRITE(importance); - - // -> BBox - // Not necessary (only used during view map computatiom) - - // -> Material - unsigned int size = vs->sshape()->frs_materials().size(); - WRITE(size); - for (unsigned int i = 0; i < size; ++i) - save(out, vs->sshape()->frs_material(i)); - - // -> VerticesList (List) - tmp = vs->sshape()->getVertexList().size(); - WRITE(tmp); - for (vector::const_iterator i1 = vs->sshape()->getVertexList().begin(); - i1 != vs->sshape()->getVertexList().end(); - i1++) - { - WRITE_IF_NON_NULL(*i1); - } - - // -> Chains (List) - tmp = vs->sshape()->getChains().size(); - WRITE(tmp); - for (vector::const_iterator i2 = vs->sshape()->getChains().begin(); - i2 != vs->sshape()->getChains().end(); - i2++) - { - WRITE_IF_NON_NULL(*i2); - } - - // -> EdgesList (List) - tmp = vs->sshape()->getEdgeList().size(); - WRITE(tmp); - for (vector::const_iterator i3 = vs->sshape()->getEdgeList().begin(); - i3 != vs->sshape()->getEdgeList().end(); - i3++) - { - WRITE_IF_NON_NULL(*i3); - } - - // ViewEdges (List) - tmp = vs->edges().size(); - WRITE(tmp); - for (vector::const_iterator i4 = vs->edges().begin(); i4 != vs->edges().end(); i4++) { - WRITE_IF_NON_NULL(*i4); - } - - // ViewVertices (List) - tmp = vs->vertices().size(); - WRITE(tmp); - for (vector::const_iterator i5 = vs->vertices().begin(); i5 != vs->vertices().end(); i5++) { - WRITE_IF_NON_NULL(*i5); - } - - return 0; + if (!vs || !vs->sshape()) { + cerr << "Warning: null ViewShape" << endl; + return 1; + } + + unsigned tmp; + + // SShape + + // -> Id + Id::id_type id = vs->sshape()->getId().getFirst(); + WRITE(id); + id = vs->sshape()->getId().getSecond(); + WRITE(id); + + // -> Importance + float importance = vs->sshape()->importance(); + WRITE(importance); + + // -> BBox + // Not necessary (only used during view map computatiom) + + // -> Material + unsigned int size = vs->sshape()->frs_materials().size(); + WRITE(size); + for (unsigned int i = 0; i < size; ++i) + save(out, vs->sshape()->frs_material(i)); + + // -> VerticesList (List) + tmp = vs->sshape()->getVertexList().size(); + WRITE(tmp); + for (vector::const_iterator i1 = vs->sshape()->getVertexList().begin(); + i1 != vs->sshape()->getVertexList().end(); + i1++) { + WRITE_IF_NON_NULL(*i1); + } + + // -> Chains (List) + tmp = vs->sshape()->getChains().size(); + WRITE(tmp); + for (vector::const_iterator i2 = vs->sshape()->getChains().begin(); + i2 != vs->sshape()->getChains().end(); + i2++) { + WRITE_IF_NON_NULL(*i2); + } + + // -> EdgesList (List) + tmp = vs->sshape()->getEdgeList().size(); + WRITE(tmp); + for (vector::const_iterator i3 = vs->sshape()->getEdgeList().begin(); + i3 != vs->sshape()->getEdgeList().end(); + i3++) { + WRITE_IF_NON_NULL(*i3); + } + + // ViewEdges (List) + tmp = vs->edges().size(); + WRITE(tmp); + for (vector::const_iterator i4 = vs->edges().begin(); i4 != vs->edges().end(); + i4++) { + WRITE_IF_NON_NULL(*i4); + } + + // ViewVertices (List) + tmp = vs->vertices().size(); + WRITE(tmp); + for (vector::const_iterator i5 = vs->vertices().begin(); + i5 != vs->vertices().end(); + i5++) { + WRITE_IF_NON_NULL(*i5); + } + + return 0; } - -static int save(ostream& out, FEdge *fe) +static int save(ostream &out, FEdge *fe) { - if (!fe) { - cerr << "Warning: null FEdge" << endl; - return 1; - } + if (!fe) { + cerr << "Warning: null FEdge" << endl; + return 1; + } - FEdgeSmooth *fesmooth = dynamic_cast(fe); - FEdgeSharp *fesharp = dynamic_cast(fe); + FEdgeSmooth *fesmooth = dynamic_cast(fe); + FEdgeSharp *fesharp = dynamic_cast(fe); - // Id - Id::id_type id = fe->getId().getFirst(); - WRITE(id); - id = fe->getId().getSecond(); - WRITE(id); + // Id + Id::id_type id = fe->getId().getFirst(); + WRITE(id); + id = fe->getId().getSecond(); + WRITE(id); - // Nature - Nature::EdgeNature nature = fe->getNature(); - WRITE(nature); + // Nature + Nature::EdgeNature nature = fe->getNature(); + WRITE(nature); - bool b; + bool b; #if 0 - // hasVisibilityPoint - b = fe->hasVisibilityPoint(); - WRITE(b); + // hasVisibilityPoint + b = fe->hasVisibilityPoint(); + WRITE(b); - // VisibilityPointA - save(out, fe->visibilityPointA()); + // VisibilityPointA + save(out, fe->visibilityPointA()); - // VisibilityPointB - save(out, fe->visibilityPointB()); + // VisibilityPointB + save(out, fe->visibilityPointB()); #endif - unsigned index; - if (fe->isSmooth()) { - // normal - save(out, fesmooth->normal()); - // material - index = fesmooth->frs_materialIndex(); - WRITE(index); - } - else { - // aNormal - save(out, fesharp->normalA()); - // bNormal - save(out, fesharp->normalB()); - // aMaterial - index = fesharp->aFrsMaterialIndex(); - WRITE(index); - // bMaterial - index = fesharp->bFrsMaterialIndex(); - WRITE(index); - } - - // VertexA - WRITE_IF_NON_NULL(fe->vertexA()); - - // VertexB - WRITE_IF_NON_NULL(fe->vertexB()); - - // NextEdge - WRITE_IF_NON_NULL(fe->nextEdge()); - - // PreviousEdge - WRITE_IF_NON_NULL(fe->previousEdge()); - - // ViewEdge - WRITE_IF_NON_NULL(fe->viewedge()); - - // Face - // Not necessary (only used during view map computatiom) - - // aFace - save(out, (Polygon3r&)fe->aFace()); - - // occludeeEmpty - b = fe->getOccludeeEmpty(); - WRITE(b); - - // occludeeIntersection - save(out, fe->getOccludeeIntersection()); - - return 0; + unsigned index; + if (fe->isSmooth()) { + // normal + save(out, fesmooth->normal()); + // material + index = fesmooth->frs_materialIndex(); + WRITE(index); + } + else { + // aNormal + save(out, fesharp->normalA()); + // bNormal + save(out, fesharp->normalB()); + // aMaterial + index = fesharp->aFrsMaterialIndex(); + WRITE(index); + // bMaterial + index = fesharp->bFrsMaterialIndex(); + WRITE(index); + } + + // VertexA + WRITE_IF_NON_NULL(fe->vertexA()); + + // VertexB + WRITE_IF_NON_NULL(fe->vertexB()); + + // NextEdge + WRITE_IF_NON_NULL(fe->nextEdge()); + + // PreviousEdge + WRITE_IF_NON_NULL(fe->previousEdge()); + + // ViewEdge + WRITE_IF_NON_NULL(fe->viewedge()); + + // Face + // Not necessary (only used during view map computatiom) + + // aFace + save(out, (Polygon3r &)fe->aFace()); + + // occludeeEmpty + b = fe->getOccludeeEmpty(); + WRITE(b); + + // occludeeIntersection + save(out, fe->getOccludeeIntersection()); + + return 0; } -static int save(ostream& out, SVertex *sv) +static int save(ostream &out, SVertex *sv) { - if (!sv) { - cerr << "Warning: null SVertex" << endl; - return 1; - } - - unsigned tmp; - - // Id - Id::id_type id = sv->getId().getFirst(); - WRITE(id); - id = sv->getId().getSecond(); - WRITE(id); - - Vec3r v; - - // Point3D - v = sv->point3D(); - save(out, sv->point3D()); - - // Point2D - v = sv->point2D(); - save(out, v); - - // Shape - WRITE_IF_NON_NULL(sv->shape()); - - // pViewVertex - WRITE_IF_NON_NULL(sv->viewvertex()); - - // Normals (List) - // Note: the 'size()' method of a set doesn't seem to return the actual size of the given set, so we have to - // hack it... - set::const_iterator i; - for (i = sv->normals().begin(), tmp = 0; i != sv->normals().end(); i++, tmp++); - WRITE(tmp); - for (i = sv->normals().begin(); i != sv->normals().end(); i++) - save(out, *i); - - // FEdges (List) - tmp = sv->fedges().size(); - WRITE(tmp); - for (vector::const_iterator j = sv->fedges_begin(); j != sv->fedges_end(); j++) { - WRITE_IF_NON_NULL(*j); - } - - return 0; + if (!sv) { + cerr << "Warning: null SVertex" << endl; + return 1; + } + + unsigned tmp; + + // Id + Id::id_type id = sv->getId().getFirst(); + WRITE(id); + id = sv->getId().getSecond(); + WRITE(id); + + Vec3r v; + + // Point3D + v = sv->point3D(); + save(out, sv->point3D()); + + // Point2D + v = sv->point2D(); + save(out, v); + + // Shape + WRITE_IF_NON_NULL(sv->shape()); + + // pViewVertex + WRITE_IF_NON_NULL(sv->viewvertex()); + + // Normals (List) + // Note: the 'size()' method of a set doesn't seem to return the actual size of the given set, so we have to + // hack it... + set::const_iterator i; + for (i = sv->normals().begin(), tmp = 0; i != sv->normals().end(); i++, tmp++) + ; + WRITE(tmp); + for (i = sv->normals().begin(); i != sv->normals().end(); i++) + save(out, *i); + + // FEdges (List) + tmp = sv->fedges().size(); + WRITE(tmp); + for (vector::const_iterator j = sv->fedges_begin(); j != sv->fedges_end(); j++) { + WRITE_IF_NON_NULL(*j); + } + + return 0; } - -static int save(ostream& out, ViewEdge *ve) +static int save(ostream &out, ViewEdge *ve) { - if (!ve) { - cerr << "Warning: null ViewEdge" << endl; - return 1; - } + if (!ve) { + cerr << "Warning: null ViewEdge" << endl; + return 1; + } - unsigned tmp; + unsigned tmp; - // Id - Id::id_type id = ve->getId().getFirst(); - WRITE(id); - id = ve->getId().getSecond(); - WRITE(id); + // Id + Id::id_type id = ve->getId().getFirst(); + WRITE(id); + id = ve->getId().getSecond(); + WRITE(id); - // Nature - Nature::EdgeNature nature = ve->getNature(); - WRITE(nature); + // Nature + Nature::EdgeNature nature = ve->getNature(); + WRITE(nature); - // QI - unsigned qi = ve->qi(); - WRITE(qi); + // QI + unsigned qi = ve->qi(); + WRITE(qi); - // Shape - WRITE_IF_NON_NULL(ve->shape()); + // Shape + WRITE_IF_NON_NULL(ve->shape()); - // aShape - WRITE_IF_NON_NULL(ve->aShape()); + // aShape + WRITE_IF_NON_NULL(ve->aShape()); - // FEdgeA - WRITE_IF_NON_NULL(ve->fedgeA()); + // FEdgeA + WRITE_IF_NON_NULL(ve->fedgeA()); - // FEdgeB - WRITE_IF_NON_NULL(ve->fedgeB()); + // FEdgeB + WRITE_IF_NON_NULL(ve->fedgeB()); - // A - WRITE_IF_NON_NULL(ve->A()); + // A + WRITE_IF_NON_NULL(ve->A()); - // B - WRITE_IF_NON_NULL(ve->B()); + // B + WRITE_IF_NON_NULL(ve->B()); - // Occluders (List) - if (!(Options::getFlags() & Options::NO_OCCLUDERS)) { - tmp = ve->occluders().size(); - WRITE(tmp); - for (vector::const_iterator i = ve->occluders().begin(); i != ve->occluders().end(); i++) { - WRITE_IF_NON_NULL((*i)); - } - } + // Occluders (List) + if (!(Options::getFlags() & Options::NO_OCCLUDERS)) { + tmp = ve->occluders().size(); + WRITE(tmp); + for (vector::const_iterator i = ve->occluders().begin(); + i != ve->occluders().end(); + i++) { + WRITE_IF_NON_NULL((*i)); + } + } - return 0; + return 0; } - -static int save(ostream& out, ViewVertex *vv) +static int save(ostream &out, ViewVertex *vv) { - if (!vv) { - cerr << "Warning: null ViewVertex" << endl; - return 1; - } - - // Nature - Nature::VertexNature nature = vv->getNature(); - WRITE(nature); - - if (vv->getNature() & Nature::T_VERTEX) { - TVertex *tv = dynamic_cast(vv); - - // Id - Id::id_type id = tv->getId().getFirst(); - WRITE(id); - id = tv->getId().getSecond(); - WRITE(id); - - // FrontSVertex - WRITE_IF_NON_NULL(tv->frontSVertex()); - - // BackSVertex - WRITE_IF_NON_NULL(tv->backSVertex()); - - // FrontEdgeA - WRITE_IF_NON_NULL(tv->frontEdgeA().first); - WRITE(tv->frontEdgeA().second); - - // FrontEdgeB - WRITE_IF_NON_NULL(tv->frontEdgeB().first); - WRITE(tv->frontEdgeB().second); - - // BackEdgeA - WRITE_IF_NON_NULL(tv->backEdgeA().first); - WRITE(tv->backEdgeA().second); - - // BackEdgeB - WRITE_IF_NON_NULL(tv->backEdgeB().first); - WRITE(tv->backEdgeB().second); - } - else if (vv->getNature() & Nature::NON_T_VERTEX) { - NonTVertex *ntv = dynamic_cast(vv); - - // SVertex - WRITE_IF_NON_NULL(ntv->svertex()); - - // ViewEdges (List) - unsigned size = ntv->viewedges().size(); - WRITE(size); - vector::const_iterator i = ntv->viewedges().begin(); - for (; i != ntv->viewedges().end(); i++) { - WRITE_IF_NON_NULL(i->first); - WRITE(i->second); - } - } - else { - cerr << "Warning: unexpected ViewVertex nature" << endl; - return 1; - } - - return 0; + if (!vv) { + cerr << "Warning: null ViewVertex" << endl; + return 1; + } + + // Nature + Nature::VertexNature nature = vv->getNature(); + WRITE(nature); + + if (vv->getNature() & Nature::T_VERTEX) { + TVertex *tv = dynamic_cast(vv); + + // Id + Id::id_type id = tv->getId().getFirst(); + WRITE(id); + id = tv->getId().getSecond(); + WRITE(id); + + // FrontSVertex + WRITE_IF_NON_NULL(tv->frontSVertex()); + + // BackSVertex + WRITE_IF_NON_NULL(tv->backSVertex()); + + // FrontEdgeA + WRITE_IF_NON_NULL(tv->frontEdgeA().first); + WRITE(tv->frontEdgeA().second); + + // FrontEdgeB + WRITE_IF_NON_NULL(tv->frontEdgeB().first); + WRITE(tv->frontEdgeB().second); + + // BackEdgeA + WRITE_IF_NON_NULL(tv->backEdgeA().first); + WRITE(tv->backEdgeA().second); + + // BackEdgeB + WRITE_IF_NON_NULL(tv->backEdgeB().first); + WRITE(tv->backEdgeB().second); + } + else if (vv->getNature() & Nature::NON_T_VERTEX) { + NonTVertex *ntv = dynamic_cast(vv); + + // SVertex + WRITE_IF_NON_NULL(ntv->svertex()); + + // ViewEdges (List) + unsigned size = ntv->viewedges().size(); + WRITE(size); + vector::const_iterator i = ntv->viewedges().begin(); + for (; i != ntv->viewedges().end(); i++) { + WRITE_IF_NON_NULL(i->first); + WRITE(i->second); + } + } + else { + cerr << "Warning: unexpected ViewVertex nature" << endl; + return 1; + } + + return 0; } -} // End of namespace Internal - +} // End of namespace Internal //////////////////// "Public" 'load' and 'save' functions //////////////////// -#define SET_PROGRESS(n) \ - if (pb) { \ - pb->setProgress((n)); \ - } (void)0 +#define SET_PROGRESS(n) \ + if (pb) { \ + pb->setProgress((n)); \ + } \ + (void)0 -int load(istream& in, ViewMap *vm, ProgressBar *pb) +int load(istream &in, ViewMap *vm, ProgressBar *pb) { - if (!vm) - return 1; - - //soc unused - unsigned tmp; - int err = 0; - Internal::g_vm = vm; - - // Management of the progress bar (if present) - if (pb) { - pb->reset(); - pb->setLabelText("Loading View Map..."); - pb->setTotalSteps(6); - pb->setProgress(0); - } - - // Read and set the options - unsigned char flags; - READ(flags); - Options::setFlags(flags); - - // Read the size of the five ViewMap's lists (with some extra information for the ViewVertices) - // and instantiate them (with default costructors) - unsigned vs_s, fe_s, fe_rle1, fe_rle2, sv_s, ve_s, vv_s, vv_rle1, vv_rle2; - READ(vs_s); - READ(fe_s); - - if (fe_s) { - bool b; - READ(b); - for (READ(fe_rle1), fe_rle2 = 0; fe_rle1 <= fe_s; fe_rle2 = fe_rle1, READ(fe_rle1)) { - if (b) { - for (unsigned int i = fe_rle2; i < fe_rle1; i++) { - FEdgeSmooth *fes = new FEdgeSmooth; - vm->AddFEdge(fes); - } - b = !b; - } - else if (!b) { - for (unsigned int i = fe_rle2; i < fe_rle1; i++) { - FEdgeSharp *fes = new FEdgeSharp; - vm->AddFEdge(fes); - } - b = !b; - } - } - } - - READ(sv_s); - READ(ve_s); - READ(vv_s); - - if (vv_s) { - Nature::VertexNature nature; - READ(nature); - for (READ(vv_rle1), vv_rle2 = 0; vv_rle1 <= vv_s; vv_rle2 = vv_rle1, READ(vv_rle1)) { - if (nature & Nature::T_VERTEX) { - for (unsigned int i = vv_rle2; i < vv_rle1; i++) { - TVertex *tv = new TVertex(); - vm->AddViewVertex(tv); - } - nature = Nature::NON_T_VERTEX; - } - else if (nature & Nature::NON_T_VERTEX) { - for (unsigned int i = vv_rle2; i < vv_rle1; i++) { - NonTVertex *ntv = new NonTVertex(); - vm->AddViewVertex(ntv); - } - nature = Nature::T_VERTEX; - } - } - } - - for (unsigned int i0 = 0; i0 < vs_s; i0++) { - SShape *ss = new SShape(); - ViewShape *vs = new ViewShape(); - vs->setSShape(ss); - ss->setViewShape(vs); - vm->AddViewShape(vs); - } + if (!vm) + return 1; + + //soc unused - unsigned tmp; + int err = 0; + Internal::g_vm = vm; + + // Management of the progress bar (if present) + if (pb) { + pb->reset(); + pb->setLabelText("Loading View Map..."); + pb->setTotalSteps(6); + pb->setProgress(0); + } + + // Read and set the options + unsigned char flags; + READ(flags); + Options::setFlags(flags); + + // Read the size of the five ViewMap's lists (with some extra information for the ViewVertices) + // and instantiate them (with default costructors) + unsigned vs_s, fe_s, fe_rle1, fe_rle2, sv_s, ve_s, vv_s, vv_rle1, vv_rle2; + READ(vs_s); + READ(fe_s); + + if (fe_s) { + bool b; + READ(b); + for (READ(fe_rle1), fe_rle2 = 0; fe_rle1 <= fe_s; fe_rle2 = fe_rle1, READ(fe_rle1)) { + if (b) { + for (unsigned int i = fe_rle2; i < fe_rle1; i++) { + FEdgeSmooth *fes = new FEdgeSmooth; + vm->AddFEdge(fes); + } + b = !b; + } + else if (!b) { + for (unsigned int i = fe_rle2; i < fe_rle1; i++) { + FEdgeSharp *fes = new FEdgeSharp; + vm->AddFEdge(fes); + } + b = !b; + } + } + } + + READ(sv_s); + READ(ve_s); + READ(vv_s); + + if (vv_s) { + Nature::VertexNature nature; + READ(nature); + for (READ(vv_rle1), vv_rle2 = 0; vv_rle1 <= vv_s; vv_rle2 = vv_rle1, READ(vv_rle1)) { + if (nature & Nature::T_VERTEX) { + for (unsigned int i = vv_rle2; i < vv_rle1; i++) { + TVertex *tv = new TVertex(); + vm->AddViewVertex(tv); + } + nature = Nature::NON_T_VERTEX; + } + else if (nature & Nature::NON_T_VERTEX) { + for (unsigned int i = vv_rle2; i < vv_rle1; i++) { + NonTVertex *ntv = new NonTVertex(); + vm->AddViewVertex(ntv); + } + nature = Nature::T_VERTEX; + } + } + } + + for (unsigned int i0 = 0; i0 < vs_s; i0++) { + SShape *ss = new SShape(); + ViewShape *vs = new ViewShape(); + vs->setSShape(ss); + ss->setViewShape(vs); + vm->AddViewShape(vs); + } #if 0 - for (unsigned int i1 = 0; i1 < fe_s; i1++) { - FEdge *fe = new FEdge(); - vm->AddFEdge(fe); - } + for (unsigned int i1 = 0; i1 < fe_s; i1++) { + FEdge *fe = new FEdge(); + vm->AddFEdge(fe); + } #endif - for (unsigned int i2 = 0; i2 < sv_s; i2++) { - SVertex *sv = new SVertex(); - vm->AddSVertex(sv); - } - for (unsigned int i3 = 0; i3 < ve_s; i3++) { - ViewEdge *ve = new ViewEdge(); - vm->AddViewEdge(ve); - } - - // Read the values for all the objects created above - SET_PROGRESS(1); - for (vector::const_iterator i4 = vm->ViewShapes().begin(); i4 != vm->ViewShapes().end(); i4++) - err += Internal::load(in, *i4); - SET_PROGRESS(2); - for (vector::const_iterator i5 = vm->FEdges().begin(); i5 != vm->FEdges().end(); i5++) - err += Internal::load(in, *i5); - SET_PROGRESS(3); - for (vector::const_iterator i6 = vm->SVertices().begin(); i6 != vm->SVertices().end(); i6++) - err += Internal::load(in, *i6); - SET_PROGRESS(4); - for (vector::const_iterator i7 = vm->ViewEdges().begin(); i7 != vm->ViewEdges().end(); i7++) - err += Internal::load(in, *i7); - SET_PROGRESS(5); - for (vector::const_iterator i8 = vm->ViewVertices().begin(); i8 != vm->ViewVertices().end(); i8++) - err += Internal::load(in, *i8); - SET_PROGRESS(6); - - // Read the shape id to index mapping - unsigned map_s; - READ(map_s); - unsigned id, index; - for (unsigned int i4 = 0; i4 < map_s; ++i4) { - READ(id); - READ(index); - vm->shapeIdToIndexMap()[id] = index; - } - - return err; + for (unsigned int i2 = 0; i2 < sv_s; i2++) { + SVertex *sv = new SVertex(); + vm->AddSVertex(sv); + } + for (unsigned int i3 = 0; i3 < ve_s; i3++) { + ViewEdge *ve = new ViewEdge(); + vm->AddViewEdge(ve); + } + + // Read the values for all the objects created above + SET_PROGRESS(1); + for (vector::const_iterator i4 = vm->ViewShapes().begin(); + i4 != vm->ViewShapes().end(); + i4++) + err += Internal::load(in, *i4); + SET_PROGRESS(2); + for (vector::const_iterator i5 = vm->FEdges().begin(); i5 != vm->FEdges().end(); i5++) + err += Internal::load(in, *i5); + SET_PROGRESS(3); + for (vector::const_iterator i6 = vm->SVertices().begin(); i6 != vm->SVertices().end(); + i6++) + err += Internal::load(in, *i6); + SET_PROGRESS(4); + for (vector::const_iterator i7 = vm->ViewEdges().begin(); + i7 != vm->ViewEdges().end(); + i7++) + err += Internal::load(in, *i7); + SET_PROGRESS(5); + for (vector::const_iterator i8 = vm->ViewVertices().begin(); + i8 != vm->ViewVertices().end(); + i8++) + err += Internal::load(in, *i8); + SET_PROGRESS(6); + + // Read the shape id to index mapping + unsigned map_s; + READ(map_s); + unsigned id, index; + for (unsigned int i4 = 0; i4 < map_s; ++i4) { + READ(id); + READ(index); + vm->shapeIdToIndexMap()[id] = index; + } + + return err; } - -int save(ostream& out, ViewMap *vm, ProgressBar *pb) +int save(ostream &out, ViewMap *vm, ProgressBar *pb) { - if (!vm) - return 1; - - int err = 0; - - // Management of the progress bar (if present) - if (pb) { - pb->reset(); - pb->setLabelText("Saving View Map..."); - pb->setTotalSteps(6); - pb->setProgress(0); - } - - // For every object, initialize its userdata member to its index in the ViewMap list - for (unsigned int i0 = 0; i0 < vm->ViewShapes().size(); i0++) { - vm->ViewShapes()[i0]->userdata = POINTER_FROM_UINT(i0); - vm->ViewShapes()[i0]->sshape()->userdata = POINTER_FROM_UINT(i0); - } - for (unsigned int i1 = 0; i1 < vm->FEdges().size(); i1++) - vm->FEdges()[i1]->userdata = POINTER_FROM_UINT(i1); - for (unsigned int i2 = 0; i2 < vm->SVertices().size(); i2++) - vm->SVertices()[i2]->userdata = POINTER_FROM_UINT(i2); - for (unsigned int i3 = 0; i3 < vm->ViewEdges().size(); i3++) - vm->ViewEdges()[i3]->userdata = POINTER_FROM_UINT(i3); - for (unsigned int i4 = 0; i4 < vm->ViewVertices().size(); i4++) - vm->ViewVertices()[i4]->userdata = POINTER_FROM_UINT(i4); - - // Write the current options - unsigned char flags = Options::getFlags(); - WRITE(flags); - - // Write the size of the five lists (with some extra information for the ViewVertices) - unsigned size; - size = vm->ViewShapes().size(); - WRITE(size); - size = vm->FEdges().size(); - WRITE(size); - if (size) { - bool b = vm->FEdges()[0]->isSmooth(); - WRITE(b); - for (unsigned int i = 0; i < size; i++) { - while (i < size && (vm->FEdges()[i]->isSmooth() == b)) - i++; - if (i < size) { - WRITE(i); - b = !b; - } - } - WRITE(size); - size++; - WRITE(size); - } - size = vm->SVertices().size(); - WRITE(size); - size = vm->ViewEdges().size(); - WRITE(size); - size = vm->ViewVertices().size(); - WRITE(size); - if (size) { - Nature::VertexNature nature = vm->ViewVertices()[0]->getNature(); - WRITE(nature); - nature &= ~Nature::VIEW_VERTEX; - for (unsigned int i = 0; i < size; i++) { - while (i < size && (vm->ViewVertices()[i]->getNature() & nature)) - i++; - if (i < size) { - WRITE(i); - nature = vm->ViewVertices()[i]->getNature() & ~Nature::VIEW_VERTEX; - } - } - WRITE(size); - size++; - WRITE(size); - } - - // Write all the elts of the ViewShapes List - SET_PROGRESS(1); - for (vector::const_iterator i5 = vm->ViewShapes().begin(); i5 != vm->ViewShapes().end(); i5++) - err += Internal::save(out, *i5); - SET_PROGRESS(2); - for (vector::const_iterator i6 = vm->FEdges().begin(); i6 != vm->FEdges().end(); i6++) - err += Internal::save(out, *i6); - SET_PROGRESS(3); - for (vector::const_iterator i7 = vm->SVertices().begin(); i7 != vm->SVertices().end(); i7++) - err += Internal::save(out, *i7); - SET_PROGRESS(4); - for (vector::const_iterator i8 = vm->ViewEdges().begin(); i8 != vm->ViewEdges().end(); i8++) - err += Internal::save(out, *i8); - SET_PROGRESS(5); - for (vector::const_iterator i9 = vm->ViewVertices().begin(); i9 != vm->ViewVertices().end(); i9++) - err += Internal::save(out, *i9); - - // Write the shape id to index mapping - size = vm->shapeIdToIndexMap().size(); - WRITE(size); - unsigned int id, index; - for (ViewMap::id_to_index_map::iterator mit = vm->shapeIdToIndexMap().begin(), - mitend = vm->shapeIdToIndexMap().end(); - mit != mitend; - ++mit) - { - id = mit->first; - index = mit->second; - WRITE(id); - WRITE(index); - } - - // Reset 'userdata' members - for (vector::const_iterator j0 = vm->ViewShapes().begin(); j0 != vm->ViewShapes().end(); j0++) { - (*j0)->userdata = NULL; - (*j0)->sshape()->userdata = NULL; - } - for (vector::const_iterator j1 = vm->FEdges().begin(); j1 != vm->FEdges().end(); j1++) - (*j1)->userdata = NULL; - for (vector::const_iterator j2 = vm->SVertices().begin(); j2 != vm->SVertices().end(); j2++) - (*j2)->userdata = NULL; - for (vector::const_iterator j3 = vm->ViewEdges().begin(); j3 != vm->ViewEdges().end(); j3++) - (*j3)->userdata = NULL; - for (vector::const_iterator j4 = vm->ViewVertices().begin(); j4 != vm->ViewVertices().end(); j4++) - (*j4)->userdata = NULL; - SET_PROGRESS(6); - - return err; + if (!vm) + return 1; + + int err = 0; + + // Management of the progress bar (if present) + if (pb) { + pb->reset(); + pb->setLabelText("Saving View Map..."); + pb->setTotalSteps(6); + pb->setProgress(0); + } + + // For every object, initialize its userdata member to its index in the ViewMap list + for (unsigned int i0 = 0; i0 < vm->ViewShapes().size(); i0++) { + vm->ViewShapes()[i0]->userdata = POINTER_FROM_UINT(i0); + vm->ViewShapes()[i0]->sshape()->userdata = POINTER_FROM_UINT(i0); + } + for (unsigned int i1 = 0; i1 < vm->FEdges().size(); i1++) + vm->FEdges()[i1]->userdata = POINTER_FROM_UINT(i1); + for (unsigned int i2 = 0; i2 < vm->SVertices().size(); i2++) + vm->SVertices()[i2]->userdata = POINTER_FROM_UINT(i2); + for (unsigned int i3 = 0; i3 < vm->ViewEdges().size(); i3++) + vm->ViewEdges()[i3]->userdata = POINTER_FROM_UINT(i3); + for (unsigned int i4 = 0; i4 < vm->ViewVertices().size(); i4++) + vm->ViewVertices()[i4]->userdata = POINTER_FROM_UINT(i4); + + // Write the current options + unsigned char flags = Options::getFlags(); + WRITE(flags); + + // Write the size of the five lists (with some extra information for the ViewVertices) + unsigned size; + size = vm->ViewShapes().size(); + WRITE(size); + size = vm->FEdges().size(); + WRITE(size); + if (size) { + bool b = vm->FEdges()[0]->isSmooth(); + WRITE(b); + for (unsigned int i = 0; i < size; i++) { + while (i < size && (vm->FEdges()[i]->isSmooth() == b)) + i++; + if (i < size) { + WRITE(i); + b = !b; + } + } + WRITE(size); + size++; + WRITE(size); + } + size = vm->SVertices().size(); + WRITE(size); + size = vm->ViewEdges().size(); + WRITE(size); + size = vm->ViewVertices().size(); + WRITE(size); + if (size) { + Nature::VertexNature nature = vm->ViewVertices()[0]->getNature(); + WRITE(nature); + nature &= ~Nature::VIEW_VERTEX; + for (unsigned int i = 0; i < size; i++) { + while (i < size && (vm->ViewVertices()[i]->getNature() & nature)) + i++; + if (i < size) { + WRITE(i); + nature = vm->ViewVertices()[i]->getNature() & ~Nature::VIEW_VERTEX; + } + } + WRITE(size); + size++; + WRITE(size); + } + + // Write all the elts of the ViewShapes List + SET_PROGRESS(1); + for (vector::const_iterator i5 = vm->ViewShapes().begin(); + i5 != vm->ViewShapes().end(); + i5++) + err += Internal::save(out, *i5); + SET_PROGRESS(2); + for (vector::const_iterator i6 = vm->FEdges().begin(); i6 != vm->FEdges().end(); i6++) + err += Internal::save(out, *i6); + SET_PROGRESS(3); + for (vector::const_iterator i7 = vm->SVertices().begin(); i7 != vm->SVertices().end(); + i7++) + err += Internal::save(out, *i7); + SET_PROGRESS(4); + for (vector::const_iterator i8 = vm->ViewEdges().begin(); + i8 != vm->ViewEdges().end(); + i8++) + err += Internal::save(out, *i8); + SET_PROGRESS(5); + for (vector::const_iterator i9 = vm->ViewVertices().begin(); + i9 != vm->ViewVertices().end(); + i9++) + err += Internal::save(out, *i9); + + // Write the shape id to index mapping + size = vm->shapeIdToIndexMap().size(); + WRITE(size); + unsigned int id, index; + for (ViewMap::id_to_index_map::iterator mit = vm->shapeIdToIndexMap().begin(), + mitend = vm->shapeIdToIndexMap().end(); + mit != mitend; + ++mit) { + id = mit->first; + index = mit->second; + WRITE(id); + WRITE(index); + } + + // Reset 'userdata' members + for (vector::const_iterator j0 = vm->ViewShapes().begin(); + j0 != vm->ViewShapes().end(); + j0++) { + (*j0)->userdata = NULL; + (*j0)->sshape()->userdata = NULL; + } + for (vector::const_iterator j1 = vm->FEdges().begin(); j1 != vm->FEdges().end(); j1++) + (*j1)->userdata = NULL; + for (vector::const_iterator j2 = vm->SVertices().begin(); j2 != vm->SVertices().end(); + j2++) + (*j2)->userdata = NULL; + for (vector::const_iterator j3 = vm->ViewEdges().begin(); + j3 != vm->ViewEdges().end(); + j3++) + (*j3)->userdata = NULL; + for (vector::const_iterator j4 = vm->ViewVertices().begin(); + j4 != vm->ViewVertices().end(); + j4++) + (*j4)->userdata = NULL; + SET_PROGRESS(6); + + return err; } - //////////////////// Options //////////////////// namespace Options { @@ -1216,40 +1233,40 @@ namespace Internal { static unsigned char g_flags = 0; static string g_models_path; -} // End of namespace Internal +} // End of namespace Internal void setFlags(const unsigned char flags) { - Internal::g_flags = flags; + Internal::g_flags = flags; } void addFlags(const unsigned char flags) { - Internal::g_flags |= flags; + Internal::g_flags |= flags; } void rmFlags(const unsigned char flags) { - Internal::g_flags &= ~flags; + Internal::g_flags &= ~flags; } unsigned char getFlags() { - return Internal::g_flags; + return Internal::g_flags; } -void setModelsPath(const string& path) +void setModelsPath(const string &path) { - Internal::g_models_path = path; + Internal::g_models_path = path; } string getModelsPath() { - return Internal::g_models_path; + return Internal::g_models_path; } -} // End of namepace Options +} // namespace Options -} // End of namespace ViewMapIO +} // End of namespace ViewMapIO } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ViewMapIO.h b/source/blender/freestyle/intern/view_map/ViewMapIO.h index 57eb450d45b..98d27852c8d 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapIO.h +++ b/source/blender/freestyle/intern/view_map/ViewMapIO.h @@ -36,9 +36,9 @@ namespace ViewMapIO { static const unsigned ZERO = UINT_MAX; -int load(istream& in, ViewMap *vm, ProgressBar *pb = NULL); +int load(istream &in, ViewMap *vm, ProgressBar *pb = NULL); -int save(ostream& out, ViewMap *vm, ProgressBar *pb = NULL); +int save(ostream &out, ViewMap *vm, ProgressBar *pb = NULL); namespace Options { @@ -53,60 +53,54 @@ void rmFlags(const unsigned char flags); unsigned char getFlags(); -void setModelsPath(const string& path); +void setModelsPath(const string &path); string getModelsPath(); -}; // End of namepace Options +}; // namespace Options #ifdef IRIX namespace Internal { -template -ostream& write(ostream& out, const char *str) +template ostream &write(ostream &out, const char *str) { - out.put(str[S - 1]); - return write(out, str); + out.put(str[S - 1]); + return write(out, str); } -template<> -ostream& write<1>(ostream& out, const char *str) +template<> ostream &write<1>(ostream &out, const char *str) { - return out.put(str[0]); + return out.put(str[0]); } -template<> -ostream& write<0>(ostream& out, const char *) +template<> ostream &write<0>(ostream &out, const char *) { - return out; + return out; } -template -istream& read(istream& in, char *str) +template istream &read(istream &in, char *str) { - in.get(str[S - 1]); - return read(in, str); + in.get(str[S - 1]); + return read(in, str); } -template<> -istream& read<1>(istream& in, char *str) +template<> istream &read<1>(istream &in, char *str) { - return in.get(str[0]); + return in.get(str[0]); } -template<> -istream& read<0>(istream& in, char *) +template<> istream &read<0>(istream &in, char *) { - return in; + return in; } -} // End of namespace Internal +} // End of namespace Internal -#endif // IRIX +#endif // IRIX -} // End of namespace ViewMapIO +} // End of namespace ViewMapIO } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_IO_H__ +#endif // __FREESTYLE_VIEW_MAP_IO_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewMapIterators.h b/source/blender/freestyle/intern/view_map/ViewMapIterators.h index c8a5b6e5d42..7182c5d3362 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapIterators.h +++ b/source/blender/freestyle/intern/view_map/ViewMapIterators.h @@ -24,7 +24,7 @@ #include "ViewMap.h" -#include "../system/Iterator.h" //soc +#include "../system/Iterator.h" //soc namespace Freestyle { @@ -51,176 +51,180 @@ namespace ViewVertexInternal { * An instance of an orientedViewEdgeIterator can only be obtained from a ViewVertex by calling edgesBegin() * or edgesEnd(). */ -class orientedViewEdgeIterator : public Iterator -{ -public: - friend class ViewVertex; - friend class TVertex; - friend class NonTVertex; - friend class ViewEdge; - - // FIXME - typedef TVertex::edge_pointers_container edge_pointers_container; - typedef NonTVertex::edges_container edges_container; - -protected: - Nature::VertexNature _Nature; // the nature of the underlying vertex - // T vertex attributes - edge_pointers_container::iterator _tbegin; - edge_pointers_container::iterator _tend; - edge_pointers_container::iterator _tvertex_iter; - - // Non TVertex attributes - edges_container::iterator _begin; - edges_container::iterator _end; - edges_container::iterator _nontvertex_iter; - -public: - /*! Default constructor */ - inline orientedViewEdgeIterator() {} - - inline orientedViewEdgeIterator(Nature::VertexNature iNature) - { - _Nature = iNature; - } - - /*! Copy constructor */ - orientedViewEdgeIterator(const orientedViewEdgeIterator& iBrother) - { - _Nature = iBrother._Nature; - if (_Nature & Nature::T_VERTEX) { - _tbegin = iBrother._tbegin; - _tend = iBrother._tend; - _tvertex_iter = iBrother._tvertex_iter; - } - else { - _begin = iBrother._begin; - _end = iBrother._end; - _nontvertex_iter = iBrother._nontvertex_iter; - } - } - - virtual ~orientedViewEdgeIterator() {} - -public: - inline orientedViewEdgeIterator(edge_pointers_container::iterator begin, edge_pointers_container::iterator end, - edge_pointers_container::iterator iter) - { - _Nature = Nature::T_VERTEX; - _tbegin = begin; - _tend = end; - _tvertex_iter = iter; - } - - inline orientedViewEdgeIterator(edges_container::iterator begin, edges_container::iterator end, - edges_container::iterator iter) - { - _Nature = Nature::NON_T_VERTEX; - _begin = begin; - _end = end; - _nontvertex_iter = iter; - } - -public: - /*! Tells whether the ViewEdge pointed by this iterator is the first one of the iteration list or not. */ - virtual bool isBegin() const - { - if (_Nature & Nature::T_VERTEX) - return (_tvertex_iter == _tbegin); - else - return (_nontvertex_iter == _begin); - } - - /*! Tells whether the ViewEdge pointed by this iterator is after the last one of the iteration list or not. */ - virtual bool isEnd() const - { - if (_Nature & Nature::T_VERTEX) - return (_tvertex_iter == _tend); - else - return (_nontvertex_iter == _end); - } - - // operators - /*! Increments. In the scripting language, call "increment()". */ - // operator corresponding to ++i - virtual orientedViewEdgeIterator& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++, i.e. which returns the value *and then* increments. - // That's why we store the value in a temp. - virtual orientedViewEdgeIterator operator++(int) - { - orientedViewEdgeIterator tmp = *this; - increment(); - return tmp; - } - - // comparibility - /*! operator != */ - virtual bool operator!=(const orientedViewEdgeIterator& b) const - { - if (_Nature & Nature::T_VERTEX) - return (_tvertex_iter != b._tvertex_iter); - else - return (_nontvertex_iter != b._nontvertex_iter); - } - - /*! operator == */ - virtual bool operator==(const orientedViewEdgeIterator& b) const - { - return !(*this != b); - } - - // dereferencing - /*! Returns a reference to the pointed orientedViewEdge. - * In the scripting language, you must call "getObject()" instead. - */ - virtual ViewVertex::directedViewEdge& operator*() const - { - if (_Nature & Nature::T_VERTEX) - //return _tvertex_iter; - return **_tvertex_iter; - else - return (*_nontvertex_iter); - } - /*! Returns a pointer to the pointed orientedViewEdge. - * Can't be called in the scripting language. - */ - virtual ViewVertex::directedViewEdge *operator->() const - { - return &(operator*()); - } - -public: - /*! increments.*/ - virtual inline int increment() - { - if (_Nature & Nature::T_VERTEX) { - ViewVertex::directedViewEdge tmp = (**_tvertex_iter); - ++_tvertex_iter; - if (_tvertex_iter != _tend) { - // FIXME : pquoi deja ? - ViewVertex::directedViewEdge tmp2 = (**_tvertex_iter); - if (tmp2.first == tmp.first) - ++_tvertex_iter; - } - } - else { - ++_nontvertex_iter; - } - return 0; - } +class orientedViewEdgeIterator : public Iterator { + public: + friend class ViewVertex; + friend class TVertex; + friend class NonTVertex; + friend class ViewEdge; + + // FIXME + typedef TVertex::edge_pointers_container edge_pointers_container; + typedef NonTVertex::edges_container edges_container; + + protected: + Nature::VertexNature _Nature; // the nature of the underlying vertex + // T vertex attributes + edge_pointers_container::iterator _tbegin; + edge_pointers_container::iterator _tend; + edge_pointers_container::iterator _tvertex_iter; + + // Non TVertex attributes + edges_container::iterator _begin; + edges_container::iterator _end; + edges_container::iterator _nontvertex_iter; + + public: + /*! Default constructor */ + inline orientedViewEdgeIterator() + { + } + + inline orientedViewEdgeIterator(Nature::VertexNature iNature) + { + _Nature = iNature; + } + + /*! Copy constructor */ + orientedViewEdgeIterator(const orientedViewEdgeIterator &iBrother) + { + _Nature = iBrother._Nature; + if (_Nature & Nature::T_VERTEX) { + _tbegin = iBrother._tbegin; + _tend = iBrother._tend; + _tvertex_iter = iBrother._tvertex_iter; + } + else { + _begin = iBrother._begin; + _end = iBrother._end; + _nontvertex_iter = iBrother._nontvertex_iter; + } + } + + virtual ~orientedViewEdgeIterator() + { + } + + public: + inline orientedViewEdgeIterator(edge_pointers_container::iterator begin, + edge_pointers_container::iterator end, + edge_pointers_container::iterator iter) + { + _Nature = Nature::T_VERTEX; + _tbegin = begin; + _tend = end; + _tvertex_iter = iter; + } + + inline orientedViewEdgeIterator(edges_container::iterator begin, + edges_container::iterator end, + edges_container::iterator iter) + { + _Nature = Nature::NON_T_VERTEX; + _begin = begin; + _end = end; + _nontvertex_iter = iter; + } + + public: + /*! Tells whether the ViewEdge pointed by this iterator is the first one of the iteration list or not. */ + virtual bool isBegin() const + { + if (_Nature & Nature::T_VERTEX) + return (_tvertex_iter == _tbegin); + else + return (_nontvertex_iter == _begin); + } + + /*! Tells whether the ViewEdge pointed by this iterator is after the last one of the iteration list or not. */ + virtual bool isEnd() const + { + if (_Nature & Nature::T_VERTEX) + return (_tvertex_iter == _tend); + else + return (_nontvertex_iter == _end); + } + + // operators + /*! Increments. In the scripting language, call "increment()". */ + // operator corresponding to ++i + virtual orientedViewEdgeIterator &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++, i.e. which returns the value *and then* increments. + // That's why we store the value in a temp. + virtual orientedViewEdgeIterator operator++(int) + { + orientedViewEdgeIterator tmp = *this; + increment(); + return tmp; + } + + // comparibility + /*! operator != */ + virtual bool operator!=(const orientedViewEdgeIterator &b) const + { + if (_Nature & Nature::T_VERTEX) + return (_tvertex_iter != b._tvertex_iter); + else + return (_nontvertex_iter != b._nontvertex_iter); + } + + /*! operator == */ + virtual bool operator==(const orientedViewEdgeIterator &b) const + { + return !(*this != b); + } + + // dereferencing + /*! Returns a reference to the pointed orientedViewEdge. + * In the scripting language, you must call "getObject()" instead. + */ + virtual ViewVertex::directedViewEdge &operator*() const + { + if (_Nature & Nature::T_VERTEX) + //return _tvertex_iter; + return **_tvertex_iter; + else + return (*_nontvertex_iter); + } + /*! Returns a pointer to the pointed orientedViewEdge. + * Can't be called in the scripting language. + */ + virtual ViewVertex::directedViewEdge *operator->() const + { + return &(operator*()); + } + + public: + /*! increments.*/ + virtual inline int increment() + { + if (_Nature & Nature::T_VERTEX) { + ViewVertex::directedViewEdge tmp = (**_tvertex_iter); + ++_tvertex_iter; + if (_tvertex_iter != _tend) { + // FIXME : pquoi deja ? + ViewVertex::directedViewEdge tmp2 = (**_tvertex_iter); + if (tmp2.first == tmp.first) + ++_tvertex_iter; + } + } + else { + ++_nontvertex_iter; + } + return 0; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:orientedViewEdgeIterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:orientedViewEdgeIterator") #endif - }; -} // ViewVertexInternal namespace +} // namespace ViewVertexInternal /**********************************/ /* */ @@ -237,166 +241,165 @@ namespace ViewEdgeInternal { // ///////////////////////////////////////////////// -class SVertexIterator : public Interface0DIteratorNested -{ -public: - SVertexIterator() - { - _vertex = NULL; - _begin = NULL; - _previous_edge = NULL; - _next_edge = NULL; - _t = 0; - } - - SVertexIterator(const SVertexIterator& vi) - { - _vertex = vi._vertex; - _begin = vi._begin; - _previous_edge = vi._previous_edge; - _next_edge = vi._next_edge; - _t = vi._t; - } - - SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t) - { - _vertex = v; - _begin = begin; - _previous_edge = prev; - _next_edge = next; - _t = t; - } - - SVertexIterator& operator=(const SVertexIterator& vi) - { - _vertex = vi._vertex; - _begin = vi._begin; - _previous_edge = vi._previous_edge; - _next_edge = vi._next_edge; - _t = vi._t; - return *this; - } - - virtual ~SVertexIterator() {} - - virtual string getExactTypeName() const - { - return "SVertexIterator"; - } - - virtual SVertex& operator*() - { - return *_vertex; - } - - virtual SVertex *operator->() - { - return &(operator*()); - } - - virtual SVertexIterator& operator++() - { - increment(); - return *this; - } - - virtual SVertexIterator operator++(int) - { - SVertexIterator ret(*this); - increment(); - return ret; - } - - virtual SVertexIterator& operator--() - { - decrement(); - return *this; - } - - virtual SVertexIterator operator--(int) - { - SVertexIterator ret(*this); - decrement(); - return ret; - } - - virtual int increment() - { - if (!_next_edge) { - _vertex = NULL; - return 0; - } - _t += (float)_next_edge->getLength2D(); - _vertex = _next_edge->vertexB(); - _previous_edge = _next_edge; - _next_edge = _next_edge->nextEdge(); - return 0; - } - - virtual int decrement() - { - if (!_previous_edge) { - _vertex = NULL; - return 0; - } - if ((!_next_edge) && (!_vertex)) { - _vertex = _previous_edge->vertexB(); - return 0; - } - _t -= (float)_previous_edge->getLength2D(); - _vertex = _previous_edge->vertexA(); - _next_edge = _previous_edge; - _previous_edge = _previous_edge->previousEdge(); - return 0; - } - - virtual bool isBegin() const - { - return _vertex == _begin; - } - - virtual bool isEnd() const - { - return (!_vertex) || (_vertex == _begin && _previous_edge); - } - - virtual float t() const - { - return _t; - } - - virtual float u() const - { - return _t / (float)_next_edge->viewedge()->getLength2D(); - } - - virtual bool operator==(const Interface0DIteratorNested& it) const - { - const SVertexIterator *it_exact = dynamic_cast(&it); - if (!it_exact) - return false; - return (_vertex == it_exact->_vertex); - } - - virtual SVertexIterator *copy() const - { - return new SVertexIterator(*this); - } - -private: - SVertex *_vertex; - SVertex *_begin; - FEdge *_previous_edge; - FEdge *_next_edge; - float _t; // curvilinear abscissa +class SVertexIterator : public Interface0DIteratorNested { + public: + SVertexIterator() + { + _vertex = NULL; + _begin = NULL; + _previous_edge = NULL; + _next_edge = NULL; + _t = 0; + } + + SVertexIterator(const SVertexIterator &vi) + { + _vertex = vi._vertex; + _begin = vi._begin; + _previous_edge = vi._previous_edge; + _next_edge = vi._next_edge; + _t = vi._t; + } + + SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t) + { + _vertex = v; + _begin = begin; + _previous_edge = prev; + _next_edge = next; + _t = t; + } + + SVertexIterator &operator=(const SVertexIterator &vi) + { + _vertex = vi._vertex; + _begin = vi._begin; + _previous_edge = vi._previous_edge; + _next_edge = vi._next_edge; + _t = vi._t; + return *this; + } + + virtual ~SVertexIterator() + { + } + + virtual string getExactTypeName() const + { + return "SVertexIterator"; + } + + virtual SVertex &operator*() + { + return *_vertex; + } + + virtual SVertex *operator->() + { + return &(operator*()); + } + + virtual SVertexIterator &operator++() + { + increment(); + return *this; + } + + virtual SVertexIterator operator++(int) + { + SVertexIterator ret(*this); + increment(); + return ret; + } + + virtual SVertexIterator &operator--() + { + decrement(); + return *this; + } + + virtual SVertexIterator operator--(int) + { + SVertexIterator ret(*this); + decrement(); + return ret; + } + + virtual int increment() + { + if (!_next_edge) { + _vertex = NULL; + return 0; + } + _t += (float)_next_edge->getLength2D(); + _vertex = _next_edge->vertexB(); + _previous_edge = _next_edge; + _next_edge = _next_edge->nextEdge(); + return 0; + } + + virtual int decrement() + { + if (!_previous_edge) { + _vertex = NULL; + return 0; + } + if ((!_next_edge) && (!_vertex)) { + _vertex = _previous_edge->vertexB(); + return 0; + } + _t -= (float)_previous_edge->getLength2D(); + _vertex = _previous_edge->vertexA(); + _next_edge = _previous_edge; + _previous_edge = _previous_edge->previousEdge(); + return 0; + } + + virtual bool isBegin() const + { + return _vertex == _begin; + } + + virtual bool isEnd() const + { + return (!_vertex) || (_vertex == _begin && _previous_edge); + } + + virtual float t() const + { + return _t; + } + + virtual float u() const + { + return _t / (float)_next_edge->viewedge()->getLength2D(); + } + + virtual bool operator==(const Interface0DIteratorNested &it) const + { + const SVertexIterator *it_exact = dynamic_cast(&it); + if (!it_exact) + return false; + return (_vertex == it_exact->_vertex); + } + + virtual SVertexIterator *copy() const + { + return new SVertexIterator(*this); + } + + private: + SVertex *_vertex; + SVertex *_begin; + FEdge *_previous_edge; + FEdge *_next_edge; + float _t; // curvilinear abscissa #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertexIterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertexIterator") #endif - }; - // // ViewEdgeIterator (base class) // @@ -407,173 +410,173 @@ private: * ViewEdge) to go when pointing on a given ViewEdge. * ::Caution::: the dereferencing operator returns a *pointer* to the pointed ViewEdge. */ -class ViewEdgeIterator : public Iterator -{ -public: - /*! Builds a ViewEdgeIterator from a starting ViewEdge and its orientation. - * \param begin: - * The ViewEdge from where to start the iteration. - * \param orientation: - * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. - * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. - */ - ViewEdgeIterator(ViewEdge *begin = NULL, bool orientation = true) - { - _orientation = orientation; - _edge = begin; - _begin = begin; - } - - /*! Copy constructor */ - ViewEdgeIterator(const ViewEdgeIterator& it) - { - _orientation = it._orientation; - _edge = it._edge; - _begin = it._begin; - } - - virtual ~ViewEdgeIterator() {} - - /*! Returns the string "ViewEdgeIterator" */ - virtual string getExactTypeName() const - { - return "ViewEdgeIterator"; - } - - /*! Returns the current pointed ViewEdge. */ - ViewEdge *getCurrentEdge() - { - return _edge; - } - - /*! Sets the current pointed ViewEdge. */ - void setCurrentEdge(ViewEdge *edge) - { - _edge = edge; - } - - /*! Returns the first ViewEdge used for the iteration. */ - ViewEdge *getBegin() - { - return _begin; - } - - /*! Sets the first ViewEdge used for the iteration. */ - void setBegin(ViewEdge *begin) - { - _begin = begin; - } - - /*! Gets the orientation of the pointed ViewEdge in the iteration. */ - bool getOrientation() const - { - return _orientation; - } - - /*! Sets the orientation of the pointed ViewEdge in the iteration. */ - void setOrientation(bool orientation) - { - _orientation = orientation; - } - - /*! Changes the current orientation. */ - void changeOrientation() - { - _orientation = !_orientation; - } - - /*! Returns a *pointer* to the pointed ViewEdge. */ - virtual ViewEdge *operator*() - { - return _edge; - } - - virtual ViewEdge *operator->() - { - return operator*(); - } - - /*! Increments. In the scripting language, call "increment()". */ - virtual ViewEdgeIterator& operator++() - { - increment(); - return *this; - } - - /*! Increments. In the scripting language, call "increment()". */ - virtual ViewEdgeIterator operator++(int) - { - ViewEdgeIterator tmp(*this); - increment(); - return tmp; - } - - /*! increments. */ - virtual int increment() - { - cerr << "Warning: method increment() not implemented" << endl; - return 0; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - virtual ViewEdgeIterator& operator--() - { - decrement(); - return *this; - } - - /*! Decrements. In the scripting language, call "decrement()". */ - virtual ViewEdgeIterator operator--(int) - { - ViewEdgeIterator tmp(*this); - decrement(); - return tmp; - } - - /*! decrements. */ - virtual int decrement() - { - cerr << "Warning: method decrement() not implemented" << endl; - return 0; - } - - /*! Returns true if the pointed ViewEdge is the first one used for the iteration. */ - virtual bool isBegin() const - { - return _edge == _begin; - } - - /*! Returns true if the pointed ViewEdge* equals 0. */ - virtual bool isEnd() const - { - return !_edge; - } - - /*! operator == */ - virtual bool operator==(ViewEdgeIterator& it) const - { - return _edge == it._edge; - } - - /*! operator != */ - virtual bool operator!=(ViewEdgeIterator& it) const - { - return !(*this == it); - } - -protected: - bool _orientation; - ViewEdge *_edge; - ViewEdge *_begin; +class ViewEdgeIterator : public Iterator { + public: + /*! Builds a ViewEdgeIterator from a starting ViewEdge and its orientation. + * \param begin: + * The ViewEdge from where to start the iteration. + * \param orientation: + * If true, we'll look for the next ViewEdge among the ViewEdges that surround the ending ViewVertex of begin. + * If false, we'll search over the ViewEdges surrounding the ending ViewVertex of begin. + */ + ViewEdgeIterator(ViewEdge *begin = NULL, bool orientation = true) + { + _orientation = orientation; + _edge = begin; + _begin = begin; + } + + /*! Copy constructor */ + ViewEdgeIterator(const ViewEdgeIterator &it) + { + _orientation = it._orientation; + _edge = it._edge; + _begin = it._begin; + } + + virtual ~ViewEdgeIterator() + { + } + + /*! Returns the string "ViewEdgeIterator" */ + virtual string getExactTypeName() const + { + return "ViewEdgeIterator"; + } + + /*! Returns the current pointed ViewEdge. */ + ViewEdge *getCurrentEdge() + { + return _edge; + } + + /*! Sets the current pointed ViewEdge. */ + void setCurrentEdge(ViewEdge *edge) + { + _edge = edge; + } + + /*! Returns the first ViewEdge used for the iteration. */ + ViewEdge *getBegin() + { + return _begin; + } + + /*! Sets the first ViewEdge used for the iteration. */ + void setBegin(ViewEdge *begin) + { + _begin = begin; + } + + /*! Gets the orientation of the pointed ViewEdge in the iteration. */ + bool getOrientation() const + { + return _orientation; + } + + /*! Sets the orientation of the pointed ViewEdge in the iteration. */ + void setOrientation(bool orientation) + { + _orientation = orientation; + } + + /*! Changes the current orientation. */ + void changeOrientation() + { + _orientation = !_orientation; + } + + /*! Returns a *pointer* to the pointed ViewEdge. */ + virtual ViewEdge *operator*() + { + return _edge; + } + + virtual ViewEdge *operator->() + { + return operator*(); + } + + /*! Increments. In the scripting language, call "increment()". */ + virtual ViewEdgeIterator &operator++() + { + increment(); + return *this; + } + + /*! Increments. In the scripting language, call "increment()". */ + virtual ViewEdgeIterator operator++(int) + { + ViewEdgeIterator tmp(*this); + increment(); + return tmp; + } + + /*! increments. */ + virtual int increment() + { + cerr << "Warning: method increment() not implemented" << endl; + return 0; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + virtual ViewEdgeIterator &operator--() + { + decrement(); + return *this; + } + + /*! Decrements. In the scripting language, call "decrement()". */ + virtual ViewEdgeIterator operator--(int) + { + ViewEdgeIterator tmp(*this); + decrement(); + return tmp; + } + + /*! decrements. */ + virtual int decrement() + { + cerr << "Warning: method decrement() not implemented" << endl; + return 0; + } + + /*! Returns true if the pointed ViewEdge is the first one used for the iteration. */ + virtual bool isBegin() const + { + return _edge == _begin; + } + + /*! Returns true if the pointed ViewEdge* equals 0. */ + virtual bool isEnd() const + { + return !_edge; + } + + /*! operator == */ + virtual bool operator==(ViewEdgeIterator &it) const + { + return _edge == it._edge; + } + + /*! operator != */ + virtual bool operator!=(ViewEdgeIterator &it) const + { + return !(*this == it); + } + + protected: + bool _orientation; + ViewEdge *_edge; + ViewEdge *_begin; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeIterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeIterator") #endif - }; -} // end of namespace ViewEdgeInternal +} // end of namespace ViewEdgeInternal } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_ITERATORS_H__ +#endif // __FREESTYLE_VIEW_MAP_ITERATORS_H__ diff --git a/source/blender/freestyle/intern/view_map/ViewMapTesselator.cpp b/source/blender/freestyle/intern/view_map/ViewMapTesselator.cpp index 62656c6ade6..8abd464b0cf 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapTesselator.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapTesselator.cpp @@ -25,16 +25,16 @@ namespace Freestyle { NodeGroup *ViewMapTesselator::Tesselate(ViewMap *iViewMap) { - if (0 == iViewMap->ViewEdges().size()) - return NULL; + if (0 == iViewMap->ViewEdges().size()) + return NULL; - const vector& viewedges = iViewMap->ViewEdges(); - return Tesselate(viewedges.begin(), viewedges.end()); + const vector &viewedges = iViewMap->ViewEdges(); + return Tesselate(viewedges.begin(), viewedges.end()); } NodeGroup *ViewMapTesselator::Tesselate(WShape *) { - return NULL; + return NULL; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/view_map/ViewMapTesselator.h b/source/blender/freestyle/intern/view_map/ViewMapTesselator.h index a24a7cfdf18..2173ea42fab 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapTesselator.h +++ b/source/blender/freestyle/intern/view_map/ViewMapTesselator.h @@ -34,7 +34,7 @@ #include "../winged_edge/WEdge.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -44,100 +44,105 @@ class NodeGroup; class SShape; class WShape; -class ViewMapTesselator -{ -public: - inline ViewMapTesselator() - { - _nature = Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE; - _FrsMaterial.setDiffuse(0, 0, 0, 1); - _overloadFrsMaterial = false; - } - - virtual ~ViewMapTesselator() {} - - /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a ViewMap */ - NodeGroup *Tesselate(ViewMap *iViewMap); - - /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a set of - * view edges - */ - template - NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end); - - /*! Builds a set of lines rep contained among a NodeShape, from a WShape */ - NodeGroup *Tesselate(WShape *iWShape); - - inline void setNature(Nature::EdgeNature iNature) - { - _nature = iNature; - } - - inline void setFrsMaterial(const FrsMaterial& iMaterial) - { - _FrsMaterial = iMaterial; - _overloadFrsMaterial = true; - } - - inline Nature::EdgeNature nature() - { - return _nature; - } - - inline const FrsMaterial& frs_material() const - { - return _FrsMaterial; - } - -protected: - virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0; - -private: - Nature::EdgeNature _nature; - FrsMaterial _FrsMaterial; - bool _overloadFrsMaterial; +class ViewMapTesselator { + public: + inline ViewMapTesselator() + { + _nature = Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE; + _FrsMaterial.setDiffuse(0, 0, 0, 1); + _overloadFrsMaterial = false; + } + + virtual ~ViewMapTesselator() + { + } + + /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a ViewMap */ + NodeGroup *Tesselate(ViewMap *iViewMap); + + /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a set of + * view edges + */ + template + NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end); + + /*! Builds a set of lines rep contained among a NodeShape, from a WShape */ + NodeGroup *Tesselate(WShape *iWShape); + + inline void setNature(Nature::EdgeNature iNature) + { + _nature = iNature; + } + + inline void setFrsMaterial(const FrsMaterial &iMaterial) + { + _FrsMaterial = iMaterial; + _overloadFrsMaterial = true; + } + + inline Nature::EdgeNature nature() + { + return _nature; + } + + inline const FrsMaterial &frs_material() const + { + return _FrsMaterial; + } + + protected: + virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0; + + private: + Nature::EdgeNature _nature; + FrsMaterial _FrsMaterial; + bool _overloadFrsMaterial; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator") #endif }; /*! Class to tesselate the 2D projected silhouette */ -class ViewMapTesselator2D : public ViewMapTesselator -{ -public: - inline ViewMapTesselator2D() : ViewMapTesselator() {} - virtual ~ViewMapTesselator2D() {} - -protected: - virtual void AddVertexToLine(LineRep *iLine, SVertex *v) - { - iLine->AddVertex(v->point2D()); - } +class ViewMapTesselator2D : public ViewMapTesselator { + public: + inline ViewMapTesselator2D() : ViewMapTesselator() + { + } + virtual ~ViewMapTesselator2D() + { + } + + protected: + virtual void AddVertexToLine(LineRep *iLine, SVertex *v) + { + iLine->AddVertex(v->point2D()); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D") #endif - }; /*! Class to tesselate the 3D silhouette */ -class ViewMapTesselator3D : public ViewMapTesselator -{ -public: - inline ViewMapTesselator3D() : ViewMapTesselator() {} - virtual ~ViewMapTesselator3D() {} - -protected: - virtual void AddVertexToLine(LineRep *iLine, SVertex *v) - { - iLine->AddVertex(v->point3D()); - } +class ViewMapTesselator3D : public ViewMapTesselator { + public: + inline ViewMapTesselator3D() : ViewMapTesselator() + { + } + virtual ~ViewMapTesselator3D() + { + } + + protected: + virtual void AddVertexToLine(LineRep *iLine, SVertex *v) + { + iLine->AddVertex(v->point3D()); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D") #endif - }; // @@ -148,73 +153,73 @@ protected: template NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end) { - NodeGroup *group = new NodeGroup; - NodeShape *tshape = new NodeShape; - group->AddChild(tshape); - //tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f); - tshape->setFrsMaterial(_FrsMaterial); + NodeGroup *group = new NodeGroup; + NodeShape *tshape = new NodeShape; + group->AddChild(tshape); + //tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f); + tshape->setFrsMaterial(_FrsMaterial); - LineRep *line; + LineRep *line; - FEdge *firstEdge; - FEdge *nextFEdge, *currentEdge; + FEdge *firstEdge; + FEdge *nextFEdge, *currentEdge; - int id = 0; - //for (vector::const_iterator c = viewedges.begin(), cend = viewedges.end(); c != cend; c++) - for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) { + int id = 0; + //for (vector::const_iterator c = viewedges.begin(), cend = viewedges.end(); c != cend; c++) + for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) { #if 0 - if ((*c)->qi() > 0) { - continue; - } - if (!((*c)->nature() & (_nature))) { - continue; - } + if ((*c)->qi() > 0) { + continue; + } + if (!((*c)->nature() & (_nature))) { + continue; + } #endif - firstEdge = (*c)->fedgeA(); + firstEdge = (*c)->fedgeA(); #if 0 - if (firstEdge->invisibility() > 0) - continue; + if (firstEdge->invisibility() > 0) + continue; #endif - line = new OrientedLineRep(); - if (_overloadFrsMaterial) - line->setFrsMaterial(_FrsMaterial); - - // there might be chains containing a single element - if (0 == (firstEdge)->nextEdge()) { - line->setStyle(LineRep::LINES); - //line->AddVertex((*c)->vertexA()->point3D()); - //line->AddVertex((*c)->vertexB()->point3D()); - AddVertexToLine(line, firstEdge->vertexA()); - AddVertexToLine(line, firstEdge->vertexB()); - } - else { - line->setStyle(LineRep::LINE_STRIP); - - //firstEdge = (*c); - nextFEdge = firstEdge; - currentEdge = firstEdge; - do { - //line->AddVertex(nextFEdge->vertexA()->point3D()); - AddVertexToLine(line, nextFEdge->vertexA()); - currentEdge = nextFEdge; - nextFEdge = nextFEdge->nextEdge(); - } while ((nextFEdge != NULL) && (nextFEdge != firstEdge)); - // Add the last vertex - //line->AddVertex(currentEdge->vertexB()->point3D()); - AddVertexToLine(line, currentEdge->vertexB()); - } - - line->setId((*c)->getId().getFirst()); - line->ComputeBBox(); - tshape->AddRep(line); - id++; - } - - return group; + line = new OrientedLineRep(); + if (_overloadFrsMaterial) + line->setFrsMaterial(_FrsMaterial); + + // there might be chains containing a single element + if (0 == (firstEdge)->nextEdge()) { + line->setStyle(LineRep::LINES); + //line->AddVertex((*c)->vertexA()->point3D()); + //line->AddVertex((*c)->vertexB()->point3D()); + AddVertexToLine(line, firstEdge->vertexA()); + AddVertexToLine(line, firstEdge->vertexB()); + } + else { + line->setStyle(LineRep::LINE_STRIP); + + //firstEdge = (*c); + nextFEdge = firstEdge; + currentEdge = firstEdge; + do { + //line->AddVertex(nextFEdge->vertexA()->point3D()); + AddVertexToLine(line, nextFEdge->vertexA()); + currentEdge = nextFEdge; + nextFEdge = nextFEdge->nextEdge(); + } while ((nextFEdge != NULL) && (nextFEdge != firstEdge)); + // Add the last vertex + //line->AddVertex(currentEdge->vertexB()->point3D()); + AddVertexToLine(line, currentEdge->vertexB()); + } + + line->setId((*c)->getId().getFirst()); + line->ComputeBBox(); + tshape->AddRep(line); + id++; + } + + return group; } } /* namespace Freestyle */ -#endif // __FREESTYLE_VIEW_MAP_TESSELATOR_H__ +#endif // __FREESTYLE_VIEW_MAP_TESSELATOR_H__ diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.cpp b/source/blender/freestyle/intern/winged_edge/Curvature.cpp index 28b38ae4854..b42c3f9b0e6 100644 --- a/source/blender/freestyle/intern/winged_edge/Curvature.cpp +++ b/source/blender/freestyle/intern/winged_edge/Curvature.cpp @@ -34,7 +34,7 @@ */ #include -#include // for malloc and free +#include // for malloc and free #include #include @@ -49,56 +49,56 @@ namespace Freestyle { static bool angle_obtuse(WVertex *v, WFace *f) { - WOEdge *e; - f->getOppositeEdge(v, e); + WOEdge *e; + f->getOppositeEdge(v, e); - Vec3r vec1(e->GetaVertex()->GetVertex() - v->GetVertex()); - Vec3r vec2(e->GetbVertex()->GetVertex() - v->GetVertex()); - return ((vec1 * vec2) < 0); + Vec3r vec1(e->GetaVertex()->GetVertex() - v->GetVertex()); + Vec3r vec2(e->GetbVertex()->GetVertex() - v->GetVertex()); + return ((vec1 * vec2) < 0); } // FIXME // WVvertex is useless but kept for history reasons static bool triangle_obtuse(WVertex *, WFace *f) { - bool b = false; - for (int i = 0; i < 3; i++) - b = b || ((f->getEdgeList()[i]->GetVec() * f->getEdgeList()[(i + 1) % 3]->GetVec()) < 0); - return b; + bool b = false; + for (int i = 0; i < 3; i++) + b = b || ((f->getEdgeList()[i]->GetVec() * f->getEdgeList()[(i + 1) % 3]->GetVec()) < 0); + return b; } static real cotan(WVertex *vo, WVertex *v1, WVertex *v2) { - /* cf. Appendix B of [Meyer et al 2002] */ - real udotv, denom; + /* cf. Appendix B of [Meyer et al 2002] */ + real udotv, denom; - Vec3r u(v1->GetVertex() - vo->GetVertex()); - Vec3r v(v2->GetVertex() - vo->GetVertex()); + Vec3r u(v1->GetVertex() - vo->GetVertex()); + Vec3r v(v2->GetVertex() - vo->GetVertex()); - udotv = u * v; - denom = sqrt(u.squareNorm() * v.squareNorm() - udotv * udotv); + udotv = u * v; + denom = sqrt(u.squareNorm() * v.squareNorm() - udotv * udotv); - /* denom can be zero if u==v. Returning 0 is acceptable, based on the callers of this function below. */ - if (denom == 0.0) - return 0.0; - return (udotv / denom); + /* denom can be zero if u==v. Returning 0 is acceptable, based on the callers of this function below. */ + if (denom == 0.0) + return 0.0; + return (udotv / denom); } static real angle_from_cotan(WVertex *vo, WVertex *v1, WVertex *v2) { - /* cf. Appendix B and the caption of Table 1 from [Meyer et al 2002] */ - real udotv, denom; + /* cf. Appendix B and the caption of Table 1 from [Meyer et al 2002] */ + real udotv, denom; - Vec3r u (v1->GetVertex() - vo->GetVertex()); - Vec3r v(v2->GetVertex() - vo->GetVertex()); + Vec3r u(v1->GetVertex() - vo->GetVertex()); + Vec3r v(v2->GetVertex() - vo->GetVertex()); - udotv = u * v; - denom = sqrt(u.squareNorm() * v.squareNorm() - udotv * udotv); + udotv = u * v; + denom = sqrt(u.squareNorm() * v.squareNorm() - udotv * udotv); - /* Note: I assume this is what they mean by using atan2(). -Ray Jones */ + /* Note: I assume this is what they mean by using atan2(). -Ray Jones */ - /* tan = denom/udotv = y/x (see man page for atan2) */ - return (fabs(atan2(denom, udotv))); + /* tan = denom/udotv = y/x (see man page for atan2) */ + return (fabs(atan2(denom, udotv))); } /*! gts_vertex_mean_curvature_normal: @@ -124,48 +124,48 @@ static real angle_from_cotan(WVertex *vo, WVertex *v1, WVertex *v2) */ bool gts_vertex_mean_curvature_normal(WVertex *v, Vec3r &Kh) { - real area = 0.0; + real area = 0.0; - if (!v) - return false; + if (!v) + return false; - /* this operator is not defined for boundary edges */ - if (v->isBoundary()) - return false; + /* this operator is not defined for boundary edges */ + if (v->isBoundary()) + return false; - WVertex::incoming_edge_iterator itE; + WVertex::incoming_edge_iterator itE; - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) - area += (*itE)->GetaFace()->getArea(); + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) + area += (*itE)->GetaFace()->getArea(); - Kh = Vec3r(0.0, 0.0, 0.0); + Kh = Vec3r(0.0, 0.0, 0.0); - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { - WOEdge *e = (*itE)->getPrevOnFace(); + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { + WOEdge *e = (*itE)->getPrevOnFace(); #if 0 - if ((e->GetaVertex() == v) || (e->GetbVertex() == v)) - cerr<< "BUG "; + if ((e->GetaVertex() == v) || (e->GetbVertex() == v)) + cerr<< "BUG "; #endif - WVertex *v1 = e->GetaVertex(); - WVertex *v2 = e->GetbVertex(); - real temp; - - temp = cotan(v1, v, v2); - Kh = Vec3r(Kh + temp * (v2->GetVertex() - v->GetVertex())); - - temp = cotan(v2, v, v1); - Kh = Vec3r(Kh + temp * (v1->GetVertex() - v->GetVertex())); - } - if (area > 0.0) { - Kh[0] /= 2 * area; - Kh[1] /= 2 * area; - Kh[2] /= 2 * area; - } - else { - return false; - } - - return true; + WVertex *v1 = e->GetaVertex(); + WVertex *v2 = e->GetbVertex(); + real temp; + + temp = cotan(v1, v, v2); + Kh = Vec3r(Kh + temp * (v2->GetVertex() - v->GetVertex())); + + temp = cotan(v2, v, v1); + Kh = Vec3r(Kh + temp * (v1->GetVertex() - v->GetVertex())); + } + if (area > 0.0) { + Kh[0] /= 2 * area; + Kh[1] /= 2 * area; + Kh[2] /= 2 * area; + } + else { + return false; + } + + return true; } /*! gts_vertex_gaussian_curvature: @@ -186,35 +186,35 @@ bool gts_vertex_mean_curvature_normal(WVertex *v, Vec3r &Kh) */ bool gts_vertex_gaussian_curvature(WVertex *v, real *Kg) { - real area = 0.0; - real angle_sum = 0.0; - - if (!v) - return false; - if (!Kg) - return false; - - /* this operator is not defined for boundary edges */ - if (v->isBoundary()) { - *Kg = 0.0; - return false; - } - - WVertex::incoming_edge_iterator itE; - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { - area += (*itE)->GetaFace()->getArea(); - } - - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { - WOEdge *e = (*itE)->getPrevOnFace(); - WVertex *v1 = e->GetaVertex(); - WVertex *v2 = e->GetbVertex(); - angle_sum += angle_from_cotan(v, v1, v2); - } - - *Kg = (2.0 * M_PI - angle_sum) / area; - - return true; + real area = 0.0; + real angle_sum = 0.0; + + if (!v) + return false; + if (!Kg) + return false; + + /* this operator is not defined for boundary edges */ + if (v->isBoundary()) { + *Kg = 0.0; + return false; + } + + WVertex::incoming_edge_iterator itE; + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { + area += (*itE)->GetaFace()->getArea(); + } + + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { + WOEdge *e = (*itE)->getPrevOnFace(); + WVertex *v1 = e->GetaVertex(); + WVertex *v2 = e->GetbVertex(); + angle_sum += angle_from_cotan(v, v1, v2); + } + + *Kg = (2.0 * M_PI - angle_sum) / area; + + return true; } /*! gts_vertex_principal_curvatures: @@ -230,41 +230,41 @@ bool gts_vertex_gaussian_curvature(WVertex *v, real *Kg) * * The Gaussian curvature can be computed with gts_vertex_gaussian_curvature(). */ -void gts_vertex_principal_curvatures (real Kh, real Kg, real *K1, real *K2) +void gts_vertex_principal_curvatures(real Kh, real Kg, real *K1, real *K2) { - real temp = Kh * Kh - Kg; + real temp = Kh * Kh - Kg; - if (!K1 || !K2) - return; + if (!K1 || !K2) + return; - if (temp < 0.0) - temp = 0.0; - temp = sqrt (temp); - *K1 = Kh + temp; - *K2 = Kh - temp; + if (temp < 0.0) + temp = 0.0; + temp = sqrt(temp); + *K1 = Kh + temp; + *K2 = Kh - temp; } /* from Maple */ static void linsolve(real m11, real m12, real b1, real m21, real m22, real b2, real *x1, real *x2) { - real temp; + real temp; - temp = 1.0 / (m21 * m12 - m11 * m22); - *x1 = (m12 * b2 - m22 * b1) * temp; - *x2 = (m11 * b2 - m21 * b1) * temp; + temp = 1.0 / (m21 * m12 - m11 * m22); + *x1 = (m12 * b2 - m22 * b1) * temp; + *x2 = (m11 * b2 - m21 * b1) * temp; } /* from Maple - largest eigenvector of [a b; b c] */ static void eigenvector(real a, real b, real c, Vec3r e) { - if (b == 0.0) { - e[0] = 0.0; - } - else { - e[0] = -(c - a - sqrt(c * c - 2 * a * c + a * a + 4 * b * b)) / (2 * b); - } - e[1] = 1.0; - e[2] = 0.0; + if (b == 0.0) { + e[0] = 0.0; + } + else { + e[0] = -(c - a - sqrt(c * c - 2 * a * c + a * a + 4 * b * b)) / (2 * b); + } + e[1] = 1.0; + e[2] = 0.0; } /*! gts_vertex_principal_directions: @@ -284,244 +284,249 @@ static void eigenvector(real a, real b, real c, Vec3r e) */ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, Vec3r &e2) { - Vec3r N; - real normKh; - - Vec3r basis1, basis2, d, eig; - real ve2, vdotN; - real aterm_da, bterm_da, cterm_da, const_da; - real aterm_db, bterm_db, cterm_db, const_db; - real a, b, c; - real K1, K2; - real *weights, *kappas, *d1s, *d2s; - int edge_count; - real err_e1, err_e2; - int e; - WVertex::incoming_edge_iterator itE; - - /* compute unit normal */ - normKh = Kh.norm(); - - if (normKh > 0.0) { - Kh.normalize(); - } - else { - /* This vertex is a point of zero mean curvature (flat or saddle point). Compute a normal by averaging - * the adjacent triangles - */ - N[0] = N[1] = N[2] = 0.0; - - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) - N = Vec3r(N + (*itE)->GetaFace()->GetNormal()); - real normN = N.norm(); - if (normN <= 0.0) - return; - N.normalize(); - } - - /* construct a basis from N: */ - /* set basis1 to any component not the largest of N */ - basis1[0] = basis1[1] = basis1[2] = 0.0; - if (fabs (N[0]) > fabs (N[1])) - basis1[1] = 1.0; - else - basis1[0] = 1.0; - - /* make basis2 orthogonal to N */ - basis2 = (N ^ basis1); - basis2.normalize(); - - /* make basis1 orthogonal to N and basis2 */ - basis1 = (N ^ basis2); - basis1.normalize(); - - aterm_da = bterm_da = cterm_da = const_da = 0.0; - aterm_db = bterm_db = cterm_db = const_db = 0.0; - int nb_edges = v->GetEdges().size(); - - weights = (real *)malloc(sizeof(real) * nb_edges); - kappas = (real *)malloc(sizeof(real) * nb_edges); - d1s = (real *)malloc(sizeof(real) * nb_edges); - d2s = (real *)malloc(sizeof(real) * nb_edges); - edge_count = 0; - - for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { - WOEdge *e; - WFace *f1, *f2; - real weight, kappa, d1, d2; - Vec3r vec_edge; - if (!*itE) - continue; - e = *itE; - - /* since this vertex passed the tests in gts_vertex_mean_curvature_normal(), this should be true. */ - //g_assert(gts_edge_face_number (e, s) == 2); - - /* identify the two triangles bordering e in s */ - f1 = e->GetaFace(); - f2 = e->GetbFace(); - - /* We are solving for the values of the curvature tensor - * B = [ a b ; b c ]. - * The computations here are from section 5 of [Meyer et al 2002]. - * - * The first step is to calculate the linear equations governing the values of (a,b,c). These can be computed - * by setting the derivatives of the error E to zero (section 5.3). - * - * Since a + c = norm(Kh), we only compute the linear equations for dE/da and dE/db. (NB: [Meyer et al 2002] - * has the equation a + b = norm(Kh), but I'm almost positive this is incorrect). - * - * Note that the w_ij (defined in section 5.2) are all scaled by (1/8*A_mixed). We drop this uniform scale - * factor because the solution of the linear equations doesn't rely on it. - * - * The terms of the linear equations are xterm_dy with x in {a,b,c} and y in {a,b}. There are also const_dy - * terms that are the constant factors in the equations. - */ - - /* find the vector from v along edge e */ - vec_edge = Vec3r(-1 * e->GetVec()); - - ve2 = vec_edge.squareNorm(); - vdotN = vec_edge * N; - - /* section 5.2 - There is a typo in the computation of kappa. The edges should be x_j-x_i. */ - kappa = 2.0 * vdotN / ve2; - - /* section 5.2 */ - - /* I don't like performing a minimization where some of the weights can be negative (as can be the case - * if f1 or f2 are obtuse). To ensure all-positive weights, we check for obtuseness. */ - weight = 0.0; - if (!triangle_obtuse(v, f1)) { - weight += ve2 * cotan(f1->GetNextOEdge(e->twin())->GetbVertex(), e->GetaVertex(), e->GetbVertex()) / 8.0; - } - else { - if (angle_obtuse(v, f1)) { - weight += ve2 * f1->getArea() / 4.0; - } - else { - weight += ve2 * f1->getArea() / 8.0; - } - } - - if (!triangle_obtuse(v, f2)) { - weight += ve2 * cotan (f2->GetNextOEdge(e)->GetbVertex(), e->GetaVertex(), e->GetbVertex()) / 8.0; - } - else { - if (angle_obtuse(v, f2)) { - weight += ve2 * f1->getArea() / 4.0; - } - else { - weight += ve2 * f1->getArea() / 8.0; - } - } - - /* projection of edge perpendicular to N (section 5.3) */ - d[0] = vec_edge[0] - vdotN * N[0]; - d[1] = vec_edge[1] - vdotN * N[1]; - d[2] = vec_edge[2] - vdotN * N[2]; - d.normalize(); - - /* not explicit in the paper, but necessary. Move d to 2D basis. */ - d1 = d * basis1; - d2 = d * basis2; - - /* store off the curvature, direction of edge, and weights for later use */ - weights[edge_count] = weight; - kappas[edge_count] = kappa; - d1s[edge_count] = d1; - d2s[edge_count] = d2; - edge_count++; - - /* Finally, update the linear equations */ - aterm_da += weight * d1 * d1 * d1 * d1; - bterm_da += weight * d1 * d1 * 2 * d1 * d2; - cterm_da += weight * d1 * d1 * d2 * d2; - const_da += weight * d1 * d1 * (-kappa); - - aterm_db += weight * d1 * d2 * d1 * d1; - bterm_db += weight * d1 * d2 * 2 * d1 * d2; - cterm_db += weight * d1 * d2 * d2 * d2; - const_db += weight * d1 * d2 * (-kappa); - } - - /* now use the identity (Section 5.3) a + c = |Kh| = 2 * kappa_h */ - aterm_da -= cterm_da; - const_da += cterm_da * normKh; - - aterm_db -= cterm_db; - const_db += cterm_db * normKh; - - /* check for solvability of the linear system */ - if (((aterm_da * bterm_db - aterm_db * bterm_da) != 0.0) && ((const_da != 0.0) || (const_db != 0.0))) { - linsolve(aterm_da, bterm_da, -const_da, aterm_db, bterm_db, -const_db, &a, &b); - - c = normKh - a; - - eigenvector(a, b, c, eig); - } - else { - /* region of v is planar */ - eig[0] = 1.0; - eig[1] = 0.0; - } - - /* Although the eigenvectors of B are good estimates of the principal directions, it seems that which one is - * attached to which curvature direction is a bit arbitrary. This may be a bug in my implementation, or just - * a side-effect of the inaccuracy of B due to the discrete nature of the sampling. - * - * To overcome this behavior, we'll evaluate which assignment best matches the given eigenvectors by comparing - * the curvature estimates computed above and the curvatures calculated from the discrete differential operators. - */ - - gts_vertex_principal_curvatures(0.5 * normKh, Kg, &K1, &K2); - - err_e1 = err_e2 = 0.0; - /* loop through the values previously saved */ - for (e = 0; e < edge_count; e++) { - real weight, kappa, d1, d2; - real temp1, temp2; - real delta; - - weight = weights[e]; - kappa = kappas[e]; - d1 = d1s[e]; - d2 = d2s[e]; - - temp1 = fabs (eig[0] * d1 + eig[1] * d2); - temp1 = temp1 * temp1; - temp2 = fabs (eig[1] * d1 - eig[0] * d2); - temp2 = temp2 * temp2; - - /* err_e1 is for K1 associated with e1 */ - delta = K1 * temp1 + K2 * temp2 - kappa; - err_e1 += weight * delta * delta; - - /* err_e2 is for K1 associated with e2 */ - delta = K2 * temp1 + K1 * temp2 - kappa; - err_e2 += weight * delta * delta; - } - free (weights); - free (kappas); - free (d1s); - free (d2s); - - /* rotate eig by a right angle if that would decrease the error */ - if (err_e2 < err_e1) { - real temp = eig[0]; - - eig[0] = eig[1]; - eig[1] = -temp; - } - - e1[0] = eig[0] * basis1[0] + eig[1] * basis2[0]; - e1[1] = eig[0] * basis1[1] + eig[1] * basis2[1]; - e1[2] = eig[0] * basis1[2] + eig[1] * basis2[2]; - e1.normalize(); - - /* make N,e1,e2 a right handed coordinate sytem */ - e2 = N ^ e1; - e2.normalize(); + Vec3r N; + real normKh; + + Vec3r basis1, basis2, d, eig; + real ve2, vdotN; + real aterm_da, bterm_da, cterm_da, const_da; + real aterm_db, bterm_db, cterm_db, const_db; + real a, b, c; + real K1, K2; + real *weights, *kappas, *d1s, *d2s; + int edge_count; + real err_e1, err_e2; + int e; + WVertex::incoming_edge_iterator itE; + + /* compute unit normal */ + normKh = Kh.norm(); + + if (normKh > 0.0) { + Kh.normalize(); + } + else { + /* This vertex is a point of zero mean curvature (flat or saddle point). Compute a normal by averaging + * the adjacent triangles + */ + N[0] = N[1] = N[2] = 0.0; + + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) + N = Vec3r(N + (*itE)->GetaFace()->GetNormal()); + real normN = N.norm(); + if (normN <= 0.0) + return; + N.normalize(); + } + + /* construct a basis from N: */ + /* set basis1 to any component not the largest of N */ + basis1[0] = basis1[1] = basis1[2] = 0.0; + if (fabs(N[0]) > fabs(N[1])) + basis1[1] = 1.0; + else + basis1[0] = 1.0; + + /* make basis2 orthogonal to N */ + basis2 = (N ^ basis1); + basis2.normalize(); + + /* make basis1 orthogonal to N and basis2 */ + basis1 = (N ^ basis2); + basis1.normalize(); + + aterm_da = bterm_da = cterm_da = const_da = 0.0; + aterm_db = bterm_db = cterm_db = const_db = 0.0; + int nb_edges = v->GetEdges().size(); + + weights = (real *)malloc(sizeof(real) * nb_edges); + kappas = (real *)malloc(sizeof(real) * nb_edges); + d1s = (real *)malloc(sizeof(real) * nb_edges); + d2s = (real *)malloc(sizeof(real) * nb_edges); + edge_count = 0; + + for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { + WOEdge *e; + WFace *f1, *f2; + real weight, kappa, d1, d2; + Vec3r vec_edge; + if (!*itE) + continue; + e = *itE; + + /* since this vertex passed the tests in gts_vertex_mean_curvature_normal(), this should be true. */ + //g_assert(gts_edge_face_number (e, s) == 2); + + /* identify the two triangles bordering e in s */ + f1 = e->GetaFace(); + f2 = e->GetbFace(); + + /* We are solving for the values of the curvature tensor + * B = [ a b ; b c ]. + * The computations here are from section 5 of [Meyer et al 2002]. + * + * The first step is to calculate the linear equations governing the values of (a,b,c). These can be computed + * by setting the derivatives of the error E to zero (section 5.3). + * + * Since a + c = norm(Kh), we only compute the linear equations for dE/da and dE/db. (NB: [Meyer et al 2002] + * has the equation a + b = norm(Kh), but I'm almost positive this is incorrect). + * + * Note that the w_ij (defined in section 5.2) are all scaled by (1/8*A_mixed). We drop this uniform scale + * factor because the solution of the linear equations doesn't rely on it. + * + * The terms of the linear equations are xterm_dy with x in {a,b,c} and y in {a,b}. There are also const_dy + * terms that are the constant factors in the equations. + */ + + /* find the vector from v along edge e */ + vec_edge = Vec3r(-1 * e->GetVec()); + + ve2 = vec_edge.squareNorm(); + vdotN = vec_edge * N; + + /* section 5.2 - There is a typo in the computation of kappa. The edges should be x_j-x_i. */ + kappa = 2.0 * vdotN / ve2; + + /* section 5.2 */ + + /* I don't like performing a minimization where some of the weights can be negative (as can be the case + * if f1 or f2 are obtuse). To ensure all-positive weights, we check for obtuseness. */ + weight = 0.0; + if (!triangle_obtuse(v, f1)) { + weight += ve2 * + cotan( + f1->GetNextOEdge(e->twin())->GetbVertex(), e->GetaVertex(), e->GetbVertex()) / + 8.0; + } + else { + if (angle_obtuse(v, f1)) { + weight += ve2 * f1->getArea() / 4.0; + } + else { + weight += ve2 * f1->getArea() / 8.0; + } + } + + if (!triangle_obtuse(v, f2)) { + weight += ve2 * cotan(f2->GetNextOEdge(e)->GetbVertex(), e->GetaVertex(), e->GetbVertex()) / + 8.0; + } + else { + if (angle_obtuse(v, f2)) { + weight += ve2 * f1->getArea() / 4.0; + } + else { + weight += ve2 * f1->getArea() / 8.0; + } + } + + /* projection of edge perpendicular to N (section 5.3) */ + d[0] = vec_edge[0] - vdotN * N[0]; + d[1] = vec_edge[1] - vdotN * N[1]; + d[2] = vec_edge[2] - vdotN * N[2]; + d.normalize(); + + /* not explicit in the paper, but necessary. Move d to 2D basis. */ + d1 = d * basis1; + d2 = d * basis2; + + /* store off the curvature, direction of edge, and weights for later use */ + weights[edge_count] = weight; + kappas[edge_count] = kappa; + d1s[edge_count] = d1; + d2s[edge_count] = d2; + edge_count++; + + /* Finally, update the linear equations */ + aterm_da += weight * d1 * d1 * d1 * d1; + bterm_da += weight * d1 * d1 * 2 * d1 * d2; + cterm_da += weight * d1 * d1 * d2 * d2; + const_da += weight * d1 * d1 * (-kappa); + + aterm_db += weight * d1 * d2 * d1 * d1; + bterm_db += weight * d1 * d2 * 2 * d1 * d2; + cterm_db += weight * d1 * d2 * d2 * d2; + const_db += weight * d1 * d2 * (-kappa); + } + + /* now use the identity (Section 5.3) a + c = |Kh| = 2 * kappa_h */ + aterm_da -= cterm_da; + const_da += cterm_da * normKh; + + aterm_db -= cterm_db; + const_db += cterm_db * normKh; + + /* check for solvability of the linear system */ + if (((aterm_da * bterm_db - aterm_db * bterm_da) != 0.0) && + ((const_da != 0.0) || (const_db != 0.0))) { + linsolve(aterm_da, bterm_da, -const_da, aterm_db, bterm_db, -const_db, &a, &b); + + c = normKh - a; + + eigenvector(a, b, c, eig); + } + else { + /* region of v is planar */ + eig[0] = 1.0; + eig[1] = 0.0; + } + + /* Although the eigenvectors of B are good estimates of the principal directions, it seems that which one is + * attached to which curvature direction is a bit arbitrary. This may be a bug in my implementation, or just + * a side-effect of the inaccuracy of B due to the discrete nature of the sampling. + * + * To overcome this behavior, we'll evaluate which assignment best matches the given eigenvectors by comparing + * the curvature estimates computed above and the curvatures calculated from the discrete differential operators. + */ + + gts_vertex_principal_curvatures(0.5 * normKh, Kg, &K1, &K2); + + err_e1 = err_e2 = 0.0; + /* loop through the values previously saved */ + for (e = 0; e < edge_count; e++) { + real weight, kappa, d1, d2; + real temp1, temp2; + real delta; + + weight = weights[e]; + kappa = kappas[e]; + d1 = d1s[e]; + d2 = d2s[e]; + + temp1 = fabs(eig[0] * d1 + eig[1] * d2); + temp1 = temp1 * temp1; + temp2 = fabs(eig[1] * d1 - eig[0] * d2); + temp2 = temp2 * temp2; + + /* err_e1 is for K1 associated with e1 */ + delta = K1 * temp1 + K2 * temp2 - kappa; + err_e1 += weight * delta * delta; + + /* err_e2 is for K1 associated with e2 */ + delta = K2 * temp1 + K1 * temp2 - kappa; + err_e2 += weight * delta * delta; + } + free(weights); + free(kappas); + free(d1s); + free(d2s); + + /* rotate eig by a right angle if that would decrease the error */ + if (err_e2 < err_e1) { + real temp = eig[0]; + + eig[0] = eig[1]; + eig[1] = -temp; + } + + e1[0] = eig[0] * basis1[0] + eig[1] * basis2[0]; + e1[1] = eig[0] * basis1[1] + eig[1] * basis2[1]; + e1[2] = eig[0] * basis1[2] + eig[1] * basis2[2]; + e1.normalize(); + + /* make N,e1,e2 a right handed coordinate sytem */ + e2 = N ^ e1; + e2.normalize(); } namespace OGF { @@ -529,107 +534,108 @@ namespace OGF { #if 0 inline static real angle(WOEdge *h) { - const Vec3r& n1 = h->GetbFace()->GetNormal(); - const Vec3r& n2 = h->GetaFace()->GetNormal(); - const Vec3r v = h->GetVec(); - real sine = (n1 ^ n2) * v / v.norm(); - if (sine >= 1.0) { - return M_PI / 2.0; - } - if (sine <= -1.0) { - return -M_PI / 2.0; - } - return ::asin(sine); + const Vec3r& n1 = h->GetbFace()->GetNormal(); + const Vec3r& n2 = h->GetaFace()->GetNormal(); + const Vec3r v = h->GetVec(); + real sine = (n1 ^ n2) * v / v.norm(); + if (sine >= 1.0) { + return M_PI / 2.0; + } + if (sine <= -1.0) { + return -M_PI / 2.0; + } + return ::asin(sine); } #endif // precondition1: P is inside the sphere // precondition2: P,V points to the outside of the sphere (i.e. OP.V > 0) -static bool sphere_clip_vector(const Vec3r& O, real r, const Vec3r& P, Vec3r& V) +static bool sphere_clip_vector(const Vec3r &O, real r, const Vec3r &P, Vec3r &V) { - Vec3r W = P - O; - real a = V.squareNorm(); - real b = 2.0 * V * W; - real c = W.squareNorm() - r * r; - real delta = b * b - 4 * a * c; - if (delta < 0) { - // Should not happen, but happens sometimes (numerical precision) - return true; - } - real t = - b + ::sqrt(delta) / (2.0 * a); - if (t < 0.0) { - // Should not happen, but happens sometimes (numerical precision) - return true; - } - if (t >= 1.0) { - // Inside the sphere - return false; - } - - V[0] = (t * V.x()); - V[1] = (t * V.y()); - V[2] = (t * V.z()); - - return true; + Vec3r W = P - O; + real a = V.squareNorm(); + real b = 2.0 * V * W; + real c = W.squareNorm() - r * r; + real delta = b * b - 4 * a * c; + if (delta < 0) { + // Should not happen, but happens sometimes (numerical precision) + return true; + } + real t = -b + ::sqrt(delta) / (2.0 * a); + if (t < 0.0) { + // Should not happen, but happens sometimes (numerical precision) + return true; + } + if (t >= 1.0) { + // Inside the sphere + return false; + } + + V[0] = (t * V.x()); + V[1] = (t * V.y()); + V[2] = (t * V.z()); + + return true; } // TODO: check optimizations: // use marking ? (measure *timings* ...) -void compute_curvature_tensor(WVertex *start, real radius, NormalCycle& nc) +void compute_curvature_tensor(WVertex *start, real radius, NormalCycle &nc) { - // in case we have a non-manifold vertex, skip it... - if (start->isBoundary()) - return; - - std::set vertices; - const Vec3r& O = start->GetVertex(); - std::stack S; - S.push(start); - vertices.insert(start); - while (!S.empty()) { - WVertex *v = S.top(); - S.pop(); - if (v->isBoundary()) - continue; - const Vec3r& P = v->GetVertex(); - WVertex::incoming_edge_iterator woeit = v->incoming_edges_begin(); - WVertex::incoming_edge_iterator woeitend = v->incoming_edges_end(); - for (; woeit != woeitend; ++woeit) { - WOEdge *h = *woeit; - if ((v == start) || h->GetVec() * (O - P) > 0.0) { - Vec3r V(-1 * h->GetVec()); - bool isect = sphere_clip_vector(O, radius, P, V); - assert (h->GetOwner()->GetNumberOfOEdges() == 2); // Because otherwise v->isBoundary() would be true - nc.accumulate_dihedral_angle(V, h->GetAngle()); - - if (!isect) { - WVertex *w = h->GetaVertex(); - if (vertices.find(w) == vertices.end()) { - vertices.insert(w); - S.push(w); - } - } - } - } - } + // in case we have a non-manifold vertex, skip it... + if (start->isBoundary()) + return; + + std::set vertices; + const Vec3r &O = start->GetVertex(); + std::stack S; + S.push(start); + vertices.insert(start); + while (!S.empty()) { + WVertex *v = S.top(); + S.pop(); + if (v->isBoundary()) + continue; + const Vec3r &P = v->GetVertex(); + WVertex::incoming_edge_iterator woeit = v->incoming_edges_begin(); + WVertex::incoming_edge_iterator woeitend = v->incoming_edges_end(); + for (; woeit != woeitend; ++woeit) { + WOEdge *h = *woeit; + if ((v == start) || h->GetVec() * (O - P) > 0.0) { + Vec3r V(-1 * h->GetVec()); + bool isect = sphere_clip_vector(O, radius, P, V); + assert(h->GetOwner()->GetNumberOfOEdges() == + 2); // Because otherwise v->isBoundary() would be true + nc.accumulate_dihedral_angle(V, h->GetAngle()); + + if (!isect) { + WVertex *w = h->GetaVertex(); + if (vertices.find(w) == vertices.end()) { + vertices.insert(w); + S.push(w); + } + } + } + } + } } -void compute_curvature_tensor_one_ring(WVertex *start, NormalCycle& nc) +void compute_curvature_tensor_one_ring(WVertex *start, NormalCycle &nc) { - // in case we have a non-manifold vertex, skip it... - if (start->isBoundary()) - return; - - WVertex::incoming_edge_iterator woeit = start->incoming_edges_begin(); - WVertex::incoming_edge_iterator woeitend = start->incoming_edges_end(); - for (; woeit != woeitend; ++woeit) { - WOEdge *h = (*woeit)->twin(); - nc.accumulate_dihedral_angle(h->GetVec(), h->GetAngle()); - WOEdge *hprev = h->getPrevOnFace(); - nc.accumulate_dihedral_angle(hprev->GetVec(), hprev->GetAngle()); - } + // in case we have a non-manifold vertex, skip it... + if (start->isBoundary()) + return; + + WVertex::incoming_edge_iterator woeit = start->incoming_edges_begin(); + WVertex::incoming_edge_iterator woeitend = start->incoming_edges_end(); + for (; woeit != woeitend; ++woeit) { + WOEdge *h = (*woeit)->twin(); + nc.accumulate_dihedral_angle(h->GetVec(), h->GetAngle()); + WOEdge *hprev = h->getPrevOnFace(); + nc.accumulate_dihedral_angle(hprev->GetVec(), hprev->GetAngle()); + } } -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.h b/source/blender/freestyle/intern/winged_edge/Curvature.h index b8f1a7b3094..32e9ea8b5cf 100644 --- a/source/blender/freestyle/intern/winged_edge/Curvature.h +++ b/source/blender/freestyle/intern/winged_edge/Curvature.h @@ -42,7 +42,7 @@ #include "../system/Precision.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -51,75 +51,75 @@ using namespace Geometry; class WVertex; -class CurvatureInfo -{ -public: - CurvatureInfo() - { - K1 = 0.0; - K2 = 0.0; - e1 = Vec3r(0.0, 0.0, 0.0); - e2 = Vec3r(0.0, 0.0, 0.0); - Kr = 0.0; - dKr = 0.0; - er = Vec3r(0.0, 0.0, 0.0); - } - - CurvatureInfo(const CurvatureInfo& iBrother) - { - K1 = iBrother.K1; - K2 = iBrother.K2; - e1 = iBrother.e1; - e2 = iBrother.e2; - Kr = iBrother.Kr; - dKr = iBrother.dKr; - er = iBrother.er; - } - - CurvatureInfo(const CurvatureInfo& ca, const CurvatureInfo& cb, real t) - { - K1 = ca.K1 + t * (cb.K1 - ca.K1); - K2 = ca.K2 + t * (cb.K2 - ca.K2); - e1 = ca.e1 + t * (cb.e1 - ca.e1); - e2 = ca.e2 + t * (cb.e2 - ca.e2); - Kr = ca.Kr + t * (cb.Kr - ca.Kr); - dKr = ca.dKr + t * (cb.dKr - ca.dKr); - er = ca.er + t * (cb.er - ca.er); - } - - real K1; // maximum curvature - real K2; // minimum curvature - Vec3r e1; // maximum curvature direction - Vec3r e2; // minimum curvature direction - real Kr; // radial curvature - real dKr; // radial curvature - Vec3r er; // radial curvature direction +class CurvatureInfo { + public: + CurvatureInfo() + { + K1 = 0.0; + K2 = 0.0; + e1 = Vec3r(0.0, 0.0, 0.0); + e2 = Vec3r(0.0, 0.0, 0.0); + Kr = 0.0; + dKr = 0.0; + er = Vec3r(0.0, 0.0, 0.0); + } + + CurvatureInfo(const CurvatureInfo &iBrother) + { + K1 = iBrother.K1; + K2 = iBrother.K2; + e1 = iBrother.e1; + e2 = iBrother.e2; + Kr = iBrother.Kr; + dKr = iBrother.dKr; + er = iBrother.er; + } + + CurvatureInfo(const CurvatureInfo &ca, const CurvatureInfo &cb, real t) + { + K1 = ca.K1 + t * (cb.K1 - ca.K1); + K2 = ca.K2 + t * (cb.K2 - ca.K2); + e1 = ca.e1 + t * (cb.e1 - ca.e1); + e2 = ca.e2 + t * (cb.e2 - ca.e2); + Kr = ca.Kr + t * (cb.Kr - ca.Kr); + dKr = ca.dKr + t * (cb.dKr - ca.dKr); + er = ca.er + t * (cb.er - ca.er); + } + + real K1; // maximum curvature + real K2; // minimum curvature + Vec3r e1; // maximum curvature direction + Vec3r e2; // minimum curvature direction + real Kr; // radial curvature + real dKr; // radial curvature + Vec3r er; // radial curvature direction #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvatureInfo") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvatureInfo") #endif }; -class Face_Curvature_Info -{ -public: - Face_Curvature_Info() {} - - ~Face_Curvature_Info() - { - for (vector::iterator ci = vec_curvature_info.begin(), ciend = vec_curvature_info.end(); - ci != ciend; - ++ci) - { - delete (*ci); - } - vec_curvature_info.clear(); - } - - vector vec_curvature_info; +class Face_Curvature_Info { + public: + Face_Curvature_Info() + { + } + + ~Face_Curvature_Info() + { + for (vector::iterator ci = vec_curvature_info.begin(), + ciend = vec_curvature_info.end(); + ci != ciend; + ++ci) { + delete (*ci); + } + vec_curvature_info.clear(); + } + + vector vec_curvature_info; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Face_Curvature_Info") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Face_Curvature_Info") #endif }; @@ -133,13 +133,13 @@ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, V namespace OGF { -class NormalCycle ; +class NormalCycle; -void compute_curvature_tensor( WVertex *start, double radius, NormalCycle& nc); +void compute_curvature_tensor(WVertex *start, double radius, NormalCycle &nc); -void compute_curvature_tensor_one_ring(WVertex *start, NormalCycle& nc); +void compute_curvature_tensor_one_ring(WVertex *start, NormalCycle &nc); -} // OGF namespace +} // namespace OGF } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/Nature.h b/source/blender/freestyle/intern/winged_edge/Nature.h index 71b306ed2d5..91f9f63b412 100644 --- a/source/blender/freestyle/intern/winged_edge/Nature.h +++ b/source/blender/freestyle/intern/winged_edge/Nature.h @@ -32,40 +32,40 @@ namespace Nature { typedef unsigned short VertexNature; /*! true for any 0D element */ -static const VertexNature POINT = 0; // 0 +static const VertexNature POINT = 0; // 0 /*! true for SVertex */ -static const VertexNature S_VERTEX = (1 << 0); // 1 +static const VertexNature S_VERTEX = (1 << 0); // 1 /*! true for ViewVertex */ -static const VertexNature VIEW_VERTEX = (1 << 1); // 2 +static const VertexNature VIEW_VERTEX = (1 << 1); // 2 /*! true for NonTVertex */ -static const VertexNature NON_T_VERTEX = (1 << 2); // 4 +static const VertexNature NON_T_VERTEX = (1 << 2); // 4 /*! true for TVertex */ -static const VertexNature T_VERTEX = (1 << 3); // 8 +static const VertexNature T_VERTEX = (1 << 3); // 8 /*! true for CUSP */ -static const VertexNature CUSP = (1 << 4); // 16 +static const VertexNature CUSP = (1 << 4); // 16 typedef unsigned short EdgeNature; /*! true for non feature edges (always false for 1D elements of the ViewMap) */ -static const EdgeNature NO_FEATURE = 0; // 0 +static const EdgeNature NO_FEATURE = 0; // 0 /*! true for silhouettes */ -static const EdgeNature SILHOUETTE = (1 << 0); // 1 +static const EdgeNature SILHOUETTE = (1 << 0); // 1 /*! true for borders */ -static const EdgeNature BORDER = (1 << 1); // 2 +static const EdgeNature BORDER = (1 << 1); // 2 /*! true for creases */ -static const EdgeNature CREASE = (1 << 2); // 4 +static const EdgeNature CREASE = (1 << 2); // 4 /*! true for ridges */ -static const EdgeNature RIDGE = (1 << 3); // 8 +static const EdgeNature RIDGE = (1 << 3); // 8 /*! true for valleys */ -static const EdgeNature VALLEY = (1 << 4); // 16 +static const EdgeNature VALLEY = (1 << 4); // 16 /*! true for suggestive contours */ -static const EdgeNature SUGGESTIVE_CONTOUR = (1 << 5); // 32 +static const EdgeNature SUGGESTIVE_CONTOUR = (1 << 5); // 32 /*! true for material boundaries */ -static const EdgeNature MATERIAL_BOUNDARY = (1 << 6); // 64 +static const EdgeNature MATERIAL_BOUNDARY = (1 << 6); // 64 /*! true for user-defined edge marks */ -static const EdgeNature EDGE_MARK = (1 << 7); // 128 +static const EdgeNature EDGE_MARK = (1 << 7); // 128 -} // end of namespace Nature +} // end of namespace Nature } /* namespace Freestyle */ -#endif // __FREESTYLE_NATURE_H__ +#endif // __FREESTYLE_NATURE_H__ diff --git a/source/blender/freestyle/intern/winged_edge/WEdge.cpp b/source/blender/freestyle/intern/winged_edge/WEdge.cpp index 12a73491989..629e8ffe901 100644 --- a/source/blender/freestyle/intern/winged_edge/WEdge.cpp +++ b/source/blender/freestyle/intern/winged_edge/WEdge.cpp @@ -26,31 +26,26 @@ namespace Freestyle { /*! Temporary structures */ -class vertexdata -{ -public: - WVertex *_copy; +class vertexdata { + public: + WVertex *_copy; }; -class oedgedata -{ -public: - WOEdge *_copy; +class oedgedata { + public: + WOEdge *_copy; }; -class edgedata -{ -public: - WEdge *_copy; +class edgedata { + public: + WEdge *_copy; }; -class facedata -{ -public: - WFace *_copy; +class facedata { + public: + WFace *_copy; }; - /********************************** * * * * @@ -59,120 +54,120 @@ public: * * **********************************/ -WVertex::WVertex(WVertex& iBrother) +WVertex::WVertex(WVertex &iBrother) { - _Id = iBrother._Id; - _Vertex = iBrother._Vertex; - _EdgeList = iBrother._EdgeList; - - _Shape = iBrother._Shape; - _Smooth = iBrother._Smooth; - _Border = iBrother._Border; - userdata = NULL; - iBrother.userdata = new vertexdata; - ((vertexdata *)(iBrother.userdata))->_copy = this; + _Id = iBrother._Id; + _Vertex = iBrother._Vertex; + _EdgeList = iBrother._EdgeList; + + _Shape = iBrother._Shape; + _Smooth = iBrother._Smooth; + _Border = iBrother._Border; + userdata = NULL; + iBrother.userdata = new vertexdata; + ((vertexdata *)(iBrother.userdata))->_copy = this; } WVertex *WVertex::duplicate() { - WVertex *clone = new WVertex(*this); - return clone; + WVertex *clone = new WVertex(*this); + return clone; } WOEdge *WVertex::incoming_edge_iterator::operator*() { - return _current; + return _current; } void WVertex::incoming_edge_iterator::increment() { - WOEdge *twin = _current->twin(); - if (!twin) { - // we reached a hole - _current = 0; - return; - } - WOEdge *next = twin->getPrevOnFace(); - if (next == _begin) { - next = NULL; - } - _current = next; + WOEdge *twin = _current->twin(); + if (!twin) { + // we reached a hole + _current = 0; + return; + } + WOEdge *next = twin->getPrevOnFace(); + if (next == _begin) { + next = NULL; + } + _current = next; } WFace *WVertex::face_iterator::operator*() { - WOEdge *woedge = *_edge_it; - if (!woedge) - return NULL; - return (woedge)->GetbFace(); + WOEdge *woedge = *_edge_it; + if (!woedge) + return NULL; + return (woedge)->GetbFace(); } #if 0 bool WVertex::isBoundary () const { - return _Border; + return _Border; } #endif -bool WVertex::isBoundary () -{ - if (_Border == 1) - return true; - else if (_Border == 0) - return false; - - vector::const_iterator it; - for (it = _EdgeList.begin(); it != _EdgeList.end(); it++) { - if ((*it)->GetNumberOfOEdges() == 1) { - _Border = 1; - return true; - } - } +bool WVertex::isBoundary() +{ + if (_Border == 1) + return true; + else if (_Border == 0) + return false; + + vector::const_iterator it; + for (it = _EdgeList.begin(); it != _EdgeList.end(); it++) { + if ((*it)->GetNumberOfOEdges() == 1) { + _Border = 1; + return true; + } + } #if 0 - if (!(*it)->GetaOEdge()->GetaFace()) - return true; + if (!(*it)->GetaOEdge()->GetaFace()) + return true; #endif - _Border = 0; - return false; + _Border = 0; + return false; } void WVertex::AddEdge(WEdge *iEdge) { - _EdgeList.push_back(iEdge); + _EdgeList.push_back(iEdge); } WVertex::incoming_edge_iterator WVertex::incoming_edges_begin() { - WOEdge *begin; - WEdge *wedge = _EdgeList.front(); - WOEdge *aOEdge = wedge->GetaOEdge(); - if (aOEdge->GetbVertex() == this) - begin = aOEdge; - else - begin = _EdgeList.front()->GetbOEdge(); - return incoming_edge_iterator(this, begin, begin); + WOEdge *begin; + WEdge *wedge = _EdgeList.front(); + WOEdge *aOEdge = wedge->GetaOEdge(); + if (aOEdge->GetbVertex() == this) + begin = aOEdge; + else + begin = _EdgeList.front()->GetbOEdge(); + return incoming_edge_iterator(this, begin, begin); } WVertex::incoming_edge_iterator WVertex::incoming_edges_end() { - WOEdge *begin; - WOEdge *aOEdge = _EdgeList.front()->GetaOEdge(); - if (aOEdge->GetbVertex() == this) - begin = aOEdge; - else - begin = _EdgeList.front()->GetbOEdge(); - return incoming_edge_iterator(this, begin, 0); + WOEdge *begin; + WOEdge *aOEdge = _EdgeList.front()->GetaOEdge(); + if (aOEdge->GetbVertex() == this) + begin = aOEdge; + else + begin = _EdgeList.front()->GetbOEdge(); + return incoming_edge_iterator(this, begin, 0); } #if 0 WOEdge **WVertex::incoming_edge_iterator::operator->() { - WOEdge **ppaOEdge = (*_iter)->GetaOEdge(); - if (aOEdge->GetbVertex() == _vertex) { - return ppaOEdge; - } - else { - WOEdge *bOEdge = (*_iter)->GetbOEdge(); - return &bOEdge; - } + WOEdge **ppaOEdge = (*_iter)->GetaOEdge(); + if (aOEdge->GetbVertex() == _vertex) { + return ppaOEdge; + } + else { + WOEdge *bOEdge = (*_iter)->GetbOEdge(); + return &bOEdge; + } } #endif @@ -184,35 +179,35 @@ WOEdge **WVertex::incoming_edge_iterator::operator->() * * **********************************/ -WOEdge::WOEdge(WOEdge& iBrother) +WOEdge::WOEdge(WOEdge &iBrother) { - _paVertex = iBrother.GetaVertex(); - _pbVertex = iBrother.GetbVertex(); - _paFace = iBrother.GetaFace(); - _pbFace = iBrother.GetbFace(); - _pOwner = iBrother.GetOwner(); - userdata = NULL; - iBrother.userdata = new oedgedata; - ((oedgedata *)(iBrother.userdata))->_copy = this; - - _vec = iBrother._vec; - _angle = iBrother._angle; + _paVertex = iBrother.GetaVertex(); + _pbVertex = iBrother.GetbVertex(); + _paFace = iBrother.GetaFace(); + _pbFace = iBrother.GetbFace(); + _pOwner = iBrother.GetOwner(); + userdata = NULL; + iBrother.userdata = new oedgedata; + ((oedgedata *)(iBrother.userdata))->_copy = this; + + _vec = iBrother._vec; + _angle = iBrother._angle; } WOEdge *WOEdge::duplicate() { - WOEdge *clone = new WOEdge(*this); - return clone; + WOEdge *clone = new WOEdge(*this); + return clone; } -WOEdge *WOEdge::twin () +WOEdge *WOEdge::twin() { - return GetOwner()->GetOtherOEdge(this); + return GetOwner()->GetOtherOEdge(this); } WOEdge *WOEdge::getPrevOnFace() { - return _pbFace->GetPrevOEdge(this); + return _pbFace->GetPrevOEdge(this); } /********************************** @@ -223,31 +218,31 @@ WOEdge *WOEdge::getPrevOnFace() * * **********************************/ -WEdge::WEdge(WEdge& iBrother) -{ - _paOEdge = NULL; - _pbOEdge = NULL; - WOEdge *aoedge = iBrother.GetaOEdge(); - WOEdge *boedge = iBrother.GetbOEdge(); - userdata = NULL; - - if (aoedge) - //_paOEdge = new WOEdge(*aoedge); - _paOEdge = aoedge->duplicate(); - if (boedge) - //_pbOEdge = new WOEdge(*boedge); - _pbOEdge = boedge->duplicate(); - - _nOEdges = iBrother.GetNumberOfOEdges(); - _Id = iBrother.GetId(); - iBrother.userdata = new edgedata; - ((edgedata *)(iBrother.userdata))->_copy = this; +WEdge::WEdge(WEdge &iBrother) +{ + _paOEdge = NULL; + _pbOEdge = NULL; + WOEdge *aoedge = iBrother.GetaOEdge(); + WOEdge *boedge = iBrother.GetbOEdge(); + userdata = NULL; + + if (aoedge) + //_paOEdge = new WOEdge(*aoedge); + _paOEdge = aoedge->duplicate(); + if (boedge) + //_pbOEdge = new WOEdge(*boedge); + _pbOEdge = boedge->duplicate(); + + _nOEdges = iBrother.GetNumberOfOEdges(); + _Id = iBrother.GetId(); + iBrother.userdata = new edgedata; + ((edgedata *)(iBrother.userdata))->_copy = this; } WEdge *WEdge::duplicate() { - WEdge *clone = new WEdge(*this); - return clone; + WEdge *clone = new WEdge(*this); + return clone; } /********************************** @@ -258,193 +253,192 @@ WEdge *WEdge::duplicate() * * **********************************/ -WFace::WFace(WFace& iBrother) -{ - _OEdgeList = iBrother.getEdgeList(); - _Normal = iBrother.GetNormal(); - _VerticesNormals = iBrother._VerticesNormals; - _VerticesTexCoords = iBrother._VerticesTexCoords; - _Id = iBrother.GetId(); - _FrsMaterialIndex = iBrother._FrsMaterialIndex; - _Mark = iBrother._Mark; - userdata = NULL; - iBrother.userdata = new facedata; - ((facedata *)(iBrother.userdata))->_copy = this; +WFace::WFace(WFace &iBrother) +{ + _OEdgeList = iBrother.getEdgeList(); + _Normal = iBrother.GetNormal(); + _VerticesNormals = iBrother._VerticesNormals; + _VerticesTexCoords = iBrother._VerticesTexCoords; + _Id = iBrother.GetId(); + _FrsMaterialIndex = iBrother._FrsMaterialIndex; + _Mark = iBrother._Mark; + userdata = NULL; + iBrother.userdata = new facedata; + ((facedata *)(iBrother.userdata))->_copy = this; } WFace *WFace::duplicate() { - WFace *clone = new WFace(*this); - return clone; + WFace *clone = new WFace(*this); + return clone; } -const FrsMaterial& WFace::frs_material() +const FrsMaterial &WFace::frs_material() { - return getShape()->frs_material(_FrsMaterialIndex); + return getShape()->frs_material(_FrsMaterialIndex); } WOEdge *WFace::MakeEdge(WVertex *v1, WVertex *v2) { - // First check whether the same oriented edge already exists or not: - vector& v1Edges = v1->GetEdges(); - for (vector::iterator it1 = v1Edges.begin(), end = v1Edges.end(); it1 != end; it1++) { - WEdge *we = (*it1); - WOEdge *woea = we->GetaOEdge(); - - if ((woea->GetaVertex() == v1) && (woea->GetbVertex() == v2)) { - // The oriented edge already exists - cerr << "Warning: edge " << v1->GetId() << " - " << v2->GetId() << " appears twice, correcting" << endl; - // Adds the edge to the face - AddEdge(woea); - (*it1)->setNumberOfOEdges((*it1)->GetNumberOfOEdges() + 1); - //sets these vertices as border: - v1->setBorder(true); - v2->setBorder(true); - return woea; - } - - WOEdge *woeb = we->GetbOEdge(); - if (woeb && (woeb->GetaVertex() == v1) && (woeb->GetbVertex() == v2)) { - // The oriented edge already exists - cerr << "Warning: edge " << v1->GetId() << " - " << v2->GetId() << " appears twice, correcting" << endl; - // Adds the edge to the face - AddEdge(woeb); - (*it1)->setNumberOfOEdges((*it1)->GetNumberOfOEdges() + 1); - //sets these vertices as border: - v1->setBorder(true); - v2->setBorder(true); - return woeb; - } - } - - // the oriented edge we're about to build - WOEdge *pOEdge = new WOEdge; - // The edge containing the oriented edge. - WEdge *edge; - - // checks whether this edge already exists or not - // If it exists, it points outward v2 - bool exist = false; - WOEdge *pInvertEdge = NULL; // The inverted edge if it exists - vector& v2Edges = v2->GetEdges(); - vector::iterator it; - for (it = v2Edges.begin(); it != v2Edges.end(); it++) { - if ((*it)->GetbVertex() == v1) { - // The invert edge already exists - exist = true; - pInvertEdge = (*it)->GetaOEdge(); - break; - } - } - - //DEBUG: - if (true == exist) { // The invert edge already exists - // Retrieves the corresponding edge - edge = pInvertEdge->GetOwner(); - - // Sets the a Face (retrieved from pInvertEdge - pOEdge->setaFace(pInvertEdge->GetbFace()); - - // Updates the invert edge: - pInvertEdge->setaFace(this); - } - else { // The invert edge does not exist yet - // we must create a new edge - //edge = new WEdge; - edge = instanciateEdge(); - - // updates the a,b vertex edges list: - v1->AddEdge(edge); - v2->AddEdge(edge); - } - - pOEdge->setOwner(edge); - // Add the vertices: - pOEdge->setaVertex(v1); - pOEdge->setbVertex(v2); - - // Debug: - if (v1->GetId() == v2->GetId()) - cerr << "Warning: edge " << this << " null with vertex " << v1->GetId() << endl; - - edge->AddOEdge(pOEdge); - //edge->setNumberOfOEdges(edge->GetNumberOfOEdges() + 1); - - // Add this face (the b face) - pOEdge->setbFace(this); - - // Adds the edge to the face - AddEdge(pOEdge); - - return pOEdge; + // First check whether the same oriented edge already exists or not: + vector &v1Edges = v1->GetEdges(); + for (vector::iterator it1 = v1Edges.begin(), end = v1Edges.end(); it1 != end; it1++) { + WEdge *we = (*it1); + WOEdge *woea = we->GetaOEdge(); + + if ((woea->GetaVertex() == v1) && (woea->GetbVertex() == v2)) { + // The oriented edge already exists + cerr << "Warning: edge " << v1->GetId() << " - " << v2->GetId() + << " appears twice, correcting" << endl; + // Adds the edge to the face + AddEdge(woea); + (*it1)->setNumberOfOEdges((*it1)->GetNumberOfOEdges() + 1); + //sets these vertices as border: + v1->setBorder(true); + v2->setBorder(true); + return woea; + } + + WOEdge *woeb = we->GetbOEdge(); + if (woeb && (woeb->GetaVertex() == v1) && (woeb->GetbVertex() == v2)) { + // The oriented edge already exists + cerr << "Warning: edge " << v1->GetId() << " - " << v2->GetId() + << " appears twice, correcting" << endl; + // Adds the edge to the face + AddEdge(woeb); + (*it1)->setNumberOfOEdges((*it1)->GetNumberOfOEdges() + 1); + //sets these vertices as border: + v1->setBorder(true); + v2->setBorder(true); + return woeb; + } + } + + // the oriented edge we're about to build + WOEdge *pOEdge = new WOEdge; + // The edge containing the oriented edge. + WEdge *edge; + + // checks whether this edge already exists or not + // If it exists, it points outward v2 + bool exist = false; + WOEdge *pInvertEdge = NULL; // The inverted edge if it exists + vector &v2Edges = v2->GetEdges(); + vector::iterator it; + for (it = v2Edges.begin(); it != v2Edges.end(); it++) { + if ((*it)->GetbVertex() == v1) { + // The invert edge already exists + exist = true; + pInvertEdge = (*it)->GetaOEdge(); + break; + } + } + + //DEBUG: + if (true == exist) { // The invert edge already exists + // Retrieves the corresponding edge + edge = pInvertEdge->GetOwner(); + + // Sets the a Face (retrieved from pInvertEdge + pOEdge->setaFace(pInvertEdge->GetbFace()); + + // Updates the invert edge: + pInvertEdge->setaFace(this); + } + else { // The invert edge does not exist yet + // we must create a new edge + //edge = new WEdge; + edge = instanciateEdge(); + + // updates the a,b vertex edges list: + v1->AddEdge(edge); + v2->AddEdge(edge); + } + + pOEdge->setOwner(edge); + // Add the vertices: + pOEdge->setaVertex(v1); + pOEdge->setbVertex(v2); + + // Debug: + if (v1->GetId() == v2->GetId()) + cerr << "Warning: edge " << this << " null with vertex " << v1->GetId() << endl; + + edge->AddOEdge(pOEdge); + //edge->setNumberOfOEdges(edge->GetNumberOfOEdges() + 1); + + // Add this face (the b face) + pOEdge->setbFace(this); + + // Adds the edge to the face + AddEdge(pOEdge); + + return pOEdge; } - bool WFace::getOppositeEdge(const WVertex *v, WOEdge *&e) { - if (_OEdgeList.size() != 3) - return false; - - vector::iterator it; - e = NULL; - for (it = _OEdgeList.begin(); it != _OEdgeList.end(); it++) { - if ((*it)->GetaVertex() == v) - e = *it; - } - if (!e) - return false; - e = NULL; - for (it = _OEdgeList.begin(); it != _OEdgeList.end(); it++) { - if (((*it)->GetaVertex() != v) && ((*it)->GetbVertex() != v)) - e = *it; - } - if (!e) - return false; - else - return true; + if (_OEdgeList.size() != 3) + return false; + + vector::iterator it; + e = NULL; + for (it = _OEdgeList.begin(); it != _OEdgeList.end(); it++) { + if ((*it)->GetaVertex() == v) + e = *it; + } + if (!e) + return false; + e = NULL; + for (it = _OEdgeList.begin(); it != _OEdgeList.end(); it++) { + if (((*it)->GetaVertex() != v) && ((*it)->GetbVertex() != v)) + e = *it; + } + if (!e) + return false; + else + return true; } float WFace::getArea() { - vector::iterator it; - Vec3f origin = (*(_OEdgeList.begin()))->GetaVertex()->GetVertex(); - it = _OEdgeList.begin(); - float a = 0; - for (it = it++; it != _OEdgeList.end(); it++) { - Vec3f v1 = Vec3f((*it)->GetaVertex()->GetVertex() - origin); - Vec3f v2 = Vec3f((*it)->GetbVertex()->GetVertex() - origin); - a += (v1 ^ v2).norm() / 2.0f; - } - return a; + vector::iterator it; + Vec3f origin = (*(_OEdgeList.begin()))->GetaVertex()->GetVertex(); + it = _OEdgeList.begin(); + float a = 0; + for (it = it++; it != _OEdgeList.end(); it++) { + Vec3f v1 = Vec3f((*it)->GetaVertex()->GetVertex() - origin); + Vec3f v2 = Vec3f((*it)->GetbVertex()->GetVertex() - origin); + a += (v1 ^ v2).norm() / 2.0f; + } + return a; } - WOEdge *WFace::GetPrevOEdge(WOEdge *iOEdge) { - vector::iterator woe, woend, woefirst; - woefirst = _OEdgeList.begin(); - woend = _OEdgeList.end(); - WOEdge *prev = *woefirst; - woe = woefirst; - ++woe; - for (; woe != woend; woe++) { - if ((*woe) == iOEdge) - return prev; - prev = *woe; - } - // We left the loop. That means that the first OEdge was the good one: - if ((*woefirst) == iOEdge) - return prev; - - return NULL; + vector::iterator woe, woend, woefirst; + woefirst = _OEdgeList.begin(); + woend = _OEdgeList.end(); + WOEdge *prev = *woefirst; + woe = woefirst; + ++woe; + for (; woe != woend; woe++) { + if ((*woe) == iOEdge) + return prev; + prev = *woe; + } + // We left the loop. That means that the first OEdge was the good one: + if ((*woefirst) == iOEdge) + return prev; + + return NULL; } WShape *WFace::getShape() { - return GetVertex(0)->shape(); + return GetVertex(0)->shape(); } - /********************************** * * * * @@ -457,255 +451,259 @@ unsigned WShape::_SceneCurrentId = 0; WShape *WShape::duplicate() { - WShape *clone = new WShape(*this); - return clone; + WShape *clone = new WShape(*this); + return clone; } -WShape::WShape(WShape& iBrother) +WShape::WShape(WShape &iBrother) { - _Id = iBrother.GetId(); - _Name = iBrother._Name; - _LibraryPath = iBrother._LibraryPath; - _FrsMaterials = iBrother._FrsMaterials; + _Id = iBrother.GetId(); + _Name = iBrother._Name; + _LibraryPath = iBrother._LibraryPath; + _FrsMaterials = iBrother._FrsMaterials; #if 0 - _meanEdgeSize = iBrother._meanEdgeSize; - iBrother.bbox(_min, _max); + _meanEdgeSize = iBrother._meanEdgeSize; + iBrother.bbox(_min, _max); #endif - vector& vertexList = iBrother.getVertexList(); - vector::iterator v = vertexList.begin(), vend = vertexList.end(); - for (; v != vend; ++v) { - //WVertex *newVertex = new WVertex(*(*v)); - WVertex *newVertex = (*v)->duplicate(); - - newVertex->setShape(this); - AddVertex(newVertex); - } - - vector& edgeList = iBrother.getEdgeList(); - vector::iterator e = edgeList.begin(), eend = edgeList.end(); - for (; e != eend; ++e) { - //WEdge *newEdge = new WEdge(*(*e)); - WEdge *newEdge = (*e)->duplicate(); - AddEdge(newEdge); - } - - vector& faceList = iBrother.GetFaceList(); - vector::iterator f = faceList.begin(), fend = faceList.end(); - for (; f != fend; ++f) { - //WFace *newFace = new WFace(*(*f)); - WFace *newFace = (*f)->duplicate(); - AddFace(newFace); - } - - // update all pointed addresses thanks to the newly created objects: - vend = _VertexList.end(); - for (v = _VertexList.begin(); v != vend; ++v) { - const vector& vedgeList = (*v)->GetEdges(); - vector newvedgelist; - unsigned int i; - for (i = 0; i < vedgeList.size(); i++) { - WEdge *current = vedgeList[i]; - edgedata *currentvedata = (edgedata *)current->userdata; - newvedgelist.push_back(currentvedata->_copy); - } - (*v)->setEdges(newvedgelist); - } - - eend = _EdgeList.end(); - for (e = _EdgeList.begin(); e != eend; ++e) { - // update aOedge: - WOEdge *aoEdge = (*e)->GetaOEdge(); - aoEdge->setaVertex(((vertexdata *)(aoEdge->GetaVertex()->userdata))->_copy); - aoEdge->setbVertex(((vertexdata *)(aoEdge->GetbVertex()->userdata))->_copy); - if (aoEdge->GetaFace()) - aoEdge->setaFace(((facedata *)(aoEdge->GetaFace()->userdata))->_copy); - aoEdge->setbFace(((facedata *)(aoEdge->GetbFace()->userdata))->_copy); - aoEdge->setOwner(((edgedata *)(aoEdge->GetOwner()->userdata))->_copy); - - // update bOedge: - WOEdge *boEdge = (*e)->GetbOEdge(); - if (boEdge) { - boEdge->setaVertex(((vertexdata *)(boEdge->GetaVertex()->userdata))->_copy); - boEdge->setbVertex(((vertexdata *)(boEdge->GetbVertex()->userdata))->_copy); - if (boEdge->GetaFace()) - boEdge->setaFace(((facedata *)(boEdge->GetaFace()->userdata))->_copy); - boEdge->setbFace(((facedata *)(boEdge->GetbFace()->userdata))->_copy); - boEdge->setOwner(((edgedata *)(boEdge->GetOwner()->userdata))->_copy); - } - } - - fend = _FaceList.end(); - for (f = _FaceList.begin(); f != fend; ++f) { - unsigned int i; - const vector& oedgeList = (*f)->getEdgeList(); - vector newoedgelist; - - unsigned int n = oedgeList.size(); - for (i = 0; i < n; i++) { - WOEdge *current = oedgeList[i]; - oedgedata *currentoedata = (oedgedata *)current->userdata; - newoedgelist.push_back(currentoedata->_copy); - //oedgeList[i] = currentoedata->_copy; - //oedgeList[i] = ((oedgedata *)(oedgeList[i]->userdata))->_copy; - } - (*f)->setEdgeList(newoedgelist); - } - - // Free all memory (arghh!) - // Vertex - vend = iBrother.getVertexList().end(); - for (v = iBrother.getVertexList().begin(); v != vend; ++v) { - delete (vertexdata *)((*v)->userdata); - (*v)->userdata = NULL; - } - - // Edges and OEdges: - eend = iBrother.getEdgeList().end(); - for (e = iBrother.getEdgeList().begin(); e != eend; ++e) { - delete (edgedata *)((*e)->userdata); - (*e)->userdata = NULL; - // OEdge a: - delete (oedgedata *)((*e)->GetaOEdge()->userdata); - (*e)->GetaOEdge()->userdata = NULL; - // OEdge b: - WOEdge *oedgeb = (*e)->GetbOEdge(); - if (oedgeb) { - delete (oedgedata *)(oedgeb->userdata); - oedgeb->userdata = NULL; - } - } - - // Faces - fend = iBrother.GetFaceList().end(); - for (f = iBrother.GetFaceList().begin(); f != fend; ++f) { - delete (facedata *)((*f)->userdata); - (*f)->userdata = NULL; - } + vector &vertexList = iBrother.getVertexList(); + vector::iterator v = vertexList.begin(), vend = vertexList.end(); + for (; v != vend; ++v) { + //WVertex *newVertex = new WVertex(*(*v)); + WVertex *newVertex = (*v)->duplicate(); + + newVertex->setShape(this); + AddVertex(newVertex); + } + + vector &edgeList = iBrother.getEdgeList(); + vector::iterator e = edgeList.begin(), eend = edgeList.end(); + for (; e != eend; ++e) { + //WEdge *newEdge = new WEdge(*(*e)); + WEdge *newEdge = (*e)->duplicate(); + AddEdge(newEdge); + } + + vector &faceList = iBrother.GetFaceList(); + vector::iterator f = faceList.begin(), fend = faceList.end(); + for (; f != fend; ++f) { + //WFace *newFace = new WFace(*(*f)); + WFace *newFace = (*f)->duplicate(); + AddFace(newFace); + } + + // update all pointed addresses thanks to the newly created objects: + vend = _VertexList.end(); + for (v = _VertexList.begin(); v != vend; ++v) { + const vector &vedgeList = (*v)->GetEdges(); + vector newvedgelist; + unsigned int i; + for (i = 0; i < vedgeList.size(); i++) { + WEdge *current = vedgeList[i]; + edgedata *currentvedata = (edgedata *)current->userdata; + newvedgelist.push_back(currentvedata->_copy); + } + (*v)->setEdges(newvedgelist); + } + + eend = _EdgeList.end(); + for (e = _EdgeList.begin(); e != eend; ++e) { + // update aOedge: + WOEdge *aoEdge = (*e)->GetaOEdge(); + aoEdge->setaVertex(((vertexdata *)(aoEdge->GetaVertex()->userdata))->_copy); + aoEdge->setbVertex(((vertexdata *)(aoEdge->GetbVertex()->userdata))->_copy); + if (aoEdge->GetaFace()) + aoEdge->setaFace(((facedata *)(aoEdge->GetaFace()->userdata))->_copy); + aoEdge->setbFace(((facedata *)(aoEdge->GetbFace()->userdata))->_copy); + aoEdge->setOwner(((edgedata *)(aoEdge->GetOwner()->userdata))->_copy); + + // update bOedge: + WOEdge *boEdge = (*e)->GetbOEdge(); + if (boEdge) { + boEdge->setaVertex(((vertexdata *)(boEdge->GetaVertex()->userdata))->_copy); + boEdge->setbVertex(((vertexdata *)(boEdge->GetbVertex()->userdata))->_copy); + if (boEdge->GetaFace()) + boEdge->setaFace(((facedata *)(boEdge->GetaFace()->userdata))->_copy); + boEdge->setbFace(((facedata *)(boEdge->GetbFace()->userdata))->_copy); + boEdge->setOwner(((edgedata *)(boEdge->GetOwner()->userdata))->_copy); + } + } + + fend = _FaceList.end(); + for (f = _FaceList.begin(); f != fend; ++f) { + unsigned int i; + const vector &oedgeList = (*f)->getEdgeList(); + vector newoedgelist; + + unsigned int n = oedgeList.size(); + for (i = 0; i < n; i++) { + WOEdge *current = oedgeList[i]; + oedgedata *currentoedata = (oedgedata *)current->userdata; + newoedgelist.push_back(currentoedata->_copy); + //oedgeList[i] = currentoedata->_copy; + //oedgeList[i] = ((oedgedata *)(oedgeList[i]->userdata))->_copy; + } + (*f)->setEdgeList(newoedgelist); + } + + // Free all memory (arghh!) + // Vertex + vend = iBrother.getVertexList().end(); + for (v = iBrother.getVertexList().begin(); v != vend; ++v) { + delete (vertexdata *)((*v)->userdata); + (*v)->userdata = NULL; + } + + // Edges and OEdges: + eend = iBrother.getEdgeList().end(); + for (e = iBrother.getEdgeList().begin(); e != eend; ++e) { + delete (edgedata *)((*e)->userdata); + (*e)->userdata = NULL; + // OEdge a: + delete (oedgedata *)((*e)->GetaOEdge()->userdata); + (*e)->GetaOEdge()->userdata = NULL; + // OEdge b: + WOEdge *oedgeb = (*e)->GetbOEdge(); + if (oedgeb) { + delete (oedgedata *)(oedgeb->userdata); + oedgeb->userdata = NULL; + } + } + + // Faces + fend = iBrother.GetFaceList().end(); + for (f = iBrother.GetFaceList().begin(); f != fend; ++f) { + delete (facedata *)((*f)->userdata); + (*f)->userdata = NULL; + } } -WFace *WShape::MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterial) +WFace *WShape::MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterial) { - // allocate the new face - WFace *face = instanciateFace(); + // allocate the new face + WFace *face = instanciateFace(); - WFace *result = MakeFace(iVertexList, iFaceEdgeMarksList, iMaterial, face); - if (!result) - delete face; - return result; + WFace *result = MakeFace(iVertexList, iFaceEdgeMarksList, iMaterial, face); + if (!result) + delete face; + return result; } -WFace *WShape::MakeFace(vector& iVertexList, vector& iNormalsList, vector& iTexCoordsList, - vector& iFaceEdgeMarksList, unsigned iMaterial) +WFace *WShape::MakeFace(vector &iVertexList, + vector &iNormalsList, + vector &iTexCoordsList, + vector &iFaceEdgeMarksList, + unsigned iMaterial) { - // allocate the new face - WFace *face = MakeFace(iVertexList, iFaceEdgeMarksList, iMaterial); + // allocate the new face + WFace *face = MakeFace(iVertexList, iFaceEdgeMarksList, iMaterial); - if (!face) - return NULL; + if (!face) + return NULL; - // set the list of per-vertex normals - face->setNormalList(iNormalsList); - // set the list of per-vertex tex coords - face->setTexCoordsList(iTexCoordsList); + // set the list of per-vertex normals + face->setNormalList(iNormalsList); + // set the list of per-vertex tex coords + face->setTexCoordsList(iTexCoordsList); - return face; + return face; } -WFace *WShape::MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterial, +WFace *WShape::MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterial, WFace *face) { - int id = _FaceList.size(); - - face->setFrsMaterialIndex(iMaterial); - - // Check whether we have a degenerated face: - - // LET'S HACK IT FOR THE TRIANGLE CASE: - - if (3 == iVertexList.size()) { - if ((iVertexList[0] == iVertexList[1]) || - (iVertexList[0] == iVertexList[2]) || - (iVertexList[2] == iVertexList[1])) - { - cerr << "Warning: degenerated triangle detected, correcting" << endl; - return NULL; - } - } - - vector::iterator it; - - // compute the face normal (v1v2 ^ v1v3) - // Double precision numbers are used here to avoid truncation errors [T47705] - Vec3r v1, v2, v3; - it = iVertexList.begin(); - v1 = (*it)->GetVertex(); - it++; - v2 = (*it)->GetVertex(); - it++; - v3 = (*it)->GetVertex(); - - Vec3r vector1(v2 - v1); - Vec3r vector2(v3 - v1); - - Vec3r normal(vector1 ^ vector2); - normal.normalize(); - face->setNormal(normal); - - vector::iterator mit = iFaceEdgeMarksList.begin(); - face->setMark(*mit); - mit++; - - // vertex pointers used to build each edge - vector::iterator va, vb; - - va = iVertexList.begin(); - vb = va; - for (; va != iVertexList.end(); va = vb) { - ++vb; - // Adds va to the vertex list: - //face->AddVertex(*va); - - WOEdge *oedge; - if (*va == iVertexList.back()) - oedge = face->MakeEdge(*va, iVertexList.front()); //for the last (closing) edge - else - oedge = face->MakeEdge(*va, *vb); - - if (!oedge) - return NULL; - - WEdge *edge = oedge->GetOwner(); - if (1 == edge->GetNumberOfOEdges()) { - // means that we just created a new edge and that we must add it to the shape's edges list - edge->setId(_EdgeList.size()); - AddEdge(edge); + int id = _FaceList.size(); + + face->setFrsMaterialIndex(iMaterial); + + // Check whether we have a degenerated face: + + // LET'S HACK IT FOR THE TRIANGLE CASE: + + if (3 == iVertexList.size()) { + if ((iVertexList[0] == iVertexList[1]) || (iVertexList[0] == iVertexList[2]) || + (iVertexList[2] == iVertexList[1])) { + cerr << "Warning: degenerated triangle detected, correcting" << endl; + return NULL; + } + } + + vector::iterator it; + + // compute the face normal (v1v2 ^ v1v3) + // Double precision numbers are used here to avoid truncation errors [T47705] + Vec3r v1, v2, v3; + it = iVertexList.begin(); + v1 = (*it)->GetVertex(); + it++; + v2 = (*it)->GetVertex(); + it++; + v3 = (*it)->GetVertex(); + + Vec3r vector1(v2 - v1); + Vec3r vector2(v3 - v1); + + Vec3r normal(vector1 ^ vector2); + normal.normalize(); + face->setNormal(normal); + + vector::iterator mit = iFaceEdgeMarksList.begin(); + face->setMark(*mit); + mit++; + + // vertex pointers used to build each edge + vector::iterator va, vb; + + va = iVertexList.begin(); + vb = va; + for (; va != iVertexList.end(); va = vb) { + ++vb; + // Adds va to the vertex list: + //face->AddVertex(*va); + + WOEdge *oedge; + if (*va == iVertexList.back()) + oedge = face->MakeEdge(*va, iVertexList.front()); //for the last (closing) edge + else + oedge = face->MakeEdge(*va, *vb); + + if (!oedge) + return NULL; + + WEdge *edge = oedge->GetOwner(); + if (1 == edge->GetNumberOfOEdges()) { + // means that we just created a new edge and that we must add it to the shape's edges list + edge->setId(_EdgeList.size()); + AddEdge(edge); #if 0 - // compute the mean edge value: - _meanEdgeSize += edge->GetaOEdge()->GetVec().norm(); + // compute the mean edge value: + _meanEdgeSize += edge->GetaOEdge()->GetVec().norm(); #endif - } + } - edge->setMark(*mit); - ++mit; - } + edge->setMark(*mit); + ++mit; + } - // Add the face to the shape's faces list: - face->setId(id); - AddFace(face); + // Add the face to the shape's faces list: + face->setId(id); + AddFace(face); - return face; + return face; } real WShape::ComputeMeanEdgeSize() const { - real meanEdgeSize = 0.0; - for (vector::const_iterator it = _EdgeList.begin(), itend = _EdgeList.end(); - it != itend; - it++) - { - meanEdgeSize += (*it)->GetaOEdge()->GetVec().norm(); - } - return meanEdgeSize / (real)_EdgeList.size(); + real meanEdgeSize = 0.0; + for (vector::const_iterator it = _EdgeList.begin(), itend = _EdgeList.end(); + it != itend; + it++) { + meanEdgeSize += (*it)->GetaOEdge()->GetVec().norm(); + } + return meanEdgeSize / (real)_EdgeList.size(); } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WEdge.h b/source/blender/freestyle/intern/winged_edge/WEdge.h index b4807a4d921..79c6a24e6d9 100644 --- a/source/blender/freestyle/intern/winged_edge/WEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WEdge.h @@ -34,7 +34,7 @@ #include "BLI_math.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif using namespace std; @@ -43,7 +43,6 @@ namespace Freestyle { using namespace Geometry; - /********************************** * * * * @@ -52,303 +51,309 @@ using namespace Geometry; * * **********************************/ - class WOEdge; class WEdge; class WShape; class WFace; -class WVertex -{ -protected: - int _Id; // an identificator - Vec3f _Vertex; - vector _EdgeList; - WShape *_Shape; // the shape to which the vertex belongs - bool _Smooth; // flag to indicate whether the Vertex belongs to a smooth edge or not - short _Border; // 1 -> border, 0 -> no border, -1 -> not set - -public: - void *userdata; // designed to store specific user data - inline WVertex(const Vec3f &v) - { - _Id = 0; - _Vertex = v; - userdata = NULL; - _Shape = NULL; - _Smooth = true; - _Border = -1; - } - - /*! Copy constructor */ - WVertex(WVertex& iBrother); - virtual WVertex *duplicate(); - virtual ~WVertex() {} - - /*! accessors */ - inline Vec3f& GetVertex() - { - return _Vertex; - } - - inline vector& GetEdges() - { - return _EdgeList; - } - - inline int GetId() - { - return _Id; - } - - inline WShape *shape() const - { - return _Shape; - } - - inline bool isSmooth() const - { - return _Smooth; - } - - bool isBoundary(); - - /*! modifiers */ - inline void setVertex(const Vec3f& v) - { - _Vertex = v; - } - - inline void setEdges(const vector& iEdgeList) - { - _EdgeList = iEdgeList; - } - - inline void setId(int id) - { - _Id = id; - } - - inline void setShape(WShape *iShape) - { - _Shape = iShape; - } - - inline void setSmooth(bool b) - { - _Smooth = b; - } - - inline void setBorder(bool b) - { - if (b) - _Border = 1; - else - _Border = 0; - } - - /*! Adds an edge to the edges list */ - void AddEdge(WEdge *iEdge); - - virtual void ResetUserData() - { - userdata = NULL; - } - -public: - /*! Iterator to iterate over a vertex incoming edges in the CCW order*/ +class WVertex { + protected: + int _Id; // an identificator + Vec3f _Vertex; + vector _EdgeList; + WShape *_Shape; // the shape to which the vertex belongs + bool _Smooth; // flag to indicate whether the Vertex belongs to a smooth edge or not + short _Border; // 1 -> border, 0 -> no border, -1 -> not set + + public: + void *userdata; // designed to store specific user data + inline WVertex(const Vec3f &v) + { + _Id = 0; + _Vertex = v; + userdata = NULL; + _Shape = NULL; + _Smooth = true; + _Border = -1; + } + + /*! Copy constructor */ + WVertex(WVertex &iBrother); + virtual WVertex *duplicate(); + virtual ~WVertex() + { + } + + /*! accessors */ + inline Vec3f &GetVertex() + { + return _Vertex; + } + + inline vector &GetEdges() + { + return _EdgeList; + } + + inline int GetId() + { + return _Id; + } + + inline WShape *shape() const + { + return _Shape; + } + + inline bool isSmooth() const + { + return _Smooth; + } + + bool isBoundary(); + + /*! modifiers */ + inline void setVertex(const Vec3f &v) + { + _Vertex = v; + } + + inline void setEdges(const vector &iEdgeList) + { + _EdgeList = iEdgeList; + } + + inline void setId(int id) + { + _Id = id; + } + + inline void setShape(WShape *iShape) + { + _Shape = iShape; + } + + inline void setSmooth(bool b) + { + _Smooth = b; + } + + inline void setBorder(bool b) + { + if (b) + _Border = 1; + else + _Border = 0; + } + + /*! Adds an edge to the edges list */ + void AddEdge(WEdge *iEdge); + + virtual void ResetUserData() + { + userdata = NULL; + } + + public: + /*! Iterator to iterate over a vertex incoming edges in the CCW order*/ #if defined(__GNUC__) && (__GNUC__ < 3) - class incoming_edge_iterator : public input_iterator + class incoming_edge_iterator : public input_iterator #else - class incoming_edge_iterator - : public iterator + class incoming_edge_iterator : public iterator #endif - { - private: - WVertex *_vertex; - // - WOEdge *_begin; - WOEdge *_current; - - public: + { + private: + WVertex *_vertex; + // + WOEdge *_begin; + WOEdge *_current; + + public: #if defined(__GNUC__) && (__GNUC__ < 3) - inline incoming_edge_iterator() : input_iterator() {} + inline incoming_edge_iterator() : input_iterator() + { + } #else - inline incoming_edge_iterator() : iterator() {} + inline incoming_edge_iterator() : iterator() + { + } #endif - virtual ~incoming_edge_iterator() {}; //soc + virtual ~incoming_edge_iterator(){}; //soc - protected: - friend class WVertex; - inline incoming_edge_iterator(WVertex *iVertex, WOEdge *iBegin, WOEdge *iCurrent) + protected: + friend class WVertex; + inline incoming_edge_iterator(WVertex *iVertex, WOEdge *iBegin, WOEdge *iCurrent) #if defined(__GNUC__) && (__GNUC__ < 3) - : input_iterator() + : input_iterator() #else - : iterator() + : iterator() #endif - { - _vertex = iVertex; - _begin = iBegin; - _current = iCurrent; - } - - public: - inline incoming_edge_iterator(const incoming_edge_iterator& iBrother) + { + _vertex = iVertex; + _begin = iBegin; + _current = iCurrent; + } + + public: + inline incoming_edge_iterator(const incoming_edge_iterator &iBrother) #if defined(__GNUC__) && (__GNUC__ < 3) - : input_iterator(iBrother) + : input_iterator(iBrother) #else - : iterator(iBrother) + : iterator(iBrother) #endif - { - _vertex = iBrother._vertex; - _begin = iBrother._begin; - _current = iBrother._current; - } - - public: - // operators - // operator corresponding to ++i - virtual incoming_edge_iterator& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++ - virtual incoming_edge_iterator operator++(int) - { - incoming_edge_iterator tmp = *this; - increment(); - return tmp; - } - - // comparibility - virtual bool operator!=(const incoming_edge_iterator& b) const - { - return ((_current) != (b._current)); - } - - virtual bool operator==(const incoming_edge_iterator& b) const - { - return ((_current) == (b._current)); - } - - // dereferencing - virtual WOEdge *operator*(); - //virtual WOEdge **operator->(); - protected: - virtual void increment(); + { + _vertex = iBrother._vertex; + _begin = iBrother._begin; + _current = iBrother._current; + } + + public: + // operators + // operator corresponding to ++i + virtual incoming_edge_iterator &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++ + virtual incoming_edge_iterator operator++(int) + { + incoming_edge_iterator tmp = *this; + increment(); + return tmp; + } + + // comparibility + virtual bool operator!=(const incoming_edge_iterator &b) const + { + return ((_current) != (b._current)); + } + + virtual bool operator==(const incoming_edge_iterator &b) const + { + return ((_current) == (b._current)); + } + + // dereferencing + virtual WOEdge *operator*(); + //virtual WOEdge **operator->(); + protected: + virtual void increment(); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:incoming_edge_iterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:incoming_edge_iterator") #endif - }; + }; - /*! Iterator to iterate over a vertex faces in the CCW order */ + /*! Iterator to iterate over a vertex faces in the CCW order */ #if defined(__GNUC__) && (__GNUC__ < 3) - class face_iterator : public input_iterator + class face_iterator : public input_iterator #else - class face_iterator : public iterator + class face_iterator : public iterator #endif - { - private: - incoming_edge_iterator _edge_it; + { + private: + incoming_edge_iterator _edge_it; - public: + public: #if defined(__GNUC__) && (__GNUC__ < 3) - inline face_iterator() : input_iterator() {} + inline face_iterator() : input_iterator() + { + } #else - inline face_iterator() : iterator() {} + inline face_iterator() : iterator() + { + } #endif - virtual ~face_iterator() {}; //soc + virtual ~face_iterator(){}; //soc - protected: - friend class WVertex; - inline face_iterator(incoming_edge_iterator it) + protected: + friend class WVertex; + inline face_iterator(incoming_edge_iterator it) #if defined(__GNUC__) && (__GNUC__ < 3) - : input_iterator() + : input_iterator() #else - : iterator() + : iterator() #endif - { - _edge_it = it; - } + { + _edge_it = it; + } - public: - inline face_iterator(const face_iterator& iBrother) + public: + inline face_iterator(const face_iterator &iBrother) #if defined(__GNUC__) && (__GNUC__ < 3) - : input_iterator(iBrother) + : input_iterator(iBrother) #else - : iterator(iBrother) + : iterator(iBrother) #endif - { - _edge_it = iBrother._edge_it; - } - - public: - // operators - // operator corresponding to ++i - virtual face_iterator& operator++() - { - increment(); - return *this; - } - - // operator corresponding to i++ - virtual face_iterator operator++(int) - { - face_iterator tmp = *this; - increment(); - return tmp; - } - - // comparibility - virtual bool operator!=(const face_iterator& b) const - { - return ((_edge_it) != (b._edge_it)); - } - - virtual bool operator==(const face_iterator& b) const - { - return ((_edge_it) == (b._edge_it)); - } - - // dereferencing - virtual WFace *operator*(); - //virtual WOEdge **operator->(); - - protected: - inline void increment() - { - ++_edge_it; - } + { + _edge_it = iBrother._edge_it; + } + + public: + // operators + // operator corresponding to ++i + virtual face_iterator &operator++() + { + increment(); + return *this; + } + + // operator corresponding to i++ + virtual face_iterator operator++(int) + { + face_iterator tmp = *this; + increment(); + return tmp; + } + + // comparibility + virtual bool operator!=(const face_iterator &b) const + { + return ((_edge_it) != (b._edge_it)); + } + + virtual bool operator==(const face_iterator &b) const + { + return ((_edge_it) == (b._edge_it)); + } + + // dereferencing + virtual WFace *operator*(); + //virtual WOEdge **operator->(); + + protected: + inline void increment() + { + ++_edge_it; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:face_iterator") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:face_iterator") #endif - }; + }; -public: - /*! iterators access */ - virtual incoming_edge_iterator incoming_edges_begin(); - virtual incoming_edge_iterator incoming_edges_end(); + public: + /*! iterators access */ + virtual incoming_edge_iterator incoming_edges_begin(); + virtual incoming_edge_iterator incoming_edges_end(); - virtual face_iterator faces_begin() - { - return face_iterator(incoming_edges_begin()); - } + virtual face_iterator faces_begin() + { + return face_iterator(incoming_edges_begin()); + } - virtual face_iterator faces_end() - { - return face_iterator(incoming_edges_end()); - } + virtual face_iterator faces_end() + { + return face_iterator(incoming_edges_end()); + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex") #endif }; - /********************************** * * * * @@ -360,178 +365,176 @@ public: class WFace; class WEdge; -class WOEdge -{ -protected: +class WOEdge { + protected: #if 0 - WOEdge *_paCWEdge; // edge reached when traveling clockwise on aFace from the edge - WOEdge *_pbCWEdge; // edge reached when traveling clockwise on bFace from the edge - WOEdge *_paCCWEdge; // edge reached when traveling counterclockwise on aFace from the edge - WOEdge *_pbCCWEdge; // edge reached when traveling counterclockwise on bFace from the edge + WOEdge *_paCWEdge; // edge reached when traveling clockwise on aFace from the edge + WOEdge *_pbCWEdge; // edge reached when traveling clockwise on bFace from the edge + WOEdge *_paCCWEdge; // edge reached when traveling counterclockwise on aFace from the edge + WOEdge *_pbCCWEdge; // edge reached when traveling counterclockwise on bFace from the edge #endif - WVertex *_paVertex; // starting vertex - WVertex *_pbVertex; // ending vertex - WFace *_paFace; // when following the edge, face on the right - WFace *_pbFace; // when following the edge, face on the left - WEdge *_pOwner; // Edge + WVertex *_paVertex; // starting vertex + WVertex *_pbVertex; // ending vertex + WFace *_paFace; // when following the edge, face on the right + WFace *_pbFace; // when following the edge, face on the left + WEdge *_pOwner; // Edge - Vec3f _vec; - float _angle; + Vec3f _vec; + float _angle; -public: - void *userdata; + public: + void *userdata; - inline WOEdge() - { + inline WOEdge() + { #if 0 - _paCWEdge = NULL; - _pbCWEdge = NULL; - _paCCWEdge = NULL; - _pbCCWEdge = NULL; + _paCWEdge = NULL; + _pbCWEdge = NULL; + _paCCWEdge = NULL; + _pbCCWEdge = NULL; #endif - _paVertex = NULL; - _pbVertex = NULL; - _paFace = NULL; - _pbFace = NULL; - _pOwner = NULL; - userdata = NULL; - } + _paVertex = NULL; + _pbVertex = NULL; + _paFace = NULL; + _pbFace = NULL; + _pOwner = NULL; + userdata = NULL; + } - virtual ~WOEdge() {}; //soc + virtual ~WOEdge(){}; //soc - /*! copy constructor */ - WOEdge(WOEdge& iBrother); - virtual WOEdge *duplicate(); + /*! copy constructor */ + WOEdge(WOEdge &iBrother); + virtual WOEdge *duplicate(); - /*! accessors */ + /*! accessors */ #if 0 - inline WOEdge *GetaCWEdge() - { - return _paCWEdge; - } - - inline WOEdge *GetbCWEdge() - { - return _pbCWEdge; - } - - inline WOEdge *GetaCCWEdge() - { - return _paCCWEdge; - } - - inline WOEdge *GetbCCWEdge() - { - return _pbCCWEdge; - } + inline WOEdge *GetaCWEdge() + { + return _paCWEdge; + } + + inline WOEdge *GetbCWEdge() + { + return _pbCWEdge; + } + + inline WOEdge *GetaCCWEdge() + { + return _paCCWEdge; + } + + inline WOEdge *GetbCCWEdge() + { + return _pbCCWEdge; + } #endif - inline WVertex *GetaVertex() - { - return _paVertex; - } - - inline WVertex *GetbVertex() - { - return _pbVertex; - } - - inline WFace *GetaFace() - { - return _paFace; - } - - inline WFace *GetbFace() - { - return _pbFace; - } - - inline WEdge *GetOwner() - { - return _pOwner; - } - - inline const Vec3f& GetVec() - { - return _vec; - } - - inline const float GetAngle() - { - return _angle; - } - - /*! modifiers */ + inline WVertex *GetaVertex() + { + return _paVertex; + } + + inline WVertex *GetbVertex() + { + return _pbVertex; + } + + inline WFace *GetaFace() + { + return _paFace; + } + + inline WFace *GetbFace() + { + return _pbFace; + } + + inline WEdge *GetOwner() + { + return _pOwner; + } + + inline const Vec3f &GetVec() + { + return _vec; + } + + inline const float GetAngle() + { + return _angle; + } + + /*! modifiers */ #if 0 - inline void SetaCWEdge(WOEdge *pe) - { - _paCWEdge = pe; - } - - inline void SetbCWEdge(WOEdge *pe) - { - _pbCWEdge = pe; - } - - inline void SetaCCWEdge(WOEdge *pe) - { - _paCCWEdge = pe; - } - - inline void SetbCCCWEdge(WOEdge *pe) - { - _pbCCWEdge = pe; - } + inline void SetaCWEdge(WOEdge *pe) + { + _paCWEdge = pe; + } + + inline void SetbCWEdge(WOEdge *pe) + { + _pbCWEdge = pe; + } + + inline void SetaCCWEdge(WOEdge *pe) + { + _paCCWEdge = pe; + } + + inline void SetbCCCWEdge(WOEdge *pe) + { + _pbCCWEdge = pe; + } #endif - inline void setVecAndAngle(); + inline void setVecAndAngle(); - inline void setaVertex(WVertex *pv) - { - _paVertex = pv; - setVecAndAngle(); - } + inline void setaVertex(WVertex *pv) + { + _paVertex = pv; + setVecAndAngle(); + } - inline void setbVertex(WVertex *pv) - { - _pbVertex = pv; - setVecAndAngle(); - } + inline void setbVertex(WVertex *pv) + { + _pbVertex = pv; + setVecAndAngle(); + } - inline void setaFace(WFace *pf) - { - _paFace = pf; - setVecAndAngle(); - } + inline void setaFace(WFace *pf) + { + _paFace = pf; + setVecAndAngle(); + } - inline void setbFace(WFace *pf) - { - _pbFace = pf; - setVecAndAngle(); - } + inline void setbFace(WFace *pf) + { + _pbFace = pf; + setVecAndAngle(); + } - inline void setOwner(WEdge *pe) - { - _pOwner = pe; - } + inline void setOwner(WEdge *pe) + { + _pOwner = pe; + } - /*! Retrieves the list of edges in CW order */ - inline void RetrieveCWOrderedEdges(vector& oEdges); + /*! Retrieves the list of edges in CW order */ + inline void RetrieveCWOrderedEdges(vector &oEdges); - WOEdge *twin (); - WOEdge *getPrevOnFace(); + WOEdge *twin(); + WOEdge *getPrevOnFace(); - virtual void ResetUserData() - { - userdata = NULL; - } + virtual void ResetUserData() + { + userdata = NULL; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WOEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WOEdge") #endif }; - /********************************** * * * * @@ -540,185 +543,184 @@ public: * * **********************************/ -class WEdge -{ -protected: - WOEdge *_paOEdge; // first oriented edge - WOEdge *_pbOEdge; // second oriented edge - short _nOEdges; // number of oriented edges associated with this edge. (1 means border edge) - bool _Mark; // user-specified edge mark for feature edge detection - int _Id; // Identifier for the edge - -public: - void *userdata; // designed to store specific user data - - inline WEdge() - { - _paOEdge = NULL; - _pbOEdge = NULL; - _nOEdges = 0; - userdata = NULL; - } - - inline WEdge(WOEdge *iOEdge) - { - _paOEdge = iOEdge; - _pbOEdge = NULL; - _nOEdges = 1; - userdata = NULL; - } - - inline WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge) - { - _paOEdge = iaOEdge; - _pbOEdge = ibOEdge; - _nOEdges = 2; - userdata = NULL; - } - - /*! Copy constructor */ - WEdge(WEdge& iBrother); - virtual WEdge *duplicate(); - - virtual ~WEdge() - { - if (_paOEdge) { - delete _paOEdge; - _paOEdge = NULL; - } - - if (_pbOEdge) { - delete _pbOEdge; - _pbOEdge = NULL; - } - } - - /*! checks whether two WEdge have a common vertex. - * Returns a pointer on the common vertex if it exists, NULL otherwise. - */ - static inline WVertex *CommonVertex(WEdge *iEdge1, WEdge *iEdge2) - { - if (!iEdge1 || !iEdge2) - return NULL; - - WVertex *wv1 = iEdge1->GetaOEdge()->GetaVertex(); - WVertex *wv2 = iEdge1->GetaOEdge()->GetbVertex(); - WVertex *wv3 = iEdge2->GetaOEdge()->GetaVertex(); - WVertex *wv4 = iEdge2->GetaOEdge()->GetbVertex(); - - if ((wv1 == wv3) || (wv1 == wv4)) { - return wv1; - } - else if ((wv2 == wv3) || (wv2 == wv4)) { - return wv2; - } - return NULL; - } - - /*! accessors */ - inline WOEdge *GetaOEdge() - { - return _paOEdge; - } - - inline WOEdge *GetbOEdge() - { - return _pbOEdge; - } - - inline short GetNumberOfOEdges() - { - return _nOEdges; - } - - inline bool GetMark() - { - return _Mark; - } - - inline int GetId() - { - return _Id; - } - - inline WVertex *GetaVertex() - { - return _paOEdge->GetaVertex(); - } - - inline WVertex *GetbVertex() - { - return _paOEdge->GetbVertex(); - } - - inline WFace *GetaFace() - { - return _paOEdge->GetaFace(); - } - - inline WFace *GetbFace() - { - return _paOEdge->GetbFace(); - } - - inline WOEdge *GetOtherOEdge(WOEdge *iOEdge) { - if (iOEdge == _paOEdge) - return _pbOEdge; - else - return _paOEdge; - } - - /*! modifiers */ - inline void setaOEdge(WOEdge *iEdge) - { - _paOEdge = iEdge; - } - - inline void setbOEdge(WOEdge *iEdge) - { - _pbOEdge = iEdge; - } - - inline void AddOEdge(WOEdge *iEdge) - { - if (!_paOEdge) { - _paOEdge = iEdge; - _nOEdges++; - return; - } - if (!_pbOEdge) { - _pbOEdge = iEdge; - _nOEdges++; - return; - } - } - - inline void setNumberOfOEdges(short n) - { - _nOEdges = n; - } - - inline void setMark(bool mark) - { - _Mark = mark; - } - - inline void setId(int id) - { - _Id = id; - } - - virtual void ResetUserData() - { - userdata = NULL; - } +class WEdge { + protected: + WOEdge *_paOEdge; // first oriented edge + WOEdge *_pbOEdge; // second oriented edge + short _nOEdges; // number of oriented edges associated with this edge. (1 means border edge) + bool _Mark; // user-specified edge mark for feature edge detection + int _Id; // Identifier for the edge + + public: + void *userdata; // designed to store specific user data + + inline WEdge() + { + _paOEdge = NULL; + _pbOEdge = NULL; + _nOEdges = 0; + userdata = NULL; + } + + inline WEdge(WOEdge *iOEdge) + { + _paOEdge = iOEdge; + _pbOEdge = NULL; + _nOEdges = 1; + userdata = NULL; + } + + inline WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge) + { + _paOEdge = iaOEdge; + _pbOEdge = ibOEdge; + _nOEdges = 2; + userdata = NULL; + } + + /*! Copy constructor */ + WEdge(WEdge &iBrother); + virtual WEdge *duplicate(); + + virtual ~WEdge() + { + if (_paOEdge) { + delete _paOEdge; + _paOEdge = NULL; + } + + if (_pbOEdge) { + delete _pbOEdge; + _pbOEdge = NULL; + } + } + + /*! checks whether two WEdge have a common vertex. + * Returns a pointer on the common vertex if it exists, NULL otherwise. + */ + static inline WVertex *CommonVertex(WEdge *iEdge1, WEdge *iEdge2) + { + if (!iEdge1 || !iEdge2) + return NULL; + + WVertex *wv1 = iEdge1->GetaOEdge()->GetaVertex(); + WVertex *wv2 = iEdge1->GetaOEdge()->GetbVertex(); + WVertex *wv3 = iEdge2->GetaOEdge()->GetaVertex(); + WVertex *wv4 = iEdge2->GetaOEdge()->GetbVertex(); + + if ((wv1 == wv3) || (wv1 == wv4)) { + return wv1; + } + else if ((wv2 == wv3) || (wv2 == wv4)) { + return wv2; + } + return NULL; + } + + /*! accessors */ + inline WOEdge *GetaOEdge() + { + return _paOEdge; + } + + inline WOEdge *GetbOEdge() + { + return _pbOEdge; + } + + inline short GetNumberOfOEdges() + { + return _nOEdges; + } + + inline bool GetMark() + { + return _Mark; + } + + inline int GetId() + { + return _Id; + } + + inline WVertex *GetaVertex() + { + return _paOEdge->GetaVertex(); + } + + inline WVertex *GetbVertex() + { + return _paOEdge->GetbVertex(); + } + + inline WFace *GetaFace() + { + return _paOEdge->GetaFace(); + } + + inline WFace *GetbFace() + { + return _paOEdge->GetbFace(); + } + + inline WOEdge *GetOtherOEdge(WOEdge *iOEdge) + { + if (iOEdge == _paOEdge) + return _pbOEdge; + else + return _paOEdge; + } + + /*! modifiers */ + inline void setaOEdge(WOEdge *iEdge) + { + _paOEdge = iEdge; + } + + inline void setbOEdge(WOEdge *iEdge) + { + _pbOEdge = iEdge; + } + + inline void AddOEdge(WOEdge *iEdge) + { + if (!_paOEdge) { + _paOEdge = iEdge; + _nOEdges++; + return; + } + if (!_pbOEdge) { + _pbOEdge = iEdge; + _nOEdges++; + return; + } + } + + inline void setNumberOfOEdges(short n) + { + _nOEdges = n; + } + + inline void setMark(bool mark) + { + _Mark = mark; + } + + inline void setId(int id) + { + _Id = id; + } + + virtual void ResetUserData() + { + userdata = NULL; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WEdge") #endif }; - /********************************** * * * * @@ -727,281 +729,287 @@ public: * * **********************************/ - -class WFace -{ -protected: - vector _OEdgeList; // list of oriented edges of bording the face - Vec3f _Normal; // normal to the face - // in case there is a normal per vertex. - // The normal number i corresponds to the aVertex of the oedge number i, for that face - vector _VerticesNormals; - vector _VerticesTexCoords; - - int _Id; - unsigned _FrsMaterialIndex; - bool _Mark; // Freestyle face mark (if true, feature edges on this face are ignored) - -public: - void *userdata; - inline WFace() - { - userdata = NULL; - _FrsMaterialIndex = 0; - } - - /*! copy constructor */ - WFace(WFace& iBrother); - virtual WFace *duplicate(); - virtual ~WFace() {} - - /*! accessors */ - inline const vector& getEdgeList() - { - return _OEdgeList; - } - - inline WOEdge *GetOEdge(int i) - { - return _OEdgeList[i]; - } - - inline Vec3f& GetNormal() - { - return _Normal; - } - - inline int GetId() - { - return _Id; - } - - inline unsigned frs_materialIndex() const - { - return _FrsMaterialIndex; - } - - inline bool GetMark() const - { - return _Mark; - } - - const FrsMaterial& frs_material(); - - /*! The vertex of index i corresponds to the a vertex of the edge of index i */ - inline WVertex *GetVertex(unsigned int index) - { +class WFace { + protected: + vector _OEdgeList; // list of oriented edges of bording the face + Vec3f _Normal; // normal to the face + // in case there is a normal per vertex. + // The normal number i corresponds to the aVertex of the oedge number i, for that face + vector _VerticesNormals; + vector _VerticesTexCoords; + + int _Id; + unsigned _FrsMaterialIndex; + bool _Mark; // Freestyle face mark (if true, feature edges on this face are ignored) + + public: + void *userdata; + inline WFace() + { + userdata = NULL; + _FrsMaterialIndex = 0; + } + + /*! copy constructor */ + WFace(WFace &iBrother); + virtual WFace *duplicate(); + virtual ~WFace() + { + } + + /*! accessors */ + inline const vector &getEdgeList() + { + return _OEdgeList; + } + + inline WOEdge *GetOEdge(int i) + { + return _OEdgeList[i]; + } + + inline Vec3f &GetNormal() + { + return _Normal; + } + + inline int GetId() + { + return _Id; + } + + inline unsigned frs_materialIndex() const + { + return _FrsMaterialIndex; + } + + inline bool GetMark() const + { + return _Mark; + } + + const FrsMaterial &frs_material(); + + /*! The vertex of index i corresponds to the a vertex of the edge of index i */ + inline WVertex *GetVertex(unsigned int index) + { #if 0 - if (index >= _OEdgeList.size()) - return NULL; + if (index >= _OEdgeList.size()) + return NULL; #endif - return _OEdgeList[index]->GetaVertex(); - } - - /*! returns the index at which iVertex is stored in the array. - * returns -1 if iVertex doesn't belong to the face. - */ - inline int GetIndex(WVertex *iVertex) - { - int index = 0; - for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); woe != woend; woe++) { - if ((*woe)->GetaVertex() == iVertex) - return index; - ++index; - } - return -1; - } - - inline void RetrieveVertexList(vector& oVertices) - { - for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); woe != woend; woe++) { - oVertices.push_back((*woe)->GetaVertex()); - } - } - - inline void RetrieveBorderFaces(vector& oWFaces) - { - for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); woe != woend; woe++) { - WFace *af; - if ((af = (*woe)->GetaFace())) - oWFaces.push_back(af); - } - } - - inline WFace *GetBordingFace(int index) - { + return _OEdgeList[index]->GetaVertex(); + } + + /*! returns the index at which iVertex is stored in the array. + * returns -1 if iVertex doesn't belong to the face. + */ + inline int GetIndex(WVertex *iVertex) + { + int index = 0; + for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); + woe != woend; + woe++) { + if ((*woe)->GetaVertex() == iVertex) + return index; + ++index; + } + return -1; + } + + inline void RetrieveVertexList(vector &oVertices) + { + for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); + woe != woend; + woe++) { + oVertices.push_back((*woe)->GetaVertex()); + } + } + + inline void RetrieveBorderFaces(vector &oWFaces) + { + for (vector::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); + woe != woend; + woe++) { + WFace *af; + if ((af = (*woe)->GetaFace())) + oWFaces.push_back(af); + } + } + + inline WFace *GetBordingFace(int index) + { #if 0 - if (index >= _OEdgeList.size()) - return NULL; + if (index >= _OEdgeList.size()) + return NULL; #endif - return _OEdgeList[index]->GetaFace(); - } - - inline WFace *GetBordingFace(WOEdge *iOEdge) - { - return iOEdge->GetaFace(); - } - - inline vector& GetPerVertexNormals() - { - return _VerticesNormals; - } - - inline vector& GetPerVertexTexCoords() - { - return _VerticesTexCoords; - } - - /*! Returns the normal of the vertex of index index */ - inline Vec3f& GetVertexNormal(int index) - { - return _VerticesNormals[index]; - } - - /*! Returns the tex coords of the vertex of index index */ - inline Vec2f& GetVertexTexCoords(int index) - { - return _VerticesTexCoords[index]; - } - - /*! Returns the normal of the vertex iVertex for that face */ - inline Vec3f& GetVertexNormal(WVertex *iVertex) - { - int i = 0; - int index = 0; - for (vector::const_iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); woe != woend; woe++) { - if ((*woe)->GetaVertex() == iVertex) { - index = i; - break; - } - ++i; - } - - return _VerticesNormals[index]; - } - - inline WOEdge *GetNextOEdge(WOEdge *iOEdge) - { - bool found = false; - vector::iterator woe, woend, woefirst; - woefirst = _OEdgeList.begin(); - for (woe = woefirst, woend = _OEdgeList.end(); woe != woend; ++woe) { - if (found) - return (*woe); - - if ((*woe) == iOEdge) { - found = true; - } - } - - // We left the loop. That means that the first OEdge was the good one: - if (found) - return (*woefirst); - - return NULL; - } - - WOEdge *GetPrevOEdge(WOEdge *iOEdge); - - inline int numberOfEdges() const - { - return _OEdgeList.size(); - } - - inline int numberOfVertices() const - { - return _OEdgeList.size(); - } - - /*! Returns true if the face has one ot its edge which is a border edge */ - inline bool isBorder() const - { - for (vector::const_iterator woe = _OEdgeList.begin(), woeend = _OEdgeList.end(); - woe != woeend; - ++woe) - { - if ((*woe)->GetOwner()->GetbOEdge() == 0) - return true; - } - return false; - } - - /*! modifiers */ - inline void setEdgeList(const vector& iEdgeList) - { - _OEdgeList = iEdgeList; - } - - inline void setNormal(const Vec3f& iNormal) - { - _Normal = iNormal; - } - - inline void setNormalList(const vector& iNormalsList) - { - _VerticesNormals = iNormalsList; - } - - inline void setTexCoordsList(const vector& iTexCoordsList) - { - _VerticesTexCoords = iTexCoordsList; - } - - inline void setId(int id) - { - _Id = id; - } - - inline void setFrsMaterialIndex(unsigned iMaterialIndex) - { - _FrsMaterialIndex = iMaterialIndex; - } - - inline void setMark(bool iMark) - { - _Mark = iMark; - } - - /*! designed to build a specialized WEdge for use in MakeEdge */ - virtual WEdge *instanciateEdge() const - { - return new WEdge; - } - - /*! Builds an oriented edge - * Returns the built edge. - * v1, v2 - * Vertices at the edge's extremities - * The edge is oriented from v1 to v2. - */ - virtual WOEdge *MakeEdge(WVertex *v1, WVertex *v2); - - /*! Adds an edge to the edges list */ - inline void AddEdge(WOEdge *iEdge) - { - _OEdgeList.push_back(iEdge); - } - - /*! For triangles, returns the edge opposite to the vertex in e. - * returns false if the face is not a triangle or if the vertex is not found - */ - bool getOppositeEdge (const WVertex *v, WOEdge *&e); - - /*! compute the area of the face */ - float getArea (); - - WShape *getShape(); - virtual void ResetUserData() - { - userdata = NULL; - } + return _OEdgeList[index]->GetaFace(); + } + + inline WFace *GetBordingFace(WOEdge *iOEdge) + { + return iOEdge->GetaFace(); + } + + inline vector &GetPerVertexNormals() + { + return _VerticesNormals; + } + + inline vector &GetPerVertexTexCoords() + { + return _VerticesTexCoords; + } + + /*! Returns the normal of the vertex of index index */ + inline Vec3f &GetVertexNormal(int index) + { + return _VerticesNormals[index]; + } + + /*! Returns the tex coords of the vertex of index index */ + inline Vec2f &GetVertexTexCoords(int index) + { + return _VerticesTexCoords[index]; + } + + /*! Returns the normal of the vertex iVertex for that face */ + inline Vec3f &GetVertexNormal(WVertex *iVertex) + { + int i = 0; + int index = 0; + for (vector::const_iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end(); + woe != woend; + woe++) { + if ((*woe)->GetaVertex() == iVertex) { + index = i; + break; + } + ++i; + } + + return _VerticesNormals[index]; + } + + inline WOEdge *GetNextOEdge(WOEdge *iOEdge) + { + bool found = false; + vector::iterator woe, woend, woefirst; + woefirst = _OEdgeList.begin(); + for (woe = woefirst, woend = _OEdgeList.end(); woe != woend; ++woe) { + if (found) + return (*woe); + + if ((*woe) == iOEdge) { + found = true; + } + } + + // We left the loop. That means that the first OEdge was the good one: + if (found) + return (*woefirst); + + return NULL; + } + + WOEdge *GetPrevOEdge(WOEdge *iOEdge); + + inline int numberOfEdges() const + { + return _OEdgeList.size(); + } + + inline int numberOfVertices() const + { + return _OEdgeList.size(); + } + + /*! Returns true if the face has one ot its edge which is a border edge */ + inline bool isBorder() const + { + for (vector::const_iterator woe = _OEdgeList.begin(), woeend = _OEdgeList.end(); + woe != woeend; + ++woe) { + if ((*woe)->GetOwner()->GetbOEdge() == 0) + return true; + } + return false; + } + + /*! modifiers */ + inline void setEdgeList(const vector &iEdgeList) + { + _OEdgeList = iEdgeList; + } + + inline void setNormal(const Vec3f &iNormal) + { + _Normal = iNormal; + } + + inline void setNormalList(const vector &iNormalsList) + { + _VerticesNormals = iNormalsList; + } + + inline void setTexCoordsList(const vector &iTexCoordsList) + { + _VerticesTexCoords = iTexCoordsList; + } + + inline void setId(int id) + { + _Id = id; + } + + inline void setFrsMaterialIndex(unsigned iMaterialIndex) + { + _FrsMaterialIndex = iMaterialIndex; + } + + inline void setMark(bool iMark) + { + _Mark = iMark; + } + + /*! designed to build a specialized WEdge for use in MakeEdge */ + virtual WEdge *instanciateEdge() const + { + return new WEdge; + } + + /*! Builds an oriented edge + * Returns the built edge. + * v1, v2 + * Vertices at the edge's extremities + * The edge is oriented from v1 to v2. + */ + virtual WOEdge *MakeEdge(WVertex *v1, WVertex *v2); + + /*! Adds an edge to the edges list */ + inline void AddEdge(WOEdge *iEdge) + { + _OEdgeList.push_back(iEdge); + } + + /*! For triangles, returns the edge opposite to the vertex in e. + * returns false if the face is not a triangle or if the vertex is not found + */ + bool getOppositeEdge(const WVertex *v, WOEdge *&e); + + /*! compute the area of the face */ + float getArea(); + + WShape *getShape(); + virtual void ResetUserData() + { + userdata = NULL; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFace") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFace") #endif }; - /********************************** * * * * @@ -1010,302 +1018,307 @@ public: * * **********************************/ - -class WShape -{ -protected: - vector _VertexList; - vector _EdgeList; - vector _FaceList; - int _Id; - string _Name; - string _LibraryPath; - static unsigned _SceneCurrentId; +class WShape { + protected: + vector _VertexList; + vector _EdgeList; + vector _FaceList; + int _Id; + string _Name; + string _LibraryPath; + static unsigned _SceneCurrentId; #if 0 - Vec3f _min; - Vec3f _max; + Vec3f _min; + Vec3f _max; #endif - vector _FrsMaterials; + vector _FrsMaterials; #if 0 - float _meanEdgeSize; + float _meanEdgeSize; #endif -public: - inline WShape() - { + public: + inline WShape() + { #if 0 - _meanEdgeSize = 0; + _meanEdgeSize = 0; #endif - _Id = _SceneCurrentId; - _SceneCurrentId++; - } - - /*! copy constructor */ - WShape(WShape& iBrother); - virtual WShape *duplicate(); - - virtual ~WShape() - { - if (_EdgeList.size() != 0) { - vector::iterator e; - for (e = _EdgeList.begin(); e != _EdgeList.end(); ++e) { - delete (*e); - } - _EdgeList.clear(); - } - - if (_VertexList.size() != 0) { - vector::iterator v; - for (v = _VertexList.begin(); v != _VertexList.end(); ++v) { - delete (*v); - } - _VertexList.clear(); - } - - if (_FaceList.size() != 0) { - vector::iterator f; - for (f = _FaceList.begin(); f != _FaceList.end(); ++f) { - delete (*f); - } - _FaceList.clear(); - } - } - - /*! accessors */ - inline vector& getEdgeList() - { - return _EdgeList; - } - - inline vector& getVertexList() - { - return _VertexList; - } - - inline vector& GetFaceList() - { - return _FaceList; - } - - inline unsigned GetId() - { - return _Id; - } + _Id = _SceneCurrentId; + _SceneCurrentId++; + } + + /*! copy constructor */ + WShape(WShape &iBrother); + virtual WShape *duplicate(); + + virtual ~WShape() + { + if (_EdgeList.size() != 0) { + vector::iterator e; + for (e = _EdgeList.begin(); e != _EdgeList.end(); ++e) { + delete (*e); + } + _EdgeList.clear(); + } + + if (_VertexList.size() != 0) { + vector::iterator v; + for (v = _VertexList.begin(); v != _VertexList.end(); ++v) { + delete (*v); + } + _VertexList.clear(); + } + + if (_FaceList.size() != 0) { + vector::iterator f; + for (f = _FaceList.begin(); f != _FaceList.end(); ++f) { + delete (*f); + } + _FaceList.clear(); + } + } + + /*! accessors */ + inline vector &getEdgeList() + { + return _EdgeList; + } + + inline vector &getVertexList() + { + return _VertexList; + } + + inline vector &GetFaceList() + { + return _FaceList; + } + + inline unsigned GetId() + { + return _Id; + } #if 0 - inline void bbox(Vec3f& min, Vec3f& max) - { - min = _min; - max = _max; - } + inline void bbox(Vec3f& min, Vec3f& max) + { + min = _min; + max = _max; + } #endif - inline const FrsMaterial& frs_material(unsigned i) const - { - return _FrsMaterials[i]; - } + inline const FrsMaterial &frs_material(unsigned i) const + { + return _FrsMaterials[i]; + } - inline const vector& frs_materials() const - { - return _FrsMaterials; - } + inline const vector &frs_materials() const + { + return _FrsMaterials; + } #if 0 - inline const float getMeanEdgeSize() const - { - return _meanEdgeSize; - } + inline const float getMeanEdgeSize() const + { + return _meanEdgeSize; + } #endif - inline const string& getName() const - { - return _Name; - } - - inline const string& getLibraryPath() const - { - return _LibraryPath; - } - - /*! modifiers */ - static inline void setCurrentId(const unsigned id) - { - _SceneCurrentId = id; - } - - inline void setEdgeList(const vector& iEdgeList) - { - _EdgeList = iEdgeList; - } - - inline void setVertexList(const vector& iVertexList) - { - _VertexList = iVertexList; - } - - inline void setFaceList(const vector& iFaceList) - { - _FaceList = iFaceList; - } - - inline void setId(int id) - { - _Id = id; - } + inline const string &getName() const + { + return _Name; + } + + inline const string &getLibraryPath() const + { + return _LibraryPath; + } + + /*! modifiers */ + static inline void setCurrentId(const unsigned id) + { + _SceneCurrentId = id; + } + + inline void setEdgeList(const vector &iEdgeList) + { + _EdgeList = iEdgeList; + } + + inline void setVertexList(const vector &iVertexList) + { + _VertexList = iVertexList; + } + + inline void setFaceList(const vector &iFaceList) + { + _FaceList = iFaceList; + } + + inline void setId(int id) + { + _Id = id; + } #if 0 - inline void setBBox(const Vec3f& min, const Vec3f& max) - { - _min = min; - _max = max; - } + inline void setBBox(const Vec3f& min, const Vec3f& max) + { + _min = min; + _max = max; + } #endif - inline void setFrsMaterial(const FrsMaterial& frs_material, unsigned i) - { - _FrsMaterials[i] = frs_material; - } - - inline void setFrsMaterials(const vector& iMaterials) - { - _FrsMaterials = iMaterials; - } - - inline void setName(const string& name) - { - _Name = name; - } - - inline void setLibraryPath(const string& path) - { - _LibraryPath = path; - } - - /*! designed to build a specialized WFace for use in MakeFace */ - virtual WFace *instanciateFace() const - { - return new WFace; - } - - /*! adds a new face to the shape - * returns the built face. - * iVertexList - * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be - * already stored when calling MakeFace. - * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the - * face orientation. - * iMaterialIndex - * The material index for this face - */ - virtual WFace *MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterialIndex); - - /*! adds a new face to the shape. The difference with the previous method is that this one is designed - * to build a WingedEdge structure for which there are per vertex normals, opposed to per face normals. - * returns the built face. - * iVertexList - * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be - * already stored when calling MakeFace. - * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the - * face orientation. - * iMaterialIndex - * The materialIndex for this face - * iNormalsList - * The list of normals, iNormalsList[i] corresponding to the normal of the vertex iVertexList[i] for that face. - * iTexCoordsList - * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for - * that face. - */ - virtual WFace *MakeFace(vector& iVertexList, vector& iNormalsList, vector& iTexCoordsList, - vector& iFaceEdgeMarksList, unsigned iMaterialIndex); - - inline void AddEdge(WEdge *iEdge) - { - _EdgeList.push_back(iEdge); - } - - inline void AddFace(WFace *iFace) - { - _FaceList.push_back(iFace); - } - - inline void AddVertex(WVertex *iVertex) - { - iVertex->setShape(this); - _VertexList.push_back(iVertex); - } - - inline void ResetUserData() - { - for (vector::iterator v = _VertexList.begin(), vend = _VertexList.end(); v != vend; v++) { - (*v)->ResetUserData(); - } - - for (vector::iterator e = _EdgeList.begin(), eend = _EdgeList.end(); e != eend; e++) { - (*e)->ResetUserData(); - // manages WOEdge: - WOEdge *oe = (*e)->GetaOEdge(); - if (oe) - oe->ResetUserData(); - oe = (*e)->GetbOEdge(); - if (oe) - oe->ResetUserData(); - } - - for (vector::iterator f = _FaceList.begin(), fend = _FaceList.end(); f != fend; f++) { - (*f)->ResetUserData(); - } - } + inline void setFrsMaterial(const FrsMaterial &frs_material, unsigned i) + { + _FrsMaterials[i] = frs_material; + } + + inline void setFrsMaterials(const vector &iMaterials) + { + _FrsMaterials = iMaterials; + } + + inline void setName(const string &name) + { + _Name = name; + } + + inline void setLibraryPath(const string &path) + { + _LibraryPath = path; + } + + /*! designed to build a specialized WFace for use in MakeFace */ + virtual WFace *instanciateFace() const + { + return new WFace; + } + + /*! adds a new face to the shape + * returns the built face. + * iVertexList + * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be + * already stored when calling MakeFace. + * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the + * face orientation. + * iMaterialIndex + * The material index for this face + */ + virtual WFace *MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex); + + /*! adds a new face to the shape. The difference with the previous method is that this one is designed + * to build a WingedEdge structure for which there are per vertex normals, opposed to per face normals. + * returns the built face. + * iVertexList + * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be + * already stored when calling MakeFace. + * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the + * face orientation. + * iMaterialIndex + * The materialIndex for this face + * iNormalsList + * The list of normals, iNormalsList[i] corresponding to the normal of the vertex iVertexList[i] for that face. + * iTexCoordsList + * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for + * that face. + */ + virtual WFace *MakeFace(vector &iVertexList, + vector &iNormalsList, + vector &iTexCoordsList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex); + + inline void AddEdge(WEdge *iEdge) + { + _EdgeList.push_back(iEdge); + } + + inline void AddFace(WFace *iFace) + { + _FaceList.push_back(iFace); + } + + inline void AddVertex(WVertex *iVertex) + { + iVertex->setShape(this); + _VertexList.push_back(iVertex); + } + + inline void ResetUserData() + { + for (vector::iterator v = _VertexList.begin(), vend = _VertexList.end(); v != vend; + v++) { + (*v)->ResetUserData(); + } + + for (vector::iterator e = _EdgeList.begin(), eend = _EdgeList.end(); e != eend; e++) { + (*e)->ResetUserData(); + // manages WOEdge: + WOEdge *oe = (*e)->GetaOEdge(); + if (oe) + oe->ResetUserData(); + oe = (*e)->GetbOEdge(); + if (oe) + oe->ResetUserData(); + } + + for (vector::iterator f = _FaceList.begin(), fend = _FaceList.end(); f != fend; f++) { + (*f)->ResetUserData(); + } + } #if 0 - inline void ComputeBBox() - { - _min = _VertexList[0]->GetVertex(); - _max = _VertexList[0]->GetVertex(); - - Vec3f v; - for (vector::iterator wv = _VertexList.begin(), wvend = _VertexList.end(); wv != wvend; wv++) { - for (unsigned int i = 0; i < 3; i++) { - v = (*wv)->GetVertex(); - if (v[i] < _min[i]) - _min[i] = v[i]; - if (v[i] > _max[i]) - _max[i] = v[i]; - } - } - } + inline void ComputeBBox() + { + _min = _VertexList[0]->GetVertex(); + _max = _VertexList[0]->GetVertex(); + + Vec3f v; + for (vector::iterator wv = _VertexList.begin(), wvend = _VertexList.end(); wv != wvend; wv++) { + for (unsigned int i = 0; i < 3; i++) { + v = (*wv)->GetVertex(); + if (v[i] < _min[i]) + _min[i] = v[i]; + if (v[i] > _max[i]) + _max[i] = v[i]; + } + } + } #endif #if 0 - inline float ComputeMeanEdgeSize() - { - _meanEdgeSize = _meanEdgeSize / _EdgeList.size(); - return _meanEdgeSize; - } + inline float ComputeMeanEdgeSize() + { + _meanEdgeSize = _meanEdgeSize / _EdgeList.size(); + return _meanEdgeSize; + } #else - real ComputeMeanEdgeSize() const; + real ComputeMeanEdgeSize() const; #endif -protected: - /*! Builds the face passed as argument (which as already been allocated) - * iVertexList - * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be - * already stored when calling MakeFace. - * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the - * face orientation. - * iMaterialIndex - * The material index for this face - * face - * The Face that is filled in - */ - virtual WFace *MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterialIndex, - WFace *face); + protected: + /*! Builds the face passed as argument (which as already been allocated) + * iVertexList + * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be + * already stored when calling MakeFace. + * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the + * face orientation. + * iMaterialIndex + * The material index for this face + * face + * The Face that is filled in + */ + virtual WFace *MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex, + WFace *face); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WShape") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WShape") #endif }; - /********************************** * * * * @@ -1314,53 +1327,51 @@ protected: * * **********************************/ -class WingedEdge -{ -public: - WingedEdge() { - _numFaces = 0; - } - - ~WingedEdge() - { - clear(); - } - - void clear() - { - for (vector::iterator it = _wshapes.begin(); it != _wshapes.end(); it++) - delete *it; - _wshapes.clear(); - _numFaces = 0; - } - - void addWShape(WShape *wshape) - { - _wshapes.push_back(wshape); - _numFaces += wshape->GetFaceList().size(); - } - - vector& getWShapes() - { - return _wshapes; - } - - unsigned getNumFaces() - { - return _numFaces; - } - -private: - vector _wshapes; - unsigned _numFaces; +class WingedEdge { + public: + WingedEdge() + { + _numFaces = 0; + } + + ~WingedEdge() + { + clear(); + } + + void clear() + { + for (vector::iterator it = _wshapes.begin(); it != _wshapes.end(); it++) + delete *it; + _wshapes.clear(); + _numFaces = 0; + } + + void addWShape(WShape *wshape) + { + _wshapes.push_back(wshape); + _numFaces += wshape->GetFaceList().size(); + } + + vector &getWShapes() + { + return _wshapes; + } + + unsigned getNumFaces() + { + return _numFaces; + } + + private: + vector _wshapes; + unsigned _numFaces; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdge") #endif }; - - /* * ############################################# * ############################################# @@ -1373,35 +1384,35 @@ private: * ############################################# */ /* for inline functions */ -void WOEdge::RetrieveCWOrderedEdges(vector& oEdges) +void WOEdge::RetrieveCWOrderedEdges(vector &oEdges) { - WOEdge *currentOEdge = this; - do { - WOEdge *nextOEdge = currentOEdge->GetbFace()->GetNextOEdge(currentOEdge); - oEdges.push_back(nextOEdge->GetOwner()); - currentOEdge = nextOEdge->GetOwner()->GetOtherOEdge(nextOEdge); - } while (currentOEdge && (currentOEdge->GetOwner() != GetOwner())); + WOEdge *currentOEdge = this; + do { + WOEdge *nextOEdge = currentOEdge->GetbFace()->GetNextOEdge(currentOEdge); + oEdges.push_back(nextOEdge->GetOwner()); + currentOEdge = nextOEdge->GetOwner()->GetOtherOEdge(nextOEdge); + } while (currentOEdge && (currentOEdge->GetOwner() != GetOwner())); } inline void WOEdge::setVecAndAngle() { - if (_paVertex && _pbVertex) { - _vec = _pbVertex->GetVertex() - _paVertex->GetVertex(); - if (_paFace && _pbFace) { - float sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm(); - if (sine >= 1.0) { - _angle = M_PI / 2.0; - return; - } - if (sine <= -1.0) { - _angle = -M_PI / 2.0; - return; - } - _angle = ::asin(sine); - } - } + if (_paVertex && _pbVertex) { + _vec = _pbVertex->GetVertex() - _paVertex->GetVertex(); + if (_paFace && _pbFace) { + float sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm(); + if (sine >= 1.0) { + _angle = M_PI / 2.0; + return; + } + if (sine <= -1.0) { + _angle = -M_PI / 2.0; + return; + } + _angle = ::asin(sine); + } + } } } /* namespace Freestyle */ -#endif // __FREESTYLE_W_EDGE_H__ +#endif // __FREESTYLE_W_EDGE_H__ diff --git a/source/blender/freestyle/intern/winged_edge/WFillGrid.cpp b/source/blender/freestyle/intern/winged_edge/WFillGrid.cpp index ea5e7dcc504..8106bcedd0c 100644 --- a/source/blender/freestyle/intern/winged_edge/WFillGrid.cpp +++ b/source/blender/freestyle/intern/winged_edge/WFillGrid.cpp @@ -26,33 +26,33 @@ namespace Freestyle { void WFillGrid::fillGrid() { - if (!_winged_edge || !_grid) - return; - - vector wshapes = _winged_edge->getWShapes(); - vector fvertices; - vector vectors; - vector faces; - - for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); ++it) { - faces = (*it)->GetFaceList(); - - for (vector::const_iterator f = faces.begin(); f != faces.end(); ++f) { - (*f)->RetrieveVertexList(fvertices); - - for (vector::const_iterator wv = fvertices.begin(); wv != fvertices.end(); ++wv) - vectors.push_back(Vec3r((*wv)->GetVertex())); - - // occluder will be deleted by the grid - Polygon3r *occluder = new Polygon3r(vectors, (*f)->GetNormal()); - occluder->setId(_polygon_id++); - occluder->userdata = (void *)(*f); - _grid->insertOccluder(occluder); - vectors.clear(); - fvertices.clear(); - } - faces.clear(); - } + if (!_winged_edge || !_grid) + return; + + vector wshapes = _winged_edge->getWShapes(); + vector fvertices; + vector vectors; + vector faces; + + for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); ++it) { + faces = (*it)->GetFaceList(); + + for (vector::const_iterator f = faces.begin(); f != faces.end(); ++f) { + (*f)->RetrieveVertexList(fvertices); + + for (vector::const_iterator wv = fvertices.begin(); wv != fvertices.end(); ++wv) + vectors.push_back(Vec3r((*wv)->GetVertex())); + + // occluder will be deleted by the grid + Polygon3r *occluder = new Polygon3r(vectors, (*f)->GetNormal()); + occluder->setId(_polygon_id++); + occluder->userdata = (void *)(*f); + _grid->insertOccluder(occluder); + vectors.clear(); + fvertices.clear(); + } + faces.clear(); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WFillGrid.h b/source/blender/freestyle/intern/winged_edge/WFillGrid.h index 0e86d1a1684..f9e63464e30 100644 --- a/source/blender/freestyle/intern/winged_edge/WFillGrid.h +++ b/source/blender/freestyle/intern/winged_edge/WFillGrid.h @@ -28,59 +28,60 @@ #include "../geometry/Polygon.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { -class WFillGrid -{ -public: - inline WFillGrid(Grid *grid = NULL, WingedEdge *winged_edge = NULL) - { - _winged_edge = winged_edge; - _grid = grid; - _polygon_id = 0; - } - - virtual ~WFillGrid() {} - - void fillGrid(); - - /*! Accessors */ - WingedEdge *getWingedEdge() - { - return _winged_edge; - } - - Grid *getGrid() - { - return _grid; - } - - /*! Modifiers */ - void setWingedEdge(WingedEdge *winged_edge) - { - if (winged_edge) - _winged_edge = winged_edge; - } - - void setGrid(Grid *grid) - { - if (grid) - _grid = grid; - } - -private: - Grid *_grid; - WingedEdge *_winged_edge; - unsigned _polygon_id; +class WFillGrid { + public: + inline WFillGrid(Grid *grid = NULL, WingedEdge *winged_edge = NULL) + { + _winged_edge = winged_edge; + _grid = grid; + _polygon_id = 0; + } + + virtual ~WFillGrid() + { + } + + void fillGrid(); + + /*! Accessors */ + WingedEdge *getWingedEdge() + { + return _winged_edge; + } + + Grid *getGrid() + { + return _grid; + } + + /*! Modifiers */ + void setWingedEdge(WingedEdge *winged_edge) + { + if (winged_edge) + _winged_edge = winged_edge; + } + + void setGrid(Grid *grid) + { + if (grid) + _grid = grid; + } + + private: + Grid *_grid; + WingedEdge *_winged_edge; + unsigned _polygon_id; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFillGrid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFillGrid") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_W_FILL_GRID_H__ +#endif // __FREESTYLE_W_FILL_GRID_H__ diff --git a/source/blender/freestyle/intern/winged_edge/WSFillGrid.cpp b/source/blender/freestyle/intern/winged_edge/WSFillGrid.cpp index 4ef3f6a775f..cd13775239b 100644 --- a/source/blender/freestyle/intern/winged_edge/WSFillGrid.cpp +++ b/source/blender/freestyle/intern/winged_edge/WSFillGrid.cpp @@ -26,33 +26,33 @@ namespace Freestyle { void WSFillGrid::fillGrid() { - if (!_winged_edge || !_grid) - return; - - vector wshapes = _winged_edge->getWShapes(); - vector fvertices; - vector vectors; - vector faces; - - for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); ++it) { - faces = (*it)->GetFaceList(); - - for (vector::const_iterator f = faces.begin(); f != faces.end(); ++f) { - (*f)->RetrieveVertexList(fvertices); - - for (vector::const_iterator wv = fvertices.begin(); wv != fvertices.end(); ++wv) - vectors.push_back(Vec3r((*wv)->GetVertex())); - - // occluder will be deleted by the grid - Polygon3r *occluder = new Polygon3r(vectors, (*f)->GetNormal()); - occluder->setId(_polygon_id++); - occluder->userdata = (void *)(*f); - _grid->insertOccluder(occluder); - vectors.clear(); - fvertices.clear(); - } - faces.clear(); - } + if (!_winged_edge || !_grid) + return; + + vector wshapes = _winged_edge->getWShapes(); + vector fvertices; + vector vectors; + vector faces; + + for (vector::const_iterator it = wshapes.begin(); it != wshapes.end(); ++it) { + faces = (*it)->GetFaceList(); + + for (vector::const_iterator f = faces.begin(); f != faces.end(); ++f) { + (*f)->RetrieveVertexList(fvertices); + + for (vector::const_iterator wv = fvertices.begin(); wv != fvertices.end(); ++wv) + vectors.push_back(Vec3r((*wv)->GetVertex())); + + // occluder will be deleted by the grid + Polygon3r *occluder = new Polygon3r(vectors, (*f)->GetNormal()); + occluder->setId(_polygon_id++); + occluder->userdata = (void *)(*f); + _grid->insertOccluder(occluder); + vectors.clear(); + fvertices.clear(); + } + faces.clear(); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WSFillGrid.h b/source/blender/freestyle/intern/winged_edge/WSFillGrid.h index 9648c3bab07..2d8ac77a15d 100644 --- a/source/blender/freestyle/intern/winged_edge/WSFillGrid.h +++ b/source/blender/freestyle/intern/winged_edge/WSFillGrid.h @@ -29,55 +29,55 @@ namespace Freestyle { -class WSFillGrid -{ -public: - inline WSFillGrid(Grid *grid = NULL, WingedEdge *winged_edge = NULL) - { - _winged_edge = winged_edge; - _grid = grid; - _polygon_id = 0; - } - - virtual ~WSFillGrid() {} - - void fillGrid(); - - /*! Accessors */ - WingedEdge *getWingedEdge() - { - return _winged_edge; - } - - Grid *getGrid() - { - return _grid; - } - - /*! Modifiers */ - void setWingedEdge(WingedEdge *winged_edge) - { - if (winged_edge) - _winged_edge = winged_edge; - } - - void setGrid(Grid *grid) - { - if (grid) - _grid = grid; - } - -private: - Grid *_grid; - WingedEdge *_winged_edge; - unsigned _polygon_id; +class WSFillGrid { + public: + inline WSFillGrid(Grid *grid = NULL, WingedEdge *winged_edge = NULL) + { + _winged_edge = winged_edge; + _grid = grid; + _polygon_id = 0; + } + + virtual ~WSFillGrid() + { + } + + void fillGrid(); + + /*! Accessors */ + WingedEdge *getWingedEdge() + { + return _winged_edge; + } + + Grid *getGrid() + { + return _grid; + } + + /*! Modifiers */ + void setWingedEdge(WingedEdge *winged_edge) + { + if (winged_edge) + _winged_edge = winged_edge; + } + + void setGrid(Grid *grid) + { + if (grid) + _grid = grid; + } + + private: + Grid *_grid; + WingedEdge *_winged_edge; + unsigned _polygon_id; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WSFillGrid") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WSFillGrid") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_WS_FILL_GRID_H__ +#endif // __FREESTYLE_WS_FILL_GRID_H__ diff --git a/source/blender/freestyle/intern/winged_edge/WXEdge.cpp b/source/blender/freestyle/intern/winged_edge/WXEdge.cpp index 611d7b3a7cf..fcac2b386ea 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdge.cpp +++ b/source/blender/freestyle/intern/winged_edge/WXEdge.cpp @@ -34,218 +34,219 @@ namespace Freestyle { unsigned int WXFaceLayer::Get0VertexIndex() const { - int i = 0; - int nEdges = _pWXFace->numberOfEdges(); - for (i = 0; i < nEdges; ++i) { - if (_DotP[i] == 0.0f) { // TODO this comparison is weak, check if it actually works - return i; - } - } - return -1; + int i = 0; + int nEdges = _pWXFace->numberOfEdges(); + for (i = 0; i < nEdges; ++i) { + if (_DotP[i] == 0.0f) { // TODO this comparison is weak, check if it actually works + return i; + } + } + return -1; } unsigned int WXFaceLayer::GetSmoothEdgeIndex() const { - int i = 0; - int nEdges = _pWXFace->numberOfEdges(); - for (i = 0; i < nEdges; ++i) { - if ((_DotP[i] == 0.0f) && (_DotP[(i + 1) % nEdges] == 0.0f)) { // TODO ditto - return i; - } - } - return -1; + int i = 0; + int nEdges = _pWXFace->numberOfEdges(); + for (i = 0; i < nEdges; ++i) { + if ((_DotP[i] == 0.0f) && (_DotP[(i + 1) % nEdges] == 0.0f)) { // TODO ditto + return i; + } + } + return -1; } -void WXFaceLayer::RetrieveCuspEdgesIndices(vector& oCuspEdges) +void WXFaceLayer::RetrieveCuspEdgesIndices(vector &oCuspEdges) { - int i = 0; - int nEdges = _pWXFace->numberOfEdges(); - for (i = 0; i < nEdges; ++i) { - if (_DotP[i] * _DotP[(i + 1) % nEdges] < 0.0f) { - // we got one - oCuspEdges.push_back(i); - } - } + int i = 0; + int nEdges = _pWXFace->numberOfEdges(); + for (i = 0; i < nEdges; ++i) { + if (_DotP[i] * _DotP[(i + 1) % nEdges] < 0.0f) { + // we got one + oCuspEdges.push_back(i); + } + } } WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() { - // if the smooth edge has already been built: exit - if (_pSmoothEdge) - return _pSmoothEdge; - float ta, tb; - WOEdge *woea(0), *woeb(0); - bool ok = false; - vector cuspEdgesIndices; - int indexStart, indexEnd; - unsigned nedges = _pWXFace->numberOfEdges(); - if (_nNullDotP == nedges) { - _pSmoothEdge = NULL; - return _pSmoothEdge; - } - if ((_nPosDotP != 0) && (_nPosDotP != _DotP.size()) && (_nNullDotP == 0)) { - // that means that we have a smooth edge that starts from an edge and ends at an edge - //----------------------------- - // We retrieve the 2 edges for which we have opposite signs for each extremity - RetrieveCuspEdgesIndices(cuspEdgesIndices); - if (cuspEdgesIndices.size() != 2) // we necessarly have 2 cusp edges - return 0; + // if the smooth edge has already been built: exit + if (_pSmoothEdge) + return _pSmoothEdge; + float ta, tb; + WOEdge *woea(0), *woeb(0); + bool ok = false; + vector cuspEdgesIndices; + int indexStart, indexEnd; + unsigned nedges = _pWXFace->numberOfEdges(); + if (_nNullDotP == nedges) { + _pSmoothEdge = NULL; + return _pSmoothEdge; + } + if ((_nPosDotP != 0) && (_nPosDotP != _DotP.size()) && (_nNullDotP == 0)) { + // that means that we have a smooth edge that starts from an edge and ends at an edge + //----------------------------- + // We retrieve the 2 edges for which we have opposite signs for each extremity + RetrieveCuspEdgesIndices(cuspEdgesIndices); + if (cuspEdgesIndices.size() != 2) // we necessarly have 2 cusp edges + return 0; - // let us determine which cusp edge corresponds to the starting: - // We can do that because we defined that a silhouette edge had the back facing part on its right. - // So if the WOEdge woea is such that woea[0].dotp > 0 and woea[1].dotp < 0, it is the starting edge. - //------------------------------------------- + // let us determine which cusp edge corresponds to the starting: + // We can do that because we defined that a silhouette edge had the back facing part on its right. + // So if the WOEdge woea is such that woea[0].dotp > 0 and woea[1].dotp < 0, it is the starting edge. + //------------------------------------------- - if (_DotP[cuspEdgesIndices[0]] > 0.0f) { - woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]); - woeb = _pWXFace->GetOEdge(cuspEdgesIndices[1]); - indexStart = cuspEdgesIndices[0]; - indexEnd = cuspEdgesIndices[1]; - } - else { - woea = _pWXFace->GetOEdge(cuspEdgesIndices[1]); - woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]); - indexStart = cuspEdgesIndices[1]; - indexEnd = cuspEdgesIndices[0]; - } + if (_DotP[cuspEdgesIndices[0]] > 0.0f) { + woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]); + woeb = _pWXFace->GetOEdge(cuspEdgesIndices[1]); + indexStart = cuspEdgesIndices[0]; + indexEnd = cuspEdgesIndices[1]; + } + else { + woea = _pWXFace->GetOEdge(cuspEdgesIndices[1]); + woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]); + indexStart = cuspEdgesIndices[1]; + indexEnd = cuspEdgesIndices[0]; + } - // Compute the interpolation: - ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]); - tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]); - ok = true; - } - else if (_nNullDotP == 1) { - // that means that we have exactly one of the 2 extremities of our silhouette edge is a vertex of the mesh - if ((_nPosDotP == 2) || (_nPosDotP == 0)) { - _pSmoothEdge = NULL; - return _pSmoothEdge; - } - RetrieveCuspEdgesIndices(cuspEdgesIndices); - // We should have only one EdgeCusp: - if (cuspEdgesIndices.size() != 1) { - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Warning in BuildSmoothEdge: weird WXFace configuration" << endl; - } - _pSmoothEdge = NULL; - return NULL; - } - unsigned index0 = Get0VertexIndex(); // retrieve the 0 vertex index - unsigned nedges = _pWXFace->numberOfEdges(); - if (_DotP[cuspEdgesIndices[0]] > 0.0f) { - woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]); - woeb = _pWXFace->GetOEdge(index0); - indexStart = cuspEdgesIndices[0]; - ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]); - tb = 0.0f; - } - else { - woea = _pWXFace->GetOEdge(index0); - woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]); - indexEnd = cuspEdgesIndices[0]; - ta = 0.0f; - tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]); - } - ok = true; - } - else if (_nNullDotP == 2) { - // that means that the silhouette edge is an edge of the mesh - int index = GetSmoothEdgeIndex(); - if (!_pWXFace->front()) { // is it in the right order ? - // the order of the WOEdge index is wrong - woea = _pWXFace->GetOEdge((index + 1) % nedges); - woeb = _pWXFace->GetOEdge((index - 1) % nedges); - ta = 0.0f; - tb = 1.0f; - ok = true; - } - else { - // here it's not good, our edge is a single point -> skip that face - ok = false; + // Compute the interpolation: + ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]); + tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]); + ok = true; + } + else if (_nNullDotP == 1) { + // that means that we have exactly one of the 2 extremities of our silhouette edge is a vertex of the mesh + if ((_nPosDotP == 2) || (_nPosDotP == 0)) { + _pSmoothEdge = NULL; + return _pSmoothEdge; + } + RetrieveCuspEdgesIndices(cuspEdgesIndices); + // We should have only one EdgeCusp: + if (cuspEdgesIndices.size() != 1) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "Warning in BuildSmoothEdge: weird WXFace configuration" << endl; + } + _pSmoothEdge = NULL; + return NULL; + } + unsigned index0 = Get0VertexIndex(); // retrieve the 0 vertex index + unsigned nedges = _pWXFace->numberOfEdges(); + if (_DotP[cuspEdgesIndices[0]] > 0.0f) { + woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]); + woeb = _pWXFace->GetOEdge(index0); + indexStart = cuspEdgesIndices[0]; + ta = _DotP[indexStart] / (_DotP[indexStart] - _DotP[(indexStart + 1) % nedges]); + tb = 0.0f; + } + else { + woea = _pWXFace->GetOEdge(index0); + woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]); + indexEnd = cuspEdgesIndices[0]; + ta = 0.0f; + tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]); + } + ok = true; + } + else if (_nNullDotP == 2) { + // that means that the silhouette edge is an edge of the mesh + int index = GetSmoothEdgeIndex(); + if (!_pWXFace->front()) { // is it in the right order ? + // the order of the WOEdge index is wrong + woea = _pWXFace->GetOEdge((index + 1) % nedges); + woeb = _pWXFace->GetOEdge((index - 1) % nedges); + ta = 0.0f; + tb = 1.0f; + ok = true; + } + else { + // here it's not good, our edge is a single point -> skip that face + ok = false; #if 0 - // the order of the WOEdge index is good - woea = _pWXFace->GetOEdge((index - 1) % nedges); - woeb = _pWXFace->GetOEdge((index + 1) % nedges); - ta = 1.0f; - tb = 0.0f; + // the order of the WOEdge index is good + woea = _pWXFace->GetOEdge((index - 1) % nedges); + woeb = _pWXFace->GetOEdge((index + 1) % nedges); + ta = 1.0f; + tb = 0.0f; #endif - } - } - if (ok) { - _pSmoothEdge = new WXSmoothEdge; - _pSmoothEdge->setWOeA(woea); - _pSmoothEdge->setWOeB(woeb); - _pSmoothEdge->setTa(ta); - _pSmoothEdge->setTb(tb); - if (_Nature & Nature::SILHOUETTE) { - if (_nNullDotP != 2) { - if (_DotP[_ClosestPointIndex] + 0.01f > 0.0f) - _pSmoothEdge->setFront(true); - else - _pSmoothEdge->setFront(false); - } - } - } + } + } + if (ok) { + _pSmoothEdge = new WXSmoothEdge; + _pSmoothEdge->setWOeA(woea); + _pSmoothEdge->setWOeB(woeb); + _pSmoothEdge->setTa(ta); + _pSmoothEdge->setTb(tb); + if (_Nature & Nature::SILHOUETTE) { + if (_nNullDotP != 2) { + if (_DotP[_ClosestPointIndex] + 0.01f > 0.0f) + _pSmoothEdge->setFront(true); + else + _pSmoothEdge->setFront(false); + } + } + } #if 0 - // check bording edges to see if they have different dotp values in bording faces. - for (int i = 0; i < numberOfEdges(); i++) { - WSFace *bface = (WSFace *)GetBordingFace(i); - if (bface) { - if ((front()) ^ (bface->front())) { // fA->front XOR fB->front (true if one is 0 and the other is 1) - // that means that the edge i of the face is a silhouette edge - // CHECK FIRST WHETHER THE EXACTSILHOUETTEEDGE HAS NOT YET BEEN BUILT ON THE OTHER FACE (1 is enough). - if (((WSExactFace *)bface)->exactSilhouetteEdge()) { - // that means that this silhouette edge has already been built - return ((WSExactFace *)bface)->exactSilhouetteEdge(); - } - // Else we must build it - WOEdge *woea, *woeb; - float ta, tb; - if (!front()) { // is it in the right order ? - // the order of the WOEdge index is wrong - woea = _OEdgeList[(i + 1) % numberOfEdges()]; - if (0 == i) - woeb = _OEdgeList[numberOfEdges() - 1]; - else - woeb = _OEdgeList[(i - 1)]; - ta = 0.0f; - tb = 1.0f; - } - else { - // the order of the WOEdge index is good - if (0 == i) - woea = _OEdgeList[numberOfEdges() - 1]; - else - woea = _OEdgeList[(i - 1)]; - woeb = _OEdgeList[(i + 1) % numberOfEdges()]; - ta = 1.0f; - tb = 0.0f; - } + // check bording edges to see if they have different dotp values in bording faces. + for (int i = 0; i < numberOfEdges(); i++) { + WSFace *bface = (WSFace *)GetBordingFace(i); + if (bface) { + if ((front()) ^ (bface->front())) { // fA->front XOR fB->front (true if one is 0 and the other is 1) + // that means that the edge i of the face is a silhouette edge + // CHECK FIRST WHETHER THE EXACTSILHOUETTEEDGE HAS NOT YET BEEN BUILT ON THE OTHER FACE (1 is enough). + if (((WSExactFace *)bface)->exactSilhouetteEdge()) { + // that means that this silhouette edge has already been built + return ((WSExactFace *)bface)->exactSilhouetteEdge(); + } + // Else we must build it + WOEdge *woea, *woeb; + float ta, tb; + if (!front()) { // is it in the right order ? + // the order of the WOEdge index is wrong + woea = _OEdgeList[(i + 1) % numberOfEdges()]; + if (0 == i) + woeb = _OEdgeList[numberOfEdges() - 1]; + else + woeb = _OEdgeList[(i - 1)]; + ta = 0.0f; + tb = 1.0f; + } + else { + // the order of the WOEdge index is good + if (0 == i) + woea = _OEdgeList[numberOfEdges() - 1]; + else + woea = _OEdgeList[(i - 1)]; + woeb = _OEdgeList[(i + 1) % numberOfEdges()]; + ta = 1.0f; + tb = 0.0f; + } - _pSmoothEdge = new ExactSilhouetteEdge(ExactSilhouetteEdge::VERTEX_VERTEX); - _pSmoothEdge->setWOeA(woea); - _pSmoothEdge->setWOeA(woeb); - _pSmoothEdge->setTa(ta); - _pSmoothEdge->setTb(tb); + _pSmoothEdge = new ExactSilhouetteEdge(ExactSilhouetteEdge::VERTEX_VERTEX); + _pSmoothEdge->setWOeA(woea); + _pSmoothEdge->setWOeA(woeb); + _pSmoothEdge->setTa(ta); + _pSmoothEdge->setTb(tb); - return _pSmoothEdge; - } - } - } + return _pSmoothEdge; + } + } + } #endif - return _pSmoothEdge; + return _pSmoothEdge; } - void WXFace::ComputeCenter() { - vector iVertexList; - RetrieveVertexList(iVertexList); - Vec3f center; - for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { - center += (*wv)->GetVertex(); - } - center /= (float)iVertexList.size(); - setCenter(center); + vector iVertexList; + RetrieveVertexList(iVertexList); + Vec3f center; + for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); + wv != wvend; + ++wv) { + center += (*wv)->GetVertex(); + } + center /= (float)iVertexList.size(); + setCenter(center); } /********************************** @@ -256,37 +257,45 @@ void WXFace::ComputeCenter() * * **********************************/ -WFace *WXShape::MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterialIndex) +WFace *WXShape::MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex) { - WFace *face = WShape::MakeFace(iVertexList, iFaceEdgeMarksList, iMaterialIndex); - if (!face) - return NULL; + WFace *face = WShape::MakeFace(iVertexList, iFaceEdgeMarksList, iMaterialIndex); + if (!face) + return NULL; - Vec3f center; - for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { - center += (*wv)->GetVertex(); - } - center /= (float)iVertexList.size(); - ((WXFace *)face)->setCenter(center); + Vec3f center; + for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); + wv != wvend; + ++wv) { + center += (*wv)->GetVertex(); + } + center /= (float)iVertexList.size(); + ((WXFace *)face)->setCenter(center); - return face; + return face; } -WFace *WXShape::MakeFace(vector& iVertexList, vector& iNormalsList, vector& iTexCoordsList, - vector& iFaceEdgeMarksList, unsigned iMaterialIndex) +WFace *WXShape::MakeFace(vector &iVertexList, + vector &iNormalsList, + vector &iTexCoordsList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex) { - WFace *face = WShape::MakeFace(iVertexList, iNormalsList, iTexCoordsList, iFaceEdgeMarksList, iMaterialIndex); + WFace *face = WShape::MakeFace( + iVertexList, iNormalsList, iTexCoordsList, iFaceEdgeMarksList, iMaterialIndex); #if 0 - Vec3f center; - for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { - center += (*wv)->GetVertex(); - } - center /= (float)iVertexList.size(); - ((WXFace *)face)->setCenter(center); + Vec3f center; + for (vector::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { + center += (*wv)->GetVertex(); + } + center /= (float)iVertexList.size(); + ((WXFace *)face)->setCenter(center); #endif - return face; + return face; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WXEdge.h b/source/blender/freestyle/intern/winged_edge/WXEdge.h index acca64b930d..63c2ef4f52b 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WXEdge.h @@ -27,7 +27,7 @@ #include "WEdge.h" #ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" +# include "MEM_guardedalloc.h" #endif namespace Freestyle { @@ -42,60 +42,58 @@ typedef Nature::EdgeNature WXNature; * * **********************************/ -class WXVertex : public WVertex -{ -private: - // Curvature info - CurvatureInfo *_curvatures; - -public: - inline WXVertex(const Vec3f &v) : WVertex(v) - { - _curvatures = NULL; - } - - /*! Copy constructor */ - WXVertex(WXVertex& iBrother) : WVertex(iBrother) - { - _curvatures = new CurvatureInfo(*iBrother._curvatures); - } - - virtual WVertex *duplicate() - { - WXVertex *clone = new WXVertex(*this); - return clone; - } - - virtual ~WXVertex() - { - if (_curvatures) - delete _curvatures; - } - - virtual void Reset() - { - if (_curvatures) - _curvatures->Kr = 0.0; - } - - inline void setCurvatures(CurvatureInfo *ci) - { - _curvatures = ci; - } - - inline bool isFeature(); - - inline CurvatureInfo *curvatures() - { - return _curvatures; - } +class WXVertex : public WVertex { + private: + // Curvature info + CurvatureInfo *_curvatures; + + public: + inline WXVertex(const Vec3f &v) : WVertex(v) + { + _curvatures = NULL; + } + + /*! Copy constructor */ + WXVertex(WXVertex &iBrother) : WVertex(iBrother) + { + _curvatures = new CurvatureInfo(*iBrother._curvatures); + } + + virtual WVertex *duplicate() + { + WXVertex *clone = new WXVertex(*this); + return clone; + } + + virtual ~WXVertex() + { + if (_curvatures) + delete _curvatures; + } + + virtual void Reset() + { + if (_curvatures) + _curvatures->Kr = 0.0; + } + + inline void setCurvatures(CurvatureInfo *ci) + { + _curvatures = ci; + } + + inline bool isFeature(); + + inline CurvatureInfo *curvatures() + { + return _curvatures; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXVertex") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXVertex") #endif }; - /********************************** * * * * @@ -104,100 +102,101 @@ public: * * **********************************/ -class WXEdge : public WEdge -{ -private: - // flag to indicate whether the edge is a silhouette edge or not - WXNature _nature; - // 0: the order doesn't matter. 1: the order is the orginal one. -1: the order is not good - short _order; - // A front facing edge is an edge for which the bording face which is the nearest from the viewpoint is front. - // A back facing edge is the opposite. - bool _front; - -public: - inline WXEdge() : WEdge() - { - _nature = Nature::NO_FEATURE; - _front = false; - _order = 0; - } - - inline WXEdge(WOEdge *iOEdge) : WEdge(iOEdge) - { - _nature = Nature::NO_FEATURE; - _front = false; - _order = 0; - } - - inline WXEdge(WOEdge *iaOEdge, WOEdge *ibOEdge) : WEdge(iaOEdge, ibOEdge) - { - _nature = Nature::NO_FEATURE; - _front = false; - _order = 0; - } - - /*! Copy constructor */ - inline WXEdge(WXEdge& iBrother) : WEdge(iBrother) - { - _nature = iBrother.nature(); - _front = iBrother._front; - _order = iBrother._order; - } - - virtual WEdge *duplicate() - { - WXEdge *clone = new WXEdge(*this); - return clone; - } - - virtual ~WXEdge() {} - - virtual void Reset() - { - _nature = _nature & ~Nature::SILHOUETTE; - _nature = _nature & ~Nature::SUGGESTIVE_CONTOUR; - } - - /*! accessors */ - inline WXNature nature() - { - return _nature; - } - - inline bool front() - { - return _front; - } - - inline short order() const - { - return _order; - } - - /*! modifiers */ - inline void setFront(bool iFront) - { - _front = iFront; - } - - inline void setNature(WXNature iNature) - { - _nature = iNature; - } - - inline void AddNature(WXNature iNature) - { - _nature = _nature | iNature; - } - - inline void setOrder(int i) - { - _order = i; - } +class WXEdge : public WEdge { + private: + // flag to indicate whether the edge is a silhouette edge or not + WXNature _nature; + // 0: the order doesn't matter. 1: the order is the orginal one. -1: the order is not good + short _order; + // A front facing edge is an edge for which the bording face which is the nearest from the viewpoint is front. + // A back facing edge is the opposite. + bool _front; + + public: + inline WXEdge() : WEdge() + { + _nature = Nature::NO_FEATURE; + _front = false; + _order = 0; + } + + inline WXEdge(WOEdge *iOEdge) : WEdge(iOEdge) + { + _nature = Nature::NO_FEATURE; + _front = false; + _order = 0; + } + + inline WXEdge(WOEdge *iaOEdge, WOEdge *ibOEdge) : WEdge(iaOEdge, ibOEdge) + { + _nature = Nature::NO_FEATURE; + _front = false; + _order = 0; + } + + /*! Copy constructor */ + inline WXEdge(WXEdge &iBrother) : WEdge(iBrother) + { + _nature = iBrother.nature(); + _front = iBrother._front; + _order = iBrother._order; + } + + virtual WEdge *duplicate() + { + WXEdge *clone = new WXEdge(*this); + return clone; + } + + virtual ~WXEdge() + { + } + + virtual void Reset() + { + _nature = _nature & ~Nature::SILHOUETTE; + _nature = _nature & ~Nature::SUGGESTIVE_CONTOUR; + } + + /*! accessors */ + inline WXNature nature() + { + return _nature; + } + + inline bool front() + { + return _front; + } + + inline short order() const + { + return _order; + } + + /*! modifiers */ + inline void setFront(bool iFront) + { + _front = iFront; + } + + inline void setNature(WXNature iNature) + { + _nature = iNature; + } + + inline void AddNature(WXNature iNature) + { + _nature = _nature | iNature; + } + + inline void setOrder(int i) + { + _order = i; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdge") #endif }; @@ -210,106 +209,107 @@ public: **********************************/ /*! Class to store a smooth edge (i.e Hertzman & Zorin smooth silhouette edges) */ -class WXSmoothEdge -{ -public: - typedef unsigned short Configuration; - static const Configuration EDGE_EDGE = 1; - static const Configuration VERTEX_EDGE = 2; - static const Configuration EDGE_VERTEX = 3; - - WOEdge *_woea; // Oriented edge from which the silhouette edge starts - WOEdge *_woeb; // Oriented edge where the silhouette edge ends - float _ta; // The silhouette starting point's coordinates are : _woea[0]+ta*(_woea[1]-_woea[0]) - float _tb; // The silhouette ending point's coordinates are : _woeb[0]+ta*(_woeb[1]-_woeb[0]) - bool _front; - Configuration _config; - - WXSmoothEdge() - { - _woea = NULL; - _woeb = NULL; - _ta = 0.0f; - _tb = 0.0f; - _front = false; - _config = EDGE_EDGE; - } - - WXSmoothEdge(const WXSmoothEdge& iBrother) - { - _woea = iBrother._woea; - _woeb = iBrother._woeb; - _ta = iBrother._ta; - _tb = iBrother._tb; - _config = iBrother._config; - _front = iBrother._front; - } - - ~WXSmoothEdge() {} - - inline WOEdge *woea() - { - return _woea; - } - - inline WOEdge *woeb() - { - return _woeb; - } - - inline float ta() const - { - return _ta; - } - - inline float tb() const - { - return _tb; - } - - inline bool front() const - { - return _front; - } - - inline Configuration configuration() const - { - return _config; - } - - /*! modifiers */ - inline void setWOeA(WOEdge *iwoea) - { - _woea = iwoea; - } - - inline void setWOeB(WOEdge *iwoeb) - { - _woeb = iwoeb; - } - - inline void setTa(float ta) - { - _ta = ta; - } - - inline void setTb(float tb) - { - _tb = tb; - } - - inline void setFront(bool iFront) - { - _front = iFront; - } - - inline void setConfiguration(Configuration iConf) - { - _config = iConf; - } +class WXSmoothEdge { + public: + typedef unsigned short Configuration; + static const Configuration EDGE_EDGE = 1; + static const Configuration VERTEX_EDGE = 2; + static const Configuration EDGE_VERTEX = 3; + + WOEdge *_woea; // Oriented edge from which the silhouette edge starts + WOEdge *_woeb; // Oriented edge where the silhouette edge ends + float _ta; // The silhouette starting point's coordinates are : _woea[0]+ta*(_woea[1]-_woea[0]) + float _tb; // The silhouette ending point's coordinates are : _woeb[0]+ta*(_woeb[1]-_woeb[0]) + bool _front; + Configuration _config; + + WXSmoothEdge() + { + _woea = NULL; + _woeb = NULL; + _ta = 0.0f; + _tb = 0.0f; + _front = false; + _config = EDGE_EDGE; + } + + WXSmoothEdge(const WXSmoothEdge &iBrother) + { + _woea = iBrother._woea; + _woeb = iBrother._woeb; + _ta = iBrother._ta; + _tb = iBrother._tb; + _config = iBrother._config; + _front = iBrother._front; + } + + ~WXSmoothEdge() + { + } + + inline WOEdge *woea() + { + return _woea; + } + + inline WOEdge *woeb() + { + return _woeb; + } + + inline float ta() const + { + return _ta; + } + + inline float tb() const + { + return _tb; + } + + inline bool front() const + { + return _front; + } + + inline Configuration configuration() const + { + return _config; + } + + /*! modifiers */ + inline void setWOeA(WOEdge *iwoea) + { + _woea = iwoea; + } + + inline void setWOeB(WOEdge *iwoeb) + { + _woeb = iwoeb; + } + + inline void setTa(float ta) + { + _ta = ta; + } + + inline void setTb(float tb) + { + _tb = tb; + } + + inline void setFront(bool iFront) + { + _front = iFront; + } + + inline void setConfiguration(Configuration iConf) + { + _config = iConf; + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXSmoothEdge") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXSmoothEdge") #endif }; @@ -318,382 +318,374 @@ public: */ class WXFace; -class WXFaceLayer -{ -public: - void *userdata; - WXFace *_pWXFace; - // in case of silhouette: the values obtained when computing the normal-view direction dot product. _DotP[i] is - // this value for the vertex i for that face. - vector _DotP; - WXSmoothEdge *_pSmoothEdge; - WXNature _Nature; - - //oldtmp values - // count the number of positive dot products for vertices. - // if this number is != 0 and !=_DotP.size() -> it is a silhouette fac - unsigned _nPosDotP; - - unsigned _nNullDotP; // count the number of null dot products for vertices. - unsigned _ClosestPointIndex; - bool _viewDependant; - - WXFaceLayer(WXFace *iFace, WXNature iNature, bool viewDependant) - { - _pWXFace = iFace; - _pSmoothEdge = NULL; - _nPosDotP = 0; - _nNullDotP = 0; - _Nature = iNature; - _viewDependant = viewDependant; - userdata = NULL; - } - - WXFaceLayer(const WXFaceLayer& iBrother) - { - _pWXFace = iBrother._pWXFace; - _pSmoothEdge = NULL; - _DotP = iBrother._DotP; - _nPosDotP = iBrother._nPosDotP; - _nNullDotP = iBrother._nNullDotP; - _Nature = iBrother._Nature; - if (iBrother._pSmoothEdge) { // XXX ? It's set to null a few lines above! - _pSmoothEdge = new WXSmoothEdge(*(iBrother._pSmoothEdge)); - } - _viewDependant = iBrother._viewDependant; - userdata = NULL; - } - - virtual ~WXFaceLayer() - { - if (!_DotP.empty()) - _DotP.clear(); - if (_pSmoothEdge) { - delete _pSmoothEdge; - _pSmoothEdge = NULL; - } - } - - inline const float dotP(int i) const - { - return _DotP[i]; - } - - inline unsigned nPosDotP() const - { - return _nPosDotP; - } - - inline unsigned nNullDotP() const - { - return _nNullDotP; - } - - inline int closestPointIndex() const - { - return _ClosestPointIndex; - } - - inline WXNature nature() const - { - return _Nature; - } - - inline bool hasSmoothEdge() const - { - if (_pSmoothEdge) - return true; - return false; - } - - inline WXFace *getFace() - { - return _pWXFace; - } - - inline WXSmoothEdge *getSmoothEdge() - { - return _pSmoothEdge; - } - - inline bool isViewDependant() const - { - return _viewDependant; - } - - inline void setClosestPointIndex(int iIndex) - { - _ClosestPointIndex = iIndex; - } - - inline void removeSmoothEdge() - { - if (!_DotP.empty()) - _DotP.clear(); - if (_pSmoothEdge) { - delete _pSmoothEdge; - _pSmoothEdge = NULL; - } - } - - /*! If one of the face layer vertex has a DotP equal to 0, this method returns the vertex where it happens */ - unsigned int Get0VertexIndex() const; - - /*! In case one of the edge of the triangle is a smooth edge, this method allows to retrieve the concerned edge */ - unsigned int GetSmoothEdgeIndex() const; - - /*! retrieves the edges of the triangle for which the signs are different (a null value is not considered) for - * the dotp values at each edge extrimity - */ - void RetrieveCuspEdgesIndices(vector& oCuspEdges); - - WXSmoothEdge *BuildSmoothEdge(); - - inline void setDotP(const vector& iDotP) - { - _DotP = iDotP; - } - - inline void PushDotP(float iDotP) - { - _DotP.push_back(iDotP); - if (iDotP > 0.0f) - ++_nPosDotP; - if (iDotP == 0.0f) // TODO this comparison is weak, check if it actually works - ++_nNullDotP; - } - - inline void ReplaceDotP(unsigned int index, float newDotP) - { - _DotP[index] = newDotP; - updateDotPInfos(); - } - - inline void updateDotPInfos() - { - _nPosDotP = 0; - _nNullDotP = 0; - for (vector::iterator d = _DotP.begin(), dend = _DotP.end(); d != dend; ++d) { - if ((*d) > 0.0f) - ++_nPosDotP; - if ((*d) == 0.0f) // TODO ditto - ++_nNullDotP; - } - } +class WXFaceLayer { + public: + void *userdata; + WXFace *_pWXFace; + // in case of silhouette: the values obtained when computing the normal-view direction dot product. _DotP[i] is + // this value for the vertex i for that face. + vector _DotP; + WXSmoothEdge *_pSmoothEdge; + WXNature _Nature; + + //oldtmp values + // count the number of positive dot products for vertices. + // if this number is != 0 and !=_DotP.size() -> it is a silhouette fac + unsigned _nPosDotP; + + unsigned _nNullDotP; // count the number of null dot products for vertices. + unsigned _ClosestPointIndex; + bool _viewDependant; + + WXFaceLayer(WXFace *iFace, WXNature iNature, bool viewDependant) + { + _pWXFace = iFace; + _pSmoothEdge = NULL; + _nPosDotP = 0; + _nNullDotP = 0; + _Nature = iNature; + _viewDependant = viewDependant; + userdata = NULL; + } + + WXFaceLayer(const WXFaceLayer &iBrother) + { + _pWXFace = iBrother._pWXFace; + _pSmoothEdge = NULL; + _DotP = iBrother._DotP; + _nPosDotP = iBrother._nPosDotP; + _nNullDotP = iBrother._nNullDotP; + _Nature = iBrother._Nature; + if (iBrother._pSmoothEdge) { // XXX ? It's set to null a few lines above! + _pSmoothEdge = new WXSmoothEdge(*(iBrother._pSmoothEdge)); + } + _viewDependant = iBrother._viewDependant; + userdata = NULL; + } + + virtual ~WXFaceLayer() + { + if (!_DotP.empty()) + _DotP.clear(); + if (_pSmoothEdge) { + delete _pSmoothEdge; + _pSmoothEdge = NULL; + } + } + + inline const float dotP(int i) const + { + return _DotP[i]; + } + + inline unsigned nPosDotP() const + { + return _nPosDotP; + } + + inline unsigned nNullDotP() const + { + return _nNullDotP; + } + + inline int closestPointIndex() const + { + return _ClosestPointIndex; + } + + inline WXNature nature() const + { + return _Nature; + } + + inline bool hasSmoothEdge() const + { + if (_pSmoothEdge) + return true; + return false; + } + + inline WXFace *getFace() + { + return _pWXFace; + } + + inline WXSmoothEdge *getSmoothEdge() + { + return _pSmoothEdge; + } + + inline bool isViewDependant() const + { + return _viewDependant; + } + + inline void setClosestPointIndex(int iIndex) + { + _ClosestPointIndex = iIndex; + } + + inline void removeSmoothEdge() + { + if (!_DotP.empty()) + _DotP.clear(); + if (_pSmoothEdge) { + delete _pSmoothEdge; + _pSmoothEdge = NULL; + } + } + + /*! If one of the face layer vertex has a DotP equal to 0, this method returns the vertex where it happens */ + unsigned int Get0VertexIndex() const; + + /*! In case one of the edge of the triangle is a smooth edge, this method allows to retrieve the concerned edge */ + unsigned int GetSmoothEdgeIndex() const; + + /*! retrieves the edges of the triangle for which the signs are different (a null value is not considered) for + * the dotp values at each edge extrimity + */ + void RetrieveCuspEdgesIndices(vector &oCuspEdges); + + WXSmoothEdge *BuildSmoothEdge(); + + inline void setDotP(const vector &iDotP) + { + _DotP = iDotP; + } + + inline void PushDotP(float iDotP) + { + _DotP.push_back(iDotP); + if (iDotP > 0.0f) + ++_nPosDotP; + if (iDotP == 0.0f) // TODO this comparison is weak, check if it actually works + ++_nNullDotP; + } + + inline void ReplaceDotP(unsigned int index, float newDotP) + { + _DotP[index] = newDotP; + updateDotPInfos(); + } + + inline void updateDotPInfos() + { + _nPosDotP = 0; + _nNullDotP = 0; + for (vector::iterator d = _DotP.begin(), dend = _DotP.end(); d != dend; ++d) { + if ((*d) > 0.0f) + ++_nPosDotP; + if ((*d) == 0.0f) // TODO ditto + ++_nNullDotP; + } + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFaceLayer") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFaceLayer") #endif }; -class WXFace : public WFace -{ -protected: - Vec3f _center; // center of the face - float _Z; // distance from viewpoint to the center of the face - bool _front; // flag to tell whether the face is front facing or back facing - float _dotp; // value obtained when computing the normal-viewpoint dot product - - vector _SmoothLayers; // The data needed to store one or several smooth edges that traverse the face - -public: - inline WXFace() : WFace() - { - _Z = 0.0f; - _front = false; - } - - /*! Copy constructor */ - WXFace(WXFace& iBrother) : WFace(iBrother) - { - _center = iBrother.center(); - _Z = iBrother.Z(); - _front = iBrother.front(); - for (vector::iterator wxf = iBrother._SmoothLayers.begin(), wxfend = iBrother._SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - _SmoothLayers.push_back(new WXFaceLayer(**wxf)); - } - } - - virtual WFace *duplicate() - { - WXFace *clone = new WXFace(*this); - return clone; - } - - virtual ~WXFace() - { - if (!_SmoothLayers.empty()) { - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - delete (*wxf); - } - _SmoothLayers.clear(); - } - } - - /*! designed to build a specialized WEdge for use in MakeEdge */ - virtual WEdge *instanciateEdge() const - { - return new WXEdge; - } - - /*! accessors */ - inline Vec3f& center() - { - return _center; - } - - inline float Z() - { - return _Z; - } - - inline bool front() - { - return _front; - } - - inline float dotp() - { - return _dotp; - } - - inline bool hasSmoothEdges() const - { - for (vector::const_iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - if ((*wxf)->hasSmoothEdge()) { - return true; - } - } - return false; - } - - vector& getSmoothLayers() - { - return _SmoothLayers; - } - - /*! retrieve the smooth edges that match the Nature given as argument */ - void retrieveSmoothEdges(WXNature iNature, vector& oSmoothEdges) - { - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - if ((*wxf)->hasSmoothEdge() && ((*wxf)->_Nature & iNature)) { - oSmoothEdges.push_back((*wxf)->_pSmoothEdge); - } - } - } - - void retrieveSmoothEdgesLayers(WXNature iNature, vector& oSmoothEdgesLayers) - { - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - if ((*wxf)->hasSmoothEdge() && ((*wxf)->_Nature & iNature)) { - oSmoothEdgesLayers.push_back((*wxf)); - } - } - } - - void retrieveSmoothLayers(WXNature iNature, vector& oSmoothLayers) - { - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - if ((*wxf)->_Nature & iNature) { - oSmoothLayers.push_back(*wxf); - } - } - } - - /*! modifiers */ - inline void setCenter(const Vec3f& iCenter) - { - _center = iCenter; - } - - void ComputeCenter(); - - inline void setZ(float z) - { - _Z = z; - } - - inline void setFront(bool iFront) - { - _front = iFront; - } - - inline void setDotP(float iDotP) - { - _dotp = iDotP; - if (_dotp > 0.0f) - _front = true; - else - _front = false; - } - - inline void AddSmoothLayer(WXFaceLayer *iLayer) - { - _SmoothLayers.push_back(iLayer); - } - - inline void Reset() - { - vector layersToKeep; - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - if ((*wxf)->isViewDependant()) - delete (*wxf); - else - layersToKeep.push_back(*wxf); - } - _SmoothLayers = layersToKeep; - } - - /*! Clears everything */ - inline void Clear() - { - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - delete (*wxf); - } - _SmoothLayers.clear(); - } - - virtual void ResetUserData() - { - WFace::ResetUserData(); - for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); - wxf != wxfend; - ++wxf) - { - (*wxf)->userdata = NULL; - } - } +class WXFace : public WFace { + protected: + Vec3f _center; // center of the face + float _Z; // distance from viewpoint to the center of the face + bool _front; // flag to tell whether the face is front facing or back facing + float _dotp; // value obtained when computing the normal-viewpoint dot product + + vector + _SmoothLayers; // The data needed to store one or several smooth edges that traverse the face + + public: + inline WXFace() : WFace() + { + _Z = 0.0f; + _front = false; + } + + /*! Copy constructor */ + WXFace(WXFace &iBrother) : WFace(iBrother) + { + _center = iBrother.center(); + _Z = iBrother.Z(); + _front = iBrother.front(); + for (vector::iterator wxf = iBrother._SmoothLayers.begin(), + wxfend = iBrother._SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + _SmoothLayers.push_back(new WXFaceLayer(**wxf)); + } + } + + virtual WFace *duplicate() + { + WXFace *clone = new WXFace(*this); + return clone; + } + + virtual ~WXFace() + { + if (!_SmoothLayers.empty()) { + for (vector::iterator wxf = _SmoothLayers.begin(), + wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + delete (*wxf); + } + _SmoothLayers.clear(); + } + } + + /*! designed to build a specialized WEdge for use in MakeEdge */ + virtual WEdge *instanciateEdge() const + { + return new WXEdge; + } + + /*! accessors */ + inline Vec3f ¢er() + { + return _center; + } + + inline float Z() + { + return _Z; + } + + inline bool front() + { + return _front; + } + + inline float dotp() + { + return _dotp; + } + + inline bool hasSmoothEdges() const + { + for (vector::const_iterator wxf = _SmoothLayers.begin(), + wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + if ((*wxf)->hasSmoothEdge()) { + return true; + } + } + return false; + } + + vector &getSmoothLayers() + { + return _SmoothLayers; + } + + /*! retrieve the smooth edges that match the Nature given as argument */ + void retrieveSmoothEdges(WXNature iNature, vector &oSmoothEdges) + { + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + if ((*wxf)->hasSmoothEdge() && ((*wxf)->_Nature & iNature)) { + oSmoothEdges.push_back((*wxf)->_pSmoothEdge); + } + } + } + + void retrieveSmoothEdgesLayers(WXNature iNature, vector &oSmoothEdgesLayers) + { + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + if ((*wxf)->hasSmoothEdge() && ((*wxf)->_Nature & iNature)) { + oSmoothEdgesLayers.push_back((*wxf)); + } + } + } + + void retrieveSmoothLayers(WXNature iNature, vector &oSmoothLayers) + { + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + if ((*wxf)->_Nature & iNature) { + oSmoothLayers.push_back(*wxf); + } + } + } + + /*! modifiers */ + inline void setCenter(const Vec3f &iCenter) + { + _center = iCenter; + } + + void ComputeCenter(); + + inline void setZ(float z) + { + _Z = z; + } + + inline void setFront(bool iFront) + { + _front = iFront; + } + + inline void setDotP(float iDotP) + { + _dotp = iDotP; + if (_dotp > 0.0f) + _front = true; + else + _front = false; + } + + inline void AddSmoothLayer(WXFaceLayer *iLayer) + { + _SmoothLayers.push_back(iLayer); + } + + inline void Reset() + { + vector layersToKeep; + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + if ((*wxf)->isViewDependant()) + delete (*wxf); + else + layersToKeep.push_back(*wxf); + } + _SmoothLayers = layersToKeep; + } + + /*! Clears everything */ + inline void Clear() + { + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + delete (*wxf); + } + _SmoothLayers.clear(); + } + + virtual void ResetUserData() + { + WFace::ResetUserData(); + for (vector::iterator wxf = _SmoothLayers.begin(), wxfend = _SmoothLayers.end(); + wxf != wxfend; + ++wxf) { + (*wxf)->userdata = NULL; + } + } #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFace") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFace") #endif }; - /********************************** * * * * @@ -702,96 +694,103 @@ public: * * **********************************/ -class WXShape : public WShape -{ +class WXShape : public WShape { #if 0 public: - typedef WXShape type_name; + typedef WXShape type_name; #endif -protected: - bool _computeViewIndependent; // flag to indicate whether the view independent stuff must be computed or not - -public: - inline WXShape() : WShape() - { - _computeViewIndependent = true; - } - - /*! copy constructor */ - inline WXShape(WXShape& iBrother) : WShape(iBrother) - { - _computeViewIndependent = iBrother._computeViewIndependent; - } - - virtual WShape *duplicate() - { - WXShape *clone = new WXShape(*this); - return clone; - } - - virtual ~WXShape() {} - - inline bool getComputeViewIndependentFlag() const - { - return _computeViewIndependent; - } - - inline void setComputeViewIndependentFlag(bool iFlag) - { - _computeViewIndependent = iFlag; - } - - /*! designed to build a specialized WFace for use in MakeFace */ - virtual WFace *instanciateFace() const - { - return new WXFace; - } - - /*! adds a new face to the shape returns the built face. - * iVertexList - * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed - * to be already stored when calling MakeFace. The order in which the vertices are stored in the list - * determines the face's edges orientation and (so) the face orientation. - */ - virtual WFace *MakeFace(vector& iVertexList, vector& iFaceEdgeMarksList, unsigned iMaterialIndex); - - /*! adds a new face to the shape. The difference with the previous method is that this one is designed to build - * a WingedEdge structure for which there are per vertex normals, opposed to per face normals. - * returns the built face. - * iVertexList - * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be - * already stored when calling MakeFace. - * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the - * face orientation. - * iNormalsList - * The list of normals, iNormalsList[i] corresponding to the normal of the vertex iVertexList[i] for that face. - * iTexCoordsList - * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for - * that face. - */ - virtual WFace *MakeFace(vector& iVertexList, vector& iNormalsList, vector& iTexCoordsList, - vector& iFaceEdgeMarksList, unsigned iMaterialIndex); - - /*! Reset all edges and vertices flags (which might have been set up on a previous pass) */ - virtual void Reset() - { - // Reset Edges - vector& wedges = getEdgeList(); - for (vector::iterator we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { - ((WXEdge *)(*we))->Reset(); - } - - //Reset faces: - vector& wfaces = GetFaceList(); - for (vector::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; ++wf) { - ((WXFace *)(*wf))->Reset(); - } - } - /*! accessors */ + protected: + bool + _computeViewIndependent; // flag to indicate whether the view independent stuff must be computed or not + + public: + inline WXShape() : WShape() + { + _computeViewIndependent = true; + } + + /*! copy constructor */ + inline WXShape(WXShape &iBrother) : WShape(iBrother) + { + _computeViewIndependent = iBrother._computeViewIndependent; + } + + virtual WShape *duplicate() + { + WXShape *clone = new WXShape(*this); + return clone; + } + + virtual ~WXShape() + { + } + + inline bool getComputeViewIndependentFlag() const + { + return _computeViewIndependent; + } + + inline void setComputeViewIndependentFlag(bool iFlag) + { + _computeViewIndependent = iFlag; + } + + /*! designed to build a specialized WFace for use in MakeFace */ + virtual WFace *instanciateFace() const + { + return new WXFace; + } + + /*! adds a new face to the shape returns the built face. + * iVertexList + * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed + * to be already stored when calling MakeFace. The order in which the vertices are stored in the list + * determines the face's edges orientation and (so) the face orientation. + */ + virtual WFace *MakeFace(vector &iVertexList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex); + + /*! adds a new face to the shape. The difference with the previous method is that this one is designed to build + * a WingedEdge structure for which there are per vertex normals, opposed to per face normals. + * returns the built face. + * iVertexList + * List of face's vertices. These vertices are not added to the WShape vertex list; they are supposed to be + * already stored when calling MakeFace. + * The order in which the vertices are stored in the list determines the face's edges orientation and (so) the + * face orientation. + * iNormalsList + * The list of normals, iNormalsList[i] corresponding to the normal of the vertex iVertexList[i] for that face. + * iTexCoordsList + * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for + * that face. + */ + virtual WFace *MakeFace(vector &iVertexList, + vector &iNormalsList, + vector &iTexCoordsList, + vector &iFaceEdgeMarksList, + unsigned iMaterialIndex); + + /*! Reset all edges and vertices flags (which might have been set up on a previous pass) */ + virtual void Reset() + { + // Reset Edges + vector &wedges = getEdgeList(); + for (vector::iterator we = wedges.begin(), weend = wedges.end(); we != weend; ++we) { + ((WXEdge *)(*we))->Reset(); + } + + //Reset faces: + vector &wfaces = GetFaceList(); + for (vector::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; ++wf) { + ((WXFace *)(*wf))->Reset(); + } + } + /*! accessors */ #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXShape") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXShape") #endif }; @@ -810,16 +809,16 @@ public: bool WXVertex::isFeature() { - int counter = 0; - vector& vedges = GetEdges(); - for (vector::iterator ve = vedges.begin(), vend = vedges.end(); ve != vend; ++ve) { - if (((WXEdge *)(*ve))->nature() != Nature::NO_FEATURE) - counter++; - } - - if ((counter == 1) || (counter > 2)) - return true; - return false; + int counter = 0; + vector &vedges = GetEdges(); + for (vector::iterator ve = vedges.begin(), vend = vedges.end(); ve != vend; ++ve) { + if (((WXEdge *)(*ve))->nature() != Nature::NO_FEATURE) + counter++; + } + + if ((counter == 1) || (counter > 2)) + return true; + return false; } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp index 6fa73c3d212..fb0b6a9b63f 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp +++ b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp @@ -25,29 +25,29 @@ namespace Freestyle { -void WXEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet& ifs) +void WXEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet &ifs) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - return; - WXShape *shape = new WXShape; - if (!buildWShape(*shape, ifs)) { - delete shape; - return; - } - shape->setId(ifs.getId().getFirst()); - shape->setName(ifs.getName()); - shape->setLibraryPath(ifs.getLibraryPath()); - //ifs.setId(shape->GetId()); + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + return; + WXShape *shape = new WXShape; + if (!buildWShape(*shape, ifs)) { + delete shape; + return; + } + shape->setId(ifs.getId().getFirst()); + shape->setName(ifs.getName()); + shape->setLibraryPath(ifs.getLibraryPath()); + //ifs.setId(shape->GetId()); } -void WXEdgeBuilder::buildWVertices(WShape& shape, const float *vertices, unsigned vsize) +void WXEdgeBuilder::buildWVertices(WShape &shape, const float *vertices, unsigned vsize) { - WXVertex *vertex; - for (unsigned int i = 0; i < vsize; i += 3) { - vertex = new WXVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); - vertex->setId(i / 3); - shape.AddVertex(vertex); - } + WXVertex *vertex; + for (unsigned int i = 0; i < vsize; i += 3) { + vertex = new WXVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); + vertex->setId(i / 3); + shape.AddVertex(vertex); + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h index a4eb270435a..e98832f4fba 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h +++ b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h @@ -29,22 +29,24 @@ namespace Freestyle { -class WXEdgeBuilder : public WingedEdgeBuilder -{ -public: - WXEdgeBuilder() : WingedEdgeBuilder() {} - virtual ~WXEdgeBuilder() {} - VISIT_DECL(IndexedFaceSet) - -protected: - virtual void buildWVertices(WShape& shape, const float *vertices, unsigned vsize); +class WXEdgeBuilder : public WingedEdgeBuilder { + public: + WXEdgeBuilder() : WingedEdgeBuilder() + { + } + virtual ~WXEdgeBuilder() + { + } + VISIT_DECL(IndexedFaceSet) + + protected: + virtual void buildWVertices(WShape &shape, const float *vertices, unsigned vsize); #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdgeBuilder") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdgeBuilder") #endif - }; } /* namespace Freestyle */ -#endif // __FREESTYLE_WX_EDGE_BUILDER_H__ +#endif // __FREESTYLE_WX_EDGE_BUILDER_H__ diff --git a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp index 48b815e0d22..977eb2b4d57 100644 --- a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp +++ b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp @@ -32,344 +32,416 @@ using namespace std; namespace Freestyle { -void WingedEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet& ifs) +void WingedEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet &ifs) { - if (_pRenderMonitor && _pRenderMonitor->testBreak()) - return; - WShape *shape = new WShape; - if (!buildWShape(*shape, ifs)) { - delete shape; - return; - } - shape->setId(ifs.getId().getFirst()); - //ifs.setId(shape->GetId()); + if (_pRenderMonitor && _pRenderMonitor->testBreak()) + return; + WShape *shape = new WShape; + if (!buildWShape(*shape, ifs)) { + delete shape; + return; + } + shape->setId(ifs.getId().getFirst()); + //ifs.setId(shape->GetId()); } -void WingedEdgeBuilder::visitNodeShape(NodeShape& ns) +void WingedEdgeBuilder::visitNodeShape(NodeShape &ns) { - //Sets the current material to iShapeode->material: - _current_frs_material = &(ns.frs_material()); + //Sets the current material to iShapeode->material: + _current_frs_material = &(ns.frs_material()); } -void WingedEdgeBuilder::visitNodeTransform(NodeTransform& tn) +void WingedEdgeBuilder::visitNodeTransform(NodeTransform &tn) { - if (!_current_matrix) { - _current_matrix = new Matrix44r(tn.matrix()); - return; - } - - _matrices_stack.push_back(_current_matrix); - Matrix44r *new_matrix = new Matrix44r(*_current_matrix * tn.matrix()); - _current_matrix = new_matrix; + if (!_current_matrix) { + _current_matrix = new Matrix44r(tn.matrix()); + return; + } + + _matrices_stack.push_back(_current_matrix); + Matrix44r *new_matrix = new Matrix44r(*_current_matrix * tn.matrix()); + _current_matrix = new_matrix; } -void WingedEdgeBuilder::visitNodeTransformAfter(NodeTransform&) +void WingedEdgeBuilder::visitNodeTransformAfter(NodeTransform &) { - if (_current_matrix) - delete _current_matrix; + if (_current_matrix) + delete _current_matrix; - if (_matrices_stack.empty()) { - _current_matrix = NULL; - return; - } + if (_matrices_stack.empty()) { + _current_matrix = NULL; + return; + } - _current_matrix = _matrices_stack.back(); - _matrices_stack.pop_back(); + _current_matrix = _matrices_stack.back(); + _matrices_stack.pop_back(); } -bool WingedEdgeBuilder::buildWShape(WShape& shape, IndexedFaceSet& ifs) +bool WingedEdgeBuilder::buildWShape(WShape &shape, IndexedFaceSet &ifs) { - unsigned int vsize = ifs.vsize(); - unsigned int nsize = ifs.nsize(); - //soc unused - unsigned tsize = ifs.tsize(); - - const float *vertices = ifs.vertices(); - const float *normals = ifs.normals(); - const float *texCoords = ifs.texCoords(); - - float *new_vertices; - float *new_normals; - - new_vertices = new float[vsize]; - new_normals = new float[nsize]; - - // transform coordinates from local to world system - if (_current_matrix) { - transformVertices(vertices, vsize, *_current_matrix, new_vertices); - transformNormals(normals, nsize, *_current_matrix, new_normals); - } - else { - memcpy(new_vertices, vertices, vsize * sizeof(*new_vertices)); - memcpy(new_normals, normals, nsize * sizeof(*new_normals)); - } - - const IndexedFaceSet::TRIANGLES_STYLE *faceStyle = ifs.trianglesStyle(); - - vector frs_materials; - if (ifs.msize()) { - const FrsMaterial *const *mats = ifs.frs_materials(); - for (unsigned i = 0; i < ifs.msize(); ++i) - frs_materials.push_back(*(mats[i])); - shape.setFrsMaterials(frs_materials); - } + unsigned int vsize = ifs.vsize(); + unsigned int nsize = ifs.nsize(); + //soc unused - unsigned tsize = ifs.tsize(); + + const float *vertices = ifs.vertices(); + const float *normals = ifs.normals(); + const float *texCoords = ifs.texCoords(); + + float *new_vertices; + float *new_normals; + + new_vertices = new float[vsize]; + new_normals = new float[nsize]; + + // transform coordinates from local to world system + if (_current_matrix) { + transformVertices(vertices, vsize, *_current_matrix, new_vertices); + transformNormals(normals, nsize, *_current_matrix, new_normals); + } + else { + memcpy(new_vertices, vertices, vsize * sizeof(*new_vertices)); + memcpy(new_normals, normals, nsize * sizeof(*new_normals)); + } + + const IndexedFaceSet::TRIANGLES_STYLE *faceStyle = ifs.trianglesStyle(); + + vector frs_materials; + if (ifs.msize()) { + const FrsMaterial *const *mats = ifs.frs_materials(); + for (unsigned i = 0; i < ifs.msize(); ++i) + frs_materials.push_back(*(mats[i])); + shape.setFrsMaterials(frs_materials); + } #if 0 - const FrsMaterial *mat = (ifs.frs_material()); - if (mat) - shape.setFrsMaterial(*mat); - else if (_current_frs_material) - shape.setFrsMaterial(*_current_frs_material); + const FrsMaterial *mat = (ifs.frs_material()); + if (mat) + shape.setFrsMaterial(*mat); + else if (_current_frs_material) + shape.setFrsMaterial(*_current_frs_material); #endif - const IndexedFaceSet::FaceEdgeMark *faceEdgeMarks = ifs.faceEdgeMarks(); - - // sets the current WShape to shape - _current_wshape = &shape; - - // create a WVertex for each vertex - buildWVertices(shape, new_vertices, vsize); - - const unsigned int *vindices = ifs.vindices(); - const unsigned int *nindices = ifs.nindices(); - const unsigned int *tindices = NULL; - if (ifs.tsize()) { - tindices = ifs.tindices(); - } - - const unsigned int *mindices = NULL; - if (ifs.msize()) - mindices = ifs.mindices(); - const unsigned int *numVertexPerFace = ifs.numVertexPerFaces(); - const unsigned int numfaces = ifs.numFaces(); - - for (unsigned int index = 0; index < numfaces; index++) { - switch (faceStyle[index]) { - case IndexedFaceSet::TRIANGLE_STRIP: - buildTriangleStrip(new_vertices, new_normals, frs_materials, texCoords, faceEdgeMarks, vindices, - nindices, mindices, tindices, numVertexPerFace[index]); - break; - case IndexedFaceSet::TRIANGLE_FAN: - buildTriangleFan(new_vertices, new_normals, frs_materials, texCoords, faceEdgeMarks, vindices, - nindices, mindices, tindices, numVertexPerFace[index]); - break; - case IndexedFaceSet::TRIANGLES: - buildTriangles(new_vertices, new_normals, frs_materials, texCoords, faceEdgeMarks, vindices, - nindices, mindices, tindices, numVertexPerFace[index]); - break; - } - vindices += numVertexPerFace[index]; - nindices += numVertexPerFace[index]; - if (mindices) - mindices += numVertexPerFace[index]; - if (tindices) - tindices += numVertexPerFace[index]; - faceEdgeMarks++; - } - - delete[] new_vertices; - delete[] new_normals; - - if (shape.GetFaceList().size() == 0) // this may happen due to degenerate triangles - return false; + const IndexedFaceSet::FaceEdgeMark *faceEdgeMarks = ifs.faceEdgeMarks(); + + // sets the current WShape to shape + _current_wshape = &shape; + + // create a WVertex for each vertex + buildWVertices(shape, new_vertices, vsize); + + const unsigned int *vindices = ifs.vindices(); + const unsigned int *nindices = ifs.nindices(); + const unsigned int *tindices = NULL; + if (ifs.tsize()) { + tindices = ifs.tindices(); + } + + const unsigned int *mindices = NULL; + if (ifs.msize()) + mindices = ifs.mindices(); + const unsigned int *numVertexPerFace = ifs.numVertexPerFaces(); + const unsigned int numfaces = ifs.numFaces(); + + for (unsigned int index = 0; index < numfaces; index++) { + switch (faceStyle[index]) { + case IndexedFaceSet::TRIANGLE_STRIP: + buildTriangleStrip(new_vertices, + new_normals, + frs_materials, + texCoords, + faceEdgeMarks, + vindices, + nindices, + mindices, + tindices, + numVertexPerFace[index]); + break; + case IndexedFaceSet::TRIANGLE_FAN: + buildTriangleFan(new_vertices, + new_normals, + frs_materials, + texCoords, + faceEdgeMarks, + vindices, + nindices, + mindices, + tindices, + numVertexPerFace[index]); + break; + case IndexedFaceSet::TRIANGLES: + buildTriangles(new_vertices, + new_normals, + frs_materials, + texCoords, + faceEdgeMarks, + vindices, + nindices, + mindices, + tindices, + numVertexPerFace[index]); + break; + } + vindices += numVertexPerFace[index]; + nindices += numVertexPerFace[index]; + if (mindices) + mindices += numVertexPerFace[index]; + if (tindices) + tindices += numVertexPerFace[index]; + faceEdgeMarks++; + } + + delete[] new_vertices; + delete[] new_normals; + + if (shape.GetFaceList().size() == 0) // this may happen due to degenerate triangles + return false; #if 0 - // compute bbox - shape.ComputeBBox(); - // compute mean edge size: - shape.ComputeMeanEdgeSize(); + // compute bbox + shape.ComputeBBox(); + // compute mean edge size: + shape.ComputeMeanEdgeSize(); #endif - // Parse the built winged-edge shape to update post-flags - set normalsSet; - vector& wvertices = shape.getVertexList(); - for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; ++wv) { - if ((*wv)->isBoundary()) - continue; - if ((*wv)->GetEdges().size() == 0) // This means that the WVertex has no incoming edges... (12-Sep-2011 T.K.) - continue; - normalsSet.clear(); - WVertex::face_iterator fit = (*wv)->faces_begin(); - WVertex::face_iterator fitend = (*wv)->faces_end(); - for (; fit != fitend; ++fit) { - WFace *face = *fit; - normalsSet.insert(face->GetVertexNormal(*wv)); - if (normalsSet.size() != 1) { - break; - } - } - if (normalsSet.size() != 1) { - (*wv)->setSmooth(false); - } - } - - // Adds the new WShape to the WingedEdge structure - _winged_edge->addWShape(&shape); - - return true; + // Parse the built winged-edge shape to update post-flags + set normalsSet; + vector &wvertices = shape.getVertexList(); + for (vector::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; + ++wv) { + if ((*wv)->isBoundary()) + continue; + if ((*wv)->GetEdges().size() == + 0) // This means that the WVertex has no incoming edges... (12-Sep-2011 T.K.) + continue; + normalsSet.clear(); + WVertex::face_iterator fit = (*wv)->faces_begin(); + WVertex::face_iterator fitend = (*wv)->faces_end(); + for (; fit != fitend; ++fit) { + WFace *face = *fit; + normalsSet.insert(face->GetVertexNormal(*wv)); + if (normalsSet.size() != 1) { + break; + } + } + if (normalsSet.size() != 1) { + (*wv)->setSmooth(false); + } + } + + // Adds the new WShape to the WingedEdge structure + _winged_edge->addWShape(&shape); + + return true; } -void WingedEdgeBuilder::buildWVertices(WShape& shape, const float *vertices, unsigned vsize) +void WingedEdgeBuilder::buildWVertices(WShape &shape, const float *vertices, unsigned vsize) { - WVertex *vertex; - for (unsigned int i = 0; i < vsize; i += 3) { - vertex = new WVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); - vertex->setId(i / 3); - shape.AddVertex(vertex); - } + WVertex *vertex; + for (unsigned int i = 0; i < vsize; i += 3) { + vertex = new WVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); + vertex->setId(i / 3); + shape.AddVertex(vertex); + } } -void WingedEdgeBuilder::buildTriangleStrip(const float * /*vertices*/, const float *normals, vector& /*iMaterials*/, - const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, - const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, - const unsigned *tindices, const unsigned nvertices) +void WingedEdgeBuilder::buildTriangleStrip(const float * /*vertices*/, + const float *normals, + vector & /*iMaterials*/, + const float *texCoords, + const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + const unsigned *vindices, + const unsigned *nindices, + const unsigned *mindices, + const unsigned *tindices, + const unsigned nvertices) { - unsigned nDoneVertices = 2; // number of vertices already treated - unsigned nTriangle = 0; // number of the triangle currently being treated - //int nVertex = 0; // vertex number - - WShape *currentShape = _current_wshape; // the current shape being built - vector triangleVertices; - vector triangleNormals; - vector triangleTexCoords; - vector triangleFaceEdgeMarks; - - while (nDoneVertices < nvertices) { - //clear the vertices list: - triangleVertices.clear(); - //Then rebuild it: - if (0 == nTriangle % 2) { // if nTriangle is even - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); - - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], - normals[nindices[nTriangle] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], - normals[nindices[nTriangle + 1] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], - normals[nindices[nTriangle + 2] + 2])); - - if (texCoords) { - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 1]], - texCoords[tindices[nTriangle + 1] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 2]], - texCoords[tindices[nTriangle + 2] + 1])); - } - } - else { // if nTriangle is odd - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); - - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], - normals[nindices[nTriangle] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], - normals[nindices[nTriangle + 2] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], - normals[nindices[nTriangle + 1] + 2])); - - if (texCoords) { - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 2]], - texCoords[tindices[nTriangle + 2] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 1]], - texCoords[tindices[nTriangle + 1] + 1])); - } - } - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::FACE_MARK) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V1V2) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V2V3) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V3V1) != 0); - if (mindices) { - currentShape->MakeFace(triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, - mindices[nTriangle / 3]); - } - else { - currentShape->MakeFace(triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0); - } - nDoneVertices++; // with a strip, each triangle is one vertex more - nTriangle++; - } + unsigned nDoneVertices = 2; // number of vertices already treated + unsigned nTriangle = 0; // number of the triangle currently being treated + //int nVertex = 0; // vertex number + + WShape *currentShape = _current_wshape; // the current shape being built + vector triangleVertices; + vector triangleNormals; + vector triangleTexCoords; + vector triangleFaceEdgeMarks; + + while (nDoneVertices < nvertices) { + //clear the vertices list: + triangleVertices.clear(); + //Then rebuild it: + if (0 == nTriangle % 2) { // if nTriangle is even + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); + + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], + normals[nindices[nTriangle] + 1], + normals[nindices[nTriangle] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], + normals[nindices[nTriangle + 1] + 1], + normals[nindices[nTriangle + 1] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], + normals[nindices[nTriangle + 2] + 1], + normals[nindices[nTriangle + 2] + 2])); + + if (texCoords) { + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle + 1]], texCoords[tindices[nTriangle + 1] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle + 2]], texCoords[tindices[nTriangle + 2] + 1])); + } + } + else { // if nTriangle is odd + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); + + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], + normals[nindices[nTriangle] + 1], + normals[nindices[nTriangle] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], + normals[nindices[nTriangle + 2] + 1], + normals[nindices[nTriangle + 2] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], + normals[nindices[nTriangle + 1] + 1], + normals[nindices[nTriangle + 1] + 2])); + + if (texCoords) { + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle + 2]], texCoords[tindices[nTriangle + 2] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[nTriangle + 1]], texCoords[tindices[nTriangle + 1] + 1])); + } + } + triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::FACE_MARK) != + 0); + triangleFaceEdgeMarks.push_back( + (iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V1V2) != 0); + triangleFaceEdgeMarks.push_back( + (iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V2V3) != 0); + triangleFaceEdgeMarks.push_back( + (iFaceEdgeMarks[nTriangle / 3] & IndexedFaceSet::EDGE_MARK_V3V1) != 0); + if (mindices) { + currentShape->MakeFace(triangleVertices, + triangleNormals, + triangleTexCoords, + triangleFaceEdgeMarks, + mindices[nTriangle / 3]); + } + else { + currentShape->MakeFace( + triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0); + } + nDoneVertices++; // with a strip, each triangle is one vertex more + nTriangle++; + } } -void WingedEdgeBuilder::buildTriangleFan(const float * /*vertices*/, const float * /*normals*/, vector& /*iMaterials*/, - const float * /*texCoords*/, const IndexedFaceSet::FaceEdgeMark * /*iFaceEdgeMarks*/, - const unsigned * /*vindices*/, const unsigned * /*nindices*/, const unsigned * /*mindices*/, - const unsigned * /*tindices*/, const unsigned /*nvertices*/) +void WingedEdgeBuilder::buildTriangleFan(const float * /*vertices*/, + const float * /*normals*/, + vector & /*iMaterials*/, + const float * /*texCoords*/, + const IndexedFaceSet::FaceEdgeMark * /*iFaceEdgeMarks*/, + const unsigned * /*vindices*/, + const unsigned * /*nindices*/, + const unsigned * /*mindices*/, + const unsigned * /*tindices*/, + const unsigned /*nvertices*/) { - // Nothing to be done + // Nothing to be done } -void WingedEdgeBuilder::buildTriangles(const float * /*vertices*/, const float *normals, vector& /*iMaterials*/, - const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, - const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, - const unsigned *tindices, const unsigned nvertices) +void WingedEdgeBuilder::buildTriangles(const float * /*vertices*/, + const float *normals, + vector & /*iMaterials*/, + const float *texCoords, + const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + const unsigned *vindices, + const unsigned *nindices, + const unsigned *mindices, + const unsigned *tindices, + const unsigned nvertices) { - WShape *currentShape = _current_wshape; // the current shape begin built - vector triangleVertices; - vector triangleNormals; - vector triangleTexCoords; - vector triangleFaceEdgeMarks; - - // Each triplet of vertices is considered as an independent triangle - for (unsigned int i = 0; i < nvertices / 3; i++) { - triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 1] / 3]); - triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 2] / 3]); - - triangleNormals.push_back(Vec3f(normals[nindices[3 * i]], normals[nindices[3 * i] + 1], - normals[nindices[3 * i] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[3 * i + 1]], normals[nindices[3 * i + 1] + 1], - normals[nindices[3 * i + 1] + 2])); - triangleNormals.push_back(Vec3f(normals[nindices[3 * i + 2]], normals[nindices[3 * i + 2] + 1], - normals[nindices[3 * i + 2] + 2])); - - if (texCoords) { - triangleTexCoords.push_back(Vec2f(texCoords[tindices[3 * i]], texCoords[tindices[3 * i] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[3 * i + 1]], texCoords[tindices[3 * i + 1] + 1])); - triangleTexCoords.push_back(Vec2f(texCoords[tindices[3 * i + 2]], texCoords[tindices[3 * i + 2] + 1])); - } - - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::FACE_MARK) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V1V2) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V2V3) != 0); - triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V3V1) != 0); - } - if (mindices) - currentShape->MakeFace(triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, - mindices[0]); - else - currentShape->MakeFace(triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0); + WShape *currentShape = _current_wshape; // the current shape begin built + vector triangleVertices; + vector triangleNormals; + vector triangleTexCoords; + vector triangleFaceEdgeMarks; + + // Each triplet of vertices is considered as an independent triangle + for (unsigned int i = 0; i < nvertices / 3; i++) { + triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 1] / 3]); + triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 2] / 3]); + + triangleNormals.push_back(Vec3f( + normals[nindices[3 * i]], normals[nindices[3 * i] + 1], normals[nindices[3 * i] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[3 * i + 1]], + normals[nindices[3 * i + 1] + 1], + normals[nindices[3 * i + 1] + 2])); + triangleNormals.push_back(Vec3f(normals[nindices[3 * i + 2]], + normals[nindices[3 * i + 2] + 1], + normals[nindices[3 * i + 2] + 2])); + + if (texCoords) { + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[3 * i]], texCoords[tindices[3 * i] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[3 * i + 1]], texCoords[tindices[3 * i + 1] + 1])); + triangleTexCoords.push_back( + Vec2f(texCoords[tindices[3 * i + 2]], texCoords[tindices[3 * i + 2] + 1])); + } + + triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::FACE_MARK) != 0); + triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V1V2) != 0); + triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V2V3) != 0); + triangleFaceEdgeMarks.push_back((iFaceEdgeMarks[i] & IndexedFaceSet::EDGE_MARK_V3V1) != 0); + } + if (mindices) + currentShape->MakeFace( + triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, mindices[0]); + else + currentShape->MakeFace( + triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0); } -void WingedEdgeBuilder::transformVertices(const float *vertices, unsigned vsize, const Matrix44r& transform, float *res) +void WingedEdgeBuilder::transformVertices(const float *vertices, + unsigned vsize, + const Matrix44r &transform, + float *res) { - const float *v = vertices; - float *pv = res; - - for (unsigned int i = 0; i < vsize / 3; i++) { - HVec3r hv_tmp(v[0], v[1], v[2]); - HVec3r hv(transform * hv_tmp); - for (unsigned int j = 0; j < 3; j++) - pv[j] = hv[j] / hv[3]; - v += 3; - pv += 3; - } + const float *v = vertices; + float *pv = res; + + for (unsigned int i = 0; i < vsize / 3; i++) { + HVec3r hv_tmp(v[0], v[1], v[2]); + HVec3r hv(transform * hv_tmp); + for (unsigned int j = 0; j < 3; j++) + pv[j] = hv[j] / hv[3]; + v += 3; + pv += 3; + } } -void WingedEdgeBuilder::transformNormals(const float *normals, unsigned nsize, const Matrix44r& transform, float *res) +void WingedEdgeBuilder::transformNormals(const float *normals, + unsigned nsize, + const Matrix44r &transform, + float *res) { - const float *n = normals; - float *pn = res; - - for (unsigned int i = 0; i < nsize / 3; i++) { - Vec3r hn(n[0], n[1], n[2]); - hn = GeomUtils::rotateVector(transform, hn); - for (unsigned int j = 0; j < 3; j++) - pn[j] = hn[j]; - n += 3; - pn += 3; - } + const float *n = normals; + float *pn = res; + + for (unsigned int i = 0; i < nsize / 3; i++) { + Vec3r hn(n[0], n[1], n[2]); + hn = GeomUtils::rotateVector(transform, hn); + for (unsigned int j = 0; j < 3; j++) + pn[j] = hn[j]; + n += 3; + pn += 3; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h index 30fe7277fdb..606e8561401 100644 --- a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h +++ b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h @@ -34,119 +34,144 @@ namespace Freestyle { -class WingedEdgeBuilder : public SceneVisitor -{ -public: - inline WingedEdgeBuilder() : SceneVisitor() - { - _current_wshape = NULL; - _current_frs_material = NULL; - _current_matrix = NULL; - _winged_edge = new WingedEdge; // Not deleted by the destructor - _pRenderMonitor = NULL; - } - - virtual ~WingedEdgeBuilder() - { - for (vector::iterator it = _matrices_stack.begin(); it != _matrices_stack.end(); ++it) - delete *it; - _matrices_stack.clear(); - } - - VISIT_DECL(IndexedFaceSet) - VISIT_DECL(NodeShape) - VISIT_DECL(NodeTransform) - - virtual void visitNodeTransformAfter(NodeTransform&); - - // - // Accessors - // - ///////////////////////////////////////////////////////////////////////////// - - inline WingedEdge *getWingedEdge() - { - return _winged_edge; - } - - inline WShape *getCurrentWShape() - { - return _current_wshape; - } - - inline FrsMaterial *getCurrentFrsMaterial() - { - return _current_frs_material; - } - - inline Matrix44r *getCurrentMatrix() - { - return _current_matrix; - } - - // - // Modifiers - // - ///////////////////////////////////////////////////////////////////////////// - - inline void setCurrentWShape(WShape *wshape) - { - _current_wshape = wshape; - } - - inline void setCurrentFrsMaterial(FrsMaterial *mat) - { - _current_frs_material = mat; - } +class WingedEdgeBuilder : public SceneVisitor { + public: + inline WingedEdgeBuilder() : SceneVisitor() + { + _current_wshape = NULL; + _current_frs_material = NULL; + _current_matrix = NULL; + _winged_edge = new WingedEdge; // Not deleted by the destructor + _pRenderMonitor = NULL; + } + + virtual ~WingedEdgeBuilder() + { + for (vector::iterator it = _matrices_stack.begin(); it != _matrices_stack.end(); + ++it) + delete *it; + _matrices_stack.clear(); + } + + VISIT_DECL(IndexedFaceSet) + VISIT_DECL(NodeShape) + VISIT_DECL(NodeTransform) + + virtual void visitNodeTransformAfter(NodeTransform &); + + // + // Accessors + // + ///////////////////////////////////////////////////////////////////////////// + + inline WingedEdge *getWingedEdge() + { + return _winged_edge; + } + + inline WShape *getCurrentWShape() + { + return _current_wshape; + } + + inline FrsMaterial *getCurrentFrsMaterial() + { + return _current_frs_material; + } + + inline Matrix44r *getCurrentMatrix() + { + return _current_matrix; + } + + // + // Modifiers + // + ///////////////////////////////////////////////////////////////////////////// + + inline void setCurrentWShape(WShape *wshape) + { + _current_wshape = wshape; + } + + inline void setCurrentFrsMaterial(FrsMaterial *mat) + { + _current_frs_material = mat; + } #if 0 - inline void setCurrentMatrix(Matrix44r *matrix) - { - _current_matrix = matrix; - } + inline void setCurrentMatrix(Matrix44r *matrix) + { + _current_matrix = matrix; + } #endif - inline void setRenderMonitor(RenderMonitor *iRenderMonitor) { - _pRenderMonitor = iRenderMonitor; - } - -protected: - virtual bool buildWShape(WShape& shape, IndexedFaceSet& ifs); - virtual void buildWVertices(WShape& shape, const float *vertices, unsigned vsize); - - RenderMonitor *_pRenderMonitor; - -private: - void buildTriangleStrip(const float *vertices, const float *normals, vector& iMaterials, - const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, - const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, - const unsigned *tindices, const unsigned nvertices); - - void buildTriangleFan(const float *vertices, const float *normals, vector& iMaterials, - const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, - const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, - const unsigned *tindices, const unsigned nvertices); - - void buildTriangles(const float *vertices, const float *normals, vector& iMaterials, - const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, - const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, - const unsigned *tindices, const unsigned nvertices); - - void transformVertices(const float *vertices, unsigned vsize, const Matrix44r& transform, float *res); - - void transformNormals(const float *normals, unsigned nsize, const Matrix44r& transform, float *res); - - WShape *_current_wshape; - FrsMaterial *_current_frs_material; - WingedEdge *_winged_edge; - Matrix44r *_current_matrix; - vector _matrices_stack; + inline void setRenderMonitor(RenderMonitor *iRenderMonitor) + { + _pRenderMonitor = iRenderMonitor; + } + + protected: + virtual bool buildWShape(WShape &shape, IndexedFaceSet &ifs); + virtual void buildWVertices(WShape &shape, const float *vertices, unsigned vsize); + + RenderMonitor *_pRenderMonitor; + + private: + void buildTriangleStrip(const float *vertices, + const float *normals, + vector &iMaterials, + const float *texCoords, + const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + const unsigned *vindices, + const unsigned *nindices, + const unsigned *mindices, + const unsigned *tindices, + const unsigned nvertices); + + void buildTriangleFan(const float *vertices, + const float *normals, + vector &iMaterials, + const float *texCoords, + const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + const unsigned *vindices, + const unsigned *nindices, + const unsigned *mindices, + const unsigned *tindices, + const unsigned nvertices); + + void buildTriangles(const float *vertices, + const float *normals, + vector &iMaterials, + const float *texCoords, + const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + const unsigned *vindices, + const unsigned *nindices, + const unsigned *mindices, + const unsigned *tindices, + const unsigned nvertices); + + void transformVertices(const float *vertices, + unsigned vsize, + const Matrix44r &transform, + float *res); + + void transformNormals(const float *normals, + unsigned nsize, + const Matrix44r &transform, + float *res); + + WShape *_current_wshape; + FrsMaterial *_current_frs_material; + WingedEdge *_winged_edge; + Matrix44r *_current_matrix; + vector _matrices_stack; #ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdgeBuilder") + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdgeBuilder") #endif }; } /* namespace Freestyle */ -#endif // __FREESTYLE_WINGED_EDGE_BUILDER_H__ +#endif // __FREESTYLE_WINGED_EDGE_BUILDER_H__ -- cgit v1.2.3