2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * ***** END GPL LICENSE BLOCK *****
21 /** \file blender/freestyle/intern/application/Controller.cpp
34 #include "AppCanvas.h"
35 #include "AppConfig.h"
36 #include "Controller.h"
38 #include "../image/Image.h"
40 #include "../scene_graph/NodeDrawingStyle.h"
41 #include "../scene_graph/NodeShape.h"
42 #include "../scene_graph/NodeTransform.h"
43 #include "../scene_graph/NodeSceneRenderLayer.h"
44 #include "../scene_graph/ScenePrettyPrinter.h"
45 #include "../scene_graph/VertexRep.h"
47 #include "../stroke/PSStrokeRenderer.h"
48 #include "../stroke/TextStrokeRenderer.h"
49 #include "../stroke/StrokeTesselator.h"
50 #include "../stroke/StyleModule.h"
52 #include "../system/StringUtils.h"
53 #include "../system/PythonInterpreter.h"
55 #include "../view_map/SteerableViewMap.h"
56 #include "../view_map/ViewMap.h"
57 #include "../view_map/ViewMapIO.h"
58 #include "../view_map/ViewMapTesselator.h"
60 #include "../winged_edge/Curvature.h"
61 #include "../winged_edge/WEdge.h"
62 #include "../winged_edge/WingedEdgeBuilder.h"
63 #include "../winged_edge/WXEdgeBuilder.h"
65 #include "../blender_interface/BlenderFileLoader.h"
66 #include "../blender_interface/BlenderStrokeRenderer.h"
67 #include "../blender_interface/BlenderStyleModule.h"
69 #include "BKE_global.h"
70 #include "BLI_utildefines.h"
71 #include "BLI_path_util.h"
73 #include "DNA_freestyle_types.h"
75 #include "FRS_freestyle.h"
79 Controller::Controller()
81 const string sep(Config::DIR_SEP.c_str());
83 const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR + sep +
84 Config::OPTIONS_CURRENT_DIRS_FILE;
85 _current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true);
88 _RootNode = new NodeGroup;
91 _SilhouetteNode = NULL;
93 _ProjectedSilhouette = NULL;
94 _VisibleProjectedSilhouette = NULL;
97 _DebugNode = new NodeGroup;
103 _pRenderMonitor = NULL;
105 _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE);
107 _ProgressBar = new ProgressBar;
109 _minEdgeSize = DBL_MAX;
117 _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
118 //_VisibilityAlgo = ViewMapBuilder::ray_casting;
120 _Canvas = new AppCanvas;
122 _inter = new PythonInterpreter();
123 _EnableViewMapCache = false;
125 _EnableFaceSmoothness = false;
126 _ComputeRidges = true;
127 _ComputeSteerableViewMap = false;
128 _ComputeSuggestive = true;
129 _ComputeMaterialBoundaries = true;
131 _creaseAngle = 134.43;
132 prevSceneHash = -1.0;
137 Controller::~Controller()
139 if (NULL != _RootNode) {
140 int ref = _RootNode->destroy();
145 if (NULL != _SilhouetteNode) {
146 int ref = _SilhouetteNode->destroy();
148 delete _SilhouetteNode;
151 if (NULL != _DebugNode) {
152 int ref = _DebugNode->destroy();
182 //delete _current_dirs;
185 void Controller::setView(AppView *iView)
191 _Canvas->setViewer(_pView);
194 void Controller::setRenderMonitor(RenderMonitor *iRenderMonitor)
196 _pRenderMonitor = iRenderMonitor;
199 void Controller::setPassDiffuse(float *buf, int width, int height)
201 AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
202 BLI_assert(app_canvas != 0);
203 app_canvas->setPassDiffuse(buf, width, height);
206 void Controller::setPassZ(float *buf, int width, int height)
208 AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
209 BLI_assert(app_canvas != 0);
210 app_canvas->setPassZ(buf, width, height);
213 void Controller::setContext(bContext *C)
215 PythonInterpreter *py_inter = dynamic_cast<PythonInterpreter*>(_inter);
216 py_inter->setContext(C);
219 bool Controller::hitViewMapCache()
221 if (!_EnableViewMapCache) {
224 if (sceneHashFunc.match()) {
225 return (NULL != _ViewMap);
227 sceneHashFunc.store();
231 int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
233 BlenderFileLoader loader(re, srl);
235 loader.setRenderMonitor(_pRenderMonitor);
239 NodeGroup *blenderScene = loader.Load();
241 if (blenderScene == NULL) {
242 if (G.debug & G_DEBUG_FREESTYLE) {
243 cout << "Cannot load scene" << endl;
248 if (blenderScene->numberOfChildren() < 1) {
249 if (G.debug & G_DEBUG_FREESTYLE) {
250 cout << "Empty scene" << endl;
252 blenderScene->destroy();
257 real duration = _Chrono.stop();
258 if (G.debug & G_DEBUG_FREESTYLE) {
259 cout << "Scene loaded" << endl;
260 printf("Mesh cleaning : %lf\n", duration);
261 printf("View map cache : %s\n", _EnableViewMapCache ? "enabled" : "disabled");
263 _SceneNumFaces += loader.numFacesRead();
265 if (loader.minEdgeSize() < _minEdgeSize) {
266 _minEdgeSize = loader.minEdgeSize();
270 ScenePrettyPrinter spp;
271 blenderScene->accept(spp);
274 _RootNode->AddChild(blenderScene);
275 _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
277 _pView->setModel(_RootNode);
280 if (_pRenderMonitor->testBreak())
283 if (_EnableViewMapCache) {
286 if (freestyle_proj[3][3] != 0.0)
287 cam = new NodeOrthographicCamera;
289 cam = new NodePerspectiveCamera;
291 for (int i = 0; i < 4; i++) {
292 for (int j = 0; j < 4; j++) {
293 proj[i * 4 + j] = freestyle_proj[i][j];
296 cam->setProjectionMatrix(proj);
297 _RootNode->AddChild(cam);
298 _RootNode->AddChild(new NodeSceneRenderLayer(*re->scene, *srl));
300 sceneHashFunc.reset();
301 //blenderScene->accept(sceneHashFunc);
302 _RootNode->accept(sceneHashFunc);
303 if (G.debug & G_DEBUG_FREESTYLE) {
304 cout << "Scene hash : " << sceneHashFunc.toString() << endl;
306 if (hitViewMapCache()) {
318 WXEdgeBuilder wx_builder;
319 wx_builder.setRenderMonitor(_pRenderMonitor);
320 blenderScene->accept(wx_builder);
321 _winged_edge = wx_builder.getWingedEdge();
323 duration = _Chrono.stop();
324 if (G.debug & G_DEBUG_FREESTYLE) {
325 printf("WEdge building : %lf\n", duration);
329 _pView->setDebug(_DebugNode);
332 if (0 != ws_builder) {
337 soc QFileInfo qfi(iFileName);
338 soc string basename((const char*)qfi.fileName().toAscii().data());
339 char cleaned[FILE_MAX];
340 BLI_strncpy(cleaned, iFileName, FILE_MAX);
341 BLI_cleanup_file(NULL, cleaned);
342 string basename = string(cleaned);
345 _ListOfModels.push_back("Blender_models");
347 _Scene3dBBox = _RootNode->bbox();
349 _bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm();
350 if (G.debug & G_DEBUG_FREESTYLE) {
351 cout << "Triangles nb : " << _SceneNumFaces << " imported, " <<
352 _winged_edge->getNumFaces() << " retained" << endl;
353 cout << "Bounding Box : " << _bboxDiag << endl;
358 _SceneNumFaces = _winged_edge->getNumFaces();
359 if (_SceneNumFaces == 0) {
367 void Controller::CloseFile()
369 WShape::setCurrentId(0);
370 _ListOfModels.clear();
372 // We deallocate the memory:
381 setPassDiffuse(NULL, 0, 0);
382 setPassZ(NULL, 0, 0);
385 void Controller::ClearRootNode()
387 _pView->DetachModel();
388 if (NULL != _RootNode) {
389 int ref = _RootNode->destroy();
392 _RootNode->clearBBox();
396 void Controller::DeleteWingedEdge()
405 _Scene3dBBox.clear();
407 _minEdgeSize = DBL_MAX;
410 void Controller::DeleteViewMap(bool freeCache)
412 _pView->DetachSilhouette();
413 if (NULL != _SilhouetteNode) {
414 int ref = _SilhouetteNode->destroy();
416 delete _SilhouetteNode;
417 _SilhouetteNode = NULL;
422 if (NULL != _ProjectedSilhouette) {
423 int ref = _ProjectedSilhouette->destroy();
425 delete _ProjectedSilhouette;
426 _ProjectedSilhouette = NULL;
429 if (NULL != _VisibleProjectedSilhouette) {
430 int ref = _VisibleProjectedSilhouette->destroy();
432 delete _VisibleProjectedSilhouette;
433 _VisibleProjectedSilhouette = NULL;
438 _pView->DetachDebug();
439 if (NULL != _DebugNode) {
440 int ref = _DebugNode->destroy();
442 _DebugNode->addRef();
445 if (NULL != _ViewMap) {
446 if (freeCache || !_EnableViewMapCache) {
449 prevSceneHash = -1.0;
457 void Controller::ComputeViewMap()
459 if (!_ListOfModels.size())
464 // retrieve the 3D viewpoint and transformations information
465 //----------------------------------------------------------
466 // Save the viewpoint context at the view level in order
467 // to be able to restore it later:
469 // Restore the context of view:
470 // we need to perform all these operations while the
472 Vec3f vp(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
475 if (G.debug & G_DEBUG_FREESTYLE) {
476 cout << "mv" << endl;
480 for (int i = 0; i < 4; i++) {
481 for (int j = 0; j < 4; j++) {
482 mv[i][j] = freestyle_mv[i][j];
484 if (G.debug & G_DEBUG_FREESTYLE) {
485 cout << mv[i][j] << " ";
490 if (G.debug & G_DEBUG_FREESTYLE) {
497 if (G.debug & G_DEBUG_FREESTYLE) {
498 cout << "\nproj" << endl;
502 for (int i = 0; i < 4; i++) {
503 for (int j = 0; j < 4; j++) {
504 proj[i][j] = freestyle_proj[i][j];
506 if (G.debug & G_DEBUG_FREESTYLE) {
507 cout << proj[i][j] << " ";
512 if (G.debug & G_DEBUG_FREESTYLE) {
519 for (int i = 0; i < 4; i++)
520 viewport[i] = freestyle_viewport[i];
523 if (G.debug & G_DEBUG_FREESTYLE) {
524 cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl;
528 // Flag the WXEdge structure for silhouette edge detection:
529 //----------------------------------------------------------
531 if (G.debug & G_DEBUG_FREESTYLE) {
532 cout << "\n=== Detecting silhouette edges ===" << endl;
536 edgeDetector.setViewpoint(vp);
537 edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0);
538 edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
539 edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
540 edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
541 edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
542 edgeDetector.setCreaseAngle(_creaseAngle);
543 edgeDetector.setSphereRadius(_sphereRadius);
544 edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
545 edgeDetector.setRenderMonitor(_pRenderMonitor);
546 edgeDetector.processShapes(*_winged_edge);
548 real duration = _Chrono.stop();
549 if (G.debug & G_DEBUG_FREESTYLE) {
550 printf("Feature lines : %lf\n", duration);
553 if (_pRenderMonitor->testBreak())
556 // Builds the view map structure from the flagged WSEdge structure:
557 //----------------------------------------------------------
558 ViewMapBuilder vmBuilder;
559 vmBuilder.setEnableQI(_EnableQI);
560 vmBuilder.setViewpoint(vp);
561 vmBuilder.setTransform(mv, proj, viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian());
562 vmBuilder.setFrustum(_pView->znear(), _pView->zfar());
563 vmBuilder.setGrid(&_Grid);
564 vmBuilder.setRenderMonitor(_pRenderMonitor);
566 // Builds a tesselated form of the silhouette for display purpose:
567 //---------------------------------------------------------------
568 ViewMapTesselator3D sTesselator3d;
570 ViewMapTesselator2D sTesselator2d;
571 sTesselator2d.setNature(_edgeTesselationNature);
573 sTesselator3d.setNature(_edgeTesselationNature);
575 if (G.debug & G_DEBUG_FREESTYLE) {
576 cout << "\n=== Building the view map ===" << endl;
580 _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces);
581 _ViewMap->setScene3dBBox(_Scene3dBBox);
583 if (G.debug & G_DEBUG_FREESTYLE) {
584 printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size());
587 // Tesselate the 3D edges:
588 _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
589 _SilhouetteNode->addRef();
591 // Tesselate 2D edges
593 _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
594 _ProjectedSilhouette->addRef();
597 duration = _Chrono.stop();
598 if (G.debug & G_DEBUG_FREESTYLE) {
599 printf("ViewMap building : %lf\n", duration);
602 _pView->AddSilhouette(_SilhouetteNode);
604 _pView->AddSilhouette(_WRoot);
605 _pView->Add2DSilhouette(_ProjectedSilhouette);
606 _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette);
608 _pView->AddDebug(_DebugNode);
610 // Draw the steerable density map:
611 //--------------------------------
612 if (_ComputeSteerableViewMap) {
613 ComputeSteerableViewMap();
615 // Reset Style modules modification flags
621 void Controller::ComputeSteerableViewMap()
624 if ((!_Canvas) || (!_ViewMap))
627 // Build 4 nodes containing the edges in the 4 directions
628 NodeGroup *ng[Canvas::NB_STEERABLE_VIEWMAP];
630 real c = 32.0f/255.0f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32.
631 for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
632 ng[i] = new NodeGroup;
634 NodeShape *completeNS = new NodeShape;
635 completeNS->material().setDiffuse(c,c,c,1);
636 ng[Canvas::NB_STEERABLE_VIEWMAP-1]->AddChild(completeNS);
637 SteerableViewMap * svm = _Canvas->getSteerableViewMap();
640 ViewMap::fedges_container& fedges = _ViewMap->FEdges();
643 for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end();
647 if ((*f)->viewedge()->qi() != 0)
649 fRep = new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d());
650 completeNS->AddRep(fRep); // add to the complete map anyway
651 double *oweights = svm->AddFEdge(*f);
652 for (i = 0; i < (Canvas::NB_STEERABLE_VIEWMAP - 1); ++i) {
654 double wc = oweights[i]*c;
655 if (oweights[i] == 0)
657 ns->material().setDiffuse(wc, wc, wc, 1);
663 GrayImage *img[Canvas::NB_STEERABLE_VIEWMAP];
665 QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height());
668 for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
669 offscreenBuffer.AddNode(ng[i]);
671 img[i] = new GrayImage(_pView->width(), _pView->height());
672 offscreenBuffer.readPixels(0,0,_pView->width(), _pView->height(), img[i]->getArray());
674 pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height());
677 if (G.debug & G_DEBUG_FREESTYLE) {
678 cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl;
681 //pm.save(QString("steerable") + QString::number(i) + QString(".bmp"), "BMP");
682 // FIXME!! Lost of time !
685 img[i] = new GrayImage(_pView->width(), _pView->height());
686 for (unsigned int y = 0; y < img[i]->height(); ++y) {
687 for (unsigned int x = 0; x < img[i]->width(); ++x) {
688 //img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)) / 255.0f);
689 img[i]->setPixel(x, y, (float)qGray(qimg.pixel(x, y)));
690 //float c = qGray(qimg.pixel(x, y));
691 //img[i]->setPixel(x, y, qGray(qimg.pixel(x, y)));
694 offscreenBuffer.DetachNode(ng[i]);
699 qimg = QImage(_pView->width(), _pView->height(), 32);
700 for (unsigned int y = 0; y < img[i]->height(); ++y) {
701 for (unsigned int x = 0; x < img[i]->width(); ++x) {
702 float v = img[i]->pixel(x, y);
703 qimg.setPixel(x, y, qRgb(v, v, v));
706 qimg.save(QString("newsteerable") + QString::number(i) + QString(".bmp"), "BMP");
711 svm->buildImagesPyramids(img, false, 0, 1.0f);
715 void Controller::saveSteerableViewMapImages()
717 SteerableViewMap * svm = _Canvas->getSteerableViewMap();
719 cerr << "the Steerable ViewMap has not been computed yet" << endl;
722 svm->saveSteerableViewMap();
725 void Controller::toggleVisibilityAlgo()
727 if (_VisibilityAlgo == ViewMapBuilder::ray_casting) {
728 _VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
730 else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) {
731 _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast;
734 _VisibilityAlgo = ViewMapBuilder::ray_casting;
738 void Controller::setVisibilityAlgo(int algo)
741 case FREESTYLE_ALGO_REGULAR:
742 _VisibilityAlgo = ViewMapBuilder::ray_casting;
744 case FREESTYLE_ALGO_FAST:
745 _VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
747 case FREESTYLE_ALGO_VERYFAST:
748 _VisibilityAlgo = ViewMapBuilder::ray_casting_very_fast;
750 case FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL:
751 _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_traditional;
753 case FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL:
754 _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_traditional;
756 case FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE:
757 _VisibilityAlgo = ViewMapBuilder::ray_casting_culled_adaptive_cumulative;
759 case FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE:
760 _VisibilityAlgo = ViewMapBuilder::ray_casting_adaptive_cumulative;
765 int Controller::getVisibilityAlgo()
767 switch (_VisibilityAlgo) {
768 case ViewMapBuilder::ray_casting:
769 return FREESTYLE_ALGO_REGULAR;
770 case ViewMapBuilder::ray_casting_fast:
771 return FREESTYLE_ALGO_FAST;
772 case ViewMapBuilder::ray_casting_very_fast:
773 return FREESTYLE_ALGO_VERYFAST;
774 case ViewMapBuilder::ray_casting_culled_adaptive_traditional:
775 return FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL;
776 case ViewMapBuilder::ray_casting_adaptive_traditional:
777 return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL;
778 case ViewMapBuilder::ray_casting_culled_adaptive_cumulative:
779 return FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE;
780 case ViewMapBuilder::ray_casting_adaptive_cumulative:
781 return FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE;
784 // ray_casting_adaptive_traditional is the most exact replacement
786 return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL;
789 void Controller::setViewMapCache(bool iBool)
791 _EnableViewMapCache = iBool;
794 bool Controller::getViewMapCache() const
796 return _EnableViewMapCache;
799 void Controller::setQuantitativeInvisibility(bool iBool)
804 bool Controller::getQuantitativeInvisibility() const
809 void Controller::setFaceSmoothness(bool iBool)
811 _EnableFaceSmoothness = iBool;
814 bool Controller::getFaceSmoothness() const
816 return _EnableFaceSmoothness;
819 void Controller::setComputeRidgesAndValleysFlag(bool iBool)
821 _ComputeRidges = iBool;
824 bool Controller::getComputeRidgesAndValleysFlag() const
826 return _ComputeRidges;
829 void Controller::setComputeSuggestiveContoursFlag(bool b)
831 _ComputeSuggestive = b;
834 bool Controller::getComputeSuggestiveContoursFlag() const
836 return _ComputeSuggestive;
839 void Controller::setComputeMaterialBoundariesFlag(bool b)
841 _ComputeMaterialBoundaries = b;
844 bool Controller::getComputeMaterialBoundariesFlag() const
846 return _ComputeMaterialBoundaries;
849 void Controller::setComputeSteerableViewMapFlag(bool iBool)
851 _ComputeSteerableViewMap = iBool;
854 bool Controller::getComputeSteerableViewMapFlag() const
856 return _ComputeSteerableViewMap;
859 void Controller::DrawStrokes()
864 if (G.debug & G_DEBUG_FREESTYLE) {
865 cout << "\n=== Stroke drawing ===" << endl;
869 real d = _Chrono.stop();
870 if (G.debug & G_DEBUG_FREESTYLE) {
871 cout << "Strokes generation : " << d << endl;
872 cout << "Stroke count : " << _Canvas->getStrokeCount() << endl;
878 void Controller::ResetRenderCount()
883 Render *Controller::RenderStrokes(Render *re, bool render)
887 BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count);
889 _Canvas->Render(blenderRenderer);
890 totmesh = blenderRenderer->GenerateScene();
892 real d = _Chrono.stop();
893 if (G.debug & G_DEBUG_FREESTYLE) {
894 cout << "Temporary scene generation: " << d << endl;
897 Render *freestyle_render = blenderRenderer->RenderScene(re, render);
899 if (G.debug & G_DEBUG_FREESTYLE) {
900 cout << "Stroke rendering : " << d << endl;
902 uintptr_t mem_in_use = MEM_get_memory_in_use();
903 uintptr_t mmap_in_use = MEM_get_mapped_memory_in_use();
904 uintptr_t peak_memory = MEM_get_peak_memory();
906 float megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0);
907 float mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0);
908 float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
910 printf("%d objs, %d verts, %d faces, mem %.2fM (%.2fM, peak %.2fM)\n",
911 totmesh, freestyle_render->i.totvert, freestyle_render->i.totface,
912 megs_used_memory, mmap_used_memory, megs_peak_memory);
914 delete blenderRenderer;
916 return freestyle_render;
919 void Controller::InsertStyleModule(unsigned index, const char *iFileName)
921 if (!BLI_testextensie(iFileName, ".py")) {
922 cerr << "Error: Cannot load \"" << string(iFileName) << "\", unknown extension" << endl;
926 StyleModule *sm = new StyleModule(iFileName, _inter);
927 _Canvas->InsertStyleModule(index, sm);
930 void Controller::InsertStyleModule(unsigned index, const char *iName, const char *iBuffer)
932 StyleModule *sm = new BufferedStyleModule(iBuffer, iName, _inter);
933 _Canvas->InsertStyleModule(index, sm);
936 void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText)
938 StyleModule *sm = new BlenderStyleModule(iText, iName, _inter);
939 _Canvas->InsertStyleModule(index, sm);
942 void Controller::AddStyleModule(const char * /*iFileName*/)
944 //_pStyleWindow->Add(iFileName);
947 void Controller::RemoveStyleModule(unsigned index)
949 _Canvas->RemoveStyleModule(index);
952 void Controller::Clear()
957 void Controller::ReloadStyleModule(unsigned index, const char * iFileName)
959 StyleModule *sm = new StyleModule(iFileName, _inter);
960 _Canvas->ReplaceStyleModule(index, sm);
963 void Controller::SwapStyleModules(unsigned i1, unsigned i2)
965 _Canvas->SwapStyleModules(i1, i2);
968 void Controller::toggleLayer(unsigned index, bool iDisplay)
970 _Canvas->setVisible(index, iDisplay);
973 void Controller::setModified(unsigned index, bool iMod)
975 //_pStyleWindow->setModified(index, iMod);
976 _Canvas->setModified(index, iMod);
977 updateCausalStyleModules(index + 1);
980 void Controller::updateCausalStyleModules(unsigned index)
982 vector<unsigned> vec;
983 _Canvas->causalStyleModules(vec, index);
984 for (vector<unsigned>::const_iterator it = vec.begin(); it != vec.end(); it++) {
985 //_pStyleWindow->setModified(*it, true);
986 _Canvas->setModified(*it, true);
990 void Controller::resetModified(bool iMod)
992 //_pStyleWindow->resetModified(iMod);
993 _Canvas->resetModified(iMod);
996 NodeGroup * Controller::BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end)
998 ViewMapTesselator2D tesselator2D;
1000 mat.setDiffuse(1, 1, 0.3, 1);
1001 tesselator2D.setFrsMaterial(mat);
1003 return (tesselator2D.Tesselate(vedges_begin, vedges_end));
1006 void Controller::toggleEdgeTesselationNature(Nature::EdgeNature iNature)
1008 _edgeTesselationNature ^= (iNature);
1012 void Controller::setModelsDir(const string& /*dir*/)
1014 //_current_dirs->setValue("models/dir", dir);
1017 string Controller::getModelsDir() const
1020 //_current_dirs->getValue("models/dir", dir);
1024 void Controller::setModulesDir(const string& /*dir*/)
1026 //_current_dirs->setValue("modules/dir", dir);
1029 string Controller::getModulesDir() const
1032 //_current_dirs->getValue("modules/dir", dir);
1036 void Controller::resetInterpreter()
1043 void Controller::displayDensityCurves(int x, int y)
1045 SteerableViewMap * svm = _Canvas->getSteerableViewMap();
1050 typedef vector<Vec3r> densityCurve;
1051 vector<densityCurve> curves(svm->getNumberOfOrientations() + 1);
1052 vector<densityCurve> curvesDirection(svm->getNumberOfPyramidLevels());
1054 // collect the curves values
1055 unsigned nbCurves = svm->getNumberOfOrientations() + 1;
1056 unsigned nbPoints = svm->getNumberOfPyramidLevels();
1060 // build the density/nbLevels curves for each orientation
1061 for (i = 0; i < nbCurves; ++i) {
1062 for (j = 0; j < nbPoints; ++j) {
1063 curves[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(i, j, x, y), 0));
1066 // build the density/nbOrientations curves for each level
1067 for (i = 0; i < nbPoints; ++i) {
1068 for (j = 0; j < nbCurves; ++j) {
1069 curvesDirection[i].push_back(Vec3r(j, svm->readSteerableViewMapPixel(j, i, x, y), 0));
1073 // display the curves
1075 for (i = 0; i < nbCurves; ++i)
1076 _pDensityCurvesWindow->setOrientationCurve(i, Vec2d(0, 0), Vec2d(nbPoints, 1), curves[i], "scale", "density");
1077 for (i = 1; i <= 8; ++i)
1078 _pDensityCurvesWindow->setLevelCurve(i, Vec2d(0, 0), Vec2d(nbCurves, 1), curvesDirection[i],
1079 "orientation", "density");
1080 _pDensityCurvesWindow->show();
1084 void Controller::init_options()
1086 // from AppOptionsWindow.cpp
1087 // Default init options
1089 Config::Path * cpath = Config::Path::getInstance();
1092 ViewMapIO::Options::setModelsPath(cpath->getModelsPath());
1093 TextureManager::Options::setPatternsPath(cpath->getPatternsPath());
1094 TextureManager::Options::setBrushesPath(cpath->getModelsPath());
1097 ViewMapIO::Options::rmFlags(ViewMapIO::Options::FLOAT_VECTORS);
1098 ViewMapIO::Options::rmFlags(ViewMapIO::Options::NO_OCCLUDERS);
1099 setComputeSteerableViewMapFlag(false);
1102 setQuantitativeInvisibility(true);
1104 // soc: initialize canvas
1107 // soc: initialize passes
1108 setPassDiffuse(NULL, 0, 0);
1109 setPassZ(NULL, 0, 0);
1112 } /* namespace Freestyle */