Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[all] Use drawtool everywhere #704

Merged
merged 24 commits into from
Aug 3, 2018

Conversation

hugtalbot
Copy link
Contributor

@hugtalbot hugtalbot commented Jun 28, 2018

Apply the use of drawTool in the open-source core of SOFA

This now makes SOFA a priori independent from OpenGL using the drawTools.
Fix #653


This PR:

  • builds with SUCCESS for all platforms on the CI.
  • does not generate new warnings.
  • does not generate new unit test failures.
  • does not generate new scene test failures.
  • does not break API compatibility.
  • is more than 1 week old (or has fast-merge label).

Reviewers will merge only if all these checks are true.

@hugtalbot hugtalbot added enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request STC#5 labels Jun 28, 2018
@hugtalbot hugtalbot changed the title Use drawtool everywhere [all] Use drawtool everywhere Jun 28, 2018
@damienmarchal
Copy link
Contributor

[ci-build]

@damienmarchal
Copy link
Contributor

[ci-build][with-scene-tests]

void DrawToolGL::drawTriangles(const std::vector<Vector3> &points, const std::vector< Vec4f > &colour)
{
std::vector<Vector3> normal;
normal.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that if the normal is empty it does nothing ?
Maybe add some comment to explain the logic the declaration of drawTriangles()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually if you look closer, this function creates a vector of normals and then calls another function (l. 277) that computes normals if the vector has a null size

{
glLineWidth(size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break code that have set the drawLine before.
cannot push/pop the attrib otherwise ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no since @fredroy set a default value for "size" to one, for functions calling it without specifying the value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normal convention is to save the attributes before changing them and restoring them to their old value when you are done. In your case you restore it to 1.0 regardless of its initial value this means that calling the function has a side effect on all future opengl drawing operation. It is way better to have side effect free functions so that the one that call them does not have to care about what the function is doing.

@@ -2401,7 +2401,7 @@ void TriangleSetGeometryAlgorithms<DataTypes>::draw(const core::visual::VisualPa

const sofa::helper::vector<Triangle> &triangleArray = this->m_topology->getTriangles();

helper::vector<defaulttype::Vector3> positions;
std::vector<defaulttype::Vector3> positions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use helper::vector as much as possible ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could but @fredroy told me that he wanted to make it as independent from SOFA as possible (in this optic, we should also remove the defaulttype calls).
But in general you're right, for the rest of SOFA, we should use helper::vector as much as possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear so much inconsistancies :)

@@ -108,6 +108,7 @@ class SOFA_MISC_COLLISION_API TetrahedronModel : public core::CollisionModel
protected:

TetrahedronModel();
void addTetraToDraw(const Tetrahedron& t, std::vector<sofa::defaulttype::Vector3>& tetraVertices, std::vector<sofa::defaulttype::Vector3>& normalVertices);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't the other parameters const ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, by looking into this function, its purpose is actually to build a vector and set new values in it

@hugtalbot
Copy link
Contributor Author

Remark : I need to fix the test on planeForceField

p3 += (c - p3)*0.1f;
p4 += (c - p4)*0.1f;
Coord n1, n2, n3, n4;
n1 = cross(p3 - p1, p2 - p1); n1.normalize();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a lambda to reduce the amount of code and make it simpler ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update done

glEnd();
glPointSize(1);
#endif /* SOFA_NO_OPENGL */
color = sofa::defaulttype::RGBAColor::magenta();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the following block of code. it would be simpler with a do_whatever(...) lambda function

}
else
{
if (d2<edgeInf[i].restlength2*0.9999)
glColor4f(1,0.5f,0,1);
{
colors.push_back(sofa::defaulttype::RGBAColor(1,0.5, 0,1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put sofa::defaulttype::RGBAColor(1,0.5, 0,1) and friends as constexpr ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update done

@sofa-framework sofa-framework deleted a comment from guparan Jul 10, 2018
@guparan guparan added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jul 11, 2018
@hugtalbot hugtalbot added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Jul 13, 2018
@guparan
Copy link
Contributor

guparan commented Jul 18, 2018

TODO: solve conflict and build with scene tests

…l_everywhere

# Conflicts:
#	modules/SofaMiscForceField/MeshMatrixMass.inl
@guparan guparan added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jul 25, 2018
Data to show the plane is reactivated
Names are updated in showPlane and showPlaneScale
@hugtalbot hugtalbot added pr: status to review To notify reviewers to review this pull-request pr: status wip Development in the pull-request is still in progress and removed pr: status wip Development in the pull-request is still in progress pr: status to review To notify reviewers to review this pull-request labels Jul 31, 2018
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status wip Development in the pull-request is still in progress labels Aug 2, 2018
@damienmarchal damienmarchal merged commit 099888f into sofa-framework:master Aug 3, 2018
@guparan guparan added this to the v18.12 milestone Oct 26, 2018
@fredroy fredroy deleted the use_drawtool_everywhere branch July 2, 2020 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement About a possible enhancement pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants