34 #include "../image/Image.h"
36 #include "../scene_graph/NodeDrawingStyle.h"
37 #include "../scene_graph/NodeShape.h"
38 #include "../scene_graph/NodeTransform.h"
39 #include "../scene_graph/NodeViewLayer.h"
40 #include "../scene_graph/ScenePrettyPrinter.h"
41 #include "../scene_graph/VertexRep.h"
43 #include "../stroke/PSStrokeRenderer.h"
44 #include "../stroke/StrokeTesselator.h"
45 #include "../stroke/StyleModule.h"
46 #include "../stroke/TextStrokeRenderer.h"
48 #include "../system/PythonInterpreter.h"
49 #include "../system/StringUtils.h"
51 #include "../view_map/SteerableViewMap.h"
52 #include "../view_map/ViewMap.h"
53 #include "../view_map/ViewMapIO.h"
54 #include "../view_map/ViewMapTesselator.h"
56 #include "../winged_edge/Curvature.h"
57 #include "../winged_edge/WEdge.h"
58 #include "../winged_edge/WXEdgeBuilder.h"
59 #include "../winged_edge/WingedEdgeBuilder.h"
61 #include "../blender_interface/BlenderFileLoader.h"
62 #include "../blender_interface/BlenderStrokeRenderer.h"
63 #include "../blender_interface/BlenderStyleModule.h"
88 _SilhouetteNode =
NULL;
89 _ProjectedSilhouette =
NULL;
90 _VisibleProjectedSilhouette =
NULL;
96 _winged_edge =
nullptr;
99 _pRenderMonitor =
nullptr;
106 _minEdgeSize = DBL_MAX;
121 _EnableViewMapCache =
false;
123 _EnableFaceSmoothness =
false;
124 _ComputeRidges =
true;
125 _ComputeSteerableViewMap =
false;
126 _ComputeSuggestive =
true;
127 _ComputeMaterialBoundaries =
true;
129 _creaseAngle = 134.43;
130 prevSceneHash = -1.0;
137 if (
nullptr != _RootNode) {
138 int ref = _RootNode->
destroy();
145 if (
NULL != _SilhouetteNode) {
146 int ref = _SilhouetteNode->
destroy();
148 delete _SilhouetteNode;
152 if (
NULL != _DebugNode) {
153 int ref = _DebugNode->destroy();
162 _winged_edge =
nullptr;
182 _ProgressBar =
nullptr;
190 if (
nullptr == iView) {
200 _pRenderMonitor = iRenderMonitor;
225 if (!_EnableViewMapCache) {
228 if (sceneHashFunc.
match()) {
231 sceneHashFunc.
store();
245 if (blenderScene ==
nullptr) {
247 cout <<
"Cannot load scene" << endl;
254 cout <<
"Empty scene" << endl;
263 cout <<
"Scene loaded" << endl;
264 printf(
"Mesh cleaning : %lf\n", duration);
265 printf(
"View map cache : %s\n", _EnableViewMapCache ?
"enabled" :
"disabled");
270 if (loader.minEdgeSize() < _minEdgeSize) {
271 _minEdgeSize = loader.minEdgeSize();
277 blenderScene->
accept(spp);
290 if (_EnableViewMapCache) {
300 for (
int i = 0; i < 4; i++) {
301 for (
int j = 0; j < 4; j++) {
309 sceneHashFunc.
reset();
311 _RootNode->
accept(sceneHashFunc);
313 cout <<
"Scene hash : " << sceneHashFunc.
toString() << endl;
328 blenderScene->
accept(wx_builder);
331 duration = _Chrono.
stop();
333 printf(
"WEdge building : %lf\n", duration);
340 if (0 != ws_builder) {
345 soc QFileInfo qfi(iFileName);
346 soc
string basename((
const char *)qfi.fileName().toAscii().data());
353 _ListOfModels.emplace_back(
"Blender_models");
355 _Scene3dBBox = _RootNode->
bbox();
357 _bboxDiag = (_RootNode->
bbox().getMax() - _RootNode->
bbox().getMin()).
norm();
359 cout <<
"Triangles nb : " << _SceneNumFaces <<
" imported, " << _winged_edge->
getNumFaces()
360 <<
" retained" << endl;
361 cout <<
"Bounding Box : " << _bboxDiag << endl;
367 if (_SceneNumFaces == 0) {
378 _ListOfModels.clear();
396 if (
nullptr != _RootNode) {
397 int ref = _RootNode->
destroy();
409 _winged_edge =
nullptr;
414 _Scene3dBBox.clear();
417 _minEdgeSize = DBL_MAX;
425 if (
NULL != _SilhouetteNode) {
426 int ref = _SilhouetteNode->destroy();
428 delete _SilhouetteNode;
429 _SilhouetteNode =
NULL;
433 if (
NULL != _ProjectedSilhouette) {
434 int ref = _ProjectedSilhouette->destroy();
436 delete _ProjectedSilhouette;
437 _ProjectedSilhouette =
NULL;
440 if (
NULL != _VisibleProjectedSilhouette) {
441 int ref = _VisibleProjectedSilhouette->destroy();
443 delete _VisibleProjectedSilhouette;
444 _VisibleProjectedSilhouette =
NULL;
449 if (
NULL != _DebugNode) {
450 int ref = _DebugNode->destroy();
452 _DebugNode->addRef();
458 if (freeCache || !_EnableViewMapCache) {
461 prevSceneHash = -1.0;
471 if (_ListOfModels.empty()) {
489 cout <<
"mv" << endl;
493 for (
int i = 0; i < 4; i++) {
494 for (
int j = 0; j < 4; j++) {
498 cout <<
mv[i][j] <<
" ";
511 cout <<
"\nproj" << endl;
515 for (
int i = 0; i < 4; i++) {
516 for (
int j = 0; j < 4; j++) {
520 cout << proj[i][j] <<
" ";
532 for (
int i = 0; i < 4; i++) {
546 cout <<
"\n=== Detecting silhouette edges ===" << endl;
564 printf(
"Feature lines : %lf\n", duration);
587 sTesselator2d.
setNature(_edgeTesselationNature);
588 sTesselator3d.
setNature(_edgeTesselationNature);
592 cout <<
"\n=== Building the view map ===" << endl;
597 *_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces);
607 _SilhouetteNode->
addRef();
611 _ProjectedSilhouette->
addRef();
614 duration = _Chrono.
stop();
616 printf(
"ViewMap building : %lf\n", duration);
629 if (_ComputeSteerableViewMap) {
655 completeNS->material().setDiffuse(
c,
c,
c, 1);
663 for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend;
665 if ((*f)->viewedge()->qi() != 0) {
668 fRep =
new LineRep((*f)->vertexA()->point2d(), (*f)->vertexB()->point2d());
670 double *oweights = svm->
AddFEdge(*f);
673 double wc = oweights[i] *
c;
674 if (oweights[i] == 0) {
677 ns->material().setDiffuse(wc, wc, wc, 1);
685 QGLBasicWidget offscreenBuffer(_pView,
"SteerableViewMap", _pView->
width(), _pView->
height());
689 offscreenBuffer.AddNode(ng[i]);
694 pm = offscreenBuffer.renderPixmap(_pView->
width(), _pView->
height());
698 cout <<
"BuildViewMap Warning: couldn't render the steerable ViewMap" << endl;
706 for (
unsigned int y = 0;
y < img[i]->
height(); ++
y) {
707 for (
unsigned int x = 0;
x < img[i]->
width(); ++
x) {
714 offscreenBuffer.DetachNode(ng[i]);
719 qimg = QImage(_pView->
width(), _pView->
height(), 32);
720 for (
unsigned int y = 0;
y < img[i]->
height(); ++
y) {
721 for (
unsigned int x = 0;
x < img[i]->
width(); ++
x) {
723 qimg.setPixel(
x,
y, qRgb(
v,
v,
v));
726 qimg.save(QString(
"newsteerable") + QString::number(i) + QString(
".bmp"),
"BMP");
738 cerr <<
"the Steerable ViewMap has not been computed yet" << endl;
786 switch (_VisibilityAlgo) {
810 _EnableViewMapCache = iBool;
815 return _EnableViewMapCache;
830 _EnableFaceSmoothness = iBool;
835 return _EnableFaceSmoothness;
845 return _ComputeRidges;
850 _ComputeSuggestive = b;
855 return _ComputeSuggestive;
860 _ComputeMaterialBoundaries = b;
865 return _ComputeMaterialBoundaries;
870 _ComputeSteerableViewMap = iBool;
875 return _ComputeSteerableViewMap;
885 cout <<
"\n=== Stroke drawing ===" << endl;
892 cout <<
"Strokes generation : " << d << endl;
893 cout <<
"Stroke count : " << strokeCount << endl;
916 cout <<
"Temporary scene generation: " << d << endl;
922 cout <<
"Stroke rendering : " << d << endl;
927 float megs_used_memory = (
mem_in_use) / (1024.0 * 1024.0);
928 float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
930 printf(
"%d objs, mem %.2fM (peak %.2fM)\n", totmesh, megs_used_memory, megs_peak_memory);
932 delete blenderRenderer;
934 return freestyle_render;
940 cerr <<
"Error: Cannot load \"" << string(iFileName) <<
"\", unknown extension" << endl;
1000 vector<unsigned> vec;
1002 for (vector<unsigned>::const_iterator it = vec.begin(); it != vec.end(); it++) {
1015 vector<ViewEdge *>::iterator vedges_end)
1022 return (tesselator2D.
Tesselate(vedges_begin, vedges_end));
1027 _edgeTesselationNature ^= (iNature);
1070 using densityCurve = vector<Vec3r>;
1082 for (i = 0; i < nbCurves; ++i) {
1083 for (j = 0; j < nbPoints; ++j) {
1088 for (i = 0; i < nbPoints; ++i) {
1089 for (j = 0; j < nbCurves; ++j) {
1096 for (i = 0; i < nbCurves; ++i) {
1097 _pDensityCurvesWindow->setOrientationCurve(
1098 i,
Vec2d(0, 0),
Vec2d(nbPoints, 1), curves[i],
"scale",
"density");
1100 for (i = 1; i <= 8; ++i) {
1101 _pDensityCurvesWindow->setLevelCurve(
1102 i,
Vec2d(0, 0),
Vec2d(nbCurves, 1), curvesDirection[i],
"orientation",
"density");
1104 _pDensityCurvesWindow->show();
void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2)
bool BLI_path_extension_check(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
The spinal tap of the system.
struct Depsgraph Depsgraph
@ FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE
@ FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL
@ FREESTYLE_ALGO_VERYFAST
@ FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE
@ FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL
struct FreestyleGlobals g_freestyle
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
void setViewer(AppView *iViewer)
void setPassZ(float *buf, int width, int height)
void setPassDiffuse(float *buf, int width, int height)
void AddDebug(NodeGroup *iDebug)
void AddSilhouette(NodeGroup *iSilhouette)
void setDebug(NodeGroup *iDebug)
void Add2DSilhouette(NodeGroup *)
void setModel(NodeGroup *iModel)
real GetFovyRadian() const
void Add2DVisibleSilhouette(NodeGroup *)
void DetachModel(Node *iModel)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
unsigned int numFacesRead()
Render * RenderScene(Render *re, bool render)
void setModified(unsigned index, bool iMod)
SteerableViewMap * getSteerableViewMap()
void RemoveStyleModule(unsigned index)
void InsertStyleModule(unsigned index, StyleModule *iStyleModule)
void causalStyleModules(std::vector< unsigned > &vec, unsigned index=0)
virtual void Render(const StrokeRenderer *iRenderer)
void SwapStyleModules(unsigned i1, unsigned i2)
void resetModified(bool iMod=false)
void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule)
static const int NB_STEERABLE_VIEWMAP
void setVisible(unsigned index, bool iVisible)
int getStrokeCount() const
const string & getPatternsPath() const
static Path * getInstance()
const string & getModelsPath() const
const string & getHomeDir() const
Render * RenderStrokes(Render *re, bool render)
string getModelsDir() const
void setComputeSuggestiveContoursFlag(bool b)
void setPassZ(float *buf, int width, int height)
bool getFaceSmoothness() const
void updateCausalStyleModules(unsigned index)
bool getComputeMaterialBoundariesFlag() const
bool getComputeSteerableViewMapFlag() const
void toggleLayer(unsigned index, bool iDisplay)
void setComputeMaterialBoundariesFlag(bool b)
void setVisibilityAlgo(int algo)
void AddStyleModule(const char *iFileName)
void setComputeRidgesAndValleysFlag(bool b)
void setFaceSmoothness(bool iBool)
void setPassDiffuse(float *buf, int width, int height)
void saveSteerableViewMapImages()
void toggleEdgeTesselationNature(Nature::EdgeNature iNature)
void toggleVisibilityAlgo()
void SwapStyleModules(unsigned i1, unsigned i2)
void RemoveStyleModule(unsigned index)
void ReloadStyleModule(unsigned index, const char *iFileName)
bool getQuantitativeInvisibility() const
void setModulesDir(const string &dir)
void DeleteViewMap(bool freeCache=false)
int LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph)
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 setContext(bContext *C)
void setComputeSteerableViewMapFlag(bool iBool)
void setModified(unsigned index, bool iMod)
void InsertStyleModule(unsigned index, const char *iFileName)
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 setModelsDir(const string &dir)
void ComputeSteerableViewMap()
void enableMaterialBoundaries(bool b)
virtual void processShapes(WingedEdge &)
void enableSuggestiveContours(bool b)
void setSuggestiveContourKrDerivativeEpsilon(float dkr)
void setCreaseAngle(float angle)
void setSphereRadius(float r)
void enableFaceSmoothness(bool b)
void enableOrthographicProjection(bool b)
void setViewpoint(const Vec3f &ivp)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
void enableRidgesAndValleysFlag(bool b)
void setDiffuse(const float r, const float g, const float b, const float a)
float pixel(unsigned x, unsigned y) const
virtual float * getArray()
void setPixel(unsigned x, unsigned y, float v)
void setProjectionMatrix(double projection_matrix[16])
virtual int numberOfChildren()
virtual void AddChild(Node *iChild)
virtual const BBox< Vec3r > & UpdateBBox()
virtual void accept(SceneVisitor &v)
virtual void AddRep(Rep *iRep)
virtual const BBox< Vec3r > & bbox() const
void setContext(bContext *C)
float readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y)
double * AddFEdge(FEdge *iFEdge)
unsigned int getNumberOfOrientations() const
void buildImagesPyramids(GrayImage **steerableBases, bool copy=false, unsigned iNbLevels=4, float iSigma=1.0f)
unsigned int getNumberOfPyramidLevels() const
void saveSteerableViewMap() const
void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], const int iViewport[4], real iFocalLength, real, real)
void setGrid(Grid *iGrid)
@ ray_casting_adaptive_cumulative
@ ray_casting_adaptive_traditional
@ ray_casting_culled_adaptive_cumulative
@ ray_casting_culled_adaptive_traditional
void setEnableQI(bool iBool)
void setViewpoint(const Vec3r &ivp)
void setFrustum(real iZnear, real iZfar)
ViewMap * BuildViewMap(WingedEdge &we, visibility_algo iAlgo, real epsilon, const BBox< Vec3r > &bbox, unsigned int sceneNumFaces)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
void setFrsMaterial(const FrsMaterial &iMaterial)
void setNature(Nature::EdgeNature iNature)
NodeGroup * Tesselate(ViewMap *iViewMap)
vector< FEdge * > fedges_container
void setScene3dBBox(const BBox< Vec3r > &bbox)
fedges_container & FEdges()
static void setCurrentId(const unsigned id)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
WingedEdge * getWingedEdge()
static char * basename(char *string)
const Depsgraph * depsgraph
size_t(* MEM_get_peak_memory)(void)
size_t(* MEM_get_memory_in_use)(void)
static const string DIR_SEP("/")
static const string OPTIONS_DIR("."+APPLICATION_NAME)
static const string OPTIONS_CURRENT_DIRS_FILE("current_dirs.xml")
static const string APPLICATION_NAME("APPNAME")
VecMat::Vec2< double > Vec2d
VecMat::Vec3< real > Vec3r
static const EdgeNature BORDER
unsigned short EdgeNature
static const EdgeNature CREASE
static const EdgeNature SILHOUETTE
static const unsigned char NO_OCCLUDERS
void rmFlags(const unsigned char flags)
static const unsigned char FLOAT_VECTORS
void setModelsPath(const string &path)
_W64 unsigned int uintptr_t
static void setPatternsPath(const string &path)
static void setBrushesPath(const string &path)