Files
test/source/blender/freestyle/intern/application/AppView.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

163 lines
4.5 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup freestyle
*/
#include <iostream>
#include "AppConfig.h"
#include "AppView.h"
#include "Controller.h"
#include "../scene_graph/LineRep.h"
#include "../scene_graph/NodeLight.h"
#include "../scene_graph/NodeShape.h"
#include "../scene_graph/VertexRep.h"
#include "../stroke/Canvas.h"
#include "../system/StringUtils.h"
#include "../view_map/Silhouette.h"
#include "../view_map/ViewMap.h"
#include "BLI_math_rotation.h"
2024-01-18 22:50:23 +02:00
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#if 1 // FRS_antialiasing
# include "BKE_global.hh"
# include "DNA_scene_types.h"
#endif
#include "FRS_freestyle.h"
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
namespace Freestyle {
AppView::AppView(const char * /*iName*/)
{
_Fovy = DEG2RADF(30.0f);
_ModelRootNode = new NodeDrawingStyle;
_SilhouetteRootNode = new NodeDrawingStyle;
_DebugRootNode = new NodeDrawingStyle;
_RootNode.AddChild(_ModelRootNode);
_SilhouetteRootNode->setStyle(DrawingStyle::LINES);
_SilhouetteRootNode->setLightingEnabled(false);
_SilhouetteRootNode->setLineWidth(2.0f);
_SilhouetteRootNode->setPointSize(3.0f);
_RootNode.AddChild(_SilhouetteRootNode);
_DebugRootNode->setStyle(DrawingStyle::LINES);
_DebugRootNode->setLightingEnabled(false);
_DebugRootNode->setLineWidth(1.0f);
_RootNode.AddChild(_DebugRootNode);
_minBBox = std::min(
std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
_ModelRootNode->bbox().getMin()[2]);
_maxBBox = std::max(
std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
_ModelRootNode->bbox().getMax()[2]);
_maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
_minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
_p2DSelectionNode = new NodeDrawingStyle;
_p2DSelectionNode->setLightingEnabled(false);
_p2DSelectionNode->setStyle(DrawingStyle::LINES);
_p2DSelectionNode->setLineWidth(5.0f);
_p2DNode.AddChild(_p2DSelectionNode);
NodeLight *light = new NodeLight;
_Light.AddChild(light);
}
AppView::~AppView()
{
/*int ref =*//* UNUSED */ _RootNode.destroy();
_Light.destroy();
/*ref =*//* UNUSED */ _p2DNode.destroy();
}
real AppView::distanceToSceneCenter()
{
BBox<Vec3r> bbox = _ModelRootNode->bbox();
Vec3r v(UNPACK3(g_freestyle.viewpoint));
v -= 0.5 * (bbox.getMin() + bbox.getMax());
return v.norm();
}
real AppView::znear()
{
BBox<Vec3r> bbox = _ModelRootNode->bbox();
Vec3r u = bbox.getMin();
Vec3r v = bbox.getMax();
Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
Vec3r w1(u[0], u[1], u[2]);
Vec3r w2(v[0], u[1], u[2]);
Vec3r w3(u[0], v[1], u[2]);
Vec3r w4(v[0], v[1], u[2]);
Vec3r w5(u[0], u[1], v[2]);
Vec3r w6(v[0], u[1], v[2]);
Vec3r w7(u[0], v[1], v[2]);
Vec3r w8(v[0], v[1], v[2]);
real _znear = std::min(
(w1 - cameraCenter).norm(),
std::min((w2 - cameraCenter).norm(),
std::min((w3 - cameraCenter).norm(),
std::min((w4 - cameraCenter).norm(),
std::min((w5 - cameraCenter).norm(),
std::min((w6 - cameraCenter).norm(),
std::min((w7 - cameraCenter).norm(),
(w8 - cameraCenter).norm())))))));
return std::max(_znear, 0.001);
}
real AppView::zfar()
{
BBox<Vec3r> bbox = _ModelRootNode->bbox();
Vec3r u = bbox.getMin();
Vec3r v = bbox.getMax();
Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
Vec3r w1(u[0], u[1], u[2]);
Vec3r w2(v[0], u[1], u[2]);
Vec3r w3(u[0], v[1], u[2]);
Vec3r w4(v[0], v[1], u[2]);
Vec3r w5(u[0], u[1], v[2]);
Vec3r w6(v[0], u[1], v[2]);
Vec3r w7(u[0], v[1], v[2]);
Vec3r w8(v[0], v[1], v[2]);
real _zfar = std::max(
(w1 - cameraCenter).norm(),
std::max((w2 - cameraCenter).norm(),
std::max((w3 - cameraCenter).norm(),
std::max((w4 - cameraCenter).norm(),
std::max((w5 - cameraCenter).norm(),
std::max((w6 - cameraCenter).norm(),
std::max((w7 - cameraCenter).norm(),
(w8 - cameraCenter).norm())))))));
return _zfar;
}
real AppView::GetFocalLength()
{
real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
return Near;
}
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
} /* namespace Freestyle */