Blender V5.3
Controller.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10extern "C" {
11#include <Python.h>
12}
13
14#include <cfloat>
15#include <fstream>
16#include <string>
17
18#include "AppCanvas.h"
19#include "AppConfig.h"
20#include "AppView.h"
21#include "Controller.h"
22
23#include "../image/Image.h"
24
31
36
39
41#include "../view_map/ViewMap.h"
43
48
52
53#include "BKE_global.hh"
54#include "BLI_path_utils.hh"
55#include "BLI_utildefines.hh"
56
57#include "DNA_freestyle_types.h"
58
59#include "FRS_freestyle.h"
60
61namespace Freestyle {
62
64{
65#if 0
66 const string sep(Config::DIR_SEP);
67 const string filename = Config::Path::getInstance()->getHomeDir() + sep + Config::OPTIONS_DIR +
68 sep + Config::OPTIONS_CURRENT_DIRS_FILE;
69 _current_dirs = new ConfigIO(filename, Config::APPLICATION_NAME + "CurrentDirs", true);
70#endif
71
72 _RootNode = new NodeGroup;
73 _RootNode->addRef();
74
75#if 0
76 _SilhouetteNode = nullptr;
77 _ProjectedSilhouette = nullptr;
78 _VisibleProjectedSilhouette = nullptr;
79
80 _DebugNode = new NodeGroup;
81 _DebugNode->addRef();
82#endif
83
84 _winged_edge = nullptr;
85
86 _pView = nullptr;
87 _pRenderMonitor = nullptr;
88
89 _edgeTesselationNature = (Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE);
90
91 _ProgressBar = new ProgressBar;
92 _SceneNumFaces = 0;
93#if 0
94 _minEdgeSize = DBL_MAX;
95#endif
96 _EPSILON = 1.0e-6;
97 _bboxDiag = 0;
98
99 _ViewMap = nullptr;
100
101 _Canvas = nullptr;
102
104 //_VisibilityAlgo = ViewMapBuilder::ray_casting;
105
106 _Canvas = new AppCanvas;
107
108 _inter = new PythonInterpreter();
109 _EnableViewMapCache = false;
110 _EnableQI = true;
111 _EnableFaceSmoothness = false;
112 _ComputeRidges = true;
113 _ComputeSteerableViewMap = false;
114 _ComputeSuggestive = true;
115 _ComputeMaterialBoundaries = true;
116 _sphereRadius = 1.0;
117 _creaseAngle = 134.43;
118 prevSceneHash = -1.0;
119
120 init_options();
121}
122
124{
125 if (nullptr != _RootNode) {
126 int ref = _RootNode->destroy();
127 if (0 == ref) {
128 delete _RootNode;
129 }
130 }
131
132#if 0
133 if (nullptr != _SilhouetteNode) {
134 int ref = _SilhouetteNode->destroy();
135 if (0 == ref) {
136 delete _SilhouetteNode;
137 }
138 }
139
140 if (nullptr != _DebugNode) {
141 int ref = _DebugNode->destroy();
142 if (0 == ref) {
143 delete _DebugNode;
144 }
145 }
146#endif
147
148 if (_winged_edge) {
149 delete _winged_edge;
150 _winged_edge = nullptr;
151 }
152
153 if (nullptr != _ViewMap) {
154 delete _ViewMap;
155 _ViewMap = nullptr;
156 }
157
158 if (nullptr != _Canvas) {
159 delete _Canvas;
160 _Canvas = nullptr;
161 }
162
163 if (_inter) {
164 delete _inter;
165 _inter = nullptr;
166 }
167
168 if (_ProgressBar) {
169 delete _ProgressBar;
170 _ProgressBar = nullptr;
171 }
172
173 // delete _current_dirs;
174}
175
177{
178 if (nullptr == iView) {
179 return;
180 }
181
182 _pView = iView;
183 _Canvas->setViewer(_pView);
184}
185
187{
188 _pRenderMonitor = iRenderMonitor;
189}
190
191void Controller::setPassDiffuse(float *buf, int width, int height)
192{
193 AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
194 BLI_assert(app_canvas != nullptr);
195 app_canvas->setPassDiffuse(buf, width, height);
196}
197
198void Controller::setPassZ(float *buf, int width, int height)
199{
200 AppCanvas *app_canvas = dynamic_cast<AppCanvas *>(_Canvas);
201 BLI_assert(app_canvas != nullptr);
202 app_canvas->setPassZ(buf, width, height);
203}
204
206{
207 PythonInterpreter *py_inter = dynamic_cast<PythonInterpreter *>(_inter);
208 py_inter->setContext(C);
209}
210
212{
213 if (!_EnableViewMapCache) {
214 return false;
215 }
216 if (sceneHashFunc.match()) {
217 return (nullptr != _ViewMap);
218 }
219 sceneHashFunc.store();
220 return false;
221}
222
224 blender::ViewLayer *view_layer,
225 blender::Depsgraph *depsgraph)
226{
227 BlenderFileLoader loader(re, view_layer, depsgraph);
228
229 loader.setRenderMonitor(_pRenderMonitor);
230
231 _Chrono.start();
232
233 NodeGroup *blenderScene = loader.Load();
234
235 if (blenderScene == nullptr) {
237 cout << "Cannot load scene" << endl;
238 }
239 return 1;
240 }
241
242 if (blenderScene->numberOfChildren() < 1) {
244 cout << "Empty scene" << endl;
245 }
246 blenderScene->destroy();
247 delete blenderScene;
248 return 1;
249 }
250
251 real duration = _Chrono.stop();
253 cout << "Scene loaded" << endl;
254 printf("Mesh cleaning : %lf\n", duration);
255 printf("View map cache : %s\n", _EnableViewMapCache ? "enabled" : "disabled");
256 }
257 _SceneNumFaces += loader.numFacesRead();
258
259#if 0
260 if (loader.minEdgeSize() < _minEdgeSize) {
261 _minEdgeSize = loader.minEdgeSize();
262 }
263#endif
264
265#if 0 // DEBUG
267 blenderScene->accept(spp);
268#endif
269
270 _RootNode->AddChild(blenderScene);
271 _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
272
273 _pView->setModel(_RootNode);
274 //_pView->FitBBox();
275
276 if (_pRenderMonitor->testBreak()) {
277 return 0;
278 }
279
280 if (_EnableViewMapCache) {
281
282 NodeCamera *cam;
283 if (blender::g_freestyle.proj[3][3] != 0.0) {
284 cam = new NodeOrthographicCamera;
285 }
286 else {
287 cam = new NodePerspectiveCamera;
288 }
289 double proj[16];
290 for (int i = 0; i < 4; i++) {
291 for (int j = 0; j < 4; j++) {
292 proj[i * 4 + j] = blender::g_freestyle.proj[i][j];
293 }
294 }
295 cam->setProjectionMatrix(proj);
296 _RootNode->AddChild(cam);
297 _RootNode->AddChild(new NodeViewLayer(*re->scene, *view_layer));
298
299 sceneHashFunc.reset();
300 // blenderScene->accept(sceneHashFunc);
301 _RootNode->accept(sceneHashFunc);
303 cout << "Scene hash : " << sceneHashFunc.toString() << endl;
304 }
305 if (hitViewMapCache()) {
307 return 0;
308 }
309
310 delete _ViewMap;
311 _ViewMap = nullptr;
312 }
313
314 _Chrono.start();
315
316 WXEdgeBuilder wx_builder;
317 wx_builder.setRenderMonitor(_pRenderMonitor);
318 blenderScene->accept(wx_builder);
319 _winged_edge = wx_builder.getWingedEdge();
320
321 duration = _Chrono.stop();
323 printf("WEdge building : %lf\n", duration);
324 }
325
326#if 0
327 _pView->setDebug(_DebugNode);
328
329 // delete stuff
330 if (0 != ws_builder) {
331 delete ws_builder;
332 ws_builder = 0;
333 }
334
335 soc QFileInfo qfi(iFileName);
336 soc string basename((const char *)qfi.fileName().toAscii().data());
337 char cleaned[FILE_MAX];
338 BLI_strncpy(cleaned, iFileName, FILE_MAX);
339 BLI_path_normalize(cleaned);
340 string basename = string(cleaned);
341#endif
342
343 _ListOfModels.emplace_back("Blender_models");
344
345 _Scene3dBBox = _RootNode->bbox();
346
347 _bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm();
349 cout << "Triangles nb : " << _SceneNumFaces << " imported, " << _winged_edge->getNumFaces()
350 << " retained" << endl;
351 cout << "Bounding Box : " << _bboxDiag << endl;
352 }
353
355
356 _SceneNumFaces = _winged_edge->getNumFaces();
357 if (_SceneNumFaces == 0) {
359 return 1;
360 }
361
362 return 0;
363}
364
366{
368 _ListOfModels.clear();
369
370 // We deallocate the memory:
374
375 // clears the canvas
376 _Canvas->Clear();
377
378 // soc: reset passes
379 setPassDiffuse(nullptr, 0, 0);
380 setPassZ(nullptr, 0, 0);
381}
382
384{
385 _pView->DetachModel();
386 if (nullptr != _RootNode) {
387 int ref = _RootNode->destroy();
388 if (0 == ref) {
389 _RootNode->addRef();
390 }
391 _RootNode->clearBBox();
392 }
393}
394
396{
397 if (_winged_edge) {
398 delete _winged_edge;
399 _winged_edge = nullptr;
400 }
401
402 // clears the grid
403 _Grid.clear();
404 _Scene3dBBox.clear();
405 _SceneNumFaces = 0;
406#if 0
407 _minEdgeSize = DBL_MAX;
408#endif
409}
410
411void Controller::DeleteViewMap(bool freeCache)
412{
413#if 0
414 _pView->DetachSilhouette();
415 if (nullptr != _SilhouetteNode) {
416 int ref = _SilhouetteNode->destroy();
417 if (0 == ref) {
418 delete _SilhouetteNode;
419 _SilhouetteNode = nullptr;
420 }
421 }
422
423 if (nullptr != _ProjectedSilhouette) {
424 int ref = _ProjectedSilhouette->destroy();
425 if (0 == ref) {
426 delete _ProjectedSilhouette;
427 _ProjectedSilhouette = nullptr;
428 }
429 }
430 if (nullptr != _VisibleProjectedSilhouette) {
431 int ref = _VisibleProjectedSilhouette->destroy();
432 if (0 == ref) {
433 delete _VisibleProjectedSilhouette;
434 _VisibleProjectedSilhouette = nullptr;
435 }
436 }
437
438 _pView->DetachDebug();
439 if (nullptr != _DebugNode) {
440 int ref = _DebugNode->destroy();
441 if (0 == ref) {
442 _DebugNode->addRef();
443 }
444 }
445#endif
446
447 if (nullptr != _ViewMap) {
448 if (freeCache || !_EnableViewMapCache) {
449 delete _ViewMap;
450 _ViewMap = nullptr;
451 prevSceneHash = -1.0;
452 }
453 else {
454 _ViewMap->Clean();
455 }
456 }
457}
458
460{
461 if (_ListOfModels.empty()) {
462 return;
463 }
464
465 DeleteViewMap(true);
466
467 // retrieve the 3D viewpoint and transformations information
468 //----------------------------------------------------------
469 // Save the viewpoint context at the view level in order
470 // to be able to restore it later:
471
472 // Restore the context of view:
473 // we need to perform all these operations while the
474 // 3D context is on.
475 Vec3f vp(UNPACK3(blender::g_freestyle.viewpoint));
476
477#if 0
479 cout << "mv" << endl;
480 }
481#endif
482 real mv[4][4];
483 for (int i = 0; i < 4; i++) {
484 for (int j = 0; j < 4; j++) {
485 mv[i][j] = blender::g_freestyle.mv[i][j];
486#if 0
488 cout << mv[i][j] << " ";
489 }
490#endif
491 }
492#if 0
494 cout << endl;
495 }
496#endif
497 }
498
499#if 0
501 cout << "\nproj" << endl;
502 }
503#endif
504 real proj[4][4];
505 for (int i = 0; i < 4; i++) {
506 for (int j = 0; j < 4; j++) {
507 proj[i][j] = blender::g_freestyle.proj[i][j];
508#if 0
510 cout << proj[i][j] << " ";
511 }
512#endif
513 }
514#if 0
516 cout << endl;
517 }
518#endif
519 }
520
521 int viewport[4];
522 for (int i = 0; i < 4; i++) {
523 viewport[i] = blender::g_freestyle.viewport[i];
524 }
525
526#if 0
528 cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl;
529 }
530#endif
531
532 // Flag the WXEdge structure for silhouette edge detection:
533 //----------------------------------------------------------
534
536 cout << "\n=== Detecting silhouette edges ===" << endl;
537 }
538 _Chrono.start();
539
540 edgeDetector.setViewpoint(vp);
541 edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0);
542 edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
543 edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
544 edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
545 edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
546 edgeDetector.setCreaseAngle(_creaseAngle);
547 edgeDetector.setSphereRadius(_sphereRadius);
548 edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
549 edgeDetector.setRenderMonitor(_pRenderMonitor);
550 edgeDetector.processShapes(*_winged_edge);
551
552 real duration = _Chrono.stop();
554 printf("Feature lines : %lf\n", duration);
555 }
556
557 if (_pRenderMonitor->testBreak()) {
558 return;
559 }
560
561 // Builds the view map structure from the flagged WSEdge structure:
562 //----------------------------------------------------------
563 ViewMapBuilder vmBuilder;
564 vmBuilder.setEnableQI(_EnableQI);
565 vmBuilder.setViewpoint(vp);
566 vmBuilder.setTransform(
567 mv, proj, viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian());
568 vmBuilder.setFrustum(_pView->znear(), _pView->zfar());
569 vmBuilder.setGrid(&_Grid);
570 vmBuilder.setRenderMonitor(_pRenderMonitor);
571
572#if 0
573 // Builds a tessellated form of the silhouette for display purpose:
574 //---------------------------------------------------------------
575 ViewMapTesselator3D sTesselator3d;
576 ViewMapTesselator2D sTesselator2d;
577 sTesselator2d.setNature(_edgeTesselationNature);
578 sTesselator3d.setNature(_edgeTesselationNature);
579#endif
580
582 cout << "\n=== Building the view map ===" << endl;
583 }
584 _Chrono.start();
585 // Build View Map
586 _ViewMap = vmBuilder.BuildViewMap(
587 *_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces);
588 _ViewMap->setScene3dBBox(_Scene3dBBox);
589
591 printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size());
592 }
593
594#if 0
595 // Tesselate the 3D edges:
596 _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
597 _SilhouetteNode->addRef();
598
599 // Tesselate 2D edges
600 _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
601 _ProjectedSilhouette->addRef();
602#endif
603
604 duration = _Chrono.stop();
606 printf("ViewMap building : %lf\n", duration);
607 }
608
609#if 0
610 _pView->AddSilhouette(_SilhouetteNode);
611 _pView->AddSilhouette(_WRoot);
612 _pView->Add2DSilhouette(_ProjectedSilhouette);
613 _pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette);
614 _pView->AddDebug(_DebugNode);
615#endif
616
617 // Draw the steerable density map:
618 //--------------------------------
619 if (_ComputeSteerableViewMap) {
621 }
622 // Reset Style modules modification flags
623 resetModified(true);
624
626}
627
629{
630#if 0 // soc
631 if ((!_Canvas) || (!_ViewMap)) {
632 return;
633 }
634
635 // Build 4 nodes containing the edges in the 4 directions
637 uint i;
638 real c =
639 32.0f /
640 255.0f; // see SteerableViewMap::readSteerableViewMapPixel() for information about this 32.
641 for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
642 ng[i] = new NodeGroup;
643 }
644 NodeShape *completeNS = new NodeShape;
645 completeNS->material().setDiffuse(c, c, c, 1);
646 ng[Canvas::NB_STEERABLE_VIEWMAP - 1]->AddChild(completeNS);
648 svm->Reset();
649
651 LineRep *fRep;
652 NodeShape *ns;
653 for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; ++f)
654 {
655 if ((*f)->viewedge()->qi() != 0) {
656 continue;
657 }
658 fRep = new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d());
659 completeNS->AddRep(fRep); // add to the complete map anyway
660 double *oweights = svm->AddFEdge(*f);
661 for (i = 0; i < (Canvas::NB_STEERABLE_VIEWMAP - 1); ++i) {
662 ns = new NodeShape;
663 double wc = oweights[i] * c;
664 if (oweights[i] == 0) {
665 continue;
666 }
667 ns->material().setDiffuse(wc, wc, wc, 1);
668 ns->AddRep(fRep);
669 ng[i]->AddChild(ns);
670 }
671 }
672
674 //#ifdef WIN32
675 QGLBasicWidget offscreenBuffer(_pView, "SteerableViewMap", _pView->width(), _pView->height());
676 QPixmap pm;
677 QImage qimg;
678 for (i = 0; i < Canvas::NB_STEERABLE_VIEWMAP; ++i) {
679 offscreenBuffer.AddNode(ng[i]);
680# if 0
681 img[i] = new GrayImage(_pView->width(), _pView->height());
682 offscreenBuffer.readPixels(0, 0, _pView->width(), _pView->height(), img[i]->getArray());
683# endif
684 pm = offscreenBuffer.renderPixmap(_pView->width(), _pView->height());
685
686 if (pm.isNull()) {
688 cout << "BuildViewMap Warning: couldn't render the steerable ViewMap" << endl;
689 }
690 }
691 // pm.save(QString("steerable") + QString::number(i) + QString(".bmp"), "BMP");
692 // FIXME!! Lost of time !
693 qimg = pm.toImage();
694 // FIXME !! again!
695 img[i] = new GrayImage(_pView->width(), _pView->height());
696 for (uint y = 0; y < img[i]->height(); ++y) {
697 for (uint x = 0; x < img[i]->width(); ++x) {
698 // img[i]->setPixel(x, y, float(qGray(qimg.pixel(x, y))) / 255.0f);
699 img[i]->setPixel(x, y, float(qGray(qimg.pixel(x, y))));
700 // float c = qGray(qimg.pixel(x, y));
701 // img[i]->setPixel(x, y, qGray(qimg.pixel(x, y)));
702 }
703 }
704 offscreenBuffer.DetachNode(ng[i]);
705 ng[i]->destroy();
706 delete ng[i];
707 // check
708# if 0
709 qimg = QImage(_pView->width(), _pView->height(), 32);
710 for (uint y = 0; y < img[i]->height(); ++y) {
711 for (uint x = 0; x < img[i]->width(); ++x) {
712 float v = img[i]->pixel(x, y);
713 qimg.setPixel(x, y, qRgb(v, v, v));
714 }
715 }
716 qimg.save(QString("newsteerable") + QString::number(i) + QString(".bmp"), "BMP");
717# endif
718 }
719
720 svm->buildImagesPyramids(img, false, 0, 1.0f);
721#endif
722}
723
725{
727 if (!svm) {
728 cerr << "the Steerable ViewMap has not been computed yet" << endl;
729 return;
730 }
732}
733
735{
736 if (_VisibilityAlgo == ViewMapBuilder::ray_casting) {
737 _VisibilityAlgo = ViewMapBuilder::ray_casting_fast;
738 }
739 else if (_VisibilityAlgo == ViewMapBuilder::ray_casting_fast) {
741 }
742 else {
743 _VisibilityAlgo = ViewMapBuilder::ray_casting;
744 }
745}
746
773
797
799{
800 _EnableViewMapCache = iBool;
801}
802
804{
805 return _EnableViewMapCache;
806}
807
809{
810 _EnableQI = iBool;
811}
812
814{
815 return _EnableQI;
816}
817
819{
820 _EnableFaceSmoothness = iBool;
821}
822
824{
825 return _EnableFaceSmoothness;
826}
827
829{
830 _ComputeRidges = b;
831}
832
834{
835 return _ComputeRidges;
836}
837
839{
840 _ComputeSuggestive = b;
841}
842
844{
845 return _ComputeSuggestive;
846}
847
849{
850 _ComputeMaterialBoundaries = b;
851}
852
854{
855 return _ComputeMaterialBoundaries;
856}
857
859{
860 _ComputeSteerableViewMap = iBool;
861}
862
864{
865 return _ComputeSteerableViewMap;
866}
867
869{
870 if (_ViewMap == nullptr) {
871 return 0;
872 }
873
875 cout << "\n=== Stroke drawing ===" << endl;
876 }
877 _Chrono.start();
878 _Canvas->Draw();
879 real d = _Chrono.stop();
880 int strokeCount = _Canvas->getStrokeCount();
882 cout << "Strokes generation : " << d << endl;
883 cout << "Stroke count : " << strokeCount << endl;
884 }
887 return strokeCount;
888}
889
891{
892 _render_count = 0;
893}
894
896{
897 int totmesh = 0;
898 _Chrono.start();
899 BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count);
900 if (render) {
901 _Canvas->Render(blenderRenderer);
902 totmesh = blenderRenderer->GenerateScene();
903 }
904 real d = _Chrono.stop();
906 cout << "Temporary scene generation: " << d << endl;
907 }
908 _Chrono.start();
909 blender::Render *freestyle_render = blenderRenderer->RenderScene(re, render);
910 d = _Chrono.stop();
912 cout << "Stroke rendering : " << d << endl;
913
914 uintptr_t mem_in_use = MEM_get_memory_in_use();
915 uintptr_t peak_memory = MEM_get_peak_memory();
916
917 float megs_used_memory = (mem_in_use) / (1024.0 * 1024.0);
918 float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
919
920 printf("%d objs, mem %.2fM (peak %.2fM)\n", totmesh, megs_used_memory, megs_peak_memory);
921 }
922 delete blenderRenderer;
923
924 return freestyle_render;
925}
926
927void Controller::InsertStyleModule(uint index, const char *iFileName)
928{
929 if (!blender::BLI_path_extension_check(iFileName, ".py")) {
930 cerr << "Error: Cannot load \"" << string(iFileName) << "\", unknown extension" << endl;
931 return;
932 }
933
934 StyleModule *sm = new StyleModule(iFileName, _inter);
936}
937
938void Controller::InsertStyleModule(uint index, const char *iName, const char *iBuffer)
939{
940 StyleModule *sm = new BufferedStyleModule(iBuffer, iName, _inter);
942}
943
944void Controller::InsertStyleModule(uint index, const char *iName, blender::Text *iText)
945{
946 StyleModule *sm = new BlenderStyleModule(iText, iName, _inter);
948}
949
950void Controller::AddStyleModule(const char * /*iFileName*/)
951{
952 //_pStyleWindow->Add(iFileName);
953}
954
959
961{
962 _Canvas->Clear();
963}
964
965void Controller::ReloadStyleModule(uint index, const char *iFileName)
966{
967 StyleModule *sm = new StyleModule(iFileName, _inter);
969}
970
971void Controller::SwapStyleModules(uint i1, uint i2)
972{
973 _Canvas->SwapStyleModules(i1, i2);
974}
975
976void Controller::toggleLayer(uint index, bool iDisplay)
977{
978 _Canvas->setVisible(index, iDisplay);
979}
980
981void Controller::setModified(uint index, bool iMod)
982{
983 //_pStyleWindow->setModified(index, iMod);
984 _Canvas->setModified(index, iMod);
986}
987
989{
990 vector<uint> vec;
992 for (vector<uint>::const_iterator it = vec.begin(); it != vec.end(); it++) {
993 //_pStyleWindow->setModified(*it, true);
994 _Canvas->setModified(*it, true);
995 }
996}
997
999{
1000 //_pStyleWindow->resetModified(iMod);
1001 _Canvas->resetModified(iMod);
1002}
1003
1004NodeGroup *Controller::BuildRep(vector<ViewEdge *>::iterator vedges_begin,
1005 vector<ViewEdge *>::iterator vedges_end)
1006{
1007 ViewMapTesselator2D tesselator2D;
1008 FrsMaterial mat;
1009 mat.setDiffuse(1, 1, 0.3, 1);
1010 tesselator2D.setFrsMaterial(mat);
1011
1012 return tesselator2D.Tesselate(vedges_begin, vedges_end);
1013}
1014
1016{
1017 _edgeTesselationNature ^= (iNature);
1019}
1020
1021void Controller::setModelsDir(const string & /*dir*/)
1022{
1023 //_current_dirs->setValue("models/dir", dir);
1024}
1025
1027{
1028 string dir = ".";
1029 //_current_dirs->getValue("models/dir", dir);
1030 return dir;
1031}
1032
1033void Controller::setModulesDir(const string & /*dir*/)
1034{
1035 //_current_dirs->setValue("modules/dir", dir);
1036}
1037
1039{
1040 string dir = ".";
1041 //_current_dirs->getValue("modules/dir", dir);
1042 return dir;
1043}
1044
1046{
1047 if (_inter) {
1048 _inter->reset();
1049 }
1050}
1051
1053{
1055 if (!svm) {
1056 return;
1057 }
1058
1059 uint i, j;
1060 using densityCurve = vector<Vec3r>;
1061 vector<densityCurve> curves(svm->getNumberOfOrientations() + 1);
1062 vector<densityCurve> curvesDirection(svm->getNumberOfPyramidLevels());
1063
1064 // collect the curves values
1065 uint nbCurves = svm->getNumberOfOrientations() + 1;
1066 uint nbPoints = svm->getNumberOfPyramidLevels();
1067 if (!nbPoints) {
1068 return;
1069 }
1070
1071 // build the density/nbLevels curves for each orientation
1072 for (i = 0; i < nbCurves; ++i) {
1073 for (j = 0; j < nbPoints; ++j) {
1074 curves[i].emplace_back(j, svm->readSteerableViewMapPixel(i, j, x, y), 0);
1075 }
1076 }
1077 // build the density/nbOrientations curves for each level
1078 for (i = 0; i < nbPoints; ++i) {
1079 for (j = 0; j < nbCurves; ++j) {
1080 curvesDirection[i].emplace_back(j, svm->readSteerableViewMapPixel(j, i, x, y), 0);
1081 }
1082 }
1083
1084 // display the curves
1085#if 0
1086 for (i = 0; i < nbCurves; ++i) {
1087 _pDensityCurvesWindow->setOrientationCurve(
1088 i, Vec2d(0, 0), Vec2d(nbPoints, 1), curves[i], "scale", "density");
1089 }
1090 for (i = 1; i <= 8; ++i) {
1091 _pDensityCurvesWindow->setLevelCurve(
1092 i, Vec2d(0, 0), Vec2d(nbCurves, 1), curvesDirection[i], "orientation", "density");
1093 }
1094 _pDensityCurvesWindow->show();
1095#endif
1096}
1097
1099{
1100 // from AppOptionsWindow.cpp
1101 // Default init options
1102
1104
1105 // Directories
1108
1109 // ViewMap Format
1111
1112 // Visibility
1114
1115 // soc: initialize canvas
1116 _Canvas->init();
1117
1118 // soc: initialize passes
1119 setPassDiffuse(nullptr, 0, 0);
1120 setPassZ(nullptr, 0, 0);
1121}
1122
1123} /* namespace Freestyle */
Configuration file.
#define FILE_MAX
The spinal tap of the system.
GTS - Library for the manipulation of triangulated surfaces.
Class to encapsulate an array of RGB or Gray level values.
Class to define a Drawing Style to be applied to the underlying children. Inherits from NodeGroup.
Class to build a shape node. It contains a Rep, which is the shape geometry.
Class to represent a transform node. A Transform node contains one or several children,...
Class to represent a view layer in Blender.
Class to define the Postscript rendering of a stroke.
Python Interpreter.
Class to display textual information about a scene graph.
Convenient access to the steerable ViewMap to which any element of the ViewMap belongs to.
String utilities.
Class to build a Node Tree designed to be displayed from a set of strokes structure.
Class representing a style module.
Class to define the representation of a vertex for displaying purpose.
Class to build a Node Tree designed to be displayed from a Silhouette View Map structure.
Classes to define a View Map (ViewVertex, ViewEdge, etc.).
Classes to define a Winged Edge data structure.
Class inherited from WingedEdgeBuilder and designed to build a WX (WingedEdge + extended info (silhou...
Class to render a WingedEdge data structure from a polyhedral data structure organized in nodes of a ...
#define BLI_assert(a)
#define UNPACK3(a)
void setViewer(AppView *iViewer)
Definition AppCanvas.cpp:43
void setPassZ(float *buf, int width, int height)
Definition AppCanvas.h:68
void setPassDiffuse(float *buf, int width, int height)
Definition AppCanvas.h:62
virtual void init()
Definition AppCanvas.cpp:78
void setRenderMonitor(RenderMonitor *iRenderMonitor)
BlenderStrokeRenderer(blender::Render *re, int render_count)
blender::Render * RenderScene(blender::Render *re, bool render)
BlenderStyleModule(blender::Text *text, const string &name, Interpreter *inter)
BufferedStyleModule(const string &buffer, const string &file_name, Interpreter *inter)
void setVisible(uint index, bool iVisible)
Definition Canvas.cpp:256
virtual void Draw()
Definition Canvas.cpp:88
void setModified(uint index, bool iMod)
Definition Canvas.cpp:261
void causalStyleModules(std::vector< uint > &vec, uint index=0)
Definition Canvas.cpp:274
void RemoveStyleModule(uint index)
Definition Canvas.cpp:190
void InsertStyleModule(uint index, StyleModule *iStyleModule)
Definition Canvas.cpp:177
void SwapStyleModules(uint i1, uint i2)
Definition Canvas.cpp:226
virtual void Render(const StrokeRenderer *iRenderer)
Definition Canvas.cpp:285
void resetModified(bool iMod=false)
Definition Canvas.cpp:266
void ReplaceStyleModule(uint index, StyleModule *iStyleModule)
Definition Canvas.cpp:239
static const int NB_STEERABLE_VIEWMAP
Definition Canvas.h:61
SteerableViewMap * getSteerableViewMap()
Definition Canvas.h:163
int getStrokeCount() const
Definition Canvas.h:199
const string & getPatternsPath() const
Definition AppConfig.h:52
static Path * getInstance()
Definition AppConfig.cpp:56
const string & getHomeDir() const
Definition AppConfig.h:68
const string & getModelsPath() const
Definition AppConfig.h:48
int LoadMesh(blender::Render *re, blender::ViewLayer *view_layer, blender::Depsgraph *depsgraph)
string getModelsDir() const
void setComputeSuggestiveContoursFlag(bool b)
void setPassZ(float *buf, int width, int height)
bool getFaceSmoothness() const
bool getComputeMaterialBoundariesFlag() const
bool getComputeSteerableViewMapFlag() const
void setComputeMaterialBoundariesFlag(bool b)
void setVisibilityAlgo(int algo)
void AddStyleModule(const char *iFileName)
void setComputeRidgesAndValleysFlag(bool b)
void ReloadStyleModule(uint index, const char *iFileName)
void setFaceSmoothness(bool iBool)
void setPassDiffuse(float *buf, int width, int height)
void setModified(uint index, bool iMod)
void toggleEdgeTesselationNature(Nature::EdgeNature iNature)
void updateCausalStyleModules(uint index)
void setContext(blender::bContext *C)
bool getQuantitativeInvisibility() const
blender::Render * RenderStrokes(blender::Render *re, bool render)
void setModulesDir(const string &dir)
void DeleteViewMap(bool freeCache=false)
bool getComputeSuggestiveContoursFlag() const
string getModulesDir() const
NodeGroup * BuildRep(vector< ViewEdge * >::iterator vedges_begin, vector< ViewEdge * >::iterator vedges_end)
void setViewMapCache(bool iBool)
void setQuantitativeInvisibility(bool iBool)
void toggleLayer(uint index, bool iDisplay)
void RemoveStyleModule(uint index)
void setComputeSteerableViewMapFlag(bool iBool)
void SwapStyleModules(uint i1, uint i2)
bool getComputeRidgesAndValleysFlag() const
void setView(AppView *iView)
void resetModified(bool iMod=false)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
bool getViewMapCache() const
void displayDensityCurves(int x, int y)
void InsertStyleModule(uint index, const char *iFileName)
void setModelsDir(const string &dir)
uint height() const
Definition Image.h:111
uint width() const
Definition Image.h:105
void setDiffuse(float r, float g, float b, float a)
virtual float * getArray()
Definition Image.h:392
void setPixel(uint x, uint y, float v)
Definition Image.h:360
float pixel(uint x, uint y) const
Definition Image.h:365
void setProjectionMatrix(const double projection_matrix[16])
virtual int numberOfChildren()
Definition NodeGroup.h:56
virtual void AddChild(Node *iChild)
Definition NodeGroup.cpp:16
virtual int destroy()
Definition NodeGroup.cpp:26
virtual void accept(SceneVisitor &v)
Definition NodeGroup.cpp:56
virtual void AddRep(Rep *iRep)
Definition NodeShape.h:39
NodeViewLayer(blender::Scene &scene, blender::ViewLayer &view_layer)
void setContext(blender::bContext *C)
double * AddFEdge(FEdge *iFEdge)
float readSteerableViewMapPixel(uint iOrientation, int iLevel, int x, int y)
void buildImagesPyramids(GrayImage **steerableBases, bool copy=false, uint iNbLevels=4, float iSigma=1.0f)
StyleModule(const string &file_name, Interpreter *inter)
Definition StyleModule.h:30
void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], const int iViewport[4], real iFocalLength, real, real)
void setGrid(Grid *iGrid)
ViewMap * BuildViewMap(WingedEdge &we, visibility_algo iAlgo, real epsilon, const BBox< Vec3r > &bbox, uint sceneNumFaces)
void setEnableQI(bool iBool)
void setViewpoint(const Vec3r &ivp)
void setFrustum(real iZnear, real iZfar)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
void setFrsMaterial(const FrsMaterial &iMaterial)
void setNature(Nature::EdgeNature iNature)
NodeGroup * Tesselate(ViewMap *iViewMap)
vector< FEdge * > fedges_container
Definition ViewMap.h:51
virtual void Clean()
Definition ViewMap.cpp:55
void setScene3dBBox(const BBox< Vec3r > &bbox)
Definition ViewMap.h:178
fedges_container & FEdges()
Definition ViewMap.h:114
static void setCurrentId(const uint id)
Definition WEdge.h:1090
void setRenderMonitor(RenderMonitor *iRenderMonitor)
#define printf
#define index(i)
size_t(*) MEM_get_memory_in_use(void)
Definition mallocn.cc:65
size_t(*) MEM_get_peak_memory(void)
Definition mallocn.cc:68
VecMat::Vec2< double > Vec2d
Definition Geom.h:23
VecMat::Vec3< float > Vec3f
Definition Geom.h:28
ushort EdgeNature
Definition Nature.h:36
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
struct FreestyleGlobals g_freestyle
@ G_DEBUG_FREESTYLE
Global G
Definition blender.cc:57
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
@ FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE
@ FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE
@ FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL
@ FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL
static void setPatternsPath(const string &path)
static void setBrushesPath(const string &path)