Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Sep 28, 2023
1 parent f087f15 commit a2c1725
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion tutorials/Tutorial_203_Viewer_wxWidgets/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

namespace easy3d {

class AppImpl;
class Application {
public:
explicit Application(const std::string &title = "Untitled", int width = 800, int height = 600);
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Tutorial_406_CollisionDetection/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char **argv) {
// initialize Easy3D.
initialize();

CollisionViewer viewer(EXAMPLE_TITLE);
TutorialCollisionDetection viewer(EXAMPLE_TITLE);

// run the viewer
return viewer.run();
Expand Down
16 changes: 9 additions & 7 deletions tutorials/Tutorial_406_CollisionDetection/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

using namespace easy3d;

CollisionViewer::CollisionViewer(const std::string &title)
TutorialCollisionDetection::TutorialCollisionDetection(const std::string &title)
: Viewer(title)
, model0_color_(0.8f, 1.0f, 0.8f)
, model1_color_(0.8f, 0.8f, 1.0f)
Expand All @@ -48,9 +48,11 @@ CollisionViewer::CollisionViewer(const std::string &title)
// use the manipulator to transform the first model (visualization only and geometry is not changed)
mesh0->set_manipulator(new Manipulator(mesh0));

// the first mesh is colored by a "face_color" property
mesh0->add_face_property<vec3>("face_color", model0_color_);
mesh0->renderer()->get_triangles_drawable("faces")->set_coloring(easy3d::State::COLOR_PROPERTY, easy3d::State::FACE, "face_color");

// the second mesh is also colored by a "face_color" property
mesh1->add_face_property<vec3>("face_color", model1_color_);
mesh1->renderer()->get_triangles_drawable("faces")->set_coloring(easy3d::State::COLOR_PROPERTY, easy3d::State::FACE, "face_color");

Expand All @@ -69,7 +71,7 @@ CollisionViewer::CollisionViewer(const std::string &title)
});
}
else
LOG(WARNING) << "not all two meshe models have been loaded";
LOG(WARNING) << "not all the two meshes have been loaded";

usage_string_ =
"--------------------- Collision Viewer usage ----------------------\n"
Expand All @@ -83,13 +85,13 @@ CollisionViewer::CollisionViewer(const std::string &title)
}


CollisionViewer::~CollisionViewer() {
TutorialCollisionDetection::~TutorialCollisionDetection() {
timer_.stop();
delete collider_;
}


bool CollisionViewer::mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) {
bool TutorialCollisionDetection::mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) {
if (collider_ && models().size() == 2 && modifiers == MODIF_ALT && timer_.is_paused()) {
auto manipulator = models_[0]->manipulator();
if (button == BUTTON_LEFT)
Expand All @@ -107,7 +109,7 @@ bool CollisionViewer::mouse_drag_event(int x, int y, int dx, int dy, int button,
}


bool CollisionViewer::key_press_event(int key, int modifiers) {
bool TutorialCollisionDetection::key_press_event(int key, int modifiers) {
if (key == KEY_SPACE) {
if (timer_.is_paused())
timer_.resume();
Expand All @@ -120,12 +122,12 @@ bool CollisionViewer::key_press_event(int key, int modifiers) {
}


void CollisionViewer::detect() {
void TutorialCollisionDetection::detect() {
const auto pairs = collider_->detect(models_[0]->manipulator()->matrix(), mat4::identity());
//std::cout << pairs.size() << " pairs of intersecting faces" << std::endl;

// mark the intersecting faces red
// Note: The following code is for visualizing the intersecting faces, and the code is not optimized.
// Note: The following code is for visualizing the intersecting faces and is not optimized.
// Ideas for better performance:
// (1) update only the color buffer;
// (2) use a shader storage buffer to transfer the *status* of the faces to the fragment shader.
Expand Down
12 changes: 6 additions & 6 deletions tutorials/Tutorial_406_CollisionDetection/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
********************************************************************/

#ifndef EASY3D_TUTORIAL_COLLISION_DETECTION_VIEWER_H
#define EASY3D_TUTORIAL_COLLISION_DETECTION_VIEWER_H
#ifndef EASY3D_TUTORIAL_COLLISION_DETECTION_H
#define EASY3D_TUTORIAL_COLLISION_DETECTION_H

#include <easy3d/viewer/viewer.h>
#include <easy3d/util/timer.h>
Expand All @@ -37,10 +37,10 @@ namespace easy3d {
class Collider;
}

class CollisionViewer : public easy3d::Viewer {
class TutorialCollisionDetection : public easy3d::Viewer {
public:
explicit CollisionViewer(const std::string &title);
~CollisionViewer() override;
explicit TutorialCollisionDetection(const std::string &title);
~TutorialCollisionDetection() override;

private:
bool mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) override;
Expand All @@ -58,4 +58,4 @@ class CollisionViewer : public easy3d::Viewer {
};


#endif // EASY3D_TUTORIAL_COLLISION_DETECTION_VIEWER_H
#endif // EASY3D_TUTORIAL_COLLISION_DETECTION_H
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool reconstruction(Viewer* viewer, Model* model) {
if (!normals) {
std::cerr << "Poisson surface reconstruction method requires normal information."
<< " Please provide normal information. Alternatively, you can use the "
<< " Tutorial_601_PointCloud_NormalEstimation for normal estimation" << std::endl;
<< " Tutorial_701_Cloud_NormalEstimation for normal estimation" << std::endl;
return false;
}

Expand Down

0 comments on commit a2c1725

Please sign in to comment.