22 namespace visualization {
30 std::shared_ptr<ccMesh> CreateAxisGeometry(
double axis_length) {
31 const double sphere_radius = 0.005 * axis_length;
32 const double cyl_radius = 0.0025 * axis_length;
33 const double cone_radius = 0.0075 * axis_length;
34 const double cyl_height = 0.975 * axis_length;
35 const double cone_height = 0.025 * axis_length;
38 mesh_frame->ComputeVertexNormals();
39 mesh_frame->PaintUniformColor(Eigen::Vector3d(0.5, 0.5, 0.5));
41 std::shared_ptr<ccMesh> mesh_arrow;
42 Eigen::Matrix4d transformation;
46 mesh_arrow->ComputeVertexNormals();
47 mesh_arrow->PaintUniformColor(Eigen::Vector3d(1.0, 0.0, 0.0));
48 transformation << 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1;
49 mesh_arrow->Transform(transformation);
50 *mesh_frame += *mesh_arrow;
54 mesh_arrow->ComputeVertexNormals();
55 mesh_arrow->PaintUniformColor(Eigen::Vector3d(0.0, 1.0, 0.0));
56 transformation << 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1;
57 mesh_arrow->Transform(transformation);
58 *mesh_frame += *mesh_arrow;
62 mesh_arrow->ComputeVertexNormals();
63 mesh_arrow->PaintUniformColor(Eigen::Vector3d(0.0, 0.0, 1.0));
64 transformation << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1;
65 mesh_arrow->Transform(transformation);
66 *mesh_frame += *mesh_arrow;
69 mesh_frame->triangle_uvs_.resize(mesh_frame->size() * 3, {0.0, 0.0});
74 void RecreateAxis(Scene* scene,
const ccBBox& bounds,
bool enabled) {
82 if (axis_length < 0.001) {
86 auto mesh = CreateAxisGeometry(axis_length);
88 mat.shader =
"defaultUnlit";
100 auto scene = renderer_.
GetScene(scene_);
101 view_ = scene->AddView(0, 0, 1, 1);
106 RecreateAxis(scene, bounds_,
false);
111 auto scene = renderer_.
GetScene(scene_);
113 scene->RemoveView(view_);
117 auto scene = renderer_.
GetScene(scene_);
133 view->EnableViewCaching(
true);
137 auto scene = renderer_.
GetScene(scene_);
142 auto scene = renderer_.
GetScene(scene_);
143 if (enable && axis_dirty_) {
144 RecreateAxis(scene, bounds_,
false);
151 const Eigen::Vector4f&
color,
152 std::shared_ptr<geometry::Image>
image ) {
153 auto scene = renderer_.
GetScene(scene_);
155 background_color =
color;
159 return background_color;
163 auto scene = renderer_.
GetScene(scene_);
168 const Eigen::Vector3f& sun_dir) {
169 auto scene = renderer_.
GetScene(scene_);
172 if (scene->GetIndirectLight().empty()) {
174 scene->SetIndirectLight(std::string(
path) +
"/default");
178 Eigen::Vector3f sun_color(1.0f, 1.0f, 1.0f);
186 scene->EnableIndirectLight(
false);
187 scene->EnableSunLight(
true);
188 scene->SetSunLight(sun_dir, sun_color, 100000);
191 scene->EnableIndirectLight(
true);
192 scene->EnableSunLight(
true);
193 scene->SetIndirectLightIntensity(10000);
194 scene->SetSunLight(sun_dir, sun_color, 85000);
198 scene->EnableIndirectLight(
true);
199 scene->EnableSunLight(
true);
200 scene->SetIndirectLightIntensity(20000);
201 scene->SetSunLight(sun_dir, sun_color, 80000);
204 scene->EnableIndirectLight(
true);
205 scene->EnableSunLight(
true);
206 scene->SetIndirectLightIntensity(37500);
207 scene->SetSunLight(sun_dir, sun_color, 75000);
210 scene->EnableIndirectLight(
true);
211 scene->SetIndirectLightIntensity(37500);
212 scene->EnableSunLight(
false);
218 auto scene = renderer_.
GetScene(scene_);
219 for (
auto& g : geometries_) {
221 if (!g.second.fast_name.empty()) {
222 scene->RemoveGeometry(g.second.fast_name);
224 if (!g.second.low_name.empty()) {
225 scene->RemoveGeometry(g.second.low_name);
234 const std::string&
name,
237 bool add_downsampled_copy_for_fast_rendering ) {
238 size_t downsample_threshold =
SIZE_MAX;
239 std::string fast_name;
240 if (add_downsampled_copy_for_fast_rendering) {
242 downsample_threshold = downsample_threshold_;
245 auto scene = renderer_.
GetScene(scene_);
246 if (scene->AddGeometry(
name, *geom, mat, fast_name, downsample_threshold)) {
247 bounds_ += scene->GetGeometryBoundingBox(
name);
248 GeometryData info(
name,
"");
252 if (add_downsampled_copy_for_fast_rendering &&
253 scene->HasGeometry(fast_name)) {
254 info.fast_name = fast_name;
255 geometries_[fast_name] = info;
257 geometries_[
name] = info;
258 SetGeometryToLOD(info, lod_);
265 const std::string&
name,
268 bool add_downsampled_copy_for_fast_rendering ) {
269 size_t downsample_threshold =
SIZE_MAX;
270 std::string fast_name;
271 if (add_downsampled_copy_for_fast_rendering) {
273 downsample_threshold = downsample_threshold_;
276 auto scene = renderer_.
GetScene(scene_);
277 if (scene->AddGeometry(
name, *geom, mat, fast_name, downsample_threshold)) {
280 GeometryData info(
name,
"");
284 if (add_downsampled_copy_for_fast_rendering &&
285 scene->HasGeometry(fast_name)) {
286 info.fast_name = fast_name;
292 bbox_mat.
base_color = {1.0f, 0.5f, 0.0f, 1.0f};
293 bbox_mat.
shader =
"unlitSolidColor";
294 scene->AddGeometry(lowq_name, *bbox_geom, bbox_mat);
295 info.low_name = lowq_name;
297 geometries_[
name] = info;
298 SetGeometryToLOD(info, lod_);
306 auto scene = renderer_.
GetScene(scene_);
311 auto scene = renderer_.
GetScene(scene_);
312 auto g = geometries_.find(
name);
313 if (g != geometries_.end()) {
314 scene->RemoveGeometry(
name);
315 if (!g->second.fast_name.empty()) {
316 scene->RemoveGeometry(g->second.fast_name);
318 if (!g->second.low_name.empty()) {
319 scene->RemoveGeometry(g->second.low_name);
321 geometries_.erase(
name);
326 auto scene = renderer_.
GetScene(scene_);
332 auto scene = renderer_.
GetScene(scene_);
333 auto g = geometries_.find(
name);
334 if (g != geometries_.end()) {
335 const Eigen::Transform<float, 3, Eigen::Affine> t(
337 scene->SetGeometryTransform(
name, t);
338 if (!g->second.fast_name.empty()) {
339 scene->SetGeometryTransform(g->second.fast_name, t);
341 if (!g->second.low_name.empty()) {
342 scene->SetGeometryTransform(g->second.low_name, t);
348 const std::string&
name) {
349 auto scene = renderer_.
GetScene(scene_);
355 auto scene = renderer_.
GetScene(scene_);
357 auto it = geometries_.find(
name);
358 if (it != geometries_.end()) {
359 if (!it->second.fast_name.empty()) {
360 scene->OverrideMaterial(it->second.fast_name, mat);
367 auto it = geometries_.find(
name);
368 if (it != geometries_.end()) {
369 it->second.visible = show;
371 int n_lowq_visible = 0;
372 for (
auto& g : geometries_) {
373 if (g.second.visible && !g.second.low_name.empty()) {
377 use_low_quality_if_available_ = (n_lowq_visible > 1);
379 SetGeometryToLOD(it->second, lod_);
385 auto scene = renderer_.
GetScene(scene_);
386 if (scene->AddGeometry(
name, model)) {
387 GeometryData info(
name,
"");
388 bounds_ += scene->GetGeometryBoundingBox(
name);
389 geometries_[
name] = info;
390 scene->ShowGeometry(
name,
true);
397 auto scene = renderer_.
GetScene(scene_);
398 for (
auto& g : geometries_) {
400 if (!g.second.fast_name.empty()) {
401 scene->OverrideMaterial(g.second.fast_name, mat);
413 auto scene = renderer_.
GetScene(scene_);
415 scene->AddGeometry(
name, model);
419 std::vector<std::string> names;
420 names.reserve(geometries_.size());
421 for (
auto& it : geometries_) {
422 names.push_back(it.first);
431 for (
auto& g : geometries_) {
432 SetGeometryToLOD(g.second, lod);
437 void CloudViewerScene::SetGeometryToLOD(
const GeometryData& data, LOD lod) {
438 auto scene = renderer_.
GetScene(scene_);
440 if (!data.fast_name.empty()) {
441 scene->ShowGeometry(data.fast_name,
false);
443 if (!data.low_name.empty()) {
444 scene->ShowGeometry(data.low_name,
false);
449 scene->ShowGeometry(data.name,
true);
452 if (use_low_quality_if_available_) {
461 scene->ShowGeometry(
id,
true);
471 auto scene = renderer_.
GetScene(scene_);
472 auto view = scene->
GetView(view_);
std::shared_ptr< core::Tensor > image
CloudViewerScene::LightingProfile profile
Type norm() const
Returns vector norm.
PointCoordinateType GetMaxExtent() const
Hierarchical CLOUDVIEWER Object.
static std::shared_ptr< ccMesh > CreateArrow(double cylinder_radius=1.0, double cone_radius=1.5, double cylinder_height=5.0, double cone_height=4.0, int resolution=20, int cylinder_split=4, int cone_split=1)
static std::shared_ptr< ccMesh > CreateSphere(double radius=1.0, int resolution=20, bool create_uv_map=false)
Vector3Tpl< T > getCenter() const
Returns center.
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const ccBBox &box)
Factory function to create a LineSet from an ccBBox.
static Application & GetInstance()
const char * GetResourcePath() const
void SetViewport(std::int32_t x, std::int32_t y, std::uint32_t width, std::uint32_t height)
Eigen::Matrix4d GetGeometryTransform(const std::string &name)
void ShowSkybox(bool enable)
void ShowGeometry(const std::string &name, bool show)
Shows or hides the geometry with the specified name.
bool HasGeometry(const std::string &name) const
void ModifyGeometryMaterial(const std::string &name, const MaterialRecord &mat)
std::vector< std::string > GetGeometries()
void UpdateModelMaterial(const std::string &name, const TriangleMeshModel &model)
Updates the named model to use this material.
void SetBackground(const Eigen::Vector4f &color, std::shared_ptr< geometry::Image > image=nullptr)
void SetGeometryTransform(const std::string &name, const Eigen::Matrix4d &transform)
const Eigen::Vector4f GetBackgroundColor() const
void RemoveGeometry(const std::string &name)
Renderer & GetRenderer() const
void ShowGroundPlane(bool enable, Scene::GroundPlane plane)
void ShowAxes(bool enable)
void UpdateMaterial(const MaterialRecord &mat)
Updates all geometries to use this material.
bool GeometryIsVisible(const std::string &name)
void SetLighting(LightingProfile profile, const Eigen::Vector3f &sun_dir)
Camera * GetCamera() const
void AddGeometry(const std::string &name, const ccHObject *geom, const MaterialRecord &mat, bool add_downsampled_copy_for_fast_rendering=true)
Adds a geometry with the specified name. Default visible is true.
CloudViewerScene(Renderer &renderer)
void AddModel(const std::string &name, const TriangleMeshModel &model)
virtual SceneHandle CreateScene()=0
virtual Scene * GetScene(const SceneHandle &id) const =0
virtual ccBBox GetGeometryBoundingBox(const std::string &object_name)=0
virtual bool GeometryIsVisible(const std::string &object_name)=0
virtual void RemoveGeometry(const std::string &object_name)=0
virtual Transform GetGeometryTransform(const std::string &object_name)=0
virtual void SetBackground(const Eigen::Vector4f &color, const std::shared_ptr< geometry::Image > image=nullptr)=0
virtual bool HasGeometry(const std::string &object_name) const =0
virtual View * GetView(const ViewHandle &view_id) const =0
virtual void EnableGroundPlane(bool enable, GroundPlane plane)=0
virtual void OverrideMaterial(const std::string &object_name, const MaterialRecord &material)=0
virtual void ShowGeometry(const std::string &object_name, bool show)=0
virtual void ShowSkybox(bool show)=0
virtual Camera * GetCamera() const =0
void Transform(benchmark::State &state, const core::Device &device)
static const std::string path
const std::string kLowQualityModelObjectSuffix("__low__")
const std::string kAxisObjectName("__axis__")
const std::string kFastModelObjectSuffix("__fast__")
Generic file read and write utility for python interface.
Eigen::Vector4f base_color