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

Compact Triangulation Integration #674

Merged
merged 19 commits into from
Dec 13, 2021
Merged

Conversation

guoxiliu
Copy link
Contributor

Thanks for contributing to TTK!

Before submitting your pull request, please:

  • Review our Contributor Guidelines, in particular regarding code formatting (with clang-format) and continuous integration.

  • Please provide a quick description of your contributions below:
    This PR adds a compact triangulation data structure and also a preconditioning plugin for it.

@julien-tierny
Copy link
Collaborator

hi @guoxiliu

thanks a lot for your PR.

it seems that the CI identified a couple of issues with this PR.
these need to be solved before we move on with the code review.

could you please make sure:

Thanks!

@guoxiliu
Copy link
Contributor Author

Thanks, @julien-tierny. I will continue to work on these issues.

hi @guoxiliu

thanks a lot for your PR.

it seems that the CI identified a couple of issues with this PR. these need to be solved before we move on with the code review.

could you please make sure:

Thanks!

Copy link
Collaborator

@julien-tierny julien-tierny left a comment

Choose a reason for hiding this comment

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

I have started a review. It is not finished at the moment.
I will resume it asap.

core/base/compactTriangulation/CompactTriangulation.cpp Outdated Show resolved Hide resolved
core/base/compactTriangulation/CompactTriangulation.h Outdated Show resolved Hide resolved
core/base/compactTriangulation/CompactTriangulation.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@julien-tierny julien-tierny left a comment

Choose a reason for hiding this comment

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

hi @guoxiliu

sorry for the late reply but here's my review for this PR.
if you could fix the few remarks I added in there, that would be wonderful.
maybe @pierre-guillou, you could also review the PR if you have time.

once the above remarks are addressed, I'll go ahead and run experiments with the code.

thanks!

Move Octree to the base folder
Remove debug message prefix in vtk file
Copy link
Collaborator

@julien-tierny julien-tierny left a comment

Choose a reason for hiding this comment

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

hi @guoxiliu
thanks a lot for your quick fix.
I have found yet a few occurrences of dynamic allocation.
could you also address these and let me know when you're done?
thanks!

core/base/octree/Octree.cpp Outdated Show resolved Hide resolved
core/base/octree/Octree.cpp Outdated Show resolved Hide resolved
core/base/octree/Octree.h Outdated Show resolved Hide resolved
@julien-tierny
Copy link
Collaborator

ok, thanks @guoxiliu
that looks all good to me.
I'll start to play around and experiment with the code a little bit.
@pierre-guillou could you have a look at this PR too?
thanks

@julien-tierny
Copy link
Collaborator

as a side note, I switched the CompactTriangulationPreconditioning to operate on vtkPointSet inputs (and outputs) instead of the more general vtkDataSet.
specifically, there is no need to call it on a regular grid for instance (and it actually crashed there).

Copy link
Contributor

@pierre-guillou pierre-guillou left a comment

Choose a reason for hiding this comment

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

Hi @guoxiliu!
I've looked at this PR and written a few comments on minor points. I hope I'm not too picky...

Comment on lines 25 to 26
using namespace ttk;
using namespace std;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit concerned with these using namespace directives inside a header file since, through preprocessor inclusion, this can have non-local effects on other parts of the TTK codebase. Would it be possible to remove those and use instead fully qualified types (with ttk:: and std:: prefixes)? (using namespace in .cpp source files is fine though)

class OctreeNode {
public:
OctreeNode() {
OctreeNode(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This creates a temporary object that is never used. Did you intend OctreeNode() : OctreeNode(0) {} instead? It is flagged by clang-tidy in the check_code CI workflow, first lint_code job, Use clang-tidy to lint code step as bugprone-undelegated-constructor

using namespace ttk;

Octree::Octree(const AbstractTriangulation *t) {
Octree(t, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

This creates a temporary object. Did you intend to call Octree::Octree(const AbstractTriangulation *t):Octree(t, 1000) {} instead?

uint32_t location;
float ncenter[3] = {0.0}, nsize[3] = {0.0};
for(int i = 0; i < dim; i++) {
SimplexId vertexId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Due to the internals of getCellVertex, this variable needs to be initialized (otherwise, a garbage value might be propagated). A simple SimplexId vertexId{}; with two braces should suffice to zero-initialize the variable. This is flagged by the clang static analyzer (check_code CI workflow, second lint_code job, Use Clang static analyzer step).

*/
uint32_t
getChildLocation(uint32_t parLoc, SimplexId vertexId, float centerArr[3]) {
float xval, yval, zval;
Copy link
Contributor

Choose a reason for hiding this comment

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

Those values should also be zero-initialized: float xval{}, yval{}, zval{};

/**
* Reorder the input cells.
*/
int reorderCells(const std::vector<SimplexId> &vertexMap,
Copy link
Contributor

Choose a reason for hiding this comment

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

inline or move to .cpp?

Comment on lines 42 to 54
#include <vtkCharArray.h>
#include <vtkDataArray.h>
#include <vtkDataSet.h>
#include <vtkDataSetAlgorithm.h>
#include <vtkDoubleArray.h>
#include <vtkFiltersCoreModule.h>
#include <vtkFloatArray.h>
#include <vtkInformation.h>
#include <vtkIntArray.h>
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
#include <vtkSmartPointer.h>
#include <vtkUnstructuredGrid.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of those includes can be moved to the .cpp

Comment on lines 78 to 79
float center[3];
float size[3];
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 std::array<float, 3> instead of C-array? std::array are zero-initialized and have additional methods (begin(), end(), ...) that make them compatible with std::vector. To get a C-array like pointer, use the data() method.

Comment on lines 106 to 107
std::vector<std::string>::iterator iter = scalarFields.begin();
while(iter != scalarFields.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A range-based for loop (for(const auto &s : scalarFields)) should be more readable here

Comment on lines 181 to 182
iter = scalarFields.begin();
while(iter != scalarFields.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A range-based for loop might be preferred here too

@julien-tierny
Copy link
Collaborator

@pierre-guillou
could you please double-check @guoxiliu 's latest commits and let me know if you approve all edits?
if so, I guess we'd be good to go for the merge :)

@pierre-guillou
Copy link
Contributor

Hi @guoxiliu,

Thanks for taking my remarks into account.
I looked at your last changes and played a bit with the code. I have some last suggestions in the form of the following diffs (you can apply them by copying these files in the root of your TTK repo then using git am on them - or reproducing the changes by hand):

0001-Reduce-variables-scope.txt
0002-Clear-state-before-computation.txt
0003-Call-parent-class-copy-constructor.txt

Also, I noticed several times some weird memory issue that filled the 64GB of RAM of my computer and makes it swap. To trigger them, I load the noisyTerrain.vtu dataset in ParaView, apply CompactTriangulationPreconditionning then launching PersistenceDiagram. Sometimes, this is enough to trigger the phenomenon, otherwise, fiddling with the input scalar fields in the CompactTriangulationPreconditionning filter causes it (my 2nd patch might also have an effect there). Using heaptrack, I found that the faulty memory allocations occured in CompactTriangulation::reorderCells. Have you already noticed this behavior?

Thanks,
Pierre

@julien-tierny
Copy link
Collaborator

@guoxiliu:
could you have a look at merging @pierre-guillou 's patch?

also, it seems that the memory issue @pierre-guillou mentioned seems to be the last obstacle to the merge of this PR.
this would be great if you could have a look into it.

thanks for your feedback.
best,

@julien-tierny julien-tierny added the discussion Ongoing discussion prior to merge label Dec 6, 2021
@guoxiliu
Copy link
Contributor Author

guoxiliu commented Dec 6, 2021

Thank you, @julien-tierny and @pierre-guillou. I am working on merging the patch and the memory issue. I will update the repo when I fix it.

Best,
Guoxi

@pierre-guillou
Copy link
Contributor

Thanks @guoxiliu! The memory issue seems to be gone with your last commit!
Everything looks good to me.
Looking forward to the merge!

@julien-tierny
Copy link
Collaborator

Alright, looks good to me.
Let's go then!

@julien-tierny julien-tierny merged commit 518dabb into topology-tool-kit:dev Dec 13, 2021
@julien-tierny
Copy link
Collaborator

julien-tierny commented Dec 13, 2021

Now @guoxiliu
I will ask you one more thing:
can you checkout our contributor guide to ttk-data and PR ttk-data to provide an example of usage of the compact triangulation?

@guoxiliu
Copy link
Contributor Author

Alright, looks good to me. Let's go then!

Thank you, @julien-tierny!

Now @guoxiliu I will ask you one more thing: can you checkout our contributor guide to ttk-data and PR ttk-data to provide an example of usage of the compact triangulation?

I will follow the guideline in the link you mentioned and prepare the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Ongoing discussion prior to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants