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

Read write obj #35

Closed
wants to merge 6 commits into from
Closed

Read write obj #35

wants to merge 6 commits into from

Conversation

acrlakshman
Copy link
Collaborator

@acrlakshman acrlakshman commented Jul 6, 2017

Please pick a relevant checklist(remove others) and make sure to finish & check all items for the PR.

Feature Completeness:

  • Algorithm Implementation
  • Unit tests

@acrlakshman acrlakshman requested a review from 9prady9 July 6, 2017 03:09
@acrlakshman acrlakshman self-assigned this Jul 6, 2017
@acrlakshman
Copy link
Collaborator Author

@9prady9 From next time I will keep updating the same branch instead of deleting it. Sorry, I realized it late.

static inline bool isEqual(const T pA, const T pB, const T pTolerance = 1e-6)
{
if (std::abs(pA - pB) <= pTolerance)
return true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@9prady9 this is perfectly valid as per https://google.github.io/styleguide/cppguide.html#Conditionals. Do we need to change this by following the convention that codacy-bot tells? or is there a way to suppress this by making this style an exception?

return false;
if (mNormals.size())
for (unsigned i = 0; i < mNormals.size(); ++i)
if (!(mNormals[i] == pGeometryDataObj.mNormals[i]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@9prady9 This way of writing is also correct as per google coding style. As an example it is present in the code snippet just above https://google.github.io/styleguide/cppguide.html#Punctuation,_Spelling_and_Grammar

What do you suggest?

Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 7, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017
Repository owner deleted a comment Jul 8, 2017

std::size_t size() const { return 2; }
viterator end() { return (Vec4<T>::end()-2); }
const_viterator end() const { return (Vec4<T>::end()-2); }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@9prady9 I couldn't get this line to be covered in test cases. Please take a look at TODO comment in test/utilities.cpp

Copy link
Owner

Choose a reason for hiding this comment

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

That's fine. Aren't we use Vec2 anywhere ? Lets just comment this out if we are not using it currently.

Copy link
Collaborator Author

@acrlakshman acrlakshman Jul 10, 2017

Choose a reason for hiding this comment

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

@9prady9 Currently we are not using Vec2, except in unit tests. I will comment out this line. But I could not understand why this is not covered though I explicitly tried to use this in unit tests test/utilities.cpp

Copy link
Owner

Choose a reason for hiding this comment

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

Not sure, but if we are not using this yet. Lets just comment it out and re-enable it when it can be used. Don't delete it though, just comment it out.

Repository owner deleted a comment Jul 8, 2017
Vec4(T pX, T pY, T pZ, T pW) : elems({pX, pY, pZ, pW}) {}
Vec4() : Vec4(0, 0, 0, 1) { } /* TODO: In graphics applications we
generally use fourth point as 1.
If this is not OK we can change it */
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@9prady9 Please take a look at this comment too. If this needs to be changed back to (0,0,0,0), then I need to change test case. However, I wanted to know which one we should use. Generally fourth parameter we use as 1 in graphics for positions. Please correct me if I am wrong.

Copy link
Owner

Choose a reason for hiding this comment

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

I think that is fine especially since we do provide constructor where the user can set the vector components explicitly to which ever values he wants to.

@acrlakshman
Copy link
Collaborator Author

@9prady9 Code is good for review

};

template<class T>
class OBJData {
Copy link
Owner

Choose a reason for hiding this comment

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

Can't we have OBJAttribute merged into OBJData ? Why two classes ?

Copy link
Collaborator Author

@acrlakshman acrlakshman Jul 11, 2017

Choose a reason for hiding this comment

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

@9prady9

  • Here, we need two vectors (i) that stores geometric attributes, (ii) material information. If I try to use one derived class from GeometryData<T>, to store entire obj information, I am unable to differentiate geometry and material information that we get from tinyobjloader. So, I introduced one derived class of GeometryData<T> and used vector of this derived class in OBJData. So, instead of using something similar to vector<STLData>, I used vector<mOBJAttribute>. It is getting difficult for me to use one class in this case.

Copy link
Owner

@9prady9 9prady9 Jul 11, 2017

Choose a reason for hiding this comment

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

I think it is better to have an class defined and accessible only from OBJData instead of a class that is accessible from everywhere. It would go something like below

class OBJData {
    typedef struct OBJAttributes {
        // ...
    } Attributes;
};

That way you can isolate tinyobjloader contents into a separate container class and also avoid creating an user-facing class - since meshio is header-only we have avoid anything and everything that can cause unintended usage by end users. In this case, they may try to use OBJAttributes. However, if the definition of this container is limited to the scope of OBJData class, then they can't even access it in the first place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, thank you. I will do it again.

}
}

bool isEqualOBJMaterials(const OBJData<T>& pOBJData) {
Copy link
Owner

Choose a reason for hiding this comment

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

May be a name like areMaterialsSame can give more readable code ? OBJ doesn't need to be part of this name I think because this is method of OBJ related class object.

mOBJMaterials.clear();
}

bool isEqualOBJAttributes(const OBJData<T>& pOBJData) {
Copy link
Owner

Choose a reason for hiding this comment

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

May be a name like areAttributesSame can give more readable code ? OBJ doesn't need to be part of this name I think because this is method of OBJ related class object.

* TODO: Thorough testing needed for this function
*/
template<typename T>
bool WriteMtl(const char* pMtlFileName,
Copy link
Owner

Choose a reason for hiding this comment

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

Lets go with writeMaterial. I don't remember exactly, didn't we agree for camel case for function naming?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@9prady9 My mistake I will update this.

/**
* Extracts filename from path.
*/
static inline std::string getFileBaseName(const std::string& pFileName)
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this return the last word found in the path? Even that is a valid file name. All files doesn't need to have an extension necessarily. If you intend to have this function not handle such cases, mention that in function documentation to be clear for whoever might use this in future. May be in a section such as limitations in the function docs.

Copy link
Collaborator Author

@acrlakshman acrlakshman Jul 10, 2017

Choose a reason for hiding this comment

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

@9prady9 I need a function that returns base name for file with file_name.obj, so that I can use it to write file_name.mtl. So, this is aimed for writing obj files and its derivative files. This is why I had it like this, any suggestion in this regard? At the end I do need a function that returns basename and it does expect an extension.

I will mention in the documentation too and I will include this when I update this patch.

Vec4(T pX, T pY, T pZ, T pW) : elems({pX, pY, pZ, pW}) {}
Vec4() : Vec4(0, 0, 0, 1) { } /* TODO: In graphics applications we
generally use fourth point as 1.
If this is not OK we can change it */
Copy link
Owner

Choose a reason for hiding this comment

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

I think that is fine especially since we do provide constructor where the user can set the vector components explicitly to which ever values he wants to.


std::size_t size() const { return 2; }
viterator end() { return (Vec4<T>::end()-2); }
const_viterator end() const { return (Vec4<T>::end()-2); }
Copy link
Owner

Choose a reason for hiding this comment

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

That's fine. Aren't we use Vec2 anywhere ? Lets just comment this out if we are not using it currently.

using namespace meshio;

TEST(VECTORS, MISCELLANEOUS)
{
Copy link
Owner

Choose a reason for hiding this comment

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

May be split tests into TEST(VECTORS, 2D) , TEST(VECTORS, 3D) and 4D if possible. Better readable and easy to debug and when they fail tests.

@9prady9
Copy link
Owner

9prady9 commented Jul 10, 2017

@acrlakshman Is tiny OBJ loeader file you placed under third_party how is this being added ? did you copy it to that location and added it to the repo directly ?

I checked it myself, may be there is a better way to include this. I am not sure how this works for header-only libraries.

Repository owner deleted a comment Jul 11, 2017
Repository owner deleted a comment Jul 11, 2017
@9prady9
Copy link
Owner

9prady9 commented Sep 26, 2017

@acrlakshman Are you done with the changes ?

@acrlakshman
Copy link
Collaborator Author

@9prady9 Not yet

acrlakshman and others added 6 commits March 17, 2019 20:53
* referencing #25, #26
* Rewrote some basic datastructures [e.g. GeometryData].
* Read function for OBJ format completed with the help of tinyobjloader.
* Write function for OBJ format completed with the help of tinyobjloader.
* Minor cleanups.
* Rewrote some components to adhere to Google C++ style guide.
* Submitting this patch to receive any comments while WIP.

Signed-off-by: Lakshman Anumolu <[email protected]>
Also fixed function naming style in vectors.hpp
* Made end() a virtual function in Vec classes.

Signed-off-by: Lakshman Anumolu <[email protected]>
* removed obj subfolder
* obj tests working
* fixed iterator bug in Vec3 class
* updated copyright year

Signed-off-by: Lakshman Anumolu <[email protected]>
Signed-off-by: Lakshman Anumolu <[email protected]>
Signed-off-by: Lakshman Anumolu <[email protected]>
@acrlakshman
Copy link
Collaborator Author

@9prady9 I am rewritting read and write of obj separately and submit as different PRs. tiny_obj_loader has changed over the past year, I will use that.

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

Successfully merging this pull request may close these issues.

2 participants