Skip to content

Dual quaternion#19026

Merged
alalek merged 19 commits intoopencv:masterfrom
chargerKong:dualquat
Feb 17, 2021
Merged

Dual quaternion#19026
alalek merged 19 commits intoopencv:masterfrom
chargerKong:dualquat

Conversation

@chargerKong
Copy link
Copy Markdown
Contributor

@chargerKong chargerKong commented Dec 6, 2020

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • [] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
build_image:Custom=centos:7
buildworker:Custom=linux-1,linux-4,linux-6

@chargerKong chargerKong force-pushed the dualquat branch 2 times, most recently from 84cf64b to cd8ef0c Compare December 6, 2020 14:26
basic operations, functions(exp,log,norm,inv), to/from mat, sclerp.
@chargerKong
Copy link
Copy Markdown
Contributor Author

Happy new year! @savuor
I’m sorry for not updating the code last month because I went to the headquarters to participate in the oral defense.
I'll update this next week

change algorithm of norm, inv, getTranslation, createFromPitch, normalize;
change type translation to Vec3;
comment improve;
std::vector<Vec<_Tp, 3>> &out_normals,
const std::vector<DualQuat<_Tp>> &dualquat,
const std::vector<std::vector<_Tp>> &weights,
const std::vector<std::vector<int>> &joints_id,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's better to use InputArray and OutputArray for vertices, normals, weights and ids instead of vectors. Internally the type and dimensionality should be checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK

std::vector<Vec<T, 3>> &out_vert, std::vector<Vec<T, 3>> &out_normals,
const std::vector<DualQuat<T>> &_dualquat, const std::vector<std::vector<T>> &weights,
const std::vector<std::vector<int>> &joint_id, QuatAssumeType assumeUnit)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this function should be moved to some .cpp file. Here's motivation why:
Typical use case for this function is to transform point clouds and vertices which are counted in thousands. This may involve massive parallel processing using parallel_for_, SIMD or OpenCL.
Having such a code in a header makes no sense; this would slow down the compilation. Having this in .inl.hpp has even less sense since this is not a good function to be inlined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I've temporarily removed this function, but have no idea where to put it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can create a separate .cpp file, like dqs.cpp or something

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to separate declarations and definitions of template functions? I did some consulting and I saw that most of the template class functions that can be run were written together. Is there a way to separate them?

}
for (size_t i = 0; i < in_vert.size(); ++i)
{
DualQuat<T> dq_blend;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here gdqblend can be reused with QUAT_ASSUME_UNIT argument

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK

add func(obj) operations;
@chargerKong chargerKong changed the title [WIP]Dual quaternion Dual quaternion Jan 21, 2021
Copy link
Copy Markdown
Contributor

@savuor savuor left a comment

Choose a reason for hiding this comment

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

Most of the code looks good to me.
The only thing to change is to use InputArray instead of vector<DualQuat<T>> or Vec<DualQuat<T>, n>. This makes sense not only for gdqblend but for dqs as well. A type should be checked along with size, it's OK to allow floats and doubles only in such functions.
Doing this would resolve the problem with definition of template function in .cpp file since there'll be no templates.
P.S. Sorry for not answering for such a long time.

* @note the type of weights' element should be the same as the date type of dual quaternion inside the dualquat.
*/
template <int cn>
static DualQuat<_Tp> gdqblend(const Vec<DualQuat<_Tp>, cn> &dualquat, InputArray weights,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think dualQuat should be an InputArray too, as well as weights, with type/size checks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK. I‘ll complete it next week

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I found it will raise an error when Vec<DualQuat<double>, n> converts into InputArray, and Matx will also happen like this

error: ‘type’ is not a member of ‘cv::DataType<cv::DualQuat<double> >’

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe to fix this by introducing a separate alias for this function with Vec<DualQuat<float/double>> as an argument type? Like, there'll be a function gdqblend(InputArray dualQuat,...) that requires dualQuat to have 8 rows/channels of float/double. And 2 functions gdqblend(const Vec<DualQuat<float/double>, 8> &dualquat,... that call the InputArray version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to call function gdqblend(const Vec<DualQuat<float/double>, n> ... ) in function gdqblend(InputArray dualQuat,...) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The opposite: the basic function is the one with InputArray, it's called by the function with const Vec<DualQuat<float/double>, n>.

@savuor
Copy link
Copy Markdown
Contributor

savuor commented Feb 16, 2021

@chargerKong @alalek Looks like #19538 fixes the problems in this build. Can we merge the one to another?

@alalek
Copy link
Copy Markdown
Member

alalek commented Feb 16, 2021

There is no automatic merge process between patches.
Multiple "merge" commits in mentioned PR makes review of changed parts hard.

@alalek alalek merged commit 0aca3fb into opencv:master Feb 17, 2021
@alalek alalek mentioned this pull request Feb 17, 2021
6 tasks
@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
Dual quaternion

* create dual quaternion;
basic operations, functions(exp,log,norm,inv), to/from mat, sclerp.

* add dqb, dqs, gdqb, to/from affine3;
change algorithm of norm, inv, getTranslation, createFromPitch, normalize;
change type translation to Vec3;
comment improve;

* try fix warning: unreferenced local function

* change exp calculation;
add func(obj) operations;

* Change the algorithm of log function;
add assumeUnit in getRotation;
remove dqs;
change std::vector to InputArray

* fix warning: doxygen and Vec<double, 0>

* fix warning: doxygen and Vec<double, 0>

* add inputarray param for gdqb

* change int to size_t

* win cl warning fix

* replace size_t by int at using Mat.at() function

* replace double by float

* interpolation fix

* replace (i, 0) to (i)

* core(quat): exclude ABI, test_dualquaternion=>test_quaternion.cpp

Co-authored-by: arsaratovtsev <arsaratovtsev@intel.com>
Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants