-
Notifications
You must be signed in to change notification settings - Fork 3
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
Read write obj #35
Conversation
@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; |
There was a problem hiding this comment.
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?
include/meshio/meshio_defines.hpp
Outdated
return false; | ||
if (mNormals.size()) | ||
for (unsigned i = 0; i < mNormals.size(); ++i) | ||
if (!(mNormals[i] == pGeometryDataObj.mNormals[i])) |
There was a problem hiding this comment.
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?
include/meshio/vectors.hpp
Outdated
|
||
std::size_t size() const { return 2; } | ||
viterator end() { return (Vec4<T>::end()-2); } | ||
const_viterator end() const { return (Vec4<T>::end()-2); } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
include/meshio/vectors.hpp
Outdated
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 */ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@9prady9 Code is good for review |
}; | ||
|
||
template<class T> | ||
class OBJData { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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 ofGeometryData<T>
and used vector of this derived class inOBJData
. So, instead of using something similar tovector<STLData>
, I usedvector<mOBJAttribute>
. It is getting difficult for me to use one class in this case.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
include/meshio/obj.hpp
Outdated
} | ||
} | ||
|
||
bool isEqualOBJMaterials(const OBJData<T>& pOBJData) { |
There was a problem hiding this comment.
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.
include/meshio/obj.hpp
Outdated
mOBJMaterials.clear(); | ||
} | ||
|
||
bool isEqualOBJAttributes(const OBJData<T>& pOBJData) { |
There was a problem hiding this comment.
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.
include/meshio/obj.inl
Outdated
* TODO: Thorough testing needed for this function | ||
*/ | ||
template<typename T> | ||
bool WriteMtl(const char* pMtlFileName, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
include/meshio/vectors.hpp
Outdated
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 */ |
There was a problem hiding this comment.
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.
include/meshio/vectors.hpp
Outdated
|
||
std::size_t size() const { return 2; } | ||
viterator end() { return (Vec4<T>::end()-2); } | ||
const_viterator end() const { return (Vec4<T>::end()-2); } |
There was a problem hiding this comment.
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) | ||
{ |
There was a problem hiding this comment.
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.
@acrlakshman 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. |
@acrlakshman Are you done with the changes ? |
@9prady9 Not yet |
* 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]>
@9prady9 I am rewritting read and write of obj separately and submit as different PRs. |
Please pick a relevant checklist(remove others) and make sure to finish & check all items for the PR.
Feature Completeness: