diff options
Diffstat (limited to 'source/blender/freestyle/intern')
119 files changed, 1779 insertions, 2810 deletions
diff --git a/source/blender/freestyle/intern/application/AppConfig.cpp b/source/blender/freestyle/intern/application/AppConfig.cpp index cf7959ffaef..44f8e9b135e 100644 --- a/source/blender/freestyle/intern/application/AppConfig.cpp +++ b/source/blender/freestyle/intern/application/AppConfig.cpp @@ -31,7 +31,7 @@ using namespace std; extern "C" { -#include "BLI_path_util.h" +#include "BKE_appdir.h" } namespace Freestyle { @@ -43,7 +43,7 @@ Path::Path() { // get the root directory // soc - setRootDir(BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL)); + setRootDir(BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, NULL)); _pInstance = this; } diff --git a/source/blender/freestyle/intern/application/AppView.cpp b/source/blender/freestyle/intern/application/AppView.cpp index ae202412c09..9de426b91ab 100644 --- a/source/blender/freestyle/intern/application/AppView.cpp +++ b/source/blender/freestyle/intern/application/AppView.cpp @@ -58,7 +58,7 @@ extern "C" { namespace Freestyle { -AppView::AppView(const char *iName) +AppView::AppView(const char * /*iName*/) { _Fovy = DEG2RADF(30.0f); _ModelRootNode = new NodeDrawingStyle; diff --git a/source/blender/freestyle/intern/application/AppView.h b/source/blender/freestyle/intern/application/AppView.h index 14101909ca1..6338ace53c0 100644 --- a/source/blender/freestyle/intern/application/AppView.h +++ b/source/blender/freestyle/intern/application/AppView.h @@ -100,12 +100,12 @@ public: _SilhouetteRootNode->AddChild(iSilhouette); } - inline void Add2DSilhouette(NodeGroup *iSilhouette) + inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/) { //_pFENode->AddChild(iSilhouette); } - inline void Add2DVisibleSilhouette(NodeGroup *iVSilhouette) + inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/) { //_pVisibleSilhouetteNode->AddChild(iVSilhouette); } diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index 176199600ac..8983a781237 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -40,6 +40,7 @@ extern "C" { #include "../scene_graph/NodeDrawingStyle.h" #include "../scene_graph/NodeShape.h" #include "../scene_graph/NodeTransform.h" +#include "../scene_graph/NodeSceneRenderLayer.h" #include "../scene_graph/ScenePrettyPrinter.h" #include "../scene_graph/VertexRep.h" @@ -67,6 +68,7 @@ extern "C" { #include "BKE_global.h" #include "BLI_utildefines.h" +#include "BLI_path_util.h" #include "DNA_freestyle_types.h" @@ -86,14 +88,14 @@ Controller::Controller() _RootNode = new NodeGroup; _RootNode->addRef(); - _SilhouetteNode = NULL; #if 0 + _SilhouetteNode = NULL; _ProjectedSilhouette = NULL; _VisibleProjectedSilhouette = NULL; -#endif _DebugNode = new NodeGroup; _DebugNode->addRef(); +#endif _winged_edge = NULL; @@ -118,6 +120,7 @@ Controller::Controller() _Canvas = new AppCanvas; _inter = new PythonInterpreter(); + _EnableViewMapCache = false; _EnableQI = true; _EnableFaceSmoothness = false; _ComputeRidges = true; @@ -126,6 +129,7 @@ Controller::Controller() _ComputeMaterialBoundaries = true; _sphereRadius = 1.0; _creaseAngle = 134.43; + prevSceneHash = -1.0; init_options(); } @@ -138,6 +142,7 @@ Controller::~Controller() delete _RootNode; } +#if 0 if (NULL != _SilhouetteNode) { int ref = _SilhouetteNode->destroy(); if (0 == ref) @@ -149,6 +154,7 @@ Controller::~Controller() if (0 == ref) delete _DebugNode; } +#endif if (_winged_edge) { delete _winged_edge; @@ -212,6 +218,18 @@ void Controller::setContext(bContext *C) py_inter->setContext(C); } +bool Controller::hitViewMapCache() +{ + if (!_EnableViewMapCache) { + return false; + } + if (sceneHashFunc.match()) { + return (NULL != _ViewMap); + } + sceneHashFunc.store(); + return false; +} + int Controller::LoadMesh(Render *re, SceneRenderLayer *srl) { BlenderFileLoader loader(re, srl); @@ -242,6 +260,7 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl) 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(); @@ -263,6 +282,39 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl) if (_pRenderMonitor->testBreak()) return 0; + if (_EnableViewMapCache) { + + NodeCamera *cam; + if (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] = freestyle_proj[i][j]; + } + } + cam->setProjectionMatrix(proj); + _RootNode->AddChild(cam); + _RootNode->AddChild(new NodeSceneRenderLayer(*re->scene, *srl)); + + 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; @@ -357,8 +409,9 @@ void Controller::DeleteWingedEdge() _minEdgeSize = DBL_MAX; } -void Controller::DeleteViewMap() +void Controller::DeleteViewMap(bool freeCache) { +#if 0 _pView->DetachSilhouette(); if (NULL != _SilhouetteNode) { int ref = _SilhouetteNode->destroy(); @@ -368,7 +421,6 @@ void Controller::DeleteViewMap() } } -#if 0 if (NULL != _ProjectedSilhouette) { int ref = _ProjectedSilhouette->destroy(); if (0 == ref) { @@ -383,18 +435,24 @@ void Controller::DeleteViewMap() _VisibleProjectedSilhouette = NULL; } } -#endif _pView->DetachDebug(); if (NULL != _DebugNode) { - int ref = _DebugNode->destroy(); + int ref = _DebugNode->destroy(); if (0 == ref) _DebugNode->addRef(); } +#endif if (NULL != _ViewMap) { - delete _ViewMap; - _ViewMap = NULL; + if (freeCache || !_EnableViewMapCache) { + delete _ViewMap; + _ViewMap = NULL; + prevSceneHash = -1.0; + } + else { + _ViewMap->Clean(); + } } } @@ -403,40 +461,7 @@ void Controller::ComputeViewMap() if (!_ListOfModels.size()) return; - if (NULL != _ViewMap) { - delete _ViewMap; - _ViewMap = 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; - } - -#if 0 - if (NULL != _ProjectedSilhouette) { - int ref = _ProjectedSilhouette->destroy(); - if (0 == ref) - delete _ProjectedSilhouette; - } - - if (NULL != _VisibleProjectedSilhouette) { - int ref = _VisibleProjectedSilhouette->destroy(); - if (0 == ref) { - delete _VisibleProjectedSilhouette; - _VisibleProjectedSilhouette = NULL; - } - } -#endif + DeleteViewMap(true); // retrieve the 3D viewpoint and transformations information //---------------------------------------------------------- @@ -446,7 +471,7 @@ void Controller::ComputeViewMap() // Restore the context of view: // we need to perform all these operations while the // 3D context is on. - Vec3r vp(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); + Vec3f vp(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]); #if 0 if (G.debug & G_DEBUG_FREESTYLE) { @@ -510,7 +535,7 @@ void Controller::ComputeViewMap() } _Chrono.start(); - edgeDetector.setViewpoint(Vec3r(vp)); + edgeDetector.setViewpoint(vp); edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0); edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges); edgeDetector.enableSuggestiveContours(_ComputeSuggestive); @@ -534,20 +559,20 @@ void Controller::ComputeViewMap() //---------------------------------------------------------- ViewMapBuilder vmBuilder; vmBuilder.setEnableQI(_EnableQI); - vmBuilder.setViewpoint(Vec3r(vp)); + 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; -#if 0 ViewMapTesselator2D sTesselator2d; sTesselator2d.setNature(_edgeTesselationNature); -#endif sTesselator3d.setNature(_edgeTesselationNature); +#endif if (G.debug & G_DEBUG_FREESTYLE) { cout << "\n=== Building the view map ===" << endl; @@ -561,12 +586,12 @@ void Controller::ComputeViewMap() printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size()); } +#if 0 // Tesselate the 3D edges: _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap); _SilhouetteNode->addRef(); // Tesselate 2D edges -#if 0 _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap); _ProjectedSilhouette->addRef(); #endif @@ -576,13 +601,13 @@ void Controller::ComputeViewMap() printf("ViewMap building : %lf\n", duration); } - _pView->AddSilhouette(_SilhouetteNode); #if 0 + _pView->AddSilhouette(_SilhouetteNode); _pView->AddSilhouette(_WRoot); _pView->Add2DSilhouette(_ProjectedSilhouette); _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette); -#endif _pView->AddDebug(_DebugNode); +#endif // Draw the steerable density map: //-------------------------------- @@ -763,6 +788,16 @@ int Controller::getVisibilityAlgo() return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL; } +void Controller::setViewMapCache(bool iBool) +{ + _EnableViewMapCache = iBool; +} + +bool Controller::getViewMapCache() const +{ + return _EnableViewMapCache; +} + void Controller::setQuantitativeInvisibility(bool iBool) { _EnableQI = iBool; @@ -836,7 +871,7 @@ void Controller::DrawStrokes() real d = _Chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { cout << "Strokes generation : " << d << endl; - cout << "Stroke count : " << _Canvas->stroke_count << endl; + cout << "Stroke count : " << _Canvas->getStrokeCount() << endl; } resetModified(); DeleteViewMap(); @@ -849,10 +884,13 @@ void Controller::ResetRenderCount() Render *Controller::RenderStrokes(Render *re, bool render) { + int totmesh = 0; _Chrono.start(); BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count); - if (render) + if (render) { _Canvas->Render(blenderRenderer); + totmesh = blenderRenderer->GenerateScene(); + } real d = _Chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { cout << "Temporary scene generation: " << d << endl; @@ -871,8 +909,8 @@ Render *Controller::RenderStrokes(Render *re, bool render) float mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); - printf("%d verts, %d faces, mem %.2fM (%.2fM, peak %.2fM)\n", - freestyle_render->i.totvert, freestyle_render->i.totface, + 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; @@ -891,13 +929,19 @@ void Controller::InsertStyleModule(unsigned index, const char *iFileName) _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); +} + void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText) { StyleModule *sm = new BlenderStyleModule(iText, iName, _inter); _Canvas->InsertStyleModule(index, sm); } -void Controller::AddStyleModule(const char *iFileName) +void Controller::AddStyleModule(const char * /*iFileName*/) { //_pStyleWindow->Add(iFileName); } @@ -967,7 +1011,7 @@ void Controller::toggleEdgeTesselationNature(Nature::EdgeNature iNature) ComputeViewMap(); } -void Controller::setModelsDir(const string& dir) +void Controller::setModelsDir(const string& /*dir*/) { //_current_dirs->setValue("models/dir", dir); } @@ -979,7 +1023,7 @@ string Controller::getModelsDir() const return dir; } -void Controller::setModulesDir(const string& dir) +void Controller::setModulesDir(const string& /*dir*/) { //_current_dirs->setValue("modules/dir", dir); } diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index f5e50347d0f..22eaaf5082f 100644 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -30,37 +30,28 @@ #include <string> -//#include "ConfigIO.h" #include "../geometry/FastGrid.h" -#include "../system/Interpreter.h" -#include "../system/ProgressBar.h" +#include "../scene_graph/SceneHash.h" #include "../system/Precision.h" -#include "../system/RenderMonitor.h" #include "../system/TimeUtils.h" #include "../view_map/FEdgeXDetector.h" #include "../view_map/ViewMapBuilder.h" -extern "C" { -#include "render_types.h" -#include "DNA_scene_types.h" -} - #ifdef WITH_CXX_GUARDEDALLOC #include "MEM_guardedalloc.h" #endif namespace Freestyle { +class AppCanvas; class AppView; +class Interpreter; class NodeGroup; -class WShape; +class ProgressBar; +class RenderMonitor; class SShape; -class ViewMap; class ViewEdge; -class AppCanvas; -class InteractiveShader; -class Shader; -class StrokeRenderer; +class ViewMap; class Controller { @@ -89,6 +80,7 @@ public: 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); @@ -96,7 +88,7 @@ public: void Clear(); void ClearRootNode(); void DeleteWingedEdge(); - void DeleteViewMap(); + void DeleteViewMap(bool freeCache = false); void toggleLayer(unsigned index, bool iDisplay); void setModified(unsigned index, bool iMod); void resetModified(bool iMod=false); @@ -118,6 +110,8 @@ public: 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); @@ -132,18 +126,20 @@ public: void setComputeSteerableViewMapFlag(bool iBool); bool getComputeSteerableViewMapFlag() const; - void setCreaseAngle(real angle) {_creaseAngle = angle;} - real getCreaseAngle() const {return _creaseAngle;} - void setSphereRadius(real s) {_sphereRadius = s;} - real getSphereRadius() const {return _sphereRadius;} - void setSuggestiveContourKrDerivativeEpsilon(real dkr) {_suggestiveContourKrDerivativeEpsilon = dkr;} - real getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;} + 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: @@ -182,11 +178,10 @@ private: // Winged-Edge structure WingedEdge *_winged_edge; - // Silhouette structure: #if 0 + // Silhouette structure: std::vector<SShape*> _SShapes; NodeGroup *_SRoot; -#endif // Silhouette NodeGroup *_SilhouetteNode; @@ -195,6 +190,7 @@ private: // more Debug info NodeGroup *_DebugNode; +#endif // debug //NodeUser<ViewMap> *_ViewMapNode; // FIXME @@ -231,19 +227,23 @@ private: string _help_index; string _browser_cmd; + bool _EnableViewMapCache; bool _EnableQI; bool _EnableFaceSmoothness; bool _ComputeRidges; bool _ComputeSuggestive; bool _ComputeMaterialBoundaries; - real _creaseAngle; - real _sphereRadius; - real _suggestiveContourKrDerivativeEpsilon; + float _creaseAngle; + float _sphereRadius; + float _suggestiveContourKrDerivativeEpsilon; bool _ComputeSteerableViewMap; FEdgeXDetector edgeDetector; + SceneHash sceneHashFunc; + real prevSceneHash; + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller") #endif diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index 57882cbce0c..2b0d3b14697 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -64,12 +64,11 @@ NodeGroup *BlenderFileLoader::Load() _viewplane_bottom = _re->viewplane.ymin; _viewplane_top = _re->viewplane.ymax; - if ((_re->r.scemode & R_VIEWPORT_PREVIEW) && (_re->r.mode & R_ORTHO)) { + if (_re->clipsta < 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->clipsta is negative, // while Freestyle assumes that imported mesh data are in the camera coordinate // system with the view point located at origin [bug #36009]. - BLI_assert(_re->clipsta < 0.f); _z_near = -0.001f; _z_offset = _re->clipsta + _z_near; _z_far = -_re->clipend + _z_offset; @@ -256,6 +255,7 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1 } } 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], @@ -457,6 +457,7 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) unsigned nSize = vSize; float *normals = new float[nSize]; unsigned *numVertexPerFaces = new unsigned[numFaces]; + vector<Material *> meshMaterials; vector<FrsMaterial> meshFrsMaterials; IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces]; @@ -535,8 +536,12 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) else { RE_vlakren_get_normal(_re, obi, vlr, facenormal); #ifndef NDEBUG + /* test if normals are inverted in rendering [T39669] */ float tnor[3]; - normal_tri_v3(tnor, v3, v2, v1); /* normals are inverted in rendering */ + if (vlr->v4) + normal_quad_v3(tnor, v4, v3, v2, v1); + else + normal_tri_v3(tnor, v3, v2, v1); BLI_assert(dot_v3v3(tnor, facenormal) > 0.0f); #endif copy_v3_v3(n1, facenormal); @@ -588,20 +593,21 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) tmpMat.setPriority(mat->line_priority); } - if (meshFrsMaterials.empty()) { + if (meshMaterials.empty()) { + meshMaterials.push_back(mat); meshFrsMaterials.push_back(tmpMat); shape->setFrsMaterial(tmpMat); } else { - // find if the material is already in the list + // find if the Blender material is already in the list unsigned int i = 0; bool found = false; - for (vector<FrsMaterial>::iterator it = meshFrsMaterials.begin(), itend = meshFrsMaterials.end(); + for (vector<Material *>::iterator it = meshMaterials.begin(), itend = meshMaterials.end(); it != itend; it++, i++) { - if (*it == tmpMat) { + if (*it == mat) { ls.currentMIndex = i; found = true; break; @@ -609,6 +615,7 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) } if (!found) { + meshMaterials.push_back(mat); meshFrsMaterials.push_back(tmpMat); ls.currentMIndex = meshFrsMaterials.size() - 1; } @@ -656,13 +663,13 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) // We might have several times the same vertex. We want a clean // shape with no real-vertex. Here, we are making a cleaning pass. - real *cleanVertices = NULL; + float *cleanVertices = NULL; unsigned int cvSize; unsigned int *cleanVIndices = NULL; GeomCleaner::CleanIndexedVertexArray(vertices, vSize, VIndices, viSize, &cleanVertices, &cvSize, &cleanVIndices); - real *cleanNormals = NULL; + float *cleanNormals = NULL; unsigned int cnSize; unsigned int *cleanNIndices = NULL; @@ -769,12 +776,12 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) 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] = 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.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(); } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index 456118d4d2f..64ef49d74a3 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -66,6 +66,8 @@ extern "C" { namespace Freestyle { +const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_tips"}; + BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : StrokeRenderer() { freestyle_bmain = re->freestyle_bmain; @@ -92,7 +94,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str //freestyle_scene->r.maximsize = old_scene->r.maximsize; /* DEPRECATED */ freestyle_scene->r.ocres = old_scene->r.ocres; 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); + freestyle_scene->r.scemode = old_scene->r.scemode & ~(R_SINGLE_LAYER | R_NO_FRAME_UPDATE | R_MULTIVIEW); 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; @@ -124,7 +126,8 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str BKE_scene_set_background(freestyle_bmain, freestyle_scene); // Camera - Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, OB_CAMERA); + Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, OB_CAMERA, NULL); + DAG_relations_tag_update(freestyle_bmain); Camera *camera = (Camera *)object_camera->data; camera->type = CAM_ORTHO; @@ -208,6 +211,8 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer() if (_use_shading_nodes) BLI_ghash_free(_nodetree_hash, NULL, NULL); + + FreeStrokeGroups(); } float BlenderStrokeRenderer::get_stroke_vertex_z(void) const @@ -414,10 +419,10 @@ Material* BlenderStrokeRenderer::GetStrokeShader(Main *bmain, bNodeTree *iNodeTr input_uvmap->locy = node->locy; NodeShaderUVMap *storage = (NodeShaderUVMap *)input_uvmap->storage; if (node->custom1 & 1) { // use_tips - BLI_strncpy(storage->uv_map, "along_stroke_tips", sizeof(storage->uv_map)); + BLI_strncpy(storage->uv_map, uvNames[1], sizeof(storage->uv_map)); } else { - BLI_strncpy(storage->uv_map, "along_stroke", sizeof(storage->uv_map)); + BLI_strncpy(storage->uv_map, uvNames[0], sizeof(storage->uv_map)); } fromsock = (bNodeSocket *)BLI_findlink(&input_uvmap->outputs, 0); // UV @@ -440,6 +445,11 @@ Material* BlenderStrokeRenderer::GetStrokeShader(Main *bmain, bNodeTree *iNodeTr void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { + RenderStrokeRepBasic(iStrokeRep); +} + +void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const +{ if (_use_shading_nodes) { bNodeTree *nt = iStrokeRep->getNodeTree(); Material *ma = (Material *)BLI_ghash_lookup(_nodetree_hash, nt); @@ -448,7 +458,7 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const BLI_ghash_insert(_nodetree_hash, nt, ma); } - if (strcmp(freestyle_scene->r.engine, "CYCLES") == 0) { + if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) { PointerRNA scene_ptr, freestyle_scene_ptr; RNA_pointer_create(NULL, &RNA_Scene, old_scene, &scene_ptr); RNA_pointer_create(NULL, &RNA_Scene, freestyle_scene, &freestyle_scene_ptr); @@ -497,6 +507,7 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const // If still no material, create one if (!has_mat) { Material *ma = BKE_material_add(freestyle_bmain, "stroke_material"); + DAG_relations_tag_update(freestyle_bmain); ma->mode |= MA_VERTEXCOLP; ma->mode |= MA_TRANSP; ma->mode |= MA_SHLESS; @@ -509,10 +520,10 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const // We'll generate both with tips and without tips // coordinates, on two different UV layers. if (ma->mtex[a]->texflag & MTEX_TIPS) { - BLI_strncpy(ma->mtex[a]->uvname, "along_stroke_tips", sizeof(ma->mtex[a]->uvname)); + BLI_strncpy(ma->mtex[a]->uvname, uvNames[1], sizeof(ma->mtex[a]->uvname)); } else { - BLI_strncpy(ma->mtex[a]->uvname, "along_stroke", sizeof(ma->mtex[a]->uvname)); + BLI_strncpy(ma->mtex[a]->uvname, uvNames[0], sizeof(ma->mtex[a]->uvname)); } a++; } @@ -521,7 +532,42 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const } } - RenderStrokeRepBasic(iStrokeRep); + const vector<Strip*>& strips = iStrokeRep->getStrips(); + const bool hasTex = iStrokeRep->hasTex(); + int totvert = 0, totedge = 0, totpoly = 0, totloop = 0; + int visible_faces, visible_segments; + for (vector<Strip*>::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<BlenderStrokeRenderer *>(this); // FIXME + vector<StrokeGroup*> *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) @@ -578,127 +624,174 @@ void BlenderStrokeRenderer::test_strip_visibility(Strip::vertex_container& strip } } -// Build a mesh object representing a stroke -void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const +// Release allocated memory for stroke groups +void BlenderStrokeRenderer::FreeStrokeGroups() { - vector<Strip*>& strips = iStrokeRep->getStrips(); - const bool hasTex = iStrokeRep->hasTex(); - Strip::vertex_container::iterator v[3]; - StrokeVertexRep *svRep[3]; - unsigned int vertex_index, edge_index, loop_index; - Vec2r p; - - int totvert = 0, totedge = 0, totpoly = 0, totloop = 0; - int visible_faces, visible_segments; + vector<StrokeGroup*>::const_iterator it, itend; - bool visible; - for (vector<Strip*>::iterator s = strips.begin(), send = strips.end(); s != send; ++s) { - Strip::vertex_container& strip_vertices = (*s)->vertices(); + for (it = strokeGroups.begin(), itend = strokeGroups.end(); + it != itend; ++it) + { + delete (*it); + } + for (it = texturedStrokeGroups.begin(), itend = texturedStrokeGroups.end(); + it != itend; ++it) + { + delete (*it); + } +} - // count visible faces and strip segments - test_strip_visibility(strip_vertices, &visible_faces, &visible_segments); - if (visible_faces == 0) - continue; +// Build a scene populated by mesh objects representing stylized strokes +int BlenderStrokeRenderer::GenerateScene() +{ + vector<StrokeGroup*>::const_iterator it, itend; - totvert += visible_faces + visible_segments * 2; - totedge += visible_faces * 2 + visible_segments; - totpoly += visible_faces; - totloop += visible_faces * 3; + 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(); +} +// 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, OB_MESH); + DAG_relations_tag_update(freestyle_bmain); #else Object *object_mesh = NewMesh(); #endif Mesh *mesh = (Mesh *)object_mesh->data; - mesh->mat = (Material **)MEM_mallocN(1 * sizeof(Material *), "MaterialList"); - mesh->mat[0] = iStrokeRep->getMaterial(); - mesh->totcol = 1; - test_object_materials(freestyle_bmain, (ID *)mesh); - - // vertices allocation - mesh->totvert = totvert; // visible_faces + visible_segments * 2; - CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert); - - // edges allocation - mesh->totedge = totedge; // visible_faces * 2 + visible_segments; - CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge); - // faces allocation - mesh->totpoly = totpoly; // visible_faces; - CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly); + mesh->totvert = group->totvert; + mesh->totedge = group->totedge; + mesh->totpoly = group->totpoly; + mesh->totloop = group->totloop; + mesh->totcol = group->totcol; - // loops allocation - mesh->totloop = totloop; // visible_faces * 3; - CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop); + 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); - // uv maps + MVert *vertices = mesh->mvert; + MEdge *edges = mesh->medge; + MPoly *polys = mesh->mpoly; + MLoop *loops = mesh->mloop; MLoopUV *loopsuv[2] = { NULL }; - if (hasTex) { - loopsuv[0] = (MLoopUV *)CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke"); - loopsuv[1] = (MLoopUV *)CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke_tips"); - CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke"); - CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, "along_stroke_tips"); + if (hasTex) { + // First UV layer + CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, uvNames[0]); + CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[0]); + CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 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->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, uvNames[1]); + CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[1]); + CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 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; - BKE_mesh_update_customdata_pointers(mesh, true); + mesh->mat = (Material **)MEM_mallocN(sizeof(Material *) * mesh->totcol, "MaterialList"); //////////////////// // Data copy //////////////////// - MVert *vertices = mesh->mvert; - MEdge *edges = mesh->medge; - MPoly *polys = mesh->mpoly; - MLoop *loops = mesh->mloop; + 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; - vertex_index = edge_index = loop_index = 0; + for (vector<StrokeRep*>::const_iterator it = group->strokes.begin(), itend = group->strokes.end(); + it != itend; ++it) + { + mesh->mat[material_index] = (*it)->getMaterial(); - for (vector<Strip*>::iterator s = strips.begin(), send = strips.end(); s != send; ++s) { - Strip::vertex_container& strip_vertices = (*s)->vertices(); - int strip_vertex_count = strip_vertices.size(); + vector<Strip*>& strips = (*it)->getStrips(); + for (vector<Strip*>::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; + // 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; + v[0] = strip_vertices.begin(); + v[1] = v[0] + 1; + v[2] = v[0] + 2; - visible = false; + 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; + // 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; - // second vertex - vertices->co[0] = svRep[1]->point2d()[0]; - vertices->co[1] = svRep[1]->point2d()[1]; + // 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; @@ -706,141 +799,130 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const ++vertices; ++vertex_index; - // first edge - edges->v1 = vertex_index - 2; - edges->v2 = vertex_index - 1; + // edges + edges->v1 = vertex_index - 1; + edges->v2 = vertex_index - 3; ++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; - - // 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; + edges->v1 = vertex_index - 1; + edges->v2 = vertex_index - 2; + ++edges; + ++edge_index; - 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(); + // 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; - loopsuv[L][1].uv[0] = svRep[1]->texCoord(L).x(); - loopsuv[L][1].uv[1] = svRep[1]->texCoord(L).y(); + loops[1].v = vertex_index - 3; + loops[1].e = edge_index - 3; - loopsuv[L][2].uv[0] = svRep[0]->texCoord(L).x(); - loopsuv[L][2].uv[1] = svRep[0]->texCoord(L).y(); + 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; } - loopsuv[L] += 3; } - } - // colors and alpha transparency - if (is_odd) { - colors[0].r = (short)(255.0f * svRep[2]->color()[0]); - colors[0].g = (short)(255.0f * svRep[2]->color()[1]); - colors[0].b = (short)(255.0f * svRep[2]->color()[2]); - colors[0].a = (short)(255.0f * svRep[2]->alpha()); - - colors[1].r = (short)(255.0f * svRep[0]->color()[0]); - colors[1].g = (short)(255.0f * svRep[0]->color()[1]); - colors[1].b = (short)(255.0f * svRep[0]->color()[2]); - colors[1].a = (short)(255.0f * svRep[0]->alpha()); - - colors[2].r = (short)(255.0f * svRep[1]->color()[0]); - colors[2].g = (short)(255.0f * svRep[1]->color()[1]); - colors[2].b = (short)(255.0f * svRep[1]->color()[2]); - colors[2].a = (short)(255.0f * svRep[1]->alpha()); - } - else { - colors[0].r = (short)(255.0f * svRep[2]->color()[0]); - colors[0].g = (short)(255.0f * svRep[2]->color()[1]); - colors[0].b = (short)(255.0f * svRep[2]->color()[2]); - colors[0].a = (short)(255.0f * svRep[2]->alpha()); - - colors[1].r = (short)(255.0f * svRep[1]->color()[0]); - colors[1].g = (short)(255.0f * svRep[1]->color()[1]); - colors[1].b = (short)(255.0f * svRep[1]->color()[2]); - colors[1].a = (short)(255.0f * svRep[1]->alpha()); - - colors[2].r = (short)(255.0f * svRep[0]->color()[0]); - colors[2].g = (short)(255.0f * svRep[0]->color()[1]); - colors[2].b = (short)(255.0f * svRep[0]->color()[2]); - colors[2].a = (short)(255.0f * svRep[0]->alpha()); + // colors and alpha transparency + if (is_odd) { + colors[0].r = (short)(255.0f * svRep[2]->color()[0]); + colors[0].g = (short)(255.0f * svRep[2]->color()[1]); + colors[0].b = (short)(255.0f * svRep[2]->color()[2]); + colors[0].a = (short)(255.0f * svRep[2]->alpha()); + + colors[1].r = (short)(255.0f * svRep[0]->color()[0]); + colors[1].g = (short)(255.0f * svRep[0]->color()[1]); + colors[1].b = (short)(255.0f * svRep[0]->color()[2]); + colors[1].a = (short)(255.0f * svRep[0]->alpha()); + + colors[2].r = (short)(255.0f * svRep[1]->color()[0]); + colors[2].g = (short)(255.0f * svRep[1]->color()[1]); + colors[2].b = (short)(255.0f * svRep[1]->color()[2]); + colors[2].a = (short)(255.0f * svRep[1]->alpha()); + } + else { + colors[0].r = (short)(255.0f * svRep[2]->color()[0]); + colors[0].g = (short)(255.0f * svRep[2]->color()[1]); + colors[0].b = (short)(255.0f * svRep[2]->color()[2]); + colors[0].a = (short)(255.0f * svRep[2]->alpha()); + + colors[1].r = (short)(255.0f * svRep[1]->color()[0]); + colors[1].g = (short)(255.0f * svRep[1]->color()[1]); + colors[1].b = (short)(255.0f * svRep[1]->color()[2]); + colors[1].a = (short)(255.0f * svRep[1]->alpha()); + + colors[2].r = (short)(255.0f * svRep[0]->color()[0]); + colors[2].g = (short)(255.0f * svRep[0]->color()[1]); + colors[2].b = (short)(255.0f * svRep[0]->color()[2]); + colors[2].a = (short)(255.0f * svRep[0]->alpha()); + } + 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; } - 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 -#if 0 - BLI_assert(totvert == vertex_index); - BLI_assert(totedge == edge_index); - BLI_assert(totloop == loop_index); - BKE_mesh_validate(mesh, true); + } // loop over strip vertices + } // loop over strips + material_index++; + } // loop over strokes + + test_object_materials(freestyle_bmain, (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 } @@ -859,6 +941,7 @@ Object *BlenderStrokeRenderer::NewMesh() const ob->lay = 1; base = BKE_scene_base_add(freestyle_scene, ob); + DAG_relations_tag_update(freestyle_bmain); #if 0 BKE_scene_base_deselect_all(scene); BKE_scene_base_select(scene, base); @@ -871,7 +954,7 @@ Object *BlenderStrokeRenderer::NewMesh() const return ob; } -Render *BlenderStrokeRenderer::RenderScene(Render *re, bool render) +Render *BlenderStrokeRenderer::RenderScene(Render * /*re*/, bool render) { Camera *camera = (Camera *)freestyle_scene->camera->data; if (camera->clipend < _z) @@ -884,7 +967,8 @@ Render *BlenderStrokeRenderer::RenderScene(Render *re, bool render) Render *freestyle_render = RE_NewRender(freestyle_scene->id.name); - RE_RenderFreestyleStrokes(freestyle_render, freestyle_bmain, freestyle_scene, render); + RE_RenderFreestyleStrokes(freestyle_render, freestyle_bmain, freestyle_scene, + render && get_stroke_count() > 0); return freestyle_render; } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h index 74e5d321df2..ec53efa14cd 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h @@ -53,6 +53,21 @@ public: Object *NewMesh() const; + struct StrokeGroup { + explicit StrokeGroup() : totvert(0), totedge(0), totpoly(0), totloop(0), totcol(0) {} + vector<StrokeRep*> strokes; + int totvert; + int totedge; + int totpoly; + int totloop; + int totcol; + }; + vector<StrokeGroup*> 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); @@ -68,16 +83,20 @@ protected: 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<StrokeRep *> _strokeReps; + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStrokeRenderer") #endif - }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h index 21776396ebc..1d73125f627 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h @@ -31,12 +31,39 @@ extern "C" { #include "BLI_utildefines.h" // BLI_assert() -struct Scene; 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<PythonInterpreter*>(_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") +#endif +}; + class BlenderStyleModule : public StyleModule { public: @@ -63,7 +90,6 @@ private: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStyleModule") #endif - }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 32f49d48ee7..46724ff530a 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -87,7 +87,7 @@ int freestyle_viewport[4]; // current scene Scene *freestyle_scene; -static void load_post_callback(struct Main *main, struct ID *id, void *arg) +static void load_post_callback(struct Main * /*main*/, struct ID * /*id*/, void * /*arg*/) { lineset_copied = false; } @@ -182,7 +182,7 @@ 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 the model-view matrix is simply the identity matrix. + // the model-view matrix is simply the identity matrix. freestyle_viewpoint[0] = 0.0; freestyle_viewpoint[1] = 0.0; @@ -211,16 +211,12 @@ static char *escape_quotes(char *name) return s; } -static Text *create_lineset_handler(Main *bmain, 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); - Text *text = BKE_text_add(bmain, lineset_name); - BKE_text_write(text, "import parameter_editor; parameter_editor.process('"); - BKE_text_write(text, s1); - BKE_text_write(text, "', '"); - BKE_text_write(text, s2); - BKE_text_write(text, "')\n"); + char *text = BLI_sprintfN(fmt, s1, s2); MEM_freeN(s1); MEM_freeN(s2); return text; @@ -293,7 +289,7 @@ static bool test_edge_type_conditions(struct edge_type_condition *conditions, return true; } -static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) +static void prepare(Render *re, SceneRenderLayer *srl) { // load mesh re->i.infostr = "Freestyle: Mesh loading"; @@ -369,9 +365,10 @@ static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) cout << " " << layer_count+1 << ": " << lineset->name << " - " << (lineset->linestyle ? (lineset->linestyle->id.name + 2) : "<NULL>") << endl; } - Text *text = create_lineset_handler(bmain, srl->name, lineset->name); - controller->InsertStyleModule(layer_count, lineset->name, text); + char *buffer = create_lineset_handler(srl->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; @@ -474,6 +471,9 @@ static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) cout << " Z = " << (z ? "enabled" : "disabled") << endl; } + if (controller->hitViewMapCache()) + return; + // compute view map re->i.infostr = "Freestyle: View map creation"; re->stats_draw(re->sdh, &re->i); @@ -491,13 +491,20 @@ void FRS_composite_result(Render *re, SceneRenderLayer *srl, Render *freestyle_r return; rl = render_get_active_layer( freestyle_render, freestyle_render->result ); - if (!rl || rl->rectf == NULL) { + if (!rl) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No source render layer to composite" << endl; + } + return; + } + + src = RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, freestyle_render->viewname); + if (!src) { if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Cannot find Freestyle result image" << endl; + cout << "No source result image to composite" << endl; } return; } - src = rl->rectf; #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << "src: " << rl->rectx << " x " << rl->recty << endl; @@ -505,13 +512,19 @@ void FRS_composite_result(Render *re, SceneRenderLayer *srl, Render *freestyle_r #endif rl = RE_GetRenderLayer(re->result, srl->name); - if (!rl || rl->rectf == NULL) { + if (!rl) { if (G.debug & G_DEBUG_FREESTYLE) { - cout << "No layer to composite to" << endl; + cout << "No destination render layer to composite to" << endl; + } + return; + } + dest = RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, re->viewname); + if (!dest) { + if (G.debug & G_DEBUG_FREESTYLE) { + cout << "No destination result image to composite to" << endl; } return; } - dest = rl->rectf; #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << "dest: " << rl->rectx << " x " << rl->recty << endl; @@ -563,7 +576,7 @@ int FRS_is_freestyle_enabled(SceneRenderLayer *srl) return (!(srl->layflag & SCE_LAY_DISABLE) && srl->layflag & SCE_LAY_FRS && displayed_layer_count(srl) > 0); } -void FRS_init_stroke_rendering(Render *re) +void FRS_init_stroke_renderer(Render *re) { if (G.debug & G_DEBUG_FREESTYLE) { cout << endl; @@ -573,22 +586,25 @@ void FRS_init_stroke_rendering(Render *re) } init_view(re); - init_camera(re); controller->ResetRenderCount(); } +void FRS_begin_stroke_rendering(Render *re) +{ + init_camera(re); +} + Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render) { - Main *freestyle_bmain = re->freestyle_bmain; Render *freestyle_render = NULL; - Text *text, *next_text; if (!render) return controller->RenderStrokes(re, false); RenderMonitor monitor(re); controller->setRenderMonitor(&monitor); + controller->setViewMapCache((srl->freestyleConfig.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false); if (G.debug & G_DEBUG_FREESTYLE) { cout << endl; @@ -602,7 +618,7 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render) // - add style modules // - set parameters // - compute view map - prepare(freestyle_bmain, re, srl); + prepare(re, srl); if (re->test_break(re->tbh)) { controller->CloseFile(); @@ -630,23 +646,26 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render) } } - // Free temp main (currently only text blocks are stored there) - for (text = (Text *)freestyle_bmain->text.first; text; text = next_text) { - next_text = (Text *) text->id.next; - - BKE_text_unlink(freestyle_bmain, text); - BKE_libblock_free(freestyle_bmain, text); - } - return freestyle_render; } -void FRS_finish_stroke_rendering(Render *re) +void FRS_end_stroke_rendering(Render * /*re*/) { // clear canvas controller->Clear(); } +void FRS_free_view_map_cache(void) +{ + // free cache + controller->DeleteViewMap(true); +#if 0 + if (G.debug & G_DEBUG_FREESTYLE) { + printf("View map cache freed\n"); + } +#endif +} + //======================================================= // Freestyle Panel Configuration //======================================================= diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp index acbc668118e..c5d1c8df17b 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp @@ -50,13 +50,13 @@ using namespace std; namespace Freestyle { void GeomCleaner::SortIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned **oIndices) + unsigned iISize, float **oVertices, unsigned **oIndices) { // First, we build a list of IndexVertex: list<IndexedVertex> indexedVertices; unsigned i; for (i = 0; i < iVSize; i += 3) { - indexedVertices.push_back(IndexedVertex(Vec3r(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3)); + indexedVertices.push_back(IndexedVertex(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3)); } // q-sort @@ -64,7 +64,7 @@ void GeomCleaner::SortIndexedVertexArray(const float *iVertices, unsigned iVSize // build the indices mapping array: unsigned *mapIndices = new unsigned[iVSize / 3]; - *oVertices = new real[iVSize]; + *oVertices = new float[iVSize]; list<IndexedVertex>::iterator iv; unsigned newIndex = 0; unsigned vIndex = 0; @@ -88,26 +88,26 @@ void GeomCleaner::SortIndexedVertexArray(const float *iVertices, unsigned iVSize delete [] mapIndices; } -void GeomCleaner::CompressIndexedVertexArray(const real *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **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<Vec3r> vertices; + vector<Vec3f> vertices; unsigned i; for (i = 0; i < iVSize; i += 3) { - vertices.push_back(Vec3r(iVertices[i], iVertices[i + 1], iVertices[i + 2])); + vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); } unsigned *mapVertex = new unsigned[iVSize]; - vector<Vec3r>::iterator v = vertices.begin(); + vector<Vec3f>::iterator v = vertices.begin(); - vector<Vec3r> compressedVertices; - Vec3r previous = *v; + vector<Vec3f> compressedVertices; + Vec3f previous = *v; mapVertex[0] = 0; compressedVertices.push_back(vertices.front()); v++; - Vec3r current; + Vec3f current; i = 1; for (; v != vertices.end(); v++) { current = *v; @@ -123,7 +123,7 @@ void GeomCleaner::CompressIndexedVertexArray(const real *iVertices, unsigned iVS // Builds the resulting vertex array: *oVSize = 3 * compressedVertices.size(); - *oVertices = new real[*oVSize]; + *oVertices = new float[*oVSize]; i = 0; for (v = compressedVertices.begin(); v != compressedVertices.end(); v++) { (*oVertices)[i] = (*v)[0]; @@ -142,11 +142,11 @@ void GeomCleaner::CompressIndexedVertexArray(const real *iVertices, unsigned iVS } void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned *oVSize, + unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices) { // tmp arrays used to store the sorted data: - real *tmpVertices; + float *tmpVertices; unsigned *tmpIndices; Chronometer chrono; @@ -154,7 +154,7 @@ void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, unsi chrono.start(); GeomCleaner::SortIndexedVertexArray(iVertices, iVSize, iIndices, iISize, &tmpVertices, &tmpIndices); if (G.debug & G_DEBUG_FREESTYLE) { - printf("Sorting: %lf\n", chrono.stop()); + printf("Sorting: %lf sec.\n", chrono.stop()); } // compress data @@ -162,7 +162,7 @@ void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, unsi GeomCleaner::CompressIndexedVertexArray(tmpVertices, iVSize, tmpIndices, iISize, oVertices, oVSize, oIndices); real duration = chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { - printf("Merging: %lf\n", duration); + printf("Merging: %lf sec.\n", duration); } // deallocates memory: @@ -185,22 +185,22 @@ struct GeomCleanerHasher { }; void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned *oVSize, unsigned **oIndices) + unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices) { - typedef map<Vec3r, unsigned> cleanHashTable; - vector<Vec3r> vertices; + typedef map<Vec3f, unsigned> cleanHashTable; + vector<Vec3f> vertices; unsigned i; for (i = 0; i < iVSize; i += 3) - vertices.push_back(Vec3r(iVertices[i], iVertices[i + 1], iVertices[i + 2])); + vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); cleanHashTable ht; vector<unsigned> newIndices; - vector<Vec3r> newVertices; + vector<Vec3f> newVertices; // elimination of needless points unsigned currentIndex = 0; - vector<Vec3r>::const_iterator v = vertices.begin(); - vector<Vec3r>::const_iterator end = vertices.end(); + vector<Vec3f>::const_iterator v = vertices.begin(); + vector<Vec3f>::const_iterator end = vertices.end(); cleanHashTable::const_iterator found; for (; v != end; v++) { found = ht.find(*v); @@ -218,7 +218,7 @@ void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, unsigned iVSiz // creation of oVertices array: *oVSize = 3 * newVertices.size(); - *oVertices = new real[*oVSize]; + *oVertices = new float[*oVSize]; currentIndex = 0; end = newVertices.end(); for (v = newVertices.begin(); v != end ; v++) { diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.h b/source/blender/freestyle/intern/geometry/GeomCleaner.h index d516c5623b9..aeca592a8c4 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.h +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.h @@ -64,7 +64,7 @@ public: * Output corresponding to the iIndices array but reorganized in order to match the sorted vertex array. */ static void SortIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned **oIndices); + unsigned iISize, float **oVertices, unsigned **oIndices); /*! Compress a SORTED indexed vertex array by eliminating multiple appearing occurences of a single vertex. * iVertices @@ -84,8 +84,8 @@ public: * oIndices * The indices array, reorganized to match the compressed oVertices array. */ - static void CompressIndexedVertexArray(const real *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned *oVSize, unsigned **oIndices); + static void CompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, + unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices); /*! Sorts and compress an array of indexed vertices. * iVertices @@ -107,7 +107,7 @@ public: * The indices array, reorganized to match the sorted and compressed oVertices array. */ static void SortAndCompressIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned *oVSize, + unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices); /*! Cleans an indexed vertex array. (Identical to SortAndCompress except that we use here a hash table @@ -131,7 +131,7 @@ public: * The indices array, reorganized to match the sorted and compressed oVertices array. */ static void CleanIndexedVertexArray(const float *iVertices, unsigned iVSize, const unsigned *iIndices, - unsigned iISize, real **oVertices, unsigned *oVSize, unsigned **oIndices); + unsigned iISize, float **oVertices, unsigned *oVSize, unsigned **oIndices); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GeomCleaner") @@ -146,20 +146,20 @@ public: class IndexedVertex { private: - Vec3r _Vector; + Vec3f _Vector; unsigned _index; public: inline IndexedVertex() {} - inline IndexedVertex(Vec3r iVector, unsigned iIndex) + inline IndexedVertex(Vec3f iVector, unsigned iIndex) { _Vector = iVector; _index = iIndex; } /*! accessors */ - inline const Vec3r& vector() const + inline const Vec3f& vector() const { return _Vector; } @@ -169,23 +169,23 @@ public: return _index; } - inline real x() + inline float x() { return _Vector[0]; } - inline real y() + inline float y() { return _Vector[1]; } - inline real z() + inline float z() { return _Vector[2]; } /*! modifiers */ - inline void setVector(const Vec3r& iVector) + inline void setVector(const Vec3f& iVector) { _Vector = iVector; } @@ -203,7 +203,7 @@ public: return *this; } - inline real operator[](const unsigned i) + inline float operator[](const unsigned i) { return _Vector[i]; } diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.cpp b/source/blender/freestyle/intern/geometry/GeomUtils.cpp index a750cf2f7cf..3eb92c559fe 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.cpp +++ b/source/blender/freestyle/intern/geometry/GeomUtils.cpp @@ -495,7 +495,7 @@ bool intersectRayBBox(const Vec3r& orig, const Vec3r& dir, // ray origin an 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) + real /*epsilon*/) { float tymin, tymax, tzmin, tzmax; Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]); diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.h b/source/blender/freestyle/intern/geometry/GeomUtils.h index 64aa6379e80..5a5d0809083 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.h +++ b/source/blender/freestyle/intern/geometry/GeomUtils.h @@ -200,7 +200,7 @@ void fromWorldToCamera(const Vec3r& p, Vec3r& q, const real model_view_matrix[4] void fromCameraToRetina(const Vec3r& p, Vec3r& q, const real projection_matrix[4][4]); /*! From retina to image. - * Returns the coordinates expressed in Image coorinates system. + * Returns the coordinates expressed in Image coordinates system. * p * point's coordinates expressed in retina system * q diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index c1d04f6b4cc..62c0e58232a 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -97,11 +97,11 @@ 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; diff --git a/source/blender/freestyle/intern/image/Image.h b/source/blender/freestyle/intern/image/Image.h index 577dc0fb866..2e78e784214 100644 --- a/source/blender/freestyle/intern/image/Image.h +++ b/source/blender/freestyle/intern/image/Image.h @@ -134,7 +134,7 @@ public: return _height; } - /*! Returns the grey value for pixel x,y */ + /*! Returns the gray value for pixel x,y */ virtual float pixel(unsigned x, unsigned y) const = 0; /*! Sets the array. diff --git a/source/blender/freestyle/intern/image/ImagePyramid.cpp b/source/blender/freestyle/intern/image/ImagePyramid.cpp index 251f47bc44c..b81f8303945 100644 --- a/source/blender/freestyle/intern/image/ImagePyramid.cpp +++ b/source/blender/freestyle/intern/image/ImagePyramid.cpp @@ -42,7 +42,7 @@ ImagePyramid::ImagePyramid(const GrayImage& level0, unsigned nbLevels) } #endif -ImagePyramid::ImagePyramid(const ImagePyramid& iBrother) +ImagePyramid::ImagePyramid(const ImagePyramid& /*iBrother*/) { if (!_levels.empty()) { for (vector<GrayImage*>::iterator im = _levels.begin(), imend = _levels.end(); im != imend; ++im) { diff --git a/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp b/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp index dd678ee6fbd..50d82656819 100644 --- a/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp +++ b/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp @@ -46,7 +46,7 @@ static char ContextFunctions_get_time_stamp___doc__[] = " :rtype: int\n"; static PyObject * -ContextFunctions_get_time_stamp(PyObject *self) +ContextFunctions_get_time_stamp(PyObject * /*self*/) { return PyLong_FromLong(ContextFunctions::GetTimeStampCF()); } @@ -60,7 +60,7 @@ static char ContextFunctions_get_canvas_width___doc__[] = " :rtype: int\n"; static PyObject * -ContextFunctions_get_canvas_width(PyObject *self) +ContextFunctions_get_canvas_width(PyObject * /*self*/) { return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF()); } @@ -74,7 +74,7 @@ static char ContextFunctions_get_canvas_height___doc__[] = " :rtype: int\n"; static PyObject * -ContextFunctions_get_canvas_height(PyObject *self) +ContextFunctions_get_canvas_height(PyObject * /*self*/) { return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF()); } @@ -88,14 +88,15 @@ static char ContextFunctions_get_border___doc__[] = " :rtype: tuple\n"; static PyObject * -ContextFunctions_get_border(PyObject *self) +ContextFunctions_get_border(PyObject * /*self*/) { BBox<Vec2i> border(ContextFunctions::GetBorderCF()); PyObject *v = PyTuple_New(4); - PyTuple_SET_ITEM(v, 0, PyLong_FromLong(border.getMin().x())); - PyTuple_SET_ITEM(v, 1, PyLong_FromLong(border.getMin().y())); - PyTuple_SET_ITEM(v, 2, PyLong_FromLong(border.getMax().x())); - PyTuple_SET_ITEM(v, 3, PyLong_FromLong(border.getMax().y())); + 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; } @@ -116,7 +117,7 @@ static char ContextFunctions_load_map___doc__[] = " :type sigma: float\n"; static PyObject * -ContextFunctions_load_map(PyObject *self, PyObject *args, PyObject *kwds) +ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", NULL}; char *fileName, *mapName; @@ -149,7 +150,7 @@ static char ContextFunctions_read_map_pixel___doc__[] = " :rtype: float\n"; static PyObject * -ContextFunctions_read_map_pixel(PyObject *self, PyObject *args, PyObject *kwds) +ContextFunctions_read_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"map_name", "level", "x", "y", NULL}; char *mapName; @@ -179,7 +180,7 @@ static char ContextFunctions_read_complete_view_map_pixel___doc__[] = " :rtype: float\n"; static PyObject * -ContextFunctions_read_complete_view_map_pixel(PyObject *self, PyObject *args, PyObject *kwds) +ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"level", "x", "y", NULL}; int level; @@ -211,7 +212,7 @@ static char ContextFunctions_read_directional_view_map_pixel___doc__[] = " :rtype: float\n"; static PyObject * -ContextFunctions_read_directional_view_map_pixel(PyObject *self, PyObject *args, PyObject *kwds) +ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"orientation", "level", "x", "y", NULL}; int orientation, level; @@ -231,7 +232,7 @@ static char ContextFunctions_get_selected_fedge___doc__[] = " :rtype: :class:`FEdge`\n"; static PyObject * -ContextFunctions_get_selected_fedge(PyObject *self) +ContextFunctions_get_selected_fedge(PyObject * /*self*/) { FEdge *fe = ContextFunctions::GetSelectedFEdgeCF(); if (fe) diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index dbd836bc562..4e1a0a119aa 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -81,7 +81,7 @@ 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, Py_NEW, NULL); + return Vector_CreatePyObject(vec_data, 2, NULL); } PyObject *Vector_from_Vec3f(Vec3f& vec) @@ -90,7 +90,7 @@ PyObject *Vector_from_Vec3f(Vec3f& vec) vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); - return Vector_CreatePyObject(vec_data, 3, Py_NEW, NULL); + return Vector_CreatePyObject(vec_data, 3, NULL); } PyObject *Vector_from_Vec3r(Vec3r& vec) @@ -99,7 +99,7 @@ PyObject *Vector_from_Vec3r(Vec3r& vec) vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); - return Vector_CreatePyObject(vec_data, 3, Py_NEW, NULL); + return Vector_CreatePyObject(vec_data, 3, NULL); } PyObject *BPy_Id_from_Id(Id& id) @@ -401,8 +401,9 @@ PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp) PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve) { PyObject *py_dve = PyTuple_New(2); - PyTuple_SET_ITEM(py_dve, 0, BPy_ViewEdge_from_ViewEdge(*(dve.first))); - PyTuple_SET_ITEM(py_dve, 1, PyBool_from_bool(dve.second)); + PyTuple_SET_ITEMS(py_dve, + BPy_ViewEdge_from_ViewEdge(*(dve.first)), + PyBool_from_bool(dve.second)); return py_dve; } diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index e6e763e763e..35c1e58369c 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -92,6 +92,7 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// #include "mathutils/mathutils.h" +#include "generic/python_utildefines.h" //============================== // C++ => Python diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index 5b8d50eb5eb..d22632040f4 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -60,6 +60,7 @@ extern "C" { #include "FRS_freestyle.h" #include "RNA_access.h" +#include "BKE_appdir.h" #include "DNA_scene_types.h" #include "bpy_rna.h" /* pyrna_struct_CreatePyObject() */ @@ -71,7 +72,7 @@ static char Freestyle_getCurrentScene___doc__[] = " :return: The current scene.\n" " :rtype: :class:`bpy.types.Scene`\n"; -static PyObject *Freestyle_getCurrentScene(PyObject *self) +static PyObject *Freestyle_getCurrentScene(PyObject * /*self*/) { if (!freestyle_scene) { PyErr_SetString(PyExc_TypeError, "current scene not available"); @@ -86,24 +87,24 @@ static PyObject *Freestyle_getCurrentScene(PyObject *self) static int ramp_blend_type(const char *type) { - if (!strcmp(type, "MIX")) return MA_RAMP_BLEND; - if (!strcmp(type, "ADD")) return MA_RAMP_ADD; - if (!strcmp(type, "MULTIPLY")) return MA_RAMP_MULT; - if (!strcmp(type, "SUBTRACT")) return MA_RAMP_SUB; - if (!strcmp(type, "SCREEN")) return MA_RAMP_SCREEN; - if (!strcmp(type, "DIVIDE")) return MA_RAMP_DIV; - if (!strcmp(type, "DIFFERENCE")) return MA_RAMP_DIFF; - if (!strcmp(type, "DARKEN")) return MA_RAMP_DARK; - if (!strcmp(type, "LIGHTEN")) return MA_RAMP_LIGHT; - if (!strcmp(type, "OVERLAY")) return MA_RAMP_OVERLAY; - if (!strcmp(type, "DODGE")) return MA_RAMP_DODGE; - if (!strcmp(type, "BURN")) return MA_RAMP_BURN; - if (!strcmp(type, "HUE")) return MA_RAMP_HUE; - if (!strcmp(type, "SATURATION")) return MA_RAMP_SAT; - if (!strcmp(type, "VALUE")) return MA_RAMP_VAL; - if (!strcmp(type, "COLOR")) return MA_RAMP_COLOR; - if (!strcmp(type, "SOFT_LIGHT")) return MA_RAMP_SOFT; - if (!strcmp(type, "LINEAR_LIGHT")) return MA_RAMP_LINEAR; + 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; } @@ -125,7 +126,7 @@ static char Freestyle_blendRamp___doc__[] = " :return: Blended color in RGB format.\n" " :rtype: :class:`mathutils.Vector`\n"; -static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args) +static PyObject *Freestyle_blendRamp(PyObject * /*self*/, PyObject *args) { PyObject *obj1, *obj2; char *s; @@ -152,7 +153,7 @@ static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args) return NULL; } ramp_blend(type, a, fac, b); - return Vector_CreatePyObject(a, 3, Py_NEW, NULL); + return Vector_CreatePyObject(a, 3, NULL); } #include "BKE_texture.h" /* do_colorband() */ @@ -169,7 +170,7 @@ static char Freestyle_evaluateColorRamp___doc__[] = " :return: color in RGBA format.\n" " :rtype: :class:`mathutils.Vector`\n"; -static PyObject *Freestyle_evaluateColorRamp(PyObject *self, PyObject *args) +static PyObject *Freestyle_evaluateColorRamp(PyObject * /*self*/, PyObject *args) { BPy_StructRNA *py_srna; ColorBand *coba; @@ -186,7 +187,7 @@ static PyObject *Freestyle_evaluateColorRamp(PyObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp"); return NULL; } - return Vector_CreatePyObject(out, 4, Py_NEW, NULL); + return Vector_CreatePyObject(out, 4, NULL); } #include "DNA_color_types.h" @@ -206,7 +207,7 @@ static char Freestyle_evaluateCurveMappingF___doc__[] = " :return: Mapped output value.\n" " :rtype: float\n"; -static PyObject *Freestyle_evaluateCurveMappingF(PyObject *self, PyObject *args) +static PyObject *Freestyle_evaluateCurveMappingF(PyObject * /*self*/, PyObject *args) { BPy_StructRNA *py_srna; CurveMapping *cumap; @@ -492,7 +493,7 @@ PyObject *Freestyle_Init(void) PyDict_SetItemString(PySys_GetObject("modules"), module_definition.m_name, module); // update 'sys.path' for Freestyle Python API modules - const char * const path = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "freestyle"); + 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"); diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp index 4d0d140474a..1866058a151 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp @@ -30,6 +30,9 @@ extern "C" { #endif +#include "BLI_hash_mm2a.h" + + /////////////////////////////////////////////////////////////////////////////////////////// //-------------------MODULE INITIALIZATION-------------------------------- @@ -220,10 +223,10 @@ static int FrsMaterial_mathutils_get_index(BaseMathObject *bmo, int subtype, int 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]; - } + { + const float *color = self->m->line(); + bmo->data[index] = color[index]; + } break; case MATHUTILS_SUBTYPE_DIFFUSE: { @@ -478,6 +481,48 @@ static PyGetSetDef BPy_FrsMaterial_getseters[] = { {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; +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; + } +} + + +static Py_hash_t FrsMaterial_hash(PyObject *self) +{ + return (Py_uhash_t)BLI_hash_mm2((const unsigned char *)self, sizeof(*self), 0); +} /*-----------------------BPy_FrsMaterial type definition ------------------------------*/ PyTypeObject FrsMaterial_Type = { @@ -494,7 +539,7 @@ PyTypeObject FrsMaterial_Type = { 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + (hashfunc)FrsMaterial_hash, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ @@ -504,7 +549,7 @@ PyTypeObject FrsMaterial_Type = { FrsMaterial_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ - 0, /* tp_richcompare */ + (richcmpfunc)BPy_FrsMaterial_richcmpr, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp index 39e4aed7cc0..3f29d9899e8 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -25,6 +25,8 @@ #include "BPy_FrsNoise.h" #include "BPy_Convert.h" +#include "../system/RandGen.h" + #include <sstream> #ifdef __cplusplus @@ -69,12 +71,14 @@ static int FrsNoise_init(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) 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); } @@ -99,6 +103,32 @@ PyDoc_STRVAR(FrsNoise_turbulence1_doc, " :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 PyObject *FrsNoise_turbulence_smooth(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"v", "oct", NULL}; + + 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)); +} + static PyObject *FrsNoise_turbulence1(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; @@ -257,6 +287,8 @@ static PyMethodDef BPy_FrsNoise_methods[] = { {"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} }; diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.h b/source/blender/freestyle/intern/python/BPy_FrsNoise.h index 19788e30a43..a5a1064ea8d 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.h +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.h @@ -30,6 +30,7 @@ extern "C" { } #include "../geometry/Noise.h" +#include "../system/PseudoNoise.h" using namespace Freestyle; @@ -47,6 +48,7 @@ extern PyTypeObject FrsNoise_Type; typedef struct { PyObject_HEAD Noise *n; + PseudoNoise *pn; } BPy_FrsNoise; /*---------------------------Python BPy_FrsNoise visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp index 7a3624f248e..0db25753caa 100644 --- a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp +++ b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp @@ -63,7 +63,7 @@ PyDoc_STRVAR(Integrator_integrate_doc, " :class:`UnaryFunction0DUnsigned` type.\n" " :rtype: int or float"); -static PyObject * Integrator_integrate(PyObject *self, PyObject *args, PyObject *kwds) +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; diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp index 6beeafe0065..1b2b18c2c99 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.cpp +++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp @@ -34,6 +34,8 @@ #include "BPy_StrokeShader.h" #include "BPy_Convert.h" +#include <sstream> + #ifdef __cplusplus extern "C" { #endif @@ -76,7 +78,7 @@ PyDoc_STRVAR(Operators_select_doc, " :arg pred: The predicate expressing this condition.\n" " :type pred: :class:`UnaryPredicate1D`"); -static PyObject *Operators_select(BPy_Operators *self, PyObject *args, PyObject *kwds) +static PyObject *Operators_select(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"pred", NULL}; PyObject *obj = 0; @@ -135,7 +137,7 @@ PyDoc_STRVAR(Operators_chain_doc, " stopping condition.\n" " :type pred: :class:`UnaryPredicate1D`"); -static PyObject *Operators_chain(BPy_Operators *self, PyObject *args, PyObject *kwds) +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; @@ -224,7 +226,7 @@ PyDoc_STRVAR(Operators_bidirectional_chain_doc, " contains the chaining rule.\n" " :type it: :class:`ChainingIterator`"); -static PyObject *Operators_bidirectional_chain(BPy_Operators *self, PyObject *args, PyObject *kwds) +static PyObject *Operators_bidirectional_chain(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"it", "pred", NULL}; PyObject *obj1 = 0, *obj2 = 0; @@ -304,7 +306,7 @@ PyDoc_STRVAR(Operators_sequential_split_doc, " resolution.)\n" " :type sampling: float"); -static PyObject *Operators_sequential_split(BPy_Operators *self, PyObject *args, PyObject *kwds) +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}; @@ -411,7 +413,7 @@ PyDoc_STRVAR(Operators_recursive_split_doc, " resolution.)\n" " :type sampling: float"); -static PyObject *Operators_recursive_split(BPy_Operators *self, PyObject *args, PyObject *kwds) +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}; @@ -486,7 +488,7 @@ PyDoc_STRVAR(Operators_sort_doc, " :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 PyObject *Operators_sort(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"pred", NULL}; PyObject *obj = 0; @@ -517,7 +519,7 @@ PyDoc_STRVAR(Operators_create_doc, " :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 PyObject *Operators_create(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"pred", "shaders", NULL}; PyObject *obj1 = 0, *obj2 = 0; @@ -532,13 +534,22 @@ static PyObject *Operators_create(BPy_Operators *self, PyObject *args, PyObject return NULL; } vector<StrokeShader *> shaders; + shaders.reserve(PyList_Size(obj2)); for (int i = 0; i < PyList_Size(obj2); i++) { - PyObject *py_ss = PyList_GetItem(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; } - shaders.push_back(((BPy_StrokeShader *)py_ss)->ss); + 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()) @@ -548,6 +559,30 @@ static PyObject *Operators_create(BPy_Operators *self, PyObject *args, PyObject 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"); + +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; +} + PyDoc_STRVAR(Operators_get_viewedge_from_index_doc, ".. staticmethod:: get_viewedge_from_index(i)\n" "\n" @@ -558,7 +593,7 @@ PyDoc_STRVAR(Operators_get_viewedge_from_index_doc, " :return: The ViewEdge object.\n" " :rtype: :class:`ViewEdge`"); -static PyObject *Operators_get_viewedge_from_index(BPy_Operators *self, PyObject *args, PyObject *kwds) +static PyObject *Operators_get_viewedge_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"i", NULL}; unsigned int i; @@ -582,7 +617,7 @@ PyDoc_STRVAR(Operators_get_chain_from_index_doc, " :return: The Chain object.\n" " :rtype: :class:`Chain`"); -static PyObject *Operators_get_chain_from_index(BPy_Operators *self, PyObject *args, PyObject *kwds) +static PyObject *Operators_get_chain_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"i", NULL}; unsigned int i; @@ -606,7 +641,7 @@ PyDoc_STRVAR(Operators_get_stroke_from_index_doc, " :return: The Stroke object.\n" " :rtype: :class:`Stroke`"); -static PyObject *Operators_get_stroke_from_index(BPy_Operators *self, PyObject *args, PyObject *kwds) +static PyObject *Operators_get_stroke_from_index(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"i", NULL}; unsigned int i; @@ -628,7 +663,7 @@ PyDoc_STRVAR(Operators_get_view_edges_size_doc, " :return: The number of ViewEdges.\n" " :rtype: int"); -static PyObject *Operators_get_view_edges_size(BPy_Operators *self) +static PyObject *Operators_get_view_edges_size(BPy_Operators * /*self*/) { return PyLong_FromLong(Operators::getViewEdgesSize()); } @@ -641,7 +676,7 @@ PyDoc_STRVAR(Operators_get_chains_size_doc, " :return: The number of Chains.\n" " :rtype: int"); -static PyObject *Operators_get_chains_size(BPy_Operators *self) +static PyObject *Operators_get_chains_size(BPy_Operators * /*self*/) { return PyLong_FromLong(Operators::getChainsSize()); } @@ -654,7 +689,7 @@ PyDoc_STRVAR(Operators_get_strokes_size_doc, " :return: The number of Strokes.\n" " :rtype: int"); -static PyObject *Operators_get_strokes_size(BPy_Operators *self) +static PyObject *Operators_get_strokes_size(BPy_Operators * /*self*/) { return PyLong_FromLong(Operators::getStrokesSize()); } @@ -671,6 +706,7 @@ static PyMethodDef BPy_Operators_methods[] = { 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, diff --git a/source/blender/freestyle/intern/python/BPy_SShape.cpp b/source/blender/freestyle/intern/python/BPy_SShape.cpp index e5a38171ecd..9169adf4d9f 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_SShape.cpp @@ -185,7 +185,7 @@ PyDoc_STRVAR(SShape_name_doc, 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()); } static int SShape_name_set(BPy_SShape *self, PyObject *value, void *UNUSED(closure)) @@ -194,7 +194,7 @@ static int SShape_name_set(BPy_SShape *self, PyObject *value, void *UNUSED(closu PyErr_SetString(PyExc_TypeError, "value must be a string"); return -1; } - const string name = _PyUnicode_AsString(value); + const char *name = _PyUnicode_AsString(value); self->ss->setName(name); return 0; } @@ -227,13 +227,14 @@ PyDoc_STRVAR(SShape_vertices_doc, static PyObject *SShape_vertices_get(BPy_SShape *self, void *UNUSED(closure)) { - PyObject *py_vertices = PyList_New(0); vector< SVertex * > vertices = self->ss->getVertexList(); vector< SVertex * >::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_Append(py_vertices, BPy_SVertex_from_SVertex(*(*it))); + PyList_SET_ITEM(py_vertices, i++, BPy_SVertex_from_SVertex(*(*it))); } return py_vertices; @@ -246,13 +247,14 @@ PyDoc_STRVAR(SShape_edges_doc, static PyObject *SShape_edges_get(BPy_SShape *self, void *UNUSED(closure)) { - PyObject *py_edges = PyList_New(0); vector< FEdge * > edges = self->ss->getEdgeList(); vector< FEdge * >::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; for (it = edges.begin(); it != edges.end(); it++) { - PyList_Append(py_edges, Any_BPy_FEdge_from_FEdge(*(*it))); + PyList_SET_ITEM(py_edges, i++, Any_BPy_FEdge_from_FEdge(*(*it))); } return py_edges; diff --git a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp index a6c7a40e780..6b4a1872b61 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeShader.cpp @@ -32,11 +32,9 @@ #include "StrokeShader/BPy_BlenderTextureShader.h" #include "StrokeShader/BPy_CalligraphicShader.h" #include "StrokeShader/BPy_ColorNoiseShader.h" -#include "StrokeShader/BPy_ColorVariationPatternShader.h" #include "StrokeShader/BPy_ConstantColorShader.h" #include "StrokeShader/BPy_ConstantThicknessShader.h" #include "StrokeShader/BPy_ConstrainedIncreasingThicknessShader.h" -#include "StrokeShader/BPy_fstreamShader.h" #include "StrokeShader/BPy_GuidingLinesShader.h" #include "StrokeShader/BPy_IncreasingColorShader.h" #include "StrokeShader/BPy_IncreasingThicknessShader.h" @@ -44,12 +42,8 @@ #include "StrokeShader/BPy_SamplingShader.h" #include "StrokeShader/BPy_SmoothingShader.h" #include "StrokeShader/BPy_SpatialNoiseShader.h" -#include "StrokeShader/BPy_streamShader.h" -#include "StrokeShader/BPy_StrokeTextureShader.h" #include "StrokeShader/BPy_StrokeTextureStepShader.h" -#include "StrokeShader/BPy_TextureAssignerShader.h" #include "StrokeShader/BPy_ThicknessNoiseShader.h" -#include "StrokeShader/BPy_ThicknessVariationPatternShader.h" #include "StrokeShader/BPy_TipRemoverShader.h" #ifdef __cplusplus @@ -94,11 +88,6 @@ int StrokeShader_Init(PyObject *module) Py_INCREF(&ColorNoiseShader_Type); PyModule_AddObject(module, "ColorNoiseShader", (PyObject *)&ColorNoiseShader_Type); - if (PyType_Ready(&ColorVariationPatternShader_Type) < 0) - return -1; - Py_INCREF(&ColorVariationPatternShader_Type); - PyModule_AddObject(module, "ColorVariationPatternShader", (PyObject *)&ColorVariationPatternShader_Type); - if (PyType_Ready(&ConstantColorShader_Type) < 0) return -1; Py_INCREF(&ConstantColorShader_Type); @@ -115,11 +104,6 @@ int StrokeShader_Init(PyObject *module) PyModule_AddObject(module, "ConstrainedIncreasingThicknessShader", (PyObject *)&ConstrainedIncreasingThicknessShader_Type); - if (PyType_Ready(&fstreamShader_Type) < 0) - return -1; - Py_INCREF(&fstreamShader_Type); - PyModule_AddObject(module, "fstreamShader", (PyObject *)&fstreamShader_Type); - if (PyType_Ready(&GuidingLinesShader_Type) < 0) return -1; Py_INCREF(&GuidingLinesShader_Type); @@ -155,36 +139,16 @@ int StrokeShader_Init(PyObject *module) Py_INCREF(&SpatialNoiseShader_Type); PyModule_AddObject(module, "SpatialNoiseShader", (PyObject *)&SpatialNoiseShader_Type); - if (PyType_Ready(&streamShader_Type) < 0) - return -1; - Py_INCREF(&streamShader_Type); - PyModule_AddObject(module, "streamShader", (PyObject *)&streamShader_Type); - - if (PyType_Ready(&StrokeTextureShader_Type) < 0) - return -1; - Py_INCREF(&StrokeTextureShader_Type); - PyModule_AddObject(module, "StrokeTextureShader", (PyObject *)&StrokeTextureShader_Type); - if (PyType_Ready(&StrokeTextureStepShader_Type) < 0) return -1; Py_INCREF(&StrokeTextureStepShader_Type); PyModule_AddObject(module, "StrokeTextureStepShader", (PyObject *)&StrokeTextureStepShader_Type); - if (PyType_Ready(&TextureAssignerShader_Type) < 0) - return -1; - Py_INCREF(&TextureAssignerShader_Type); - PyModule_AddObject(module, "TextureAssignerShader", (PyObject *)&TextureAssignerShader_Type); - if (PyType_Ready(&ThicknessNoiseShader_Type) < 0) return -1; Py_INCREF(&ThicknessNoiseShader_Type); PyModule_AddObject(module, "ThicknessNoiseShader", (PyObject *)&ThicknessNoiseShader_Type); - if (PyType_Ready(&ThicknessVariationPatternShader_Type) < 0) - return -1; - Py_INCREF(&ThicknessVariationPatternShader_Type); - PyModule_AddObject(module, "ThicknessVariationPatternShader", (PyObject *)&ThicknessVariationPatternShader_Type); - if (PyType_Ready(&TipRemoverShader_Type) < 0) return -1; Py_INCREF(&TipRemoverShader_Type); diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp index be20febba2b..0941efe9df5 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction0D.cpp @@ -93,7 +93,7 @@ static void UnaryFunction0D___dealloc__(BPy_UnaryFunction0D *self) Py_TYPE(self)->tp_free((PyObject *)self); } -static PyObject *UnaryFunction0D___repr__(BPy_UnaryFunction0D *self) +static PyObject *UnaryFunction0D___repr__(BPy_UnaryFunction0D * /*self*/) { return PyUnicode_FromString("UnaryFunction0D"); } diff --git a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp index b88d609e48d..1b82c7777c7 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryFunction1D.cpp @@ -87,7 +87,7 @@ static void UnaryFunction1D___dealloc__(BPy_UnaryFunction1D *self) Py_TYPE(self)->tp_free((PyObject *)self); } -static PyObject *UnaryFunction1D___repr__(BPy_UnaryFunction1D *self) +static PyObject *UnaryFunction1D___repr__(BPy_UnaryFunction1D * /*self*/) { return PyUnicode_FromString("UnaryFunction1D"); } diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index 2c767eacaec..253bf278478 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -207,19 +207,19 @@ PyDoc_STRVAR(ViewShape_vertices_doc, static PyObject *ViewShape_vertices_get(BPy_ViewShape *self, void *UNUSED(closure)) { - PyObject *py_vertices = PyList_New(0); - vector<ViewVertex *> vertices = self->vs->vertices(); vector<ViewVertex *>::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; + for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_Append( py_vertices, Any_BPy_ViewVertex_from_ViewVertex(*(*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 *list = 0; PyObject *item; vector< ViewVertex *> v; @@ -227,8 +227,10 @@ static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void *UN PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); return -1; } - for (int i = 0; i < PyList_Size(list); i++) { - item = PyList_GetItem(list, i); + + 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); } @@ -248,20 +250,19 @@ PyDoc_STRVAR(ViewShape_edges_doc, static PyObject *ViewShape_edges_get(BPy_ViewShape *self, void *UNUSED(closure)) { - PyObject *py_edges = PyList_New(0); - vector<ViewEdge *> edges = self->vs->edges(); vector<ViewEdge *>::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; for (it = edges.begin(); it != edges.end(); it++) { - PyList_Append(py_edges, BPy_ViewEdge_from_ViewEdge(*(*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 *list = 0; PyObject *item; vector<ViewEdge *> v; @@ -269,8 +270,10 @@ static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void *UNUSE PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects"); return -1; } - for (int i = 0; i < PyList_Size(list); i++) { - item = PyList_GetItem(list, i); + + 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); } @@ -290,7 +293,7 @@ PyDoc_STRVAR(ViewShape_name_doc, 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()); } PyDoc_STRVAR(ViewShape_id_doc, diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index 653fd0b1d29..9f85e84e297 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -265,8 +265,9 @@ int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0D } else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) { vector<ViewShape*> vec; + vec.reserve(PyList_Size(result)); for (int i = 0; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GetItem(result, i))->vs; + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; vec.push_back(b); } ((UnaryFunction0D< vector<ViewShape*> > *)uf0D)->result = vec; @@ -318,8 +319,9 @@ int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D } else if (BPy_UnaryFunction1DVectorViewShape_Check(obj)) { vector<ViewShape*> vec; + vec.reserve(PyList_Size(result)); for (int i = 1; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GetItem(result, i))->vs; + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; vec.push_back(b); } ((UnaryFunction1D< vector<ViewShape*> > *)uf1D)->result = vec; diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index 1ef29792d56..446587c2388 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -188,7 +188,10 @@ static PyObject *CurvePoint_fedge_get(BPy_CurvePoint *self, void *UNUSED(closure { SVertex *A = self->cp->A(); Interface0D *B = (Interface0D *)self->cp->B(); - return Any_BPy_Interface1D_from_Interface1D(*(A->getFEdge(*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, @@ -217,8 +220,8 @@ static PyGetSetDef BPy_CurvePoint_getseters[] = { (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 *)"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 */ }; diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 6f47ce93ca8..39919b41423 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -342,13 +342,14 @@ PyDoc_STRVAR(SVertex_normals_doc, static PyObject *SVertex_normals_get(BPy_SVertex *self, void *UNUSED(closure)) { PyObject *py_normals; - set< Vec3r > normals; - - py_normals = PyList_New(0); - normals = self->sv->normals(); - for (set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++) { - Vec3r v(*set_iterator); - PyList_Append(py_normals, Vector_from_Vec3r(v)); + 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; } @@ -386,7 +387,7 @@ PyDoc_STRVAR(SVertex_curvatures_doc, "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, repectively.\n" +"derivative of the radial curvature at this SVertex, respectively.\n" "\n" ":type: tuple"); @@ -399,13 +400,14 @@ static PyObject *SVertex_curvatures_get(BPy_SVertex *self, void *UNUSED(closure) 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_ITEM(retval, 0, PyFloat_FromDouble(info->K1)); - PyTuple_SET_ITEM(retval, 2, Vector_from_Vec3r(e1)); - PyTuple_SET_ITEM(retval, 1, PyFloat_FromDouble(info->K2)); - PyTuple_SET_ITEM(retval, 3, Vector_from_Vec3r(e2)); - PyTuple_SET_ITEM(retval, 4, PyFloat_FromDouble(info->Kr)); - PyTuple_SET_ITEM(retval, 5, Vector_from_Vec3r(er)); - PyTuple_SET_ITEM(retval, 6, PyFloat_FromDouble(info->dKr)); + 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; } diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index 5e2130ac8e7..f8d0b34d6a9 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -49,7 +49,7 @@ PyDoc_STRVAR(ViewVertex_doc, "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) +static int ViewVertex_init(BPy_ViewVertex * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/) { PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class"); return -1; @@ -82,7 +82,7 @@ PyDoc_STRVAR(ViewVertex_edges_end_doc, " :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n" " :rtype: :class:`orientedViewEdgeIterator`"); -static PyObject *ViewVertex_edges_end(BPy_ViewVertex *self) +static PyObject *ViewVertex_edges_end(BPy_ViewVertex * /*self*/) { #if 0 ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesEnd()); 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 ae4fe0764b6..ba773d4f4cf 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -166,7 +166,7 @@ static int StrokeVertex_mathutils_check(BaseMathObject *bmo) return 0; } -static int StrokeVertex_mathutils_get(BaseMathObject *bmo, int subtype) +static int StrokeVertex_mathutils_get(BaseMathObject *bmo, int /*subtype*/) { BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; bmo->data[0] = (float)self->sv->x(); @@ -174,7 +174,7 @@ static int StrokeVertex_mathutils_get(BaseMathObject *bmo, int subtype) return 0; } -static int StrokeVertex_mathutils_set(BaseMathObject *bmo, int subtype) +static int StrokeVertex_mathutils_set(BaseMathObject *bmo, int /*subtype*/) { BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; self->sv->setX((real)bmo->data[0]); @@ -182,7 +182,7 @@ static int StrokeVertex_mathutils_set(BaseMathObject *bmo, int subtype) return 0; } -static int StrokeVertex_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) +static int StrokeVertex_mathutils_get_index(BaseMathObject *bmo, int /*subtype*/, int index) { BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; switch (index) { @@ -194,7 +194,7 @@ static int StrokeVertex_mathutils_get_index(BaseMathObject *bmo, int subtype, in return 0; } -static int StrokeVertex_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) +static int StrokeVertex_mathutils_set_index(BaseMathObject *bmo, int /*subtype*/, int index) { BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user; switch (index) { diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index 7592508902b..4c9e0630d40 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -100,7 +100,7 @@ static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds) /*----------------------FEdge sequence protocol ----------------------------*/ -static Py_ssize_t FEdge_sq_length(BPy_FEdge *self) +static Py_ssize_t FEdge_sq_length(BPy_FEdge * /*self*/) { return 2; } 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 a2079c7d685..cf893ad9481 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -99,7 +99,7 @@ static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo) return 0; } -static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int subtype) +static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int /*subtype*/) { BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; Vec3r p(self->fes->normal()); @@ -109,7 +109,7 @@ static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int subtype) return 0; } -static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int subtype) +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]); @@ -117,7 +117,7 @@ static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int subtype) return 0; } -static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) +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()); @@ -125,7 +125,7 @@ static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int subtype, int return 0; } -static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) +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()); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 9329bd40c76..edc49eb8004 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -117,7 +117,7 @@ static PyObject *AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) self->at_start = false; else { self->a_it->increment(); - if (self->a_it->isEnd()){ + if (self->a_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index c972db1e680..7419f0ed127 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -120,14 +120,20 @@ static PyObject *Interface0DIterator_iternext(BPy_Interface0DIterator *self) self->if0D_it->decrement(); } else { - if (self->if0D_it->atLast() || self->if0D_it->isEnd()) { + if (self->if0D_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - if (self->at_start) + else if (self->at_start) { self->at_start = false; - else + } + 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); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 18d1b37eb3b..e35076ec7fe 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -115,19 +115,25 @@ static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) self->sv_it->decrement(); } else { - /* if sv_it.isEnd() is true, the iterator can't be incremented. if sv_it.isLast() is true, - * the iterator is currently pointing to the final valid argument. Incrementing it further would - * give a python object that can't be dereferenced. */ - if (self->sv_it->atLast() || self->sv_it->isEnd()) { + /* 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 */ - if (self->at_start) + /* 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; - else + } + /* 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); @@ -149,9 +155,9 @@ static PyObject *StrokeVertexIterator_incremented(BPy_StrokeVertexIterator *self PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); return NULL; } - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - copy->increment(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.increment(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_decremented_doc, @@ -168,10 +174,9 @@ static PyObject *StrokeVertexIterator_decremented(BPy_StrokeVertexIterator *self PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); return NULL; } - - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - copy->decrement(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.decrement(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, @@ -185,8 +190,7 @@ PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, static PyObject *StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self) { - StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, !self->reversed); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); } static PyMethodDef BPy_StrokeVertexIterator_methods[] = { diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h index 46294c07b66..c4fead6a4e4 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_BlenderTextureShader.h @@ -31,7 +31,6 @@ extern "C" { #endif -struct MTex; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.cpp deleted file mode 100644 index 173e00b0ed8..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.cpp - * \ingroup freestyle - */ - -#include "BPy_ColorVariationPatternShader.h" - -#include "../../stroke/BasicStrokeShaders.h" -#include "../BPy_Convert.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char ColorVariationPatternShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ColorVariationPatternShader`\n" -"\n" -"[Color shader]\n" -"\n" -".. method:: __init__(pattern_name, stretch=True)\n" -"\n" -" Builds a ColorVariationPatternShader object.\n" -"\n" -" :arg pattern_name: The file name of the texture file to use as\n" -" pattern.\n" -" :type pattern_name: str\n" -" :arg stretch: Tells whether the texture must be strecthed or\n" -" repeted to fit the stroke.\n" -" :type stretch: bool\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Applies a pattern to vary the original color. The new color is the\n" -" result of the multiplication of the pattern and the original color.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int ColorVariationPatternShader___init__(BPy_ColorVariationPatternShader *self, PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {"pattern_name", "stretch", NULL}; - const char *s; - PyObject *obj = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O!", (char **)kwlist, &s, &PyBool_Type, &obj)) - return -1; - bool b = (!obj) ? true : bool_from_PyBool(obj); - self->py_ss.ss = new StrokeShaders::ColorVariationPatternShader(s, b); - return 0; -} - -/*-----------------------BPy_ColorVariationPatternShader type definition ------------------------------*/ - -PyTypeObject ColorVariationPatternShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ColorVariationPatternShader", /* tp_name */ - sizeof(BPy_ColorVariationPatternShader), /* 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 */ - ColorVariationPatternShader___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)ColorVariationPatternShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.h deleted file mode 100644 index af5cf17caff..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_ColorVariationPatternShader.h - * \ingroup freestyle - */ - -#ifndef __FREESTYLE_PYTHON_COLORVARIATIONPATTERNSHADER_H__ -#define __FREESTYLE_PYTHON_COLORVARIATIONPATTERNSHADER_H__ - -#include "../BPy_StrokeShader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject ColorVariationPatternShader_Type; - -#define BPy_ColorVariationPatternShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ColorVariationPatternShader_Type)) - -/*---------------------------Python BPy_ColorVariationPatternShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_ColorVariationPatternShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* __FREESTYLE_PYTHON_COLORVARIATIONPATTERNSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp deleted file mode 100644 index db2807addc4..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.cpp - * \ingroup freestyle - */ - -#include "BPy_StrokeTextureShader.h" - -#include "../../stroke/BasicStrokeShaders.h" -#include "../BPy_Convert.h" -#include "../BPy_MediumType.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char StrokeTextureShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`StrokeTextureShader`\n" -"\n" -"[Texture shader]\n" -"\n" -".. method:: __init__(texture_file, medium_type=Stroke.OPAQUE_MEDIUM, tips=False)\n" -"\n" -" Builds a StrokeTextureShader object.\n" -"\n" -" :arg texture_file: \n" -" :type texture_file: str\n" -" :arg medium_type: The medium type and therefore, the blending mode\n" -" that must be used for the rendering of this stroke.\n" -" :type medium_type: :class:`freestyle.types.MediumType`\n" -" :arg tips: Tells whether the texture includes tips or not. If it\n" -" is the case, the texture image must respect the following format.\n" -" :type tips: bool\n" -"\n" -" The format of a texture image including tips::\n" -"\n" -" ___________\n" -" | |\n" -" | A |\n" -" |___________|\n" -" | | |\n" -" | B | C |\n" -" |_____|_____|\n" -"\n" -" * A : The stroke's corpus texture.\n" -" * B : The stroke's left extremity texture.\n" -" * C : The stroke's right extremity texture.\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a texture and a blending mode to the stroke in order to\n" -" simulate its marks system.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int StrokeTextureShader___init__(BPy_StrokeTextureShader *self, PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {"texture_file", "medium_type", "tips", NULL}; - const char *s1; - PyObject *obj2 = 0, *obj3 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O!O!", (char **)kwlist, - &s1, &MediumType_Type, &obj2, &PyBool_Type, &obj3)) - { - return -1; - } - Stroke::MediumType mt = (!obj2) ? Stroke::OPAQUE_MEDIUM : MediumType_from_BPy_MediumType(obj2); - bool b = (!obj3) ? false : bool_from_PyBool(obj3); - self->py_ss.ss = new StrokeShaders::StrokeTextureShader(s1, mt, b); - return 0; -} - -/*-----------------------BPy_StrokeTextureShader type definition ------------------------------*/ - -PyTypeObject StrokeTextureShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeTextureShader", /* tp_name */ - sizeof(BPy_StrokeTextureShader), /* 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 */ - StrokeTextureShader___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)StrokeTextureShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.h deleted file mode 100644 index d025e8b7c2d..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_StrokeTextureShader.h - * \ingroup freestyle - */ - -#ifndef __FREESTYLE_PYTHON_STROKETEXTURESHADER_H__ -#define __FREESTYLE_PYTHON_STROKETEXTURESHADER_H__ - -#include "../BPy_StrokeShader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject StrokeTextureShader_Type; - -#define BPy_StrokeTextureShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeTextureShader_Type)) - -/*---------------------------Python BPy_StrokeTextureShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_StrokeTextureShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* __FREESTYLE_PYTHON_STROKETEXTURESHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.cpp deleted file mode 100644 index 78a07cb6c38..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.cpp - * \ingroup freestyle - */ - -#include "BPy_TextureAssignerShader.h" - -#include "../../stroke/BasicStrokeShaders.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char TextureAssignerShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`TextureAssignerShader`\n" -"\n" -"[Texture shader]\n" -"\n" -".. method:: __init__(preset)\n" -"\n" -" Builds a TextureAssignerShader object.\n" -"\n" -" :arg preset: The preset number to use.\n" -" :type preset: int\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Assigns a texture to the stroke in order to simulate its marks\n" -" system. This shader takes as input an integer value telling which\n" -" texture and blending mode to use among a set of predefined\n" -" textures. Here are the different presets:\n" -"\n" -" * 0: `/brushes/charcoalAlpha.bmp`, `Stroke.HUMID_MEDIUM`\n" -" * 1: `/brushes/washbrushAlpha.bmp`, `Stroke.HUMID_MEDIUM`\n" -" * 2: `/brushes/oil.bmp`, `Stroke.HUMID_MEDIUM`\n" -" * 3: `/brushes/oilnoblend.bmp`, `Stroke.HUMID_MEDIUM`\n" -" * 4: `/brushes/charcoalAlpha.bmp`, `Stroke.DRY_MEDIUM`\n" -" * 5: `/brushes/washbrushAlpha.bmp`, `Stroke.DRY_MEDIUM`\n" -" * 6: `/brushes/opaqueDryBrushAlpha.bmp`, `Stroke.OPAQUE_MEDIUM`\n" -" * 7: `/brushes/opaqueBrushAlpha.bmp`, `Stroke.OPAQUE_MEDIUM`\n" -"\n" -" Any other value will lead to the following preset:\n" -"\n" -" * Default: `/brushes/smoothAlpha.bmp`, `Stroke.OPAQUE_MEDIUM`\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int TextureAssignerShader___init__(BPy_TextureAssignerShader *self, PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {"preset", NULL}; - int i; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", (char **)kwlist, &i)) - return -1; - self->py_ss.ss = new StrokeShaders::TextureAssignerShader(i); - return 0; -} - -/*-----------------------BPy_TextureAssignerShader type definition ------------------------------*/ - -PyTypeObject TextureAssignerShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "TextureAssignerShader", /* tp_name */ - sizeof(BPy_TextureAssignerShader), /* 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 */ - TextureAssignerShader___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)TextureAssignerShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.h deleted file mode 100644 index 046f785dc57..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_TextureAssignerShader.h - * \ingroup freestyle - */ - -#ifndef __FREESTYLE_PYTHON_TEXTUREASSIGNERSHADER_H__ -#define __FREESTYLE_PYTHON_TEXTUREASSIGNERSHADER_H__ - -#include "../BPy_StrokeShader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject TextureAssignerShader_Type; - -#define BPy_TextureAssignerShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&TextureAssignerShader_Type)) - -/*---------------------------Python BPy_TextureAssignerShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_TextureAssignerShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* __FREESTYLE_PYTHON_TEXTUREASSIGNERSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp deleted file mode 100644 index 3196065cd34..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.cpp - * \ingroup freestyle - */ - -#include "BPy_ThicknessVariationPatternShader.h" - -#include "../../stroke/BasicStrokeShaders.h" -#include "../BPy_Convert.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char ThicknessVariationPatternShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`ThicknessVariationPatternShader`\n" -"\n" -"[Thickness shader]\n" -"\n" -".. method:: __init__(pattern_name, thickness_min=1.0, thickness_max=5.0, stretch=True)\n" -"\n" -" Builds a ThicknessVariationPatternShader object.\n" -"\n" -" :arg pattern_name: The texture file name.\n" -" :type pattern_name: str\n" -" :arg thickness_min: The minimum thickness we don't want to exceed.\n" -" :type thickness_min: float\n" -" :arg thickness_max: The maximum thickness we don't want to exceed.\n" -" :type thickness_max: float\n" -" :arg stretch: Tells whether the pattern texture must be stretched\n" -" or repeated to fit the stroke.\n" -" :type stretch: bool\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Applies a pattern (texture) to vary thickness. The new thicknesses\n" -" are the result of the multiplication of the pattern and the\n" -" original thickness.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int ThicknessVariationPatternShader___init__(BPy_ThicknessVariationPatternShader *self, - PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {"pattern_name", "thickness_min", "thickness_max", "stretch", NULL}; - const char *s1; - float f2 = 1.0, f3 = 5.0; - PyObject *obj4 = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ffO!", (char **)kwlist, &s1, &f2, &f3, &PyBool_Type, &obj4)) - return -1; - bool b = (!obj4) ? true : bool_from_PyBool(obj4); - self->py_ss.ss = new StrokeShaders::ThicknessVariationPatternShader(s1, f2, f3, b); - return 0; -} - -/*-----------------------BPy_ThicknessVariationPatternShader type definition ------------------------------*/ - -PyTypeObject ThicknessVariationPatternShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ThicknessVariationPatternShader", /* tp_name */ - sizeof(BPy_ThicknessVariationPatternShader), /* 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 */ - ThicknessVariationPatternShader___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)ThicknessVariationPatternShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.h deleted file mode 100644 index 604e875f815..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_ThicknessVariationPatternShader.h - * \ingroup freestyle - */ - -#ifndef __FREESTYLE_PYTHON_THICKNESSVARIATIONPATTERNSHADER_H__ -#define __FREESTYLE_PYTHON_THICKNESSVARIATIONPATTERNSHADER_H__ - -#include "../BPy_StrokeShader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject ThicknessVariationPatternShader_Type; - -#define BPy_ThicknessVariationPatternShader_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ThicknessVariationPatternShader_Type)) - -/*---------------------------Python BPy_ThicknessVariationPatternShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_ThicknessVariationPatternShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* __FREESTYLE_PYTHON_THICKNESSVARIATIONPATTERNSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.cpp deleted file mode 100644 index b838cae9817..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.cpp - * \ingroup freestyle - */ - -#include "BPy_fstreamShader.h" - -#include "../../stroke/AdvancedStrokeShaders.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char fstreamShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`fstreamShader`\n" -"\n" -"[Output shader]\n" -"\n" -".. method:: __init__(filename)\n" -"\n" -" Builds a fstreamShader object.\n" -"\n" -" :arg filename: The output file name.\n" -" :type filename: str\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Streams the Stroke in a file.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int fstreamShader___init__(BPy_fstreamShader *self, PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {"filename", NULL}; - const char *s; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", (char **)kwlist, &s)) - return -1; - self->py_ss.ss = new StrokeShaders::fstreamShader(s); - return 0; -} - -/*-----------------------BPy_fstreamShader type definition ------------------------------*/ - -PyTypeObject fstreamShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "fstreamShader", /* tp_name */ - sizeof(BPy_fstreamShader), /* 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 */ - fstreamShader___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)fstreamShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.h b/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.h deleted file mode 100644 index 9f2371a3756..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_fstreamShader.h - * \ingroup freestyle - */ - -#ifndef __FREESTYLE_PYTHON_FSTREAMSHADER_H__ -#define __FREESTYLE_PYTHON_FSTREAMSHADER_H__ - -#include "../BPy_StrokeShader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject fstreamShader_Type; - -#define BPy_fstreamShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&fstreamShader_Type)) - -/*---------------------------Python BPy_fstreamShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_fstreamShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* __FREESTYLE_PYTHON_FSTREAMSHADER_H__ */ diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.cpp deleted file mode 100644 index 97a6ca0d39e..00000000000 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.cpp - * \ingroup freestyle - */ - -#include "BPy_streamShader.h" - -#include "../../stroke/BasicStrokeShaders.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -//------------------------INSTANCE METHODS ---------------------------------- - -static char streamShader___doc__[] = -"Class hierarchy: :class:`freestyle.types.StrokeShader` > :class:`streamShader`\n" -"\n" -"[Output shader]\n" -"\n" -".. method:: __init__()\n" -"\n" -" Builds a streamShader object.\n" -"\n" -".. method:: shade(stroke)\n" -"\n" -" Streams the Stroke into stdout.\n" -"\n" -" :arg stroke: A Stroke object.\n" -" :type stroke: :class:`freestyle.types.Stroke`\n"; - -static int streamShader___init__(BPy_streamShader *self, PyObject *args, PyObject *kwds) -{ - static const char *kwlist[] = {NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) - return -1; - self->py_ss.ss = new StrokeShaders::streamShader(); - return 0; -} - -/*-----------------------BPy_streamShader type definition ------------------------------*/ - -PyTypeObject streamShader_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "streamShader", /* tp_name */ - sizeof(BPy_streamShader), /* 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 */ - streamShader___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)streamShader___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp index c72ab2aba71..2a61dfb075a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp @@ -112,20 +112,14 @@ static PyObject *UnaryFunction0DVectorViewShape___call__(BPy_UnaryFunction0DVect } return NULL; } - PyObject *list = PyList_New(0); - PyObject *item; - for (unsigned int i = 0; i < self->uf0D_vectorviewshape->result.size(); i++) { + + 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]; - if (v) { - item = BPy_ViewShape_from_ViewShape(*v); - } - else { - item = Py_None; - Py_INCREF(item); - } - PyList_Append(list, item); + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); } - + return list; } diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp index a028952fa69..c15d974e771 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp @@ -142,18 +142,12 @@ static PyObject *UnaryFunction1DVectorViewShape___call__(BPy_UnaryFunction1DVect } return NULL; } - PyObject *list = PyList_New(0); - PyObject *item; - for (unsigned int i = 0; i < self->uf1D_vectorviewshape->result.size(); i++) { + + 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]; - if (v) { - item = BPy_ViewShape_from_ViewShape(*v); - } - else { - item = Py_None; - Py_INCREF(item); - } - PyList_Append(list, item); + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); } return list; 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 517b07f5c7f..041bb60b507 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 @@ -63,7 +63,7 @@ static char GetDirectionalViewMapDensityF1D___doc__[] = "\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 explicitely specified by the user. The density is evaluated for a\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" diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp index 8a2740b94df..9c462bb6b2b 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp @@ -34,7 +34,7 @@ IndexedFaceSet::IndexedFaceSet() : Rep() _Vertices = NULL; _Normals = NULL; _FrsMaterials = 0; - _TexCoords = 0; + _TexCoords = NULL; _FaceEdgeMarks = 0; _VSize = 0; _NSize = 0; @@ -54,8 +54,8 @@ IndexedFaceSet::IndexedFaceSet() : Rep() _displayList = 0; } -IndexedFaceSet::IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, unsigned iNSize, - FrsMaterial **iMaterials, unsigned iMSize, real *iTexCoords, unsigned iTSize, +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, @@ -64,12 +64,12 @@ IndexedFaceSet::IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, { if (1 == iCopy) { _VSize = iVSize; - _Vertices = new real[_VSize]; - memcpy(_Vertices, iVertices, iVSize * sizeof(real)); + _Vertices = new float[_VSize]; + memcpy(_Vertices, iVertices, iVSize * sizeof(float)); _NSize = iNSize; - _Normals = new real[_NSize]; - memcpy(_Normals, iNormals, iNSize * sizeof(real)); + _Normals = new float[_NSize]; + memcpy(_Normals, iNormals, iNSize * sizeof(float)); _MSize = iMSize; _FrsMaterials = 0; @@ -81,8 +81,8 @@ IndexedFaceSet::IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, _TSize = iTSize; _TexCoords = 0; if (_TSize) { - _TexCoords = new real[_TSize]; - memcpy(_TexCoords, iTexCoords, iTSize * sizeof(real)); + _TexCoords = new float[_TSize]; + memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float)); } _NumFaces = iNumFaces; @@ -157,12 +157,12 @@ IndexedFaceSet::IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother) { _VSize = iBrother.vsize(); - _Vertices = new real[_VSize]; - memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(real)); + _Vertices = new float[_VSize]; + memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float)); _NSize = iBrother.nsize(); - _Normals = new real[_NSize]; - memcpy(_Normals, iBrother.normals(), _NSize * sizeof(real)); + _Normals = new float[_NSize]; + memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float)); _MSize = iBrother.msize(); if (_MSize) { @@ -178,8 +178,8 @@ IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother) _TSize = iBrother.tsize(); _TexCoords = 0; if (_TSize) { - _TexCoords = new real[_TSize]; - memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(real)); + _TexCoords = new float[_TSize]; + memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float)); } _NumFaces = iBrother.numFaces(); @@ -290,16 +290,16 @@ void IndexedFaceSet::accept(SceneVisitor& v) void IndexedFaceSet::ComputeBBox() { - real XMax = _Vertices[0]; - real YMax = _Vertices[1]; - real ZMax = _Vertices[2]; + float XMax = _Vertices[0]; + float YMax = _Vertices[1]; + float ZMax = _Vertices[2]; - real XMin = _Vertices[0]; - real YMin = _Vertices[1]; - real ZMin = _Vertices[2]; + float XMin = _Vertices[0]; + float YMin = _Vertices[1]; + float ZMin = _Vertices[2]; // parse all the coordinates to find the Xmax, YMax, ZMax - real *v = _Vertices; + float *v = _Vertices; for (unsigned int i = 0; i < (_VSize / 3); ++i) { if (*v > XMax) @@ -321,7 +321,7 @@ void IndexedFaceSet::ComputeBBox() ++v; } - setBBox(BBox<Vec3r>(Vec3r(XMin, YMin, ZMin), Vec3r(XMax, YMax, ZMax))); + setBBox(BBox<Vec3f>(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 d3a10aab4dd..8d7bf986bde 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h @@ -114,8 +114,8 @@ public: * arrays desallocation in charge. * 1 : the arrays are copied. The caller is in charge of the arrays, passed as arguments desallocation. */ - IndexedFaceSet(real *iVertices, unsigned iVSize, real *iNormals, unsigned iNSize, FrsMaterial **iMaterials, - unsigned iMSize, real *iTexCoords, unsigned iTSize, unsigned iNumFaces, unsigned *iNumVertexPerFace, + 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); @@ -180,12 +180,12 @@ public: } /*! Accessors */ - virtual const real *vertices() const + virtual const float *vertices() const { return _Vertices; } - virtual const real *normals() const + virtual const float *normals() const { return _Normals; } @@ -195,7 +195,7 @@ public: return _FrsMaterials; } - virtual const real *texCoords() const + virtual const float *texCoords() const { return _TexCoords; } @@ -286,10 +286,10 @@ public: } protected: - real *_Vertices; - real *_Normals; + float *_Vertices; + float *_Normals; FrsMaterial **_FrsMaterials; - real *_TexCoords; + float *_TexCoords; unsigned _VSize; unsigned _NSize; @@ -316,7 +316,6 @@ protected: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedFaceSet") #endif - }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h b/source/blender/freestyle/intern/scene_graph/NodeCamera.h index 5d84a624830..78c34fdef6d 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeCamera.h +++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h @@ -53,7 +53,9 @@ public: /*! 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() {} diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.h b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp index 047ff4b58b5..24c56ff4e28 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.h +++ b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp @@ -18,36 +18,18 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file source/blender/freestyle/intern/python/StrokeShader/BPy_streamShader.h +/** \file blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp * \ingroup freestyle + * \brief Class to represent a scene render layer in Blender. */ -#ifndef __FREESTYLE_PYTHON_STREAMSHADER_H__ -#define __FREESTYLE_PYTHON_STREAMSHADER_H__ +#include "NodeSceneRenderLayer.h" -#include "../BPy_StrokeShader.h" +namespace Freestyle { -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -extern PyTypeObject streamShader_Type; - -#define BPy_streamShader_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&streamShader_Type)) - -/*---------------------------Python BPy_streamShader structure definition----------*/ -typedef struct { - BPy_StrokeShader py_ss; -} BPy_streamShader; - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus +void NodeSceneRenderLayer::accept(SceneVisitor& v) +{ + v.visitNodeSceneRenderLayer(*this); } -#endif - -#endif /* __FREESTYLE_PYTHON_STREAMSHADER_H__ */ +} /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h new file mode 100644 index 00000000000..4b079df5632 --- /dev/null +++ b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h @@ -0,0 +1,76 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__ +#define __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__ + +/** \file blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h + * \ingroup freestyle + * \brief Class to represent a scene render layer in Blender. + */ + +#include "Node.h" + +extern "C" { +#include "DNA_scene_types.h" /* for Scene and SceneRenderLayer */ +} + +using namespace std; + +namespace Freestyle { + +class NodeSceneRenderLayer : public Node +{ +public: + inline NodeSceneRenderLayer(Scene& scene, SceneRenderLayer& srl) : Node(), _Scene(scene), _SceneRenderLayer(srl) {} + virtual ~NodeSceneRenderLayer() {} + + inline struct Scene& scene() const + { + return _Scene; + } + + inline struct SceneRenderLayer& sceneRenderLayer() const + { + return _SceneRenderLayer; + } + + inline void setSceneRenderLayer(Scene& scene) + { + _Scene = scene; + } + + inline void setSceneRenderLayer(SceneRenderLayer& srl) + { + _SceneRenderLayer = srl; + } + + /*! Accept the corresponding visitor */ + virtual void accept(SceneVisitor& v); + +protected: + + Scene& _Scene; + SceneRenderLayer& _SceneRenderLayer; +}; + +} /* namespace Freestyle */ + +#endif // __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__ diff --git a/source/blender/freestyle/intern/scene_graph/Rep.h b/source/blender/freestyle/intern/scene_graph/Rep.h index 88ee0d2a801..c5036cdb153 100644 --- a/source/blender/freestyle/intern/scene_graph/Rep.h +++ b/source/blender/freestyle/intern/scene_graph/Rep.h @@ -117,7 +117,7 @@ public: virtual void ComputeBBox() = 0; /*! Returns the rep bounding box */ - virtual const BBox<Vec3r>& bbox() const + virtual const BBox<Vec3f>& bbox() const { return _BBox; } @@ -127,7 +127,7 @@ public: return _Id; } - inline const string& getName() const + inline const char *getName() const { return _Name; } @@ -138,7 +138,7 @@ public: } /*! Sets the Rep bounding box */ - virtual void setBBox(const BBox<Vec3r>& iBox) + virtual void setBBox(const BBox<Vec3f>& iBox) { _BBox = iBox; } @@ -148,7 +148,7 @@ public: _Id = id; } - inline void setName(const string& name) + inline void setName(const char *name) { _Name = name; } @@ -159,9 +159,9 @@ public: } private: - BBox<Vec3r> _BBox; + BBox<Vec3f> _BBox; Id _Id; - string _Name; + const char *_Name; FrsMaterial *_FrsMaterial; }; diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp new file mode 100644 index 00000000000..9d595c235c2 --- /dev/null +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp @@ -0,0 +1,84 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/freestyle/intern/scene_graph/SceneHash.cpp + * \ingroup freestyle + */ + +#include "SceneHash.h" + +#include <sstream> + +namespace Freestyle { + +string SceneHash::toString() +{ + stringstream ss; + ss << hex << _sum; + return ss.str(); +} + +void SceneHash::visitNodeSceneRenderLayer(NodeSceneRenderLayer& 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 FreestyleConfig *config = &node.sceneRenderLayer().freestyleConfig; + 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) +{ + double *proj = cam.projectionMatrix(); + for (int i = 0; i < 16; i++) { + adler32((unsigned char *)&proj[i], sizeof(double)); + } +} + +void SceneHash::visitIndexedFaceSet(IndexedFaceSet& ifs) +{ + 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])); + } +} + +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; + + 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 new file mode 100644 index 00000000000..9da711673f0 --- /dev/null +++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h @@ -0,0 +1,82 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_SCENE_HASH_H__ +#define __FREESTYLE_SCENE_HASH_H__ + +/** \file blender/freestyle/intern/scene_graph/SceneHash.h + * \ingroup freestyle + */ + +#include "IndexedFaceSet.h" +#include "NodeSceneRenderLayer.h" +#include "NodeCamera.h" +#include "SceneVisitor.h" + +#include "BLI_sys_types.h" + +#ifdef WITH_CXX_GUARDEDALLOC +#include "MEM_guardedalloc.h" +#endif + +namespace Freestyle { + +class SceneHash : public SceneVisitor +{ +public: + inline SceneHash() : SceneVisitor() + { + _sum = 1; + } + + virtual ~SceneHash() {} + + VISIT_DECL(NodeCamera) + VISIT_DECL(NodeSceneRenderLayer) + VISIT_DECL(IndexedFaceSet) + + string toString(); + + inline bool match() { + return _sum == _prevSum; + } + + inline void store() { + _prevSum = _sum; + } + + inline void reset() { + _sum = 1; + } + +private: + void adler32(unsigned char *data, int size); + + uint32_t _sum; + uint32_t _prevSum; + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash") +#endif +}; + +} /* namespace Freestyle */ + +#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 4e87625f6f9..e7041f04cf0 100644 --- a/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp +++ b/source/blender/freestyle/intern/scene_graph/ScenePrettyPrinter.cpp @@ -93,11 +93,11 @@ VISIT(VertexRep) void ScenePrettyPrinter::visitIndexedFaceSet(IndexedFaceSet& ifs) { - const real *vertices = ifs.vertices(); + const float *vertices = ifs.vertices(); unsigned vsize = ifs.vsize(); _ofs << _space << "IndexedFaceSet" << endl; - const real *p = vertices; + 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; diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h index c00f5124a31..712585c4064 100644 --- a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h +++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h @@ -56,6 +56,7 @@ class NodeLight; class NodeCamera; class NodeDrawingStyle; class NodeTransform; +class NodeSceneRenderLayer; class Rep; class LineRep; @@ -87,6 +88,7 @@ public: VISIT_COMPLETE_DEF(NodeCamera) VISIT_COMPLETE_DEF(NodeDrawingStyle) VISIT_COMPLETE_DEF(NodeTransform) + VISIT_COMPLETE_DEF(NodeSceneRenderLayer) VISIT_COMPLETE_DEF(Rep) VISIT_COMPLETE_DEF(LineRep) diff --git a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h index cbdff4ed96c..9df690cf5b0 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h +++ b/source/blender/freestyle/intern/stroke/AdvancedFunctions1D.h @@ -168,7 +168,7 @@ private: // GetDirectionalViewMapDensity /*! Returns the density evaluated for an Interface1D in of the steerable viewmaps image. - * The direction telling which Directional map to choose is explicitely specified by the user. + * The direction telling which Directional map to choose is explicitly specified by the user. * 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. */ diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp index 274e36a4c9b..e37631e5bd6 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.cpp @@ -81,20 +81,6 @@ int CalligraphicShader::shade(Stroke &ioStroke) const return 0; } -#if 0 -void TipRemoverShader::shade(Stroke &ioStroke) const -{ - StrokeInternal::StrokeVertexIterator v, vend; - for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v) { - if (((*v)->curvilinearAbscissa() < _tipLength) || - (((*v)->strokeLength() - (*v)->curvilinearAbscissa()) < _tipLength)) { - (*v)->attribute().setThickness(0.0, 0.0); - (*v)->attribute().setColor(1, 1, 1); - } - } -} -#endif - ///////////////////////////////////////// // // SPATIAL NOISE SHADER @@ -347,63 +333,4 @@ void Smoother::copyVertices() _stroke->UpdateLength(); } -#if 0 // FIXME - -///////////////////////////////////////// -// -// OMISSION SHADER -// -///////////////////////////////////////// - -OmissionShader::OmissionShader(real sizeWindow, real thrVari, real thrFlat, real lFlat) -{ - _sizeWindow = sizeWindow; - _thresholdVariation = thrVari; - _thresholdFlat = thrFlat; - _lengthFlat = lFlat; -} - -int OmissionShader::shade(Stroke &ioStroke) const -{ - Omitter omi(ioStroke); - omi.omit(_sizeWindow, _thresholdVariation, _thresholdFlat, _lengthFlat); - - return 0; -} - - -// OMITTER -/////////////////////////// - -Omitter::Omitter(Stroke &ioStroke) : Smoother(ioStroke) -{ - StrokeInternal::StrokeVertexIterator v, vend; - int i = 0; - for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v, ++i) { - _u[i] = (v)->curvilinearAbscissa(); - } -} - -void Omitter::omit(real sizeWindow, real thrVari, real thrFlat, real lFlat) -{ - _sizeWindow=sizeWindow; - _thresholdVariation=thrVari; - _thresholdFlat=thrFlat; - _lengthFlat=lFlat; - - for (int i = 1; i < _nbVertices-1; ++i) { - if (_u[i] < _lengthFlat) - continue; - // is the previous segment flat? - int j = i - 1; - while ((j >= 0) && (_u[i] - _u[j] < _lengthFlat)) { - if ((_normal[j] * _normal[i]) < _thresholdFlat) - ; // FIXME - --j; - } - } -} - -#endif - } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index 69ca45d3ec7..eed90a53d77 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -43,9 +43,6 @@ #include "BKE_global.h" -//soc #include <qimage.h> -//soc #include <QString> - extern "C" { # include "IMB_imbuf.h" # include "IMB_imbuf_types.h" @@ -53,32 +50,6 @@ extern "C" { namespace Freestyle { -// Internal function - -#if 0 // soc -void convert(const QImage& iImage, float **oArray, unsigned &oSize) -{ - oSize = iImage.width(); - *oArray = new float[oSize]; - for (unsigned int i = 0; i < oSize; ++i) { - QRgb rgb = iImage.pixel(i,0); - (*oArray)[i] = ((float)qBlue(rgb)) / 255.0f; - } -} -#endif - -static void convert(ImBuf *imBuf, float **oArray, unsigned &oSize) -{ - oSize = imBuf->x; - *oArray = new float[oSize]; - - char *pix; - for (unsigned int i = 0; i < oSize; ++i) { - pix = (char *) imBuf->rect + i * 4; - (*oArray)[i] = ((float) pix[2]) / 255.0f; - } -} - namespace StrokeShaders { // @@ -191,76 +162,6 @@ int LengthDependingThicknessShader::shade(Stroke& stroke) const return 0; } - -ThicknessVariationPatternShader::ThicknessVariationPatternShader(const string pattern_name, float iMinThickness, - float iMaxThickness, bool stretch) -: StrokeShader() -{ - _stretch = stretch; - _minThickness = iMinThickness; - _maxThickness = iMaxThickness; - ImBuf *image = NULL; - vector<string> pathnames; - StringUtils::getPathName(TextureManager::Options::getPatternsPath(), pattern_name, pathnames); - for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); ++j) { - ifstream ifs(j->c_str()); - if (ifs.is_open()) { - /* OCIO_TODO: support different input color space */ - image = IMB_loadiffname(j->c_str(), 0, NULL); - break; - } - } - if (image == NULL) - cerr << "Error: cannot find pattern \"" << pattern_name << "\" - check the path in the Options" << endl; - else - convert(image, &_aThickness, _size); - IMB_freeImBuf(image); -} - - -int ThicknessVariationPatternShader::shade(Stroke& stroke) const -{ - StrokeInternal::StrokeVertexIterator v, vend; - float *array = NULL; - /* int size; */ /* UNUSED */ - array = _aThickness; - /* size = _size; */ /* UNUSED */ - int vert_size = stroke.strokeVerticesSize(); - int sig = 0; - unsigned index; - const float *originalThickness; - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - originalThickness = v->attribute().getThickness(); - if (_stretch) { - float tmp = v->u() * (_size - 1); - index = (unsigned)floor(tmp); - if ((tmp - index) > (index + 1 - tmp)) - ++index; - } - else { - index = (unsigned)floor(v->curvilinearAbscissa()); - } - index %= _size; - float thicknessR = array[index] * originalThickness[0]; - float thicknessL = array[index] * originalThickness[1]; - if (thicknessR + thicknessL < _minThickness) { - thicknessL = _minThickness / 2.0f; - thicknessR = _minThickness / 2.0f; - } - if (thicknessR + thicknessL > _maxThickness) { - thicknessL = _maxThickness / 2.0f; - thicknessR = _maxThickness / 2.0f; - } - if ((sig == 0) || (sig == vert_size - 1)) - v->attribute().setThickness(1, 1); - else - v->attribute().setThickness(thicknessR, thicknessL); - ++sig; - } - return 0; -} - - static const unsigned NB_VALUE_NOISE = 512; ThicknessNoiseShader::ThicknessNoiseShader() : StrokeShader() @@ -284,7 +185,7 @@ int ThicknessNoiseShader::shade(Stroke& stroke) const real bruit, bruit2; PseudoNoise mynoise, mynoise2; for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU1, 2); // 2 : nbOctaves + 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]; @@ -328,51 +229,6 @@ int IncreasingColorShader::shade(Stroke& stroke) const return 0; } -ColorVariationPatternShader::ColorVariationPatternShader(const string pattern_name, bool stretch) : StrokeShader() -{ - _stretch = stretch; - ImBuf *image = NULL; - vector<string> pathnames; - StringUtils::getPathName(TextureManager::Options::getPatternsPath(), pattern_name, pathnames); - for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); ++j) { - ifstream ifs(j->c_str()); - if (ifs.is_open()) { - /* OCIO_TODO: support different input color space */ - image = IMB_loadiffname(j->c_str(), 0, NULL); //soc - break; - } - } - if (image == NULL) - cerr << "Error: cannot find pattern \"" << pattern_name << "\" - check the path in the Options" << endl; - else - convert(image, &_aVariation, _size); - IMB_freeImBuf(image); -} - -int ColorVariationPatternShader::shade(Stroke& stroke) const -{ - StrokeInternal::StrokeVertexIterator v, vend; - unsigned index; - for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - const float *originalColor = v->attribute().getColor(); - if (_stretch) { - float tmp = v->u() * (_size - 1); - index = (unsigned)floor(tmp); - if ((tmp - index) > (index + 1 - tmp)) - ++index; - } - else { - index = (unsigned)floor(v->curvilinearAbscissa()); - } - index %= _size; - float r = _aVariation[index] * originalColor[0]; - float g = _aVariation[index] * originalColor[1]; - float b = _aVariation[index] * originalColor[2]; - v->attribute().setColor(r, g, b); - } - return 0; -} - int MaterialColorShader::shade(Stroke& stroke) const { Interface0DIterator v, vend; @@ -389,29 +245,6 @@ int MaterialColorShader::shade(Stroke& stroke) const return 0; } - -int CalligraphicColorShader::shade(Stroke& stroke) const -{ - Interface0DIterator v; - Functions0D::VertexOrientation2DF0D fun; - StrokeVertex *sv; - for (v = stroke.verticesBegin(); !v.isEnd(); ++v) { - if (fun(v) < 0) - return -1; - Vec2f vertexOri(fun.result); - Vec2d ori2d(-vertexOri[1], vertexOri[0]); - ori2d.normalizeSafe(); - real scal = ori2d * _orientation; - sv = dynamic_cast<StrokeVertex*>(&(*v)); - if ((scal < 0)) - sv->attribute().setColor(0, 0, 0); - else - sv->attribute().setColor(1, 1, 1); - } - return 0; -} - - ColorNoiseShader::ColorNoiseShader() : StrokeShader() { _amplitude = 1.0f; @@ -439,11 +272,9 @@ int ColorNoiseShader::shade(Stroke& stroke) const float b = bruit * _amplitude + originalColor[2]; v->attribute().setColor(r, g, b); } - return 0; } - // // Texture Shaders // @@ -466,19 +297,6 @@ int StrokeTextureStepShader::shade(Stroke& stroke) const return 0; } -// Legacy shaders from freestyle standalone texture system -int TextureAssignerShader::shade(Stroke& stroke) const -{ - cout << "TextureAssignerShader is not supported in blender, please use the BlenderTextureShader" << endl; - return 0; -} - -int StrokeTextureShader::shade(Stroke& stroke) const -{ - cout << "StrokeTextureShader is not supported in blender, please use the BlenderTextureShader" << endl; - return 0; -} - // // Geometry Shaders // @@ -541,119 +359,6 @@ int ExternalContourStretcherShader::shade(Stroke& stroke) const return 0; } -int BSplineShader::shade(Stroke& stroke) const -{ - if (stroke.strokeVerticesSize() < 4) - return 0; - - // Find the new vertices - vector<Vec2d> newVertices; - double t = 0.0; - float _sampling = 5.0f; - - StrokeInternal::StrokeVertexIterator p0, p1, p2, p3, end; - p0 = stroke.strokeVerticesBegin(); - p1 = p0; - p2 = p1; - p3 = p2; - end = stroke.strokeVerticesEnd(); - double a[4], b[4]; - int n = 0; - while (p1 != end) { -#if 0 - if (p1 == end) - p1 = p0; -#endif - if (p2 == end) - p2 = p1; - if (p3 == end) - p3 = p2; - // compute new matrix - a[0] = (-(p0)->x() + 3 * (p1)->x() - 3 * (p2)->x() + (p3)->x()) / 6.0; - a[1] = (3 * (p0)->x() - 6 * (p1)->x() + 3 * (p2)->x()) / 6.0; - a[2] = (-3 * (p0)->x() + 3 * (p2)->x()) / 6.0; - a[3] = ((p0)->x() + 4 * (p1)->x() + (p2)->x()) / 6.0; - - b[0] = (-(p0)->y() + 3 * (p1)->y() - 3 * (p2)->y() + (p3)->y()) / 6.0; - b[1] = (3 * (p0)->y() - 6 * (p1)->y() + 3 * (p2)->y()) / 6.0; - b[2] = (-3 * (p0)->y() + 3 * (p2)->y()) / 6.0; - b[3] = ((p0)->y() + 4 * (p1)->y() + (p2)->y()) / 6.0; - - // draw the spline depending on resolution: - Vec2d p1p2((p2)->x() - (p1)->x(), (p2)->y() - (p1)->y()); - double norm = p1p2.norm(); - //t = _sampling / norm; - t = 0; - while (t < 1) { - newVertices.push_back(Vec2d((a[3] + t * (a[2] + t * (a[1] + t * a[0]))), - (b[3] + t * (b[2] + t * (b[1] + t * b[0]))))); - t = t + _sampling / norm; - } - if (n > 2) { - ++p0; - ++p1; - ++p2; - ++p3; - } - else { - if (n == 0) - ++p3; - if (n == 1) { - ++p2; - ++p3; - } - if (n == 2) { - ++p1; - ++p2; - ++p3; - } - ++n; - } - } - //last point: - newVertices.push_back(Vec2d((p0)->x(), (p0)->y())); - - int originalSize = newVertices.size(); - _sampling = stroke.ComputeSampling(originalSize); - - // Resample and set x,y coordinates - stroke.Resample(_sampling); - int newsize = stroke.strokeVerticesSize(); - - int nExtraVertex = 0; - if (newsize < originalSize) { - cerr << "Warning: unsufficient resampling" << endl; - } - else { - nExtraVertex = newsize - originalSize; - } - - // assigns the new coordinates: - vector<Vec2d>::iterator p = newVertices.begin(), pend = newVertices.end(); - vector<Vec2d>::iterator last = p; - n = 0; - StrokeInternal::StrokeVertexIterator it, itend; - for (it = stroke.strokeVerticesBegin(), itend = stroke.strokeVerticesEnd(); - (it != itend) && (p != pend); - ++it, ++p, ++n) - { - it->setX(p->x()); - it->setY(p->y()); - last = p; - } - - // nExtraVertex should stay unassigned - for (int i = 0; i < nExtraVertex; ++i, ++it, ++n) { - it->setX(last->x()); - it->setY(last->y()); - if (it.isEnd()) { - // XXX Shouldn't we break in this case??? - cerr << "Warning: Problem encountered while creating B-spline" << endl; - } - } - stroke.UpdateLength(); - return 0; -} //!! Bezier curve stroke shader int BezierCurveShader::shade(Stroke& stroke) const @@ -673,15 +378,6 @@ int BezierCurveShader::shade(Stroke& stroke) const previous = v; } -#if 0 - Vec2d tmp; - bool equal = false; - if (data.front() == data.back()) { - tmp = data.back(); - data.pop_back(); - equal = true; - } -#endif // here we build the bezier curve BezierCurve bcurve(data, _error); @@ -702,25 +398,6 @@ int BezierCurveShader::shade(Stroke& stroke) const } } -#if 0 - if (equal) { - if (data.back() == data.front()) { - vector<Vec2d>::iterator d = data.begin(), dend; - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "ending point = starting point" << endl; - cout << "---------------DATA----------" << endl; - for (dend = data.end(); d != dend; ++d) { - cout << d->x() << "-" << d->y() << endl; - } - cout << "--------------BEZIER RESULT----------" << endl; - for (d = CurveVertices.begin(), dend = CurveVertices.end(); d != dend; ++d) { - cout << d->x() << "-" << d->y() << endl; - } - } - } - } -#endif - // Resample the Stroke depending on the number of vertices of the bezier curve: int originalSize = CurveVertices.size(); #if 0 @@ -734,11 +411,6 @@ int BezierCurveShader::shade(Stroke& stroke) const cerr << "Warning: unsufficient resampling" << endl; } else { -#if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "Oversampling" << endl; - } -#endif nExtraVertex = newsize - originalSize; if (nExtraVertex != 0) { if (G.debug & G_DEBUG_FREESTYLE) { @@ -752,22 +424,12 @@ int BezierCurveShader::shade(Stroke& stroke) const vector<Vec2d>::iterator last = p; int n; StrokeInternal::StrokeVertexIterator it, itend; -#if 0 - for (; p != pend; ++n, ++p); -#endif 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()); -#if 0 - double x = p->x(); - double y = p->y(); - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "x = " << x << "-" << "y = " << y << endl; - } -#endif last = p; } stroke.UpdateLength(); @@ -816,46 +478,6 @@ int BezierCurveShader::shade(Stroke& stroke) const return 0; } -int InflateShader::shade(Stroke& stroke) const -{ - // we're computing the curvature variance of the stroke. (Combo 5) - // If it's too high, forget about it - Functions1D::Curvature2DAngleF1D fun; - if (fun(stroke) < 0) - return -1; - if (fun.result > _curvatureThreshold) - return 0; - - Functions0D::VertexOrientation2DF0D ori_fun; - Functions0D::Curvature2DAngleF0D curv_fun; - Functions1D::Normal2DF1D norm_fun; - Interface0DIterator it; - StrokeVertex *sv; - for (it = stroke.verticesBegin(); !it.isEnd(); ++it) { - if (ori_fun(it) < 0) - return -1; - Vec2f ntmp(ori_fun.result); - Vec2f n(ntmp.y(), -ntmp.x()); - if (norm_fun(stroke) < 0) - return -1; - Vec2f strokeN(norm_fun.result); - if (n * strokeN < 0) { - n[0] = -n[0]; - n[1] = -n[1]; - } - sv = dynamic_cast<StrokeVertex*>(&(*it)); - float u = sv->u(); - float t = 4.0f * (0.25f - (u - 0.5) * (u - 0.5)); - if (curv_fun(it) < 0) - return -1; - float curvature_coeff = (M_PI - curv_fun.result) / M_PI; - Vec2d newPoint(sv->x() + curvature_coeff * t * _amount * n.x(), - sv->y() + curvature_coeff * t * _amount * n.y()); - sv->setPoint(newPoint[0], newPoint[1]); - } - stroke.UpdateLength(); - return 0; -} class CurvePiece { @@ -1040,40 +662,16 @@ int TipRemoverShader::shade(Stroke& stroke) const // assign old attributes to new stroke vertices: vector<StrokeAttribute>::iterator a = oldAttributes.begin(), aend = oldAttributes.end(); -#if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "-----------------------------------------------" << endl; - } -#endif for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); (v != vend) && (a != aend); ++v, ++a) { v->setAttribute(*a); -#if 0 - if (G.debug & G_DEBUG_FREESTYLE) { - cout << "thickness = " << (*a).getThickness()[0] << "-" << (*a).getThickness()[1] << endl; - } -#endif } // we're done! return 0; } -int streamShader::shade(Stroke& stroke) const -{ - if (G.debug & G_DEBUG_FREESTYLE) { - cout << stroke << endl; - } - return 0; -} - -int fstreamShader::shade(Stroke& stroke) const -{ - _stream << stroke << endl; - return 0; -} - } // 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 6ac22c5b2d1..e3842f45eb0 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h @@ -218,51 +218,6 @@ public: virtual int shade(Stroke& stroke) const; }; -/*! [ Thickness Shader ]. -* Applys a pattern (texture) to vary thickness. -* The new thicknesses are the result of the multiplication -* of the pattern and the original thickness -*/ -class ThicknessVariationPatternShader : public StrokeShader -{ -public: - /*! Builds the shader. - * \param pattern_name - * The texture file name. - * \param iMinThickness - * The minimum thickness we don't want to exceed. - * \param iMaxThickness - * The maximum thickness we don't want to exceed. - * \param stretch - * Tells whether the pattern texture must be stretched or repeted to fit the stroke. - */ - ThicknessVariationPatternShader(const string pattern_name, float iMinThickness = 1.0f, float iMaxThickness = 5.0f, - bool stretch = true); - - /*! Destructor.*/ - virtual ~ThicknessVariationPatternShader() - { - if (0 != _aThickness) { - delete[] _aThickness; - _aThickness = 0; - } - } - - virtual string getName() const - { - return "ThicknessVariationPatternShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; - -private: - float *_aThickness; // array of thickness values, in % of the max (i.e comprised between 0 and 1) - unsigned _size; - float _minThickness; - float _maxThickness; - bool _stretch; -}; /*! [ Thickness Shader ]. * Adds some noise to the stroke thickness. @@ -389,44 +344,6 @@ public: virtual int shade(Stroke& stroke) const; }; -/*! [ Color Shader ]. - * Applys a pattern to vary original color. - * The new color is the result of the multiplication of the pattern and the original color - */ -class ColorVariationPatternShader : public StrokeShader -{ -public: - /*! Builds the shader from the pattern texture file name. - * \param pattern_name - * The file name of the texture file to use as pattern - * \param stretch - * Tells whether the texture must be strecthed or repeted to fit the stroke. - */ - ColorVariationPatternShader(const string pattern_name, bool stretch = true); - - /*! Destructor */ - virtual ~ColorVariationPatternShader() - { - if (0 != _aVariation) { - delete[] _aVariation; - _aVariation = 0; - } - } - - virtual string getName() const - { - return "ColorVariationPatternShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; - -private: - float *_aVariation; // array of coef values, in % of the max (i.e comprised between 0 and 1) - unsigned _size; - bool _stretch; -}; - /* [ Color Shader ]. * Assigns a color to the stroke depending on the material of the shape to which ot belongs to. (Disney shader) */ @@ -449,28 +366,6 @@ public: virtual int shade(Stroke& stroke) const; }; -class CalligraphicColorShader : public StrokeShader -{ -private: - /* UNUSED */ - // int _textureId; - Vec2d _orientation; - -public: - CalligraphicColorShader(const Vec2d &iOrientation) : StrokeShader() - { - _orientation = iOrientation; - _orientation.normalize(); - } - - virtual string getName() const - { - return "CalligraphicColorShader"; - } - - virtual int shade(Stroke& stroke) const; -}; - /*! [ Color Shader ]. * Shader to add noise to the stroke colors. */ @@ -501,105 +396,6 @@ public: }; // -// Texture Shaders -// -/////////////////////////////////////////////////////////////////////////////// -/*! [ Texture Shader ]. -* Assigns a texture to the stroke in order to simulate -* its marks system. This shader takes as input an integer value -* telling which texture and blending mode to use among a set of -* predefined textures. -* Here are the different presets: -* 0) -> /brushes/charcoalAlpha.bmp, HUMID_MEDIUM -* 1) -> /brushes/washbrushAlpha.bmp, HUMID_MEDIUM -* 2) -> /brushes/oil.bmp, HUMID_MEDIUM -* 3) -> /brushes/oilnoblend.bmp, HUMID_MEDIUM -* 4) -> /brushes/charcoalAlpha.bmp, DRY_MEDIUM -* 5) -> /brushes/washbrushAlpha.bmp, DRY_MEDIUM -* 6) -> /brushes/opaqueDryBrushAlpha.bmp, OPAQUE_MEDIUM -* 7) -> /brushes/opaqueBrushAlpha.bmp, Stroke::OPAQUE_MEDIUM -* Any other value will lead to the following preset: -* default) -> /brushes/smoothAlpha.bmp, OPAQUE_MEDIUM. -*/ -class TextureAssignerShader : public StrokeShader // FIXME -{ -private: - int _textureId; - -public: - /*! Builds the shader. - * \param id - * The number of the preset to use. - */ - TextureAssignerShader(int id) : StrokeShader() - { - _textureId = id; - } - - virtual string getName() const - { - return "TextureAssignerShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; -}; - -/*! [ Texture Shader ]. -* Assigns a texture and a blending mode to the stroke -* in order to simulate its marks system. -*/ -class StrokeTextureShader : public StrokeShader -{ -private: - string _texturePath; - Stroke::MediumType _mediumType; - bool _tips; // 0 or 1 - -public: - /*! Builds the shader from the texture file name and the blending mode to use. - * \param textureFile - * The the texture file name. - * \attention The textures must be placed in the $FREESTYLE_DIR/data/textures/brushes directory. - * \param mediumType - * The medium type and therefore, the blending mode that must be used for the rendering of this stroke. - * \param iTips - * Tells whether the texture includes tips or not. - * If it is the case, the texture image must respect the following format: - * \verbatim - * __________ - * | | - * | A | - * |__________| - * | | | - * | B | C | - * |_____|____| - * - * \endverbatim - * - A : The stroke's corpus texture - * - B : The stroke's left extremity texture - * - C : The stroke's right extremity texture - */ - StrokeTextureShader(const string textureFile, Stroke::MediumType mediumType = Stroke::OPAQUE_MEDIUM, - bool iTips = false) - : StrokeShader() - { - _texturePath = textureFile; - _mediumType = mediumType; - _tips = iTips; - } - - virtual string getName() const - { - return "StrokeTextureShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; -}; - - -// // Geometry Shaders // /////////////////////////////////////////////////////////////////////////////// @@ -678,20 +474,6 @@ public: virtual int shade(Stroke& stroke) const; }; -// B-Spline stroke shader -class BSplineShader: public StrokeShader -{ -public: - BSplineShader() : StrokeShader() {} - - virtual string getName() const - { - return "BSplineShader"; - } - - virtual int shade(Stroke& stroke) const; -}; - // Bezier curve stroke shader /*! [ Geometry Shader ]. @@ -724,37 +506,6 @@ public: virtual int shade(Stroke& stroke) const; }; -/* Shader to inflate the curves. It keeps the extreme points positions and moves the other ones along the 2D normal. - * The displacement value is proportional to the 2d curvature at the considered point (the higher the curvature, - * the smaller the displacement) and to a value specified by the user. - */ -class InflateShader : public StrokeShader -{ -private: - float _amount; - float _curvatureThreshold; - -public: - /*! Builds an inflate shader - * \param iAmount - * A multiplicative coefficient that acts on the amount and direction of displacement - * \param iThreshold - * The curves having a 2d curvature > iThreshold at one of their points is not inflated - */ - InflateShader(float iAmount, float iThreshold) : StrokeShader() - { - _amount = iAmount; - _curvatureThreshold = iThreshold; - } - - virtual string getName() const - { - return "InflateShader"; - } - - /*! The shading method */ - virtual int shade(Stroke& stroke) const; -}; /*! [ Geometry Shader ]. * Shader to modify the Stroke geometry so that it looks more "polygonal". @@ -846,59 +597,6 @@ protected: real _tipLength; }; -/*! [ output Shader ]. - * streams the Stroke - */ -class streamShader : public StrokeShader -{ -public: - /*! Destructor. */ - virtual ~streamShader() {} - - /*! Returns the string "streamShader".*/ - virtual string getName() const - { - return "streamShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; -}; - -/*! [ output Shader ]. - * streams the Stroke in a file - */ -class fstreamShader : public StrokeShader -{ -protected: - mutable ofstream _stream; - -public: - /*! Builds the shader from the output file name */ - fstreamShader(const char *iFileName) : StrokeShader() - { - _stream.open(iFileName); - if (!_stream.is_open()) { - cerr << "couldn't open file " << iFileName << endl; - } - } - - /*! Destructor. */ - virtual ~fstreamShader() - { - _stream.close(); - } - - /*! Returns the string "fstreamShader".*/ - virtual string getName() const - { - return "fstreamShader"; - } - - /*! The shading method. */ - virtual int shade(Stroke& stroke) const; -}; - /*! [ Texture Shader ]. * Shader to assign texture to the Stroke material. */ diff --git a/source/blender/freestyle/intern/stroke/Canvas.cpp b/source/blender/freestyle/intern/stroke/Canvas.cpp index 69d37f61df9..63cb58b4042 100644 --- a/source/blender/freestyle/intern/stroke/Canvas.cpp +++ b/source/blender/freestyle/intern/stroke/Canvas.cpp @@ -425,7 +425,7 @@ void Canvas::loadMap(const char *iFileName, const char *iMapName, unsigned int i stringstream filename; filename << base; filename << i << ".bmp"; - qtmp->ftype = BMP; + qtmp->ftype = IMB_FTYPE_BMP; IMB_saveiff(qtmp, const_cast<char *>(filename.str().c_str()), 0); } diff --git a/source/blender/freestyle/intern/stroke/Canvas.h b/source/blender/freestyle/intern/stroke/Canvas.h index b56b5f92c14..5919344b6e0 100644 --- a/source/blender/freestyle/intern/stroke/Canvas.h +++ b/source/blender/freestyle/intern/stroke/Canvas.h @@ -95,6 +95,7 @@ protected: static const char *_MapsPath; SteerableViewMap *_steerableViewMap; bool _basic; + int stroke_count; public: /* Builds the Canvas */ @@ -213,7 +214,10 @@ public: return false; } - int stroke_count; + inline int getStrokeCount() const + { + return stroke_count; + } /*! modifiers */ inline void setSelectedFEdge(FEdge *iFEdge) diff --git a/source/blender/freestyle/intern/stroke/Chain.cpp b/source/blender/freestyle/intern/stroke/Chain.cpp index 7fd756472b0..0e8c2c9ae6f 100644 --- a/source/blender/freestyle/intern/stroke/Chain.cpp +++ b/source/blender/freestyle/intern/stroke/Chain.cpp @@ -59,6 +59,7 @@ void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation) 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); @@ -119,6 +120,7 @@ void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation) 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); diff --git a/source/blender/freestyle/intern/stroke/Chain.h b/source/blender/freestyle/intern/stroke/Chain.h index 95e825e270b..6cf3a7199bf 100644 --- a/source/blender/freestyle/intern/stroke/Chain.h +++ b/source/blender/freestyle/intern/stroke/Chain.h @@ -106,6 +106,10 @@ public: { return _splittingId; } + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chain") +#endif }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/ChainingIterators.h b/source/blender/freestyle/intern/stroke/ChainingIterators.h index 5d05ed2776d..4ece24c5ecf 100644 --- a/source/blender/freestyle/intern/stroke/ChainingIterators.h +++ b/source/blender/freestyle/intern/stroke/ChainingIterators.h @@ -101,7 +101,7 @@ public: return _internalIterator.isBegin(); } - /*! Returns true if the current ViewEdge is is coming towards the iteration vertex. False otherwise. */ + /*! Returns true if the current ViewEdge is coming towards the iteration vertex. False otherwise. */ bool isIncoming() const; /*! Returns a *pointer* to the pointed ViewEdge. */ diff --git a/source/blender/freestyle/intern/stroke/Curve.cpp b/source/blender/freestyle/intern/stroke/Curve.cpp index 32cfac016d6..69c5dcdfe28 100644 --- a/source/blender/freestyle/intern/stroke/Curve.cpp +++ b/source/blender/freestyle/intern/stroke/Curve.cpp @@ -25,6 +25,8 @@ * \date 11/01/2003 */ +#include <stdio.h> /* printf */ + #include "Curve.h" #include "CurveIterators.h" #include "CurveAdvancedIterators.h" diff --git a/source/blender/freestyle/intern/stroke/Curve.h b/source/blender/freestyle/intern/stroke/Curve.h index 6b799c921a4..726b238c74b 100644 --- a/source/blender/freestyle/intern/stroke/Curve.h +++ b/source/blender/freestyle/intern/stroke/Curve.h @@ -341,6 +341,10 @@ public: real curvatureFredo() const; Vec2d directionFredo() const; #endif + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint") +#endif }; @@ -586,6 +590,10 @@ public: * 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") +#endif }; } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/stroke/Operators.cpp b/source/blender/freestyle/intern/stroke/Operators.cpp index 427994f80f1..87ba34e8f42 100644 --- a/source/blender/freestyle/intern/stroke/Operators.cpp +++ b/source/blender/freestyle/intern/stroke/Operators.cpp @@ -1242,7 +1242,7 @@ error: return -1; } -void Operators::reset() +void Operators::reset(bool removeStrokes) { ViewMap *vm = ViewMap::getInstance(); if (!vm) { @@ -1253,11 +1253,7 @@ void Operators::reset() for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end(); ++it) delete *it; _current_chains_set.clear(); -#if 0 - _current_view_edges_set.insert(_current_view_edges_set.begin(), - vm->ViewEdges().begin(), - vm->ViewEdges().end()); -#else + ViewMap::viewedges_container& vedges = vm->ViewEdges(); ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end(); for (; ve != veend; ++ve) { @@ -1265,9 +1261,9 @@ void Operators::reset() continue; _current_view_edges_set.push_back(*ve); } -#endif _current_set = &_current_view_edges_set; - _current_strokes_set.clear(); + 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 59ebec57246..c7b0e3f8b81 100644 --- a/source/blender/freestyle/intern/stroke/Operators.h +++ b/source/blender/freestyle/intern/stroke/Operators.h @@ -259,7 +259,7 @@ public: return &_current_strokes_set; } - static void reset(); + static void reset(bool removeStrokes=true); private: Operators() {} diff --git a/source/blender/freestyle/intern/stroke/Predicates1D.h b/source/blender/freestyle/intern/stroke/Predicates1D.h index 46efeae9f12..05fc043822f 100644 --- a/source/blender/freestyle/intern/stroke/Predicates1D.h +++ b/source/blender/freestyle/intern/stroke/Predicates1D.h @@ -471,7 +471,7 @@ public: } /*! The () operator. */ - int operator()(Interface1D& i1, Interface1D& i2) + int operator()(Interface1D& /*i1*/, Interface1D& /*i2*/) { result = true; return 0; @@ -490,7 +490,7 @@ public: } /*! The () operator. */ - int operator()(Interface1D& i1, Interface1D& i2) + int operator()(Interface1D& /*i1*/, Interface1D& /*i2*/) { result = false; return 0; diff --git a/source/blender/freestyle/intern/stroke/Stroke.cpp b/source/blender/freestyle/intern/stroke/Stroke.cpp index 863da069259..b4a3646edef 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.cpp +++ b/source/blender/freestyle/intern/stroke/Stroke.cpp @@ -400,6 +400,7 @@ Stroke::Stroke() } _nodeTree = NULL; _tips = false; + _rep = NULL; } Stroke::Stroke(const Stroke& iBrother) @@ -427,6 +428,10 @@ Stroke::Stroke(const Stroke& iBrother) } _nodeTree = iBrother._nodeTree; _tips = iBrother._tips; + if (iBrother._rep) + _rep = new StrokeRep(*(iBrother._rep)); + else + _rep = NULL; } Stroke::~Stroke() @@ -439,6 +444,10 @@ Stroke::~Stroke() } _ViewEdges.clear(); + if (_rep) { + delete _rep; + _rep = NULL; + } } Stroke& Stroke::operator=(const Stroke& iBrother) @@ -456,6 +465,12 @@ Stroke& Stroke::operator=(const Stroke& iBrother) _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; } @@ -737,12 +752,12 @@ Interface0DIterator Stroke::verticesEnd() return ret; } -Interface0DIterator Stroke::pointsBegin(float t) +Interface0DIterator Stroke::pointsBegin(float /*t*/) { return verticesBegin(); // FIXME } -Interface0DIterator Stroke::pointsEnd(float t) +Interface0DIterator Stroke::pointsEnd(float /*t*/) { return verticesEnd(); } @@ -757,14 +772,16 @@ void Stroke::ScaleThickness(float iFactor) void Stroke::Render(const StrokeRenderer *iRenderer) { - StrokeRep rep(this); - iRenderer->RenderStrokeRep(&rep); + if (!_rep) + _rep = new StrokeRep(this); + iRenderer->RenderStrokeRep(_rep); } void Stroke::RenderBasic(const StrokeRenderer *iRenderer) { - StrokeRep rep(this); - iRenderer->RenderStrokeRepBasic(&rep); + if (!_rep) + _rep = new StrokeRep(this); + iRenderer->RenderStrokeRep(_rep); } Stroke::vertex_iterator Stroke::vertices_begin(float sampling) diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index 86c667a38b6..5f0b4eab309 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -474,6 +474,10 @@ public: /* interface definition */ /* inherited */ + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertex") +#endif }; @@ -545,6 +549,7 @@ private: MTex *_mtex[MAX_MTEX]; bNodeTree *_nodeTree; bool _tips; + StrokeRep *_rep; Vec2r _extremityOrientations[2]; // the orientations of the first and last extermity public: @@ -862,6 +867,10 @@ public: 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") +#endif }; diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index f7857107006..ab06e207331 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -425,7 +425,7 @@ void Strip::cleanUpSingularities (const vector<StrokeVertex*>& iStrokeVertices) 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); + 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]; diff --git a/source/blender/freestyle/intern/system/BaseObject.h b/source/blender/freestyle/intern/system/BaseObject.h index 8cabd9130b4..945c2c8d35e 100644 --- a/source/blender/freestyle/intern/system/BaseObject.h +++ b/source/blender/freestyle/intern/system/BaseObject.h @@ -46,7 +46,7 @@ public: virtual ~BaseObject() {} /*! At least makes a release on this. - * The BaseObject::destroy method must be explicitely called at the end of any overloaded destroy + * The BaseObject::destroy method must be explicitly called at the end of any overloaded destroy */ virtual int destroy() { diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h index 60193590944..ddb79b2df0b 100644 --- a/source/blender/freestyle/intern/system/PythonInterpreter.h +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -51,6 +51,8 @@ extern "C" { #include "BKE_text.h" #include "BPY_extern.h" + +#include "bpy_util.h" } namespace Freestyle { @@ -105,6 +107,26 @@ public: return 0; } + int interpretString(const string& str, const string& name) + { + ReportList *reports = CTX_wm_reports(_context); + + BKE_reports_clear(reports); + + if (BPY_string_exec(_context, str.c_str()) != 0) { + 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); + + return 0; + } + int interpretText(struct Text *text, const string& name) { ReportList *reports = CTX_wm_reports(_context); diff --git a/source/blender/freestyle/intern/system/StringUtils.h b/source/blender/freestyle/intern/system/StringUtils.h index 77b543c7886..e11798762e4 100644 --- a/source/blender/freestyle/intern/system/StringUtils.h +++ b/source/blender/freestyle/intern/system/StringUtils.h @@ -36,7 +36,8 @@ extern "C" { #include "BKE_utildefines.h" -#include "BLI_blenlib.h" +#include "BLI_string.h" +#include "BLI_path_util.h" } using namespace std; diff --git a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp index 8bc7c0952a8..3243c4d1fb7 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.cpp @@ -100,22 +100,22 @@ ArbitraryGridDensityProviderFactory::ArbitraryGridDensityProviderFactory(unsigne ArbitraryGridDensityProviderFactory::~ArbitraryGridDensityProviderFactory() {} -auto_ptr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, - const real proscenium[4]) +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, + const real proscenium[4]) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, proscenium, numCells)); + return AutoPtr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, proscenium, numCells)); } -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, const GridHelpers::Transform& transform) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); + return AutoPtr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, bbox, transform, numCells)); } -auto_ptr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr<GridDensityProvider> ArbitraryGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) { - return auto_ptr<GridDensityProvider>(new ArbitraryGridDensityProvider(source, numCells)); + return AutoPtr<GridDensityProvider>(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 652cb9b34b0..c7939d34da4 100644 --- a/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/ArbitraryGridDensityProvider.h @@ -58,10 +58,10 @@ public: ArbitraryGridDensityProviderFactory(unsigned numCells); ~ArbitraryGridDensityProviderFactory(); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); protected: unsigned numCells; diff --git a/source/blender/freestyle/intern/view_map/AutoPtrHelper.h b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h new file mode 100644 index 00000000000..17a43c184c7 --- /dev/null +++ b/source/blender/freestyle/intern/view_map/AutoPtrHelper.h @@ -0,0 +1,60 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __FREESTYLE_AUTOPTR_HELPER_H__ +#define __FREESTYLE_AUTOPTR_HELPER_H__ + +/** \file blender/freestyle/intern/view_map/AutoPtrHelper.h + * \ingroup freestyle + * \brief Utility header for auto_ptr/unique_ptr selection + * \author Sergey Sharybin + * \date 2015-02-09 + */ + +#include <memory> + +namespace Freestyle { + +#if __cplusplus > 199711L +template<typename T> +class AutoPtr : public std::unique_ptr<T> { +public: + AutoPtr() : std::unique_ptr<T>() {} + AutoPtr(T *ptr) : std::unique_ptr<T>(ptr) {} + + /* TODO(sergey): Is there more clear way to do this? */ + template<typename X> + AutoPtr(AutoPtr<X>& other) : std::unique_ptr<T>(other.get()) { + other.release(); + } +}; +#else +template<typename T> +class AutoPtr : public std::auto_ptr<T> { +public: + AutoPtr() : std::auto_ptr<T>() {} + AutoPtr(T *ptr) : std::auto_ptr<T>(ptr) {} + AutoPtr(std::auto_ptr_ref<T> ref) : std::auto_ptr<T>(ref) {} +}; +#endif + +} /* 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 952b9752a3e..b5e133ec441 100644 --- a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.cpp @@ -121,22 +121,22 @@ AverageAreaGridDensityProviderFactory::AverageAreaGridDensityProviderFactory(rea AverageAreaGridDensityProviderFactory::~AverageAreaGridDensityProviderFactory() {} -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) { - return auto_ptr<GridDensityProvider>(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + return AutoPtr<GridDensityProvider>(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); } -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, const GridHelpers::Transform& transform) { - return auto_ptr<GridDensityProvider>(new AverageAreaGridDensityProvider(source, bbox, transform, sizeFactor)); + return AutoPtr<GridDensityProvider>(new AverageAreaGridDensityProvider(source, bbox, transform, sizeFactor)); } -auto_ptr<GridDensityProvider> AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr<GridDensityProvider> AverageAreaGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) { - return auto_ptr<GridDensityProvider>(new AverageAreaGridDensityProvider(source, sizeFactor)); + return AutoPtr<GridDensityProvider>(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 d63557f5cda..2c58cc32da9 100644 --- a/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/AverageAreaGridDensityProvider.h @@ -55,10 +55,10 @@ public: AverageAreaGridDensityProviderFactory(real sizeFactor); ~AverageAreaGridDensityProviderFactory(); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); protected: real sizeFactor; diff --git a/source/blender/freestyle/intern/view_map/BoxGrid.cpp b/source/blender/freestyle/intern/view_map/BoxGrid.cpp index f770bf6843f..ae22a26ec9b 100644 --- a/source/blender/freestyle/intern/view_map/BoxGrid.cpp +++ b/source/blender/freestyle/intern/view_map/BoxGrid.cpp @@ -71,18 +71,18 @@ void BoxGrid::Cell::indexPolygons() // Iterator ////////////////// -BoxGrid::Iterator::Iterator (BoxGrid& grid, Vec3r& center, real epsilon) +BoxGrid::Iterator::Iterator (BoxGrid& grid, Vec3r& center, real /*epsilon*/) : _target(grid.transform(center)), _foundOccludee(false) { // Find target cell _cell = grid.findCell(_target); - #if BOX_GRID_LOGGING +#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; } - #endif +#endif // Set iterator _current = _cell->faces.begin(); @@ -122,7 +122,7 @@ BoxGrid::BoxGrid(OccluderSource& source, GridDensityProvider& density, ViewMap * BoxGrid::~BoxGrid() {} -void BoxGrid::assignCells (OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap) +void BoxGrid::assignCells (OccluderSource& /*source*/, GridDensityProvider& density, ViewMap *viewMap) { _cellSize = density.cellSize(); _cellsX = density.cellsX(); diff --git a/source/blender/freestyle/intern/view_map/BoxGrid.h b/source/blender/freestyle/intern/view_map/BoxGrid.h index 0ef4ce37b11..b8e751d041d 100644 --- a/source/blender/freestyle/intern/view_map/BoxGrid.h +++ b/source/blender/freestyle/intern/view_map/BoxGrid.h @@ -303,11 +303,11 @@ 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]; - #if BOX_GRID_LOGGING +#if BOX_GRID_LOGGING if (G.debug & G_DEBUG_FREESTYLE) { std::cout << "\t\tReporting depth of occluder/ee: " << depth; } - #endif +#endif if (depth > _target[2]) { #if BOX_GRID_LOGGING if (G.debug & G_DEBUG_FREESTYLE) { diff --git a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp index 9c9cd88f188..85c6390cb9e 100644 --- a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp +++ b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp @@ -39,7 +39,9 @@ namespace Freestyle { void FEdgeXDetector::processShapes(WingedEdge& we) { bool progressBarDisplay = false; +#if 0 Vec3r Min, Max; +#endif vector<WShape*> wshapes = we.getWShapes(); WXShape *wxs; @@ -55,22 +57,24 @@ void FEdgeXDetector::processShapes(WingedEdge& we) if (_pRenderMonitor && _pRenderMonitor->testBreak()) break; wxs = dynamic_cast<WXShape*>(*it); +#if 0 wxs->bbox(Min, Max); _bbox_diagonal = (Max - Min).norm(); +#endif if (_changes) { vector<WFace*>& wfaces = wxs->GetFaceList(); for (vector<WFace*>::iterator wf = wfaces.begin(), wfend = wfaces.end(); wf != wfend; ++wf) { WXFace *wxf = dynamic_cast<WXFace*>(*wf); wxf->Clear(); } - _computeViewIndependant = true; + _computeViewIndependent = true; } - else if (!(wxs)->getComputeViewIndependantFlag()) { + else if (!(wxs)->getComputeViewIndependentFlag()) { wxs->Reset(); - _computeViewIndependant = false; + _computeViewIndependent = false; } else { - _computeViewIndependant = true; + _computeViewIndependent = true; } preProcessShape(wxs); if (progressBarDisplay) @@ -97,8 +101,8 @@ void FEdgeXDetector::processShapes(WingedEdge& we) if (progressBarDisplay) _pProgressBar->setProgress(_pProgressBar->getProgress() + 1); - wxs->setComputeViewIndependantFlag(false); - _computeViewIndependant = false; + wxs->setComputeViewIndependentFlag(false); + _computeViewIndependent = false; _changes = false; // reset user data @@ -117,7 +121,11 @@ void FEdgeXDetector::preProcessShape(WXShape *iWShape) _minKr = FLT_MAX; _maxKr = -FLT_MAX; _nPoints = 0; +#if 0 _meanEdgeSize = iWShape->getMeanEdgeSize(); +#else + _meanEdgeSize = iWShape->ComputeMeanEdgeSize(); +#endif vector<WFace*>& wfaces = iWShape->GetFaceList(); vector<WFace*>::iterator f, fend; @@ -140,16 +148,16 @@ void FEdgeXDetector::preProcessShape(WXShape *iWShape) void FEdgeXDetector::preProcessFace(WXFace *iFace) { - Vec3r firstPoint = iFace->GetVertex(0)->GetVertex(); - Vec3r N = iFace->GetNormal(); + Vec3f firstPoint = iFace->GetVertex(0)->GetVertex(); + Vec3f N = iFace->GetNormal(); // Compute the dot product between V (=_Viewpoint - firstPoint) and N: - Vec3r V; + Vec3f V; if (_orthographicProjection) { - V = Vec3r(0.0, 0.0, _Viewpoint.z() - firstPoint.z()); + V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - firstPoint.z()); } else { - V = Vec3r(_Viewpoint - firstPoint); + V = Vec3f(_Viewpoint - firstPoint); } N.normalize(); V.normalize(); @@ -160,7 +168,7 @@ void FEdgeXDetector::preProcessFace(WXFace *iFace) iFace->setZ(iFace->center().z() - _Viewpoint.z()); } else { - Vec3r dist_vec(iFace->center() - _Viewpoint); + Vec3f dist_vec(iFace->center() - _Viewpoint); iFace->setZ(dist_vec.norm()); } } @@ -187,8 +195,8 @@ void FEdgeXDetector::computeCurvatures(WXVertex *vertex) CurvatureInfo *C; float radius = _sphereRadius * _meanEdgeSize; - // view independant stuff - if (_computeViewIndependant) { + // view independent stuff + if (_computeViewIndependent) { C = new CurvatureInfo(); vertex->setCurvatures(C); OGF::NormalCycle ncycle; @@ -265,33 +273,33 @@ void FEdgeXDetector::processSilhouetteShape(WXShape *iWShape) void FEdgeXDetector::ProcessSilhouetteFace(WXFace *iFace) { // SILHOUETTE LAYER - Vec3r normal; + Vec3f normal; // Compute the dot products between View direction and N at each vertex of the face: - Vec3r point; + Vec3f point; int closestPointId = 0; - real dist, minDist = FLT_MAX; + 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(); - Vec3r V; + Vec3f V; if (_orthographicProjection) { - V = Vec3r(0.0, 0.0, _Viewpoint.z() - point.z()); + V = Vec3f(0.0f, 0.0f, _Viewpoint.z() - point.z()); } else { - V = Vec3r(_Viewpoint - point); + V = Vec3f(_Viewpoint - point); } V.normalize(); - real d = normal * V; + float d = normal * V; faceLayer->PushDotP(d); // Find the point the closest to the viewpoint if (_orthographicProjection) { dist = point.z() - _Viewpoint.z(); } else { - Vec3r dist_vec(point - _Viewpoint); + Vec3f dist_vec(point - _Viewpoint); dist = dist_vec.norm(); } if (dist < minDist) { @@ -333,7 +341,7 @@ void FEdgeXDetector::ProcessSilhouetteEdge(WXEdge *iEdge) ///////// void FEdgeXDetector::processBorderShape(WXShape *iWShape) { - if (!_computeViewIndependant) + if (!_computeViewIndependent) return; // Make a pass on the edges to detect the BORDER vector<WEdge*>::iterator we, weend; @@ -358,7 +366,7 @@ void FEdgeXDetector::ProcessBorderEdge(WXEdge *iEdge) ///////// void FEdgeXDetector::processCreaseShape(WXShape *iWShape) { - if (!_computeViewIndependant) + if (!_computeViewIndependent) return; // Make a pass on the edges to detect the CREASE @@ -390,7 +398,7 @@ 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 (!_computeViewIndependant) + if (!_computeViewIndependent) return; // Here the curvatures must already have been computed @@ -416,6 +424,7 @@ void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) 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; @@ -428,6 +437,7 @@ void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) flayer->ReplaceDotP(2, 0); } } +#endif } #if 0 @@ -497,7 +507,7 @@ void FEdgeXDetector::ProcessRidgeFace(WXFace *iFace) } } } - // Once we have K1 along the the ppal direction compute the derivative : K1b - K1a put it in DotP + // 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; @@ -684,7 +694,7 @@ void FEdgeXDetector::postProcessSuggestiveContourFace(WXFace *iFace) //////////////////// void FEdgeXDetector::processMaterialBoundaryShape(WXShape *iWShape) { - if (!_computeViewIndependant) + if (!_computeViewIndependent) return; // Make a pass on the edges to detect material boundaries vector<WEdge*>::iterator we, weend; diff --git a/source/blender/freestyle/intern/view_map/FEdgeXDetector.h b/source/blender/freestyle/intern/view_map/FEdgeXDetector.h index 8adf685a6eb..cbb47d387fb 100644 --- a/source/blender/freestyle/intern/view_map/FEdgeXDetector.h +++ b/source/blender/freestyle/intern/view_map/FEdgeXDetector.h @@ -57,8 +57,10 @@ public: { _pProgressBar = NULL; _pRenderMonitor = NULL; - _computeViewIndependant = true; + _computeViewIndependent = true; +#if 0 _bbox_diagonal = 1.0; +#endif _meanEdgeSize = 0; _computeRidgesAndValleys = true; _computeSuggestiveContours = true; @@ -96,7 +98,7 @@ public: * 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(real angle) + inline void setCreaseAngle(float angle) { if (angle < 0.0) angle = 0.0; @@ -126,7 +128,7 @@ public: * \param dkr * The minimal derivative of the radial curvature */ - inline void setSuggestiveContourKrDerivativeEpsilon(real dkr) + inline void setSuggestiveContourKrDerivativeEpsilon(float dkr) { if (dkr != _kr_derivative_epsilon) { _kr_derivative_epsilon = dkr; @@ -146,7 +148,7 @@ public: virtual void buildSmoothEdges(WXShape *iShape); /*! Sets the current viewpoint */ - inline void setViewpoint(const Vec3r& ivp) + inline void setViewpoint(const Vec3f& ivp) { _Viewpoint = ivp; } @@ -191,7 +193,7 @@ public: * \param r * The radius of the sphere expressed as a ratio of the mean edge size */ - inline void setSphereRadius(real r) + inline void setSphereRadius(float r) { if (r != _sphereRadius) { _sphereRadius = r; @@ -210,10 +212,12 @@ public: } protected: - Vec3r _Viewpoint; + Vec3f _Viewpoint; +#if 0 real _bbox_diagonal; // diagonal of the current processed shape bbox +#endif //oldtmp values - bool _computeViewIndependant; + bool _computeViewIndependent; real _meanK1; real _meanKr; real _minK1; @@ -229,11 +233,11 @@ protected: bool _computeMaterialBoundaries; bool _faceSmoothness; bool _faceMarks; - real _sphereRadius; // expressed as a ratio of the mean edge size - real _creaseAngle; // [-1, 1] compared with the inner product of face normals + 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; - real _kr_derivative_epsilon; + float _kr_derivative_epsilon; ProgressBar *_pProgressBar; RenderMonitor *_pRenderMonitor; diff --git a/source/blender/freestyle/intern/view_map/GridDensityProvider.h b/source/blender/freestyle/intern/view_map/GridDensityProvider.h index 272d64dd6de..b49e74d6402 100644 --- a/source/blender/freestyle/intern/view_map/GridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/GridDensityProvider.h @@ -32,6 +32,7 @@ #include <algorithm> #include <memory> +#include "AutoPtrHelper.h" #include "OccluderSource.h" #include "../geometry/BBox.h" @@ -148,12 +149,12 @@ class GridDensityProviderFactory public: GridDensityProviderFactory() {} - virtual auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]) = 0; + virtual AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]) = 0; - virtual auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform) = 0; + virtual AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform) = 0; - virtual auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source) = 0; + virtual AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source) = 0; virtual ~GridDensityProviderFactory () {} diff --git a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp index 00f5cc90cc4..18edc82b096 100644 --- a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp +++ b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.cpp @@ -36,45 +36,45 @@ HeuristicGridDensityProviderFactory::HeuristicGridDensityProviderFactory(real si HeuristicGridDensityProviderFactory::~HeuristicGridDensityProviderFactory() {} -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) { - auto_ptr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); - auto_ptr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); + AutoPtr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + AutoPtr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); if (avg->cellSize() > p23->cellSize()) { - return (auto_ptr<GridDensityProvider>) p23; + return (AutoPtr<GridDensityProvider>) p23; } else { - return (auto_ptr<GridDensityProvider>) avg; + return (AutoPtr<GridDensityProvider>) avg; } } -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, const GridHelpers::Transform& transform) { - auto_ptr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, bbox, - transform, sizeFactor)); - auto_ptr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); + AutoPtr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, bbox, + transform, sizeFactor)); + AutoPtr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); if (avg->cellSize() > p23->cellSize()) { - return (auto_ptr<GridDensityProvider>) p23; + return (AutoPtr<GridDensityProvider>) p23; } else { - return (auto_ptr<GridDensityProvider>) avg; + return (AutoPtr<GridDensityProvider>) avg; } } -auto_ptr<GridDensityProvider> HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr<GridDensityProvider> HeuristicGridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) { real proscenium[4]; GridDensityProvider::calculateOptimalProscenium(source, proscenium); - auto_ptr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); - auto_ptr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); + AutoPtr<AverageAreaGridDensityProvider> avg(new AverageAreaGridDensityProvider(source, proscenium, sizeFactor)); + AutoPtr<Pow23GridDensityProvider> p23(new Pow23GridDensityProvider(source, proscenium, numFaces)); if (avg->cellSize() > p23->cellSize()) { - return (auto_ptr<GridDensityProvider>) p23; + return (AutoPtr<GridDensityProvider>) p23; } else { - return (auto_ptr<GridDensityProvider>) avg; + return (AutoPtr<GridDensityProvider>) avg; } } diff --git a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h index 65f2af6df2f..9414e4931f5 100644 --- a/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h +++ b/source/blender/freestyle/intern/view_map/HeuristicGridDensityProviderFactory.h @@ -42,10 +42,10 @@ public: HeuristicGridDensityProviderFactory(real sizeFactor, unsigned numFaces); ~HeuristicGridDensityProviderFactory(); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); protected: real sizeFactor; diff --git a/source/blender/freestyle/intern/view_map/Interface1D.cpp b/source/blender/freestyle/intern/view_map/Interface1D.cpp index 985310e52b5..f4abad11479 100644 --- a/source/blender/freestyle/intern/view_map/Interface1D.cpp +++ b/source/blender/freestyle/intern/view_map/Interface1D.cpp @@ -42,13 +42,13 @@ Interface0DIterator Interface1D::verticesEnd() return Interface0DIterator(); } -Interface0DIterator Interface1D::pointsBegin(float t) +Interface0DIterator Interface1D::pointsBegin(float /*t*/) { PyErr_SetString(PyExc_TypeError, "method pointsBegin() not properly overridden"); return Interface0DIterator(); } -Interface0DIterator Interface1D::pointsEnd(float t) +Interface0DIterator Interface1D::pointsEnd(float /*t*/) { PyErr_SetString(PyExc_TypeError, "method pointsEnd() not properly overridden"); return Interface0DIterator(); diff --git a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp index e3bb9b87ecc..8dff079e0cf 100644 --- a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp +++ b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.cpp @@ -99,22 +99,22 @@ Pow23GridDensityProviderFactory::Pow23GridDensityProviderFactory(unsigned numFac Pow23GridDensityProviderFactory::~Pow23GridDensityProviderFactory () {} -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const real proscenium[4]) { - return auto_ptr<GridDensityProvider>(new Pow23GridDensityProvider(source, proscenium, numFaces)); + return AutoPtr<GridDensityProvider>(new Pow23GridDensityProvider(source, proscenium, numFaces)); } -auto_ptr<GridDensityProvider> +AutoPtr<GridDensityProvider> Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, const GridHelpers::Transform& transform) { - return auto_ptr<GridDensityProvider>(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); + return AutoPtr<GridDensityProvider>(new Pow23GridDensityProvider(source, bbox, transform, numFaces)); } -auto_ptr<GridDensityProvider> Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) +AutoPtr<GridDensityProvider> Pow23GridDensityProviderFactory::newGridDensityProvider(OccluderSource& source) { - return auto_ptr<GridDensityProvider>(new Pow23GridDensityProvider(source, numFaces)); + return AutoPtr<GridDensityProvider>(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 7f646790ab6..5dfa9cdfc87 100644 --- a/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h +++ b/source/blender/freestyle/intern/view_map/Pow23GridDensityProvider.h @@ -58,10 +58,10 @@ public: Pow23GridDensityProviderFactory(unsigned numFaces); ~Pow23GridDensityProviderFactory(); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, - const GridHelpers::Transform& transform); - auto_ptr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const real proscenium[4]); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source, const BBox<Vec3r>& bbox, + const GridHelpers::Transform& transform); + AutoPtr<GridDensityProvider> newGridDensityProvider(OccluderSource& source); protected: unsigned numFaces; diff --git a/source/blender/freestyle/intern/view_map/Silhouette.h b/source/blender/freestyle/intern/view_map/Silhouette.h index d838b98c1a8..0b20c9f6aa2 100644 --- a/source/blender/freestyle/intern/view_map/Silhouette.h +++ b/source/blender/freestyle/intern/view_map/Silhouette.h @@ -378,6 +378,17 @@ public: _FEdges.push_back(iFEdge); } + /*! Remove an FEdge from the list of edges emanating from this SVertex. */ + inline void RemoveFEdge(FEdge *iFEdge) + { + for (vector<FEdge *>::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) { @@ -441,6 +452,10 @@ public: /*! angle in radians */ inline real curvature2d_as_angle() const; #endif + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertex") +#endif }; /**********************************/ @@ -518,6 +533,8 @@ protected: 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(). @@ -538,6 +555,7 @@ public: _occludeeEmpty = true; _isSmooth = false; _isInImage = true; + _isTemporary = false; } /*! Builds an FEdge going from vA to vB. */ @@ -554,6 +572,7 @@ public: _occludeeEmpty = true; _isSmooth = false; _isInImage = true; + _isTemporary = false; } /*! Copy constructor */ @@ -573,6 +592,7 @@ public: _occludeeEmpty = iBrother._occludeeEmpty; _isSmooth = iBrother._isSmooth; _isInImage = iBrother._isInImage; + _isTemporary = iBrother._isTemporary; iBrother.userdata = this; userdata = 0; } @@ -708,6 +728,11 @@ public: return _isInImage; } + inline bool isTemporary() const + { + return _isTemporary; + } + /* modifiers */ /*! Sets the first SVertex. */ inline void setVertexA(SVertex *vA) @@ -803,6 +828,11 @@ public: _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. */ @@ -931,6 +961,10 @@ public: * 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") +#endif }; // @@ -1088,12 +1122,12 @@ Interface0DIterator FEdge::verticesEnd() return ret; } -Interface0DIterator FEdge::pointsBegin(float t) +Interface0DIterator FEdge::pointsBegin(float /*t*/) { return verticesBegin(); } -Interface0DIterator FEdge::pointsEnd(float t) +Interface0DIterator FEdge::pointsEnd(float /*t*/) { return verticesEnd(); } @@ -1241,6 +1275,10 @@ public: { _bFaceMark = iFaceMark; } + +#ifdef WITH_CXX_GUARDEDALLOC + 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 @@ -1353,6 +1391,10 @@ public: { _FrsMaterialIndex = i; } + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FEdgeSmooth") +#endif }; @@ -1373,7 +1415,7 @@ private: vector<SVertex*> _verticesList; // list of all vertices vector<FEdge*> _edgesList; // list of all edges Id _Id; - string _Name; + const char *_Name; BBox<Vec3r> _BBox; vector<FrsMaterial> _FrsMaterials; @@ -1393,6 +1435,7 @@ public: userdata = NULL; _importance = 0.0f; _ViewShape = NULL; + _Name = NULL; } /*! Copy constructor */ @@ -1845,7 +1888,7 @@ public: } /*! Returns the name of the Shape. */ - inline const string& getName() const + inline const char *getName() const { return _Name; } @@ -1858,7 +1901,7 @@ public: } /*! Sets the name of the shape.*/ - inline void setName(const string& name) + inline void setName(const char *name) { _Name = name; } diff --git a/source/blender/freestyle/intern/view_map/SphericalGrid.cpp b/source/blender/freestyle/intern/view_map/SphericalGrid.cpp index 60ad7daea0a..10c88190cb3 100644 --- a/source/blender/freestyle/intern/view_map/SphericalGrid.cpp +++ b/source/blender/freestyle/intern/view_map/SphericalGrid.cpp @@ -72,18 +72,18 @@ void SphericalGrid::Cell::indexPolygons() // Iterator ////////////////// -SphericalGrid::Iterator::Iterator(SphericalGrid& grid, Vec3r& center, real epsilon) +SphericalGrid::Iterator::Iterator(SphericalGrid& grid, Vec3r& center, real /*epsilon*/) : _target(SphericalGrid::Transform::sphericalProjection(center)), _foundOccludee(false) { // Find target cell _cell = grid.findCell(_target); - #if SPHERICAL_GRID_LOGGING +#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; } - #endif +#endif // Set iterator _current = _cell->faces.begin(); @@ -120,7 +120,7 @@ SphericalGrid::SphericalGrid(OccluderSource& source, GridDensityProvider& densit SphericalGrid::~SphericalGrid() {} -void SphericalGrid::assignCells(OccluderSource& source, GridDensityProvider& density, ViewMap *viewMap) +void SphericalGrid::assignCells(OccluderSource& /*source*/, GridDensityProvider& density, ViewMap *viewMap) { _cellSize = density.cellSize(); _cellsX = density.cellsX(); diff --git a/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp b/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp index fe6f3f1892d..4f5b4cba779 100644 --- a/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp +++ b/source/blender/freestyle/intern/view_map/SteerableViewMap.cpp @@ -268,7 +268,7 @@ void SteerableViewMap::saveSteerableViewMap() const //soc qtmp.save(base+QString::number(i)+"-"+QString::number(j)+".png", "PNG"); filename << base; filename << i << "-" << j << ".png"; - ibuf->ftype = PNG; + ibuf->ftype = IMB_FTYPE_PNG; IMB_saveiff(ibuf, const_cast<char *>(filename.str().c_str()), 0); } #if 0 diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp index b5d73640c11..139502e8d5e 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp @@ -632,18 +632,18 @@ FEdge *ViewEdgeXBuilder::BuildSharpFEdge(FEdge *feprevious, const OWXEdge& iwe) { SVertex *va, *vb; FEdgeSharp *fe; - WXVertex *wxVA, *wxVB; + Vec3r vA, vB; if (iwe.order) { - wxVA = (WXVertex *)iwe.e->GetaVertex(); - wxVB = (WXVertex *)iwe.e->GetbVertex(); + vA = iwe.e->GetaVertex()->GetVertex(); + vB = iwe.e->GetbVertex()->GetVertex(); } else { - wxVA = (WXVertex *)iwe.e->GetbVertex(); - wxVB = (WXVertex *)iwe.e->GetaVertex(); + vA = iwe.e->GetbVertex()->GetVertex(); + vB = iwe.e->GetaVertex()->GetVertex(); } // Make the 2 SVertex - va = MakeSVertex(wxVA->GetVertex(), true); - vb = MakeSVertex(wxVB->GetVertex(), true); + va = MakeSVertex(vA, true); + vb = MakeSVertex(vB, true); // get the faces normals and the material indices Vec3r normalA, normalB; diff --git a/source/blender/freestyle/intern/view_map/ViewMap.cpp b/source/blender/freestyle/intern/view_map/ViewMap.cpp index fd5ebb99f72..52769413e79 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMap.cpp @@ -63,6 +63,30 @@ ViewMap::~ViewMap() _VEdges.clear(); } +void ViewMap::Clean() +{ + vector<FEdge*> tmpEdges; + + for (vector<ViewShape*>::iterator vs = _VShapes.begin(), vsend = _VShapes.end(); vs != vsend; vs++) { + vector<FEdge*>& edges = (*vs)->sshape()->getEdgeList(); + for (vector<FEdge*>::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<FEdge*>::iterator it = tmpEdges.begin(), itend = tmpEdges.end(); it != itend; it++) { + for (vector<ViewShape*>::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]; @@ -677,12 +701,12 @@ Interface0DIterator ViewEdge::verticesEnd() return ret; } -Interface0DIterator ViewEdge::pointsBegin(float t) +Interface0DIterator ViewEdge::pointsBegin(float /*t*/) { return verticesBegin(); } -Interface0DIterator ViewEdge::pointsEnd(float t) +Interface0DIterator ViewEdge::pointsEnd(float /*t*/) { return verticesEnd(); } diff --git a/source/blender/freestyle/intern/view_map/ViewMap.h b/source/blender/freestyle/intern/view_map/ViewMap.h index d87341503fa..74297e1dbfd 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.h +++ b/source/blender/freestyle/intern/view_map/ViewMap.h @@ -236,6 +236,9 @@ public: /* 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") #endif @@ -369,7 +372,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewVertex") #endif - }; /**********************************/ @@ -642,7 +644,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TVertex") #endif - }; @@ -859,7 +860,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:NonTVertex") #endif - }; /**********************************/ @@ -1379,7 +1379,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdge") #endif - }; @@ -1567,7 +1566,7 @@ public: } /*! Returns the ViewShape id. */ - inline const string& getName() const + inline const char *getName() const { return _SShape->getName(); } diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp index a0a1282219c..9ca021475b2 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp @@ -56,7 +56,7 @@ static const Global &_global = G; using namespace std; template <typename G, typename I> -static void findOccludee(FEdge *fe, G& grid, I& occluders, real epsilon, WFace **oaWFace, +static void findOccludee(FEdge *fe, G& /*grid*/, I& occluders, real epsilon, WFace **oaWFace, Vec3r& u, Vec3r& A, Vec3r& origin, Vec3r& edge, vector<WVertex*>& faceVertices) { WFace *face = NULL; @@ -169,7 +169,7 @@ static void findOccludee(FEdge *fe, G& grid, I& occluders, real epsilon, WFace * } template <typename G, typename I> -static void findOccludee(FEdge *fe, G& grid, real epsilon, ViewEdge *ve, WFace **oaFace) +static void findOccludee(FEdge *fe, G& grid, real epsilon, ViewEdge * /*ve*/, WFace **oaFace) { Vec3r A; Vec3r edge; @@ -205,7 +205,7 @@ static void findOccludee(FEdge *fe, G& grid, real epsilon, ViewEdge *ve, WFace * // computeVisibility takes a pointer to foundOccluders, instead of using a reference, // so that computeVeryFastVisibility can skip the AddOccluders step with minimal overhead. template <typename G, typename I> -static int computeVisibility(ViewMap *viewMap, FEdge *fe, G& grid, real epsilon, ViewEdge *ve, WFace **oaWFace, +static int computeVisibility(ViewMap *viewMap, FEdge *fe, G& grid, real epsilon, ViewEdge * /*ve*/, WFace **oaWFace, set<ViewShape*> *foundOccluders) { int qi = 0; @@ -1300,8 +1300,8 @@ void ViewMapBuilder::computeCusps(ViewMap *ioViewMap) void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox<Vec3r>& bbox, real epsilon, bool cull, GridDensityProviderFactory& factory) { - auto_ptr<GridHelpers::Transform> transform; - auto_ptr<OccluderSource> source; + AutoPtr<GridHelpers::Transform> transform; + AutoPtr<OccluderSource> source; if (_orthographicProjection) { transform.reset(new BoxGrid::Transform); @@ -1317,7 +1317,7 @@ void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap, WingedEdge& source.reset(new OccluderSource(*transform, we)); } - auto_ptr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); + AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); if (_orthographicProjection) { BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); @@ -1332,8 +1332,8 @@ void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap, WingedEdge& void ViewMapBuilder::ComputeDetailedVisibility(ViewMap *ioViewMap, WingedEdge& we, const BBox<Vec3r>& bbox, real epsilon, bool cull, GridDensityProviderFactory& factory) { - auto_ptr<GridHelpers::Transform> transform; - auto_ptr<OccluderSource> source; + AutoPtr<GridHelpers::Transform> transform; + AutoPtr<OccluderSource> source; if (_orthographicProjection) { transform.reset(new BoxGrid::Transform); @@ -1349,7 +1349,7 @@ void ViewMapBuilder::ComputeDetailedVisibility(ViewMap *ioViewMap, WingedEdge& w source.reset(new OccluderSource(*transform, we)); } - auto_ptr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); + AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); if (_orthographicProjection) { BoxGrid grid(*source, *density, ioViewMap, _viewpoint, _EnableQI); @@ -2112,14 +2112,14 @@ void ViewMapBuilder::ComputeIntersections(ViewMap *ioViewMap, intersection_algo default: break; } - 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); - if (_global.debug & G_DEBUG_FREESTYLE) { +#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; @@ -2128,6 +2128,7 @@ void ViewMapBuilder::ComputeIntersections(ViewMap *ioViewMap, intersection_algo } } } +#endif } struct less_SVertex2D : public binary_function<SVertex *, SVertex *, bool> diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.h b/source/blender/freestyle/intern/view_map/ViewMapBuilder.h index 08b2fde8f31..36497bf8d22 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.h +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.h @@ -145,7 +145,7 @@ public: * 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) + const int iViewport[4], real iFocalLength, real /*iAspect*/, real /*iFovy*/) { _orthographicProjection = (iProjectionMatrix[3][3] != 0.0); SilhouetteGeomEngine::setTransform(iModelViewMatrix, iProjectionMatrix, iViewport, iFocalLength); diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.cpp b/source/blender/freestyle/intern/winged_edge/Curvature.cpp index 38941b23357..97dcc86cf31 100644 --- a/source/blender/freestyle/intern/winged_edge/Curvature.cpp +++ b/source/blender/freestyle/intern/winged_edge/Curvature.cpp @@ -211,8 +211,9 @@ bool gts_vertex_gaussian_curvature(WVertex *v, real *Kg) } 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(); + } for (itE = v->incoming_edges_begin(); itE != v->incoming_edges_end(); itE++) { WOEdge *e = (*itE)->getPrevOnFace(); @@ -535,6 +536,7 @@ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, V namespace OGF { +#if 0 inline static real angle(WOEdge *h) { const Vec3r& n1 = h->GetbFace()->GetNormal(); @@ -549,6 +551,7 @@ inline static real angle(WOEdge *h) } 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) diff --git a/source/blender/freestyle/intern/winged_edge/Nature.h b/source/blender/freestyle/intern/winged_edge/Nature.h index 99a3f902cd0..b1b5c88df5a 100644 --- a/source/blender/freestyle/intern/winged_edge/Nature.h +++ b/source/blender/freestyle/intern/winged_edge/Nature.h @@ -34,6 +34,7 @@ namespace Freestyle { namespace Nature { /* XXX Why not using enums??? */ +/* In order to optimize for space (enum is int) - T.K. */ typedef unsigned short VertexNature; /*! true for any 0D element */ diff --git a/source/blender/freestyle/intern/winged_edge/WEdge.cpp b/source/blender/freestyle/intern/winged_edge/WEdge.cpp index de166531d8b..87ca3a4235f 100644 --- a/source/blender/freestyle/intern/winged_edge/WEdge.cpp +++ b/source/blender/freestyle/intern/winged_edge/WEdge.cpp @@ -410,16 +410,16 @@ bool WFace::getOppositeEdge(const WVertex *v, WOEdge *&e) return true; } -real WFace::getArea () +float WFace::getArea() { vector<WOEdge *>::iterator it; - Vec3r origin = (*(_OEdgeList.begin()))->GetaVertex()->GetVertex(); + Vec3f origin = (*(_OEdgeList.begin()))->GetaVertex()->GetVertex(); it = _OEdgeList.begin(); - real a = 0; + float a = 0; for (it = it++; it != _OEdgeList.end(); it++) { - Vec3r v1 = Vec3r((*it)->GetaVertex()->GetVertex() - origin); - Vec3r v2 = Vec3r((*it)->GetbVertex()->GetVertex() - origin); - a += (v1 ^ v2).norm() / 2.0; + Vec3f v1 = Vec3f((*it)->GetaVertex()->GetVertex() - origin); + Vec3f v2 = Vec3f((*it)->GetbVertex()->GetVertex() - origin); + a += (v1 ^ v2).norm() / 2.0f; } return a; } @@ -472,8 +472,10 @@ WShape::WShape(WShape& iBrother) _Id = iBrother.GetId(); _Name = iBrother._Name; _FrsMaterials = iBrother._FrsMaterials; +#if 0 _meanEdgeSize = iBrother._meanEdgeSize; iBrother.bbox(_min, _max); +#endif vector<WVertex *>& vertexList = iBrother.getVertexList(); vector<WVertex *>::iterator v = vertexList.begin(), vend = vertexList.end(); for (; v != vend; ++v) { @@ -597,7 +599,7 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM return result; } -WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<Vec3r>& iNormalsList, vector<Vec2r>& iTexCoordsList, +WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<Vec3f>& iNormalsList, vector<Vec2f>& iTexCoordsList, vector<bool>& iFaceEdgeMarksList, unsigned iMaterial) { // allocate the new face @@ -646,10 +648,10 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM it++; v3 = *it; - Vec3r vector1(v2->GetVertex() - v1->GetVertex()); - Vec3r vector2(v3->GetVertex() - v1->GetVertex()); + Vec3f vector1(v2->GetVertex() - v1->GetVertex()); + Vec3f vector2(v3->GetVertex() - v1->GetVertex()); - Vec3r normal(vector1 ^ vector2); + Vec3f normal(vector1 ^ vector2); normal.normalize(); face->setNormal(normal); @@ -681,8 +683,10 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM // 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(); +#endif } edge->setMark(*mit); @@ -696,4 +700,16 @@ WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeM return face; } +real WShape::ComputeMeanEdgeSize() const +{ + real meanEdgeSize = 0.0; + for (vector<WEdge *>::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 41525e03d8e..8001342775b 100644 --- a/source/blender/freestyle/intern/winged_edge/WEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WEdge.h @@ -68,15 +68,15 @@ class WVertex { protected: int _Id; // an identificator - Vec3r _Vertex; + Vec3f _Vertex; vector<WEdge*> _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 - int _Border; // 1 -> border, 0 -> no border, -1 -> not set + short _Border; // 1 -> border, 0 -> no border, -1 -> not set public: void *userdata; // designed to store specific user data - inline WVertex(const Vec3r &v) + inline WVertex(const Vec3f &v) { _Id = 0; _Vertex = v; @@ -92,7 +92,7 @@ public: virtual ~WVertex() {} /*! accessors */ - inline Vec3r& GetVertex() + inline Vec3f& GetVertex() { return _Vertex; } @@ -120,7 +120,7 @@ public: bool isBoundary(); /*! modifiers */ - inline void setVertex(const Vec3r& v) + inline void setVertex(const Vec3f& v) { _Vertex = v; } @@ -381,8 +381,8 @@ protected: WFace *_pbFace; // when following the edge, face on the left WEdge *_pOwner; // Edge - Vec3r _vec; - real _angle; + Vec3f _vec; + float _angle; public: void *userdata; @@ -457,17 +457,16 @@ public: return _pOwner; } - inline const Vec3r& GetVec() + inline const Vec3f& GetVec() { return _vec; } - inline const real GetAngle() + inline const float GetAngle() { return _angle; } - /*! modifiers */ #if 0 inline void SetaCWEdge(WOEdge *pe) @@ -552,7 +551,7 @@ class WEdge protected: WOEdge *_paOEdge; // first oriented edge WOEdge *_pbOEdge; // second oriented edge - int _nOEdges; // number of oriented edges associated with this edge. (1 means border 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 @@ -633,7 +632,7 @@ public: return _pbOEdge; } - inline int GetNumberOfOEdges() + inline short GetNumberOfOEdges() { return _nOEdges; } @@ -700,7 +699,7 @@ public: } } - inline void setNumberOfOEdges(int n) + inline void setNumberOfOEdges(short n) { _nOEdges = n; } @@ -739,11 +738,11 @@ class WFace { protected: vector<WOEdge *> _OEdgeList; // list of oriented edges of bording the face - Vec3r _Normal; // normal to 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<Vec3r> _VerticesNormals; - vector<Vec2r> _VerticesTexCoords; + vector<Vec3f> _VerticesNormals; + vector<Vec2f> _VerticesTexCoords; int _Id; unsigned _FrsMaterialIndex; @@ -773,7 +772,7 @@ public: return _OEdgeList[i]; } - inline Vec3r& GetNormal() + inline Vec3f& GetNormal() { return _Normal; } @@ -849,30 +848,30 @@ public: return iOEdge->GetaFace(); } - inline vector<Vec3r>& GetPerVertexNormals() + inline vector<Vec3f>& GetPerVertexNormals() { return _VerticesNormals; } - inline vector<Vec2r>& GetPerVertexTexCoords() + inline vector<Vec2f>& GetPerVertexTexCoords() { return _VerticesTexCoords; } /*! Returns the normal of the vertex of index index */ - inline Vec3r& GetVertexNormal(int index) + inline Vec3f& GetVertexNormal(int index) { return _VerticesNormals[index]; } /*! Returns the tex coords of the vertex of index index */ - inline Vec2r& GetVertexTexCoords(int index) + inline Vec2f& GetVertexTexCoords(int index) { return _VerticesTexCoords[index]; } /*! Returns the normal of the vertex iVertex for that face */ - inline Vec3r& GetVertexNormal(WVertex *iVertex) + inline Vec3f& GetVertexNormal(WVertex *iVertex) { int i = 0; int index = 0; @@ -939,17 +938,17 @@ public: _OEdgeList = iEdgeList; } - inline void setNormal(const Vec3r& iNormal) + inline void setNormal(const Vec3f& iNormal) { _Normal = iNormal; } - inline void setNormalList(const vector<Vec3r>& iNormalsList) + inline void setNormalList(const vector<Vec3f>& iNormalsList) { _VerticesNormals = iNormalsList; } - inline void setTexCoordsList(const vector<Vec2r>& iTexCoordsList) + inline void setTexCoordsList(const vector<Vec2f>& iTexCoordsList) { _VerticesTexCoords = iTexCoordsList; } @@ -990,12 +989,12 @@ public: } /*! For triangles, returns the edge opposite to the vertex in e. - * returns flase if the face is not a triangle or if the vertex is not found + * 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 */ - real getArea (); + float getArea (); WShape *getShape(); virtual void ResetUserData() @@ -1025,17 +1024,23 @@ protected: vector<WEdge *> _EdgeList; vector<WFace *> _FaceList; int _Id; - string _Name; + const char *_Name; static unsigned _SceneCurrentId; - Vec3r _min; - Vec3r _max; +#if 0 + Vec3f _min; + Vec3f _max; +#endif vector<FrsMaterial> _FrsMaterials; - real _meanEdgeSize; +#if 0 + float _meanEdgeSize; +#endif public: inline WShape() { +#if 0 _meanEdgeSize = 0; +#endif _Id = _SceneCurrentId; _SceneCurrentId++; } @@ -1092,11 +1097,13 @@ public: return _Id; } - inline void bbox(Vec3r& min, Vec3r& max) +#if 0 + inline void bbox(Vec3f& min, Vec3f& max) { min = _min; max = _max; } +#endif inline const FrsMaterial& frs_material(unsigned i) const { @@ -1108,12 +1115,14 @@ public: return _FrsMaterials; } - inline const real getMeanEdgeSize() const +#if 0 + inline const float getMeanEdgeSize() const { return _meanEdgeSize; } +#endif - inline const string& getName() const + inline const char *getName() const { return _Name; } @@ -1144,11 +1153,13 @@ public: _Id = id; } - inline void setBBox(const Vec3r& min, const Vec3r& max) +#if 0 + inline void setBBox(const Vec3f& min, const Vec3f& max) { _min = min; _max = max; } +#endif inline void setFrsMaterial(const FrsMaterial& frs_material, unsigned i) { @@ -1160,7 +1171,7 @@ public: _FrsMaterials = iMaterials; } - inline void setName(const string& name) + inline void setName(const char *name) { _Name = name; } @@ -1199,7 +1210,7 @@ public: * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for * that face. */ - virtual WFace *MakeFace(vector<WVertex *>& iVertexList, vector<Vec3r>& iNormalsList, vector<Vec2r>& iTexCoordsList, + virtual WFace *MakeFace(vector<WVertex *>& iVertexList, vector<Vec3f>& iNormalsList, vector<Vec2f>& iTexCoordsList, vector<bool>& iFaceEdgeMarksList, unsigned iMaterialIndex); inline void AddEdge(WEdge *iEdge) @@ -1240,12 +1251,13 @@ public: } } +#if 0 inline void ComputeBBox() { _min = _VertexList[0]->GetVertex(); _max = _VertexList[0]->GetVertex(); - Vec3r v; + Vec3f v; for (vector<WVertex *>::iterator wv = _VertexList.begin(), wvend = _VertexList.end(); wv != wvend; wv++) { for (unsigned int i = 0; i < 3; i++) { v = (*wv)->GetVertex(); @@ -1256,12 +1268,17 @@ public: } } } +#endif - inline real ComputeMeanEdgeSize() +#if 0 + inline float ComputeMeanEdgeSize() { _meanEdgeSize = _meanEdgeSize / _EdgeList.size(); return _meanEdgeSize; } +#else + real ComputeMeanEdgeSize() const; +#endif protected: /*! Builds the face passed as argument (which as already been allocated) @@ -1368,7 +1385,7 @@ inline void WOEdge::setVecAndAngle() if (_paVertex && _pbVertex) { _vec = _pbVertex->GetVertex() - _paVertex->GetVertex(); if (_paFace && _pbFace) { - real sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm(); + float sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm(); if (sine >= 1.0) { _angle = M_PI / 2.0; return; diff --git a/source/blender/freestyle/intern/winged_edge/WXEdge.cpp b/source/blender/freestyle/intern/winged_edge/WXEdge.cpp index 84dbd5fbef8..11bce2b007e 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdge.cpp +++ b/source/blender/freestyle/intern/winged_edge/WXEdge.cpp @@ -43,7 +43,7 @@ unsigned int WXFaceLayer::Get0VertexIndex() const int i = 0; int nEdges = _pWXFace->numberOfEdges(); for (i = 0; i < nEdges; ++i) { - if (_DotP[i] == 0) { + if (_DotP[i] == 0.0f) { // TODO this comparison is weak, check if it actually works return i; } } @@ -54,7 +54,7 @@ unsigned int WXFaceLayer::GetSmoothEdgeIndex() const int i = 0; int nEdges = _pWXFace->numberOfEdges(); for (i = 0; i < nEdges; ++i) { - if ((_DotP[i] == 0) && (_DotP[(i + 1) % nEdges] == 0)) { + if ((_DotP[i] == 0.0f) && (_DotP[(i + 1) % nEdges] == 0.0f)) { // TODO ditto return i; } } @@ -66,7 +66,7 @@ void WXFaceLayer::RetrieveCuspEdgesIndices(vector<int>& oCuspEdges) int i = 0; int nEdges = _pWXFace->numberOfEdges(); for (i = 0; i < nEdges; ++i) { - if (_DotP[i] * _DotP[(i + 1) % nEdges] < 0) { + if (_DotP[i] * _DotP[(i + 1) % nEdges] < 0.0f) { // we got one oCuspEdges.push_back(i); } @@ -78,7 +78,7 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() // if the smooth edge has already been built: exit if (_pSmoothEdge) return _pSmoothEdge; - real ta, tb; + float ta, tb; WOEdge *woea(0), *woeb(0); bool ok = false; vector<int> cuspEdgesIndices; @@ -101,7 +101,7 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() // 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) { + if (_DotP[cuspEdgesIndices[0]] > 0.0f) { woea = _pWXFace->GetOEdge(cuspEdgesIndices[0]); woeb = _pWXFace->GetOEdge(cuspEdgesIndices[1]); indexStart = cuspEdgesIndices[0]; @@ -136,18 +136,18 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() } unsigned index0 = Get0VertexIndex(); // retrieve the 0 vertex index unsigned nedges = _pWXFace->numberOfEdges(); - if (_DotP[cuspEdgesIndices[0]] > 0) { + 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.0; + tb = 0.0f; } else { woea = _pWXFace->GetOEdge(index0); woeb = _pWXFace->GetOEdge(cuspEdgesIndices[0]); indexEnd = cuspEdgesIndices[0]; - ta = 0.0; + ta = 0.0f; tb = _DotP[indexEnd] / (_DotP[indexEnd] - _DotP[(indexEnd + 1) % nedges]); } ok = true; @@ -159,8 +159,8 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() // the order of the WOEdge index is wrong woea = _pWXFace->GetOEdge((index + 1) % nedges); woeb = _pWXFace->GetOEdge((index - 1) % nedges); - ta = 0; - tb = 1; + ta = 0.0f; + tb = 1.0f; ok = true; } else { @@ -170,8 +170,8 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() // the order of the WOEdge index is good woea = _pWXFace->GetOEdge((index - 1) % nedges); woeb = _pWXFace->GetOEdge((index + 1) % nedges); - ta = 1; - tb = 0; + ta = 1.0f; + tb = 0.0f; #endif } } @@ -183,7 +183,7 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() _pSmoothEdge->setTb(tb); if (_Nature & Nature::SILHOUETTE) { if (_nNullDotP != 2) { - if (_DotP[_ClosestPointIndex] + 0.01 > 0) + if (_DotP[_ClosestPointIndex] + 0.01f > 0.0f) _pSmoothEdge->setFront(true); else _pSmoothEdge->setFront(false); @@ -205,7 +205,7 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() } // Else we must build it WOEdge *woea, *woeb; - real ta, tb; + float ta, tb; if (!front()) { // is it in the right order ? // the order of the WOEdge index is wrong woea = _OEdgeList[(i + 1) % numberOfEdges()]; @@ -213,8 +213,8 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() woeb = _OEdgeList[numberOfEdges() - 1]; else woeb = _OEdgeList[(i - 1)]; - ta = 0; - tb = 1; + ta = 0.0f; + tb = 1.0f; } else { // the order of the WOEdge index is good @@ -223,8 +223,8 @@ WXSmoothEdge *WXFaceLayer::BuildSmoothEdge() else woea = _OEdgeList[(i - 1)]; woeb = _OEdgeList[(i + 1) % numberOfEdges()]; - ta = 1; - tb = 0; + ta = 1.0f; + tb = 0.0f; } _pSmoothEdge = new ExactSilhouetteEdge(ExactSilhouetteEdge::VERTEX_VERTEX); @@ -246,11 +246,11 @@ void WXFace::ComputeCenter() { vector<WVertex *> iVertexList; RetrieveVertexList(iVertexList); - Vec3r center; + Vec3f center; for (vector<WVertex *>::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { center += (*wv)->GetVertex(); } - center /= (real)iVertexList.size(); + center /= (float)iVertexList.size(); setCenter(center); } @@ -268,28 +268,28 @@ WFace *WXShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdge if (!face) return NULL; - Vec3r center; + Vec3f center; for (vector<WVertex *>::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { center += (*wv)->GetVertex(); } - center /= (real)iVertexList.size(); + center /= (float)iVertexList.size(); ((WXFace *)face)->setCenter(center); return face; } -WFace *WXShape::MakeFace(vector<WVertex *>& iVertexList, vector<Vec3r>& iNormalsList, vector<Vec2r>& iTexCoordsList, +WFace *WXShape::MakeFace(vector<WVertex *>& iVertexList, vector<Vec3f>& iNormalsList, vector<Vec2f>& iTexCoordsList, vector<bool>& iFaceEdgeMarksList, unsigned iMaterialIndex) { WFace *face = WShape::MakeFace(iVertexList, iNormalsList, iTexCoordsList, iFaceEdgeMarksList, iMaterialIndex); #if 0 - Vec3r center; + Vec3f center; for (vector<WVertex *>::iterator wv = iVertexList.begin(), wvend = iVertexList.end(); wv != wvend; ++wv) { center += (*wv)->GetVertex(); } - center /= (real)iVertexList.size(); - ((WSFace *)face)->setCenter(center); + center /= (float)iVertexList.size(); + ((WXFace *)face)->setCenter(center); #endif return face; diff --git a/source/blender/freestyle/intern/winged_edge/WXEdge.h b/source/blender/freestyle/intern/winged_edge/WXEdge.h index ce9749369fc..774cc67f3ab 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WXEdge.h @@ -55,7 +55,7 @@ private: CurvatureInfo *_curvatures; public: - inline WXVertex(const Vec3r &v) : WVertex(v) + inline WXVertex(const Vec3f &v) : WVertex(v) { _curvatures = NULL; } @@ -99,7 +99,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXVertex") #endif - }; @@ -117,7 +116,7 @@ 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 - int _order; + 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; @@ -177,7 +176,7 @@ public: return _front; } - inline int order() const + inline short order() const { return _order; } @@ -206,7 +205,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdge") #endif - }; /********************************** @@ -221,16 +219,15 @@ public: class WXSmoothEdge { public: - typedef enum { - EDGE_EDGE, - VERTEX_EDGE, - EDGE_VERTEX, - } Configuration; + 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 - real _ta; // The silhouette starting point's coordinates are : _woea[0]+ta*(_woea[1]-_woea[0]) - real _tb; // The silhouette ending point's coordinates are : _woeb[0]+ta*(_woeb[1]-_woeb[0]) + 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; @@ -238,8 +235,8 @@ public: { _woea = NULL; _woeb = NULL; - _ta = 0; - _tb = 0; + _ta = 0.0f; + _tb = 0.0f; _front = false; _config = EDGE_EDGE; } @@ -266,12 +263,12 @@ public: return _woeb; } - inline real ta() const + inline float ta() const { return _ta; } - inline real tb() const + inline float tb() const { return _tb; } @@ -297,12 +294,12 @@ public: _woeb = iwoeb; } - inline void setTa(real ta) + inline void setTa(float ta) { _ta = ta; } - inline void setTb(real tb) + inline void setTb(float tb) { _tb = tb; } @@ -334,7 +331,7 @@ public: 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<real> _DotP; + vector<float> _DotP; WXSmoothEdge *_pSmoothEdge; WXNature _Nature; @@ -383,7 +380,7 @@ public: } } - inline const real dotP(int i) const + inline const float dotP(int i) const { return _DotP[i]; } @@ -403,7 +400,7 @@ public: return _ClosestPointIndex; } - inline Nature::EdgeNature nature() const + inline WXNature nature() const { return _Nature; } @@ -458,21 +455,21 @@ public: WXSmoothEdge *BuildSmoothEdge(); - inline void setDotP(const vector<real>& iDotP) + inline void setDotP(const vector<float>& iDotP) { _DotP = iDotP; } - inline void PushDotP(real iDotP) + inline void PushDotP(float iDotP) { _DotP.push_back(iDotP); - if (iDotP > 0) + if (iDotP > 0.0f) ++_nPosDotP; - if (iDotP == 0) + if (iDotP == 0.0f) // TODO this comparison is weak, check if it actually works ++_nNullDotP; } - inline void ReplaceDotP(unsigned int index, real newDotP) + inline void ReplaceDotP(unsigned int index, float newDotP) { _DotP[index] = newDotP; updateDotPInfos(); @@ -482,10 +479,10 @@ public: { _nPosDotP = 0; _nNullDotP = 0; - for (vector<real>::iterator d = _DotP.begin(), dend = _DotP.end(); d != dend; ++d) { - if ((*d) > 0) + for (vector<float>::iterator d = _DotP.begin(), dend = _DotP.end(); d != dend; ++d) { + if ((*d) > 0.0f) ++_nPosDotP; - if ((*d) == 0) + if ((*d) == 0.0f) // TODO ditto ++_nNullDotP; } } @@ -498,17 +495,17 @@ public: class WXFace : public WFace { protected: - Vec3r _center; // center of the face - real _Z; // distance from viewpoint to the center of the face + 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 - real _dotp; // value obtained when computing the normal-viewpoint dot product + float _dotp; // value obtained when computing the normal-viewpoint dot product vector<WXFaceLayer *> _SmoothLayers; // The data needed to store one or several smooth edges that traverse the face public: inline WXFace() : WFace() { - _Z = 0.0; + _Z = 0.0f; _front = false; } @@ -552,12 +549,12 @@ public: } /*! accessors */ - inline Vec3r& center() + inline Vec3f& center() { return _center; } - inline real Z() + inline float Z() { return _Z; } @@ -567,7 +564,7 @@ public: return _front; } - inline real dotp() + inline float dotp() { return _dotp; } @@ -628,14 +625,14 @@ public: } /*! modifiers */ - inline void setCenter(const Vec3r& iCenter) + inline void setCenter(const Vec3f& iCenter) { _center = iCenter; } void ComputeCenter(); - inline void setZ(real z) + inline void setZ(float z) { _Z = z; } @@ -645,10 +642,10 @@ public: _front = iFront; } - inline void setDotP(real iDotP) + inline void setDotP(float iDotP) { _dotp = iDotP; - if (_dotp > 0) + if (_dotp > 0.0f) _front = true; else _front = false; @@ -700,7 +697,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXFace") #endif - }; @@ -714,22 +710,24 @@ public: class WXShape : public WShape { +#if 0 public: typedef WXShape type_name; +#endif protected: - bool _computeViewIndependant; // flag to indicate whether the view independant stuff must be computed or not + bool _computeViewIndependent; // flag to indicate whether the view independent stuff must be computed or not public: inline WXShape() : WShape() { - _computeViewIndependant = true; + _computeViewIndependent = true; } /*! copy constructor */ inline WXShape(WXShape& iBrother) : WShape(iBrother) { - _computeViewIndependant = iBrother._computeViewIndependant; + _computeViewIndependent = iBrother._computeViewIndependent; } virtual WShape *duplicate() @@ -740,14 +738,14 @@ public: virtual ~WXShape() {} - inline bool getComputeViewIndependantFlag() const + inline bool getComputeViewIndependentFlag() const { - return _computeViewIndependant; + return _computeViewIndependent; } - inline void setComputeViewIndependantFlag(bool iFlag) + inline void setComputeViewIndependentFlag(bool iFlag) { - _computeViewIndependant = iFlag; + _computeViewIndependent = iFlag; } /*! designed to build a specialized WFace for use in MakeFace */ @@ -778,7 +776,7 @@ public: * The list of tex coords, iTexCoordsList[i] corresponding to the normal of the vertex iVertexList[i] for * that face. */ - virtual WFace *MakeFace(vector<WVertex *>& iVertexList, vector<Vec3r>& iNormalsList, vector<Vec2r>& iTexCoordsList, + virtual WFace *MakeFace(vector<WVertex *>& iVertexList, vector<Vec3f>& iNormalsList, vector<Vec2f>& iTexCoordsList, vector<bool>& iFaceEdgeMarksList, unsigned iMaterialIndex); /*! Reset all edges and vertices flags (which might have been set up on a previous pass) */ @@ -801,7 +799,6 @@ public: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXShape") #endif - }; /* diff --git a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp index 590e03255f5..78773a9680d 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp +++ b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.cpp @@ -45,11 +45,11 @@ void WXEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet& ifs) //ifs.setId(shape->GetId()); } -void WXEdgeBuilder::buildWVertices(WShape& shape, const real *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(Vec3r(vertices[i], vertices[i + 1], vertices[i + 2])); + vertex = new WXVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); vertex->setId(i / 3); shape.AddVertex(vertex); } diff --git a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h index 143c2e33608..6df4efcd9b7 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h +++ b/source/blender/freestyle/intern/winged_edge/WXEdgeBuilder.h @@ -43,7 +43,7 @@ public: VISIT_DECL(IndexedFaceSet) protected: - virtual void buildWVertices(WShape& shape, const real *vertices, unsigned vsize); + virtual void buildWVertices(WShape& shape, const float *vertices, unsigned vsize); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WXEdgeBuilder") diff --git a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp index c9f2f3badab..2ddc821da78 100644 --- a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp +++ b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.cpp @@ -89,15 +89,15 @@ bool WingedEdgeBuilder::buildWShape(WShape& shape, IndexedFaceSet& ifs) unsigned int nsize = ifs.nsize(); //soc unused - unsigned tsize = ifs.tsize(); - const real *vertices = ifs.vertices(); - const real *normals = ifs.normals(); - const real *texCoords = ifs.texCoords(); + const float *vertices = ifs.vertices(); + const float *normals = ifs.normals(); + const float *texCoords = ifs.texCoords(); - real *new_vertices; - real *new_normals; + float *new_vertices; + float *new_normals; - new_vertices = new real[vsize]; - new_normals = new real[nsize]; + new_vertices = new float[vsize]; + new_normals = new float[nsize]; // transform coordinates from local to world system if (_current_matrix) { @@ -177,13 +177,15 @@ bool WingedEdgeBuilder::buildWShape(WShape& shape, IndexedFaceSet& ifs) 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(); +#endif // Parse the built winged-edge shape to update post-flags - set<Vec3r> normalsSet; + set<Vec3f> normalsSet; vector<WVertex *>& wvertices = shape.getVertexList(); for (vector<WVertex *>::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend; ++wv) { if ((*wv)->isBoundary()) @@ -211,18 +213,18 @@ bool WingedEdgeBuilder::buildWShape(WShape& shape, IndexedFaceSet& ifs) return true; } -void WingedEdgeBuilder::buildWVertices(WShape& shape, const real *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(Vec3r(vertices[i], vertices[i + 1], vertices[i + 2])); + vertex = new WVertex(Vec3f(vertices[i], vertices[i + 1], vertices[i + 2])); vertex->setId(i / 3); shape.AddVertex(vertex); } } -void WingedEdgeBuilder::buildTriangleStrip(const real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, +void WingedEdgeBuilder::buildTriangleStrip(const float * /*vertices*/, const float *normals, vector<FrsMaterial>& /*iMaterials*/, + const float *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, const unsigned *vindices, const unsigned *nindices, const unsigned *mindices, const unsigned *tindices, const unsigned nvertices) { @@ -232,8 +234,8 @@ void WingedEdgeBuilder::buildTriangleStrip(const real *vertices, const real *nor WShape *currentShape = _current_wshape; // the current shape being built vector<WVertex *> triangleVertices; - vector<Vec3r> triangleNormals; - vector<Vec2r> triangleTexCoords; + vector<Vec3f> triangleNormals; + vector<Vec2f> triangleTexCoords; vector<bool> triangleFaceEdgeMarks; while (nDoneVertices < nvertices) { @@ -245,18 +247,18 @@ void WingedEdgeBuilder::buildTriangleStrip(const real *vertices, const real *nor triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], normals[nindices[nTriangle] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], normals[nindices[nTriangle + 1] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], normals[nindices[nTriangle + 2] + 2])); if (texCoords) { - triangleTexCoords.push_back(Vec2r(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); - triangleTexCoords.push_back(Vec2r(texCoords[tindices[nTriangle + 1]], + 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(Vec2r(texCoords[tindices[nTriangle + 2]], + triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 2]], texCoords[tindices[nTriangle + 2] + 1])); } } @@ -265,18 +267,18 @@ void WingedEdgeBuilder::buildTriangleStrip(const real *vertices, const real *nor triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 2] / 3]); triangleVertices.push_back(currentShape->getVertexList()[vindices[nTriangle + 1] / 3]); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle]], normals[nindices[nTriangle] + 1], normals[nindices[nTriangle] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 2]], normals[nindices[nTriangle + 2] + 1], normals[nindices[nTriangle + 2] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[nTriangle + 1]], normals[nindices[nTriangle + 1] + 1], normals[nindices[nTriangle + 1] + 2])); if (texCoords) { - triangleTexCoords.push_back(Vec2r(texCoords[tindices[nTriangle]], texCoords[tindices[nTriangle] + 1])); - triangleTexCoords.push_back(Vec2r(texCoords[tindices[nTriangle + 2]], + 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(Vec2r(texCoords[tindices[nTriangle + 1]], + triangleTexCoords.push_back(Vec2f(texCoords[tindices[nTriangle + 1]], texCoords[tindices[nTriangle + 1] + 1])); } } @@ -296,23 +298,23 @@ void WingedEdgeBuilder::buildTriangleStrip(const real *vertices, const real *nor } } -void WingedEdgeBuilder::buildTriangleFan(const real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *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<FrsMaterial>& /*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 } -void WingedEdgeBuilder::buildTriangles(const real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, +void WingedEdgeBuilder::buildTriangles(const float * /*vertices*/, const float *normals, vector<FrsMaterial>& /*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<WVertex *> triangleVertices; - vector<Vec3r> triangleNormals; - vector<Vec2r> triangleTexCoords; + vector<Vec3f> triangleNormals; + vector<Vec2f> triangleTexCoords; vector<bool> triangleFaceEdgeMarks; // Each triplet of vertices is considered as an independent triangle @@ -321,17 +323,17 @@ void WingedEdgeBuilder::buildTriangles(const real *vertices, const real *normals triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 1] / 3]); triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 2] / 3]); - triangleNormals.push_back(Vec3r(normals[nindices[3 * i]], normals[nindices[3 * i] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[3 * i]], normals[nindices[3 * i] + 1], normals[nindices[3 * i] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[3 * i + 1]], normals[nindices[3 * i + 1] + 1], + triangleNormals.push_back(Vec3f(normals[nindices[3 * i + 1]], normals[nindices[3 * i + 1] + 1], normals[nindices[3 * i + 1] + 2])); - triangleNormals.push_back(Vec3r(normals[nindices[3 * i + 2]], normals[nindices[3 * i + 2] + 1], + 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(Vec2r(texCoords[tindices[3 * i]], texCoords[tindices[3 * i] + 1])); - triangleTexCoords.push_back(Vec2r(texCoords[tindices[3 * i + 1]], texCoords[tindices[3 * i + 1] + 1])); - triangleTexCoords.push_back(Vec2r(texCoords[tindices[3 * i + 2]], texCoords[tindices[3 * i + 2] + 1])); + 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); @@ -346,10 +348,10 @@ void WingedEdgeBuilder::buildTriangles(const real *vertices, const real *normals currentShape->MakeFace(triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0); } -void WingedEdgeBuilder::transformVertices(const real *vertices, unsigned vsize, const Matrix44r& transform, real *res) +void WingedEdgeBuilder::transformVertices(const float *vertices, unsigned vsize, const Matrix44r& transform, float *res) { - const real *v = vertices; - real *pv = 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]); @@ -361,10 +363,10 @@ void WingedEdgeBuilder::transformVertices(const real *vertices, unsigned vsize, } } -void WingedEdgeBuilder::transformNormals(const real *normals, unsigned nsize, const Matrix44r& transform, real *res) +void WingedEdgeBuilder::transformNormals(const float *normals, unsigned nsize, const Matrix44r& transform, float *res) { - const real *n = normals; - real *pn = 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]); diff --git a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h index 36f090f4ae9..5683b39fd28 100644 --- a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h +++ b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h @@ -118,29 +118,29 @@ public: protected: virtual bool buildWShape(WShape& shape, IndexedFaceSet& ifs); - virtual void buildWVertices(WShape& shape, const real *vertices, unsigned vsize); + virtual void buildWVertices(WShape& shape, const float *vertices, unsigned vsize); RenderMonitor *_pRenderMonitor; private: - void buildTriangleStrip(const real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + void buildTriangleStrip(const float *vertices, const float *normals, vector<FrsMaterial>& 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 real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + void buildTriangleFan(const float *vertices, const float *normals, vector<FrsMaterial>& 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 real *vertices, const real *normals, vector<FrsMaterial>& iMaterials, - const real *texCoords, const IndexedFaceSet::FaceEdgeMark *iFaceEdgeMarks, + void buildTriangles(const float *vertices, const float *normals, vector<FrsMaterial>& 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 real *vertices, unsigned vsize, const Matrix44r& transform, real *res); + void transformVertices(const float *vertices, unsigned vsize, const Matrix44r& transform, float *res); - void transformNormals(const real *normals, unsigned nsize, const Matrix44r& transform, real *res); + void transformNormals(const float *normals, unsigned nsize, const Matrix44r& transform, float *res); WShape *_current_wshape; FrsMaterial *_current_frs_material; @@ -151,7 +151,6 @@ private: #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdgeBuilder") #endif - }; } /* namespace Freestyle */ |