19 namespace visualization {
24 void CreateCircle(
const Eigen::Vector3d& center,
25 const Eigen::Vector3d& u,
26 const Eigen::Vector3d& v,
30 for (
int i = 0; i <= n_segs; ++i) {
31 double theta = 2.0 *
M_PI * double(i) / double(n_segs);
32 double cosT = std::cos(theta);
33 double sinT = std::sin(theta);
34 Eigen::Vector3d p = center + radius * cosT * u + radius * sinT * v;
35 Eigen::Vector3d n = (cosT * u + sinT * v).normalized();
41 std::shared_ptr<ccMesh> CreateArrow(
const Eigen::Vector3d& dir,
46 Eigen::Vector3d tmp(dir.y(), dir.z(), dir.x());
47 Eigen::Vector3d u = dir.cross(tmp).normalized();
48 Eigen::Vector3d v = dir.cross(u);
50 Eigen::Vector3d start(0, 0, 0);
51 Eigen::Vector3d head_start((
length - head_length) * dir.x(),
52 (
length - head_length) * dir.y(),
53 (
length - head_length) * dir.z());
58 auto arrow = std::make_shared<ccMesh>(baseVertices);
59 if (!arrow->reserveAssociatedCloud(n_segs + 1,
false,
true)) {
64 CreateCircle(start, u, v, radius, n_segs, *baseVertices);
65 int n_verts_in_circle = n_segs + 1;
66 CreateCircle(head_start, u, v, radius, n_segs, *baseVertices);
67 for (
int i = 0; i < n_segs; ++i) {
71 n_verts_in_circle + i, i));
75 int start_idx = int(baseVertices->
size());
76 CreateCircle(head_start, u, v, 2.0 * radius, n_segs, *baseVertices);
78 for (
int i = start_idx; i < int(baseVertices->
size()); ++i) {
82 int center_idx = int(baseVertices->
size());
85 for (
int i = 0; i < n_segs; ++i) {
91 start_idx = int(baseVertices->
size());
92 CreateCircle(head_start, u, v, 2.0 * radius, n_segs, *baseVertices);
93 for (
int i = 0; i < n_segs; ++i) {
94 int pointIdx = int(baseVertices->
size());
97 static_cast<size_t>(start_idx + i)));
105 arrow->shrinkToFit();
115 arrow->addChild(baseVertices);
122 static const Eigen::Vector3d
kSkyColor(0.0f, 0.0f, 1.0f);
123 static const Eigen::Vector3d
kSunColor(1.0f, 0.9f, 0.0f);
127 : scene_(scene), camera_(camera) {}
138 auto identity = Camera::Transform::Identity();
149 double sphere_size = 0.5 *
size;
157 auto t0 = Camera::Transform::Identity();
159 mat.
shader =
"defaultUnlit";
160 scene_->
AddGeometry(
"__suncagesphere__", *sphere, mat);
163 ui_objs_.push_back({
"__suncagesphere__", t0});
165 auto sun_radius = 0.05 *
size;
168 sun->ComputeVertexNormals();
169 sun->triangle_uvs_.resize(sun->size() * 3, {0.f, 0.f});
170 auto t1 = Camera::Transform::Identity();
171 t1.translate(-sphere_size * dir);
175 ui_objs_.push_back({
"__sunsphere__", t1});
177 const double arrow_radius = 0.075 * sun_radius;
178 const double arrow_length = 0.333 *
size;
179 auto sun_dir = CreateArrow(dir.cast<
double>(), arrow_radius, arrow_length,
180 0.1 * arrow_length, 20);
182 sun_dir->ComputeVertexNormals();
183 sun_dir->triangle_uvs_.resize(sun_dir->size() * 3, {0.f, 0.f});
184 auto t2 = Camera::Transform::Identity();
185 t2.translate(-sphere_size * dir);
186 scene_->
AddGeometry(
"__sunarrow__", *sun_dir, mat);
189 ui_objs_.push_back({
"__sunarrow__", t2});
196 for (
auto& o : ui_objs_) {
198 t.pretranslate(model_center);
205 void LightDirectionInteractorLogic::ClearUI() {
206 for (
auto& o : ui_objs_) {
213 return GetMatrix() * light_dir_at_mouse_down_;
Array of compressed 3D normals (single index)
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
static std::shared_ptr< ccMesh > CreateSphere(double radius=1.0, int resolution=20, bool create_uv_map=false)
virtual void setLocked(bool state)
Sets the "enabled" property.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void addEigenNorm(const Eigen::Vector3d &N)
Eigen::Vector3d getEigenNormal(size_t index) const
void shrinkToFit()
Removes unused capacity.
void addEigenPoint(const Eigen::Vector3d &point)
unsigned size() const override
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const ccMesh &mesh)
virtual Eigen::Vector3f GetUpVector() const =0
virtual Eigen::Vector3f GetLeftVector() const =0
Eigen::Transform< float, 3, Eigen::Affine > Transform
Eigen::Vector3f GetCurrentDirection() const
LightDirectionInteractorLogic(Scene *scene, Camera *camera)
void Rotate(int dx, int dy) override
void SetMouseDownInfo(const Camera::Transform &matrix, const Eigen::Vector3f ¢er_of_rotation)
const Camera::Transform & GetMatrix() const
virtual void RotateWorld(int dx, int dy, const Eigen::Vector3f &x_axis, const Eigen::Vector3f &y_axis)
virtual void GeometryShadows(const std::string &object_name, bool cast_shadows, bool receive_shadows)=0
virtual void RemoveGeometry(const std::string &object_name)=0
virtual void SetGeometryTransform(const std::string &object_name, const Transform &transform)=0
virtual bool AddGeometry(const std::string &object_name, const ccHObject &geometry, const MaterialRecord &material, const std::string &downsampled_name="", size_t downsample_threshold=SIZE_MAX)=0
virtual Eigen::Vector3f GetSunLightDirection()=0
__host__ __device__ float length(float2 v)
static const Eigen::Vector3d kSkyColor(0.0f, 0.0f, 1.0f)
static const Eigen::Vector3d kSunColor(1.0f, 0.9f, 0.0f)
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 3, 1 > Vector3i