Thursday, May 2, 2019

Writing a new book on ArrayFire library

My first post after a hiatus of a few months. I was bogged down in a lot of administrative stuff recently at my university. Meanwhile, I was exploring a few libraries. At GTC, I came to know about a new library called ArrayFire. I started exploring it and I found it to be really useful. I then decided to do a book on it. I am done with the first two chapters almost. For those of you who might want to have a look, here is a free pdf so far. All content will be BSD so you can use it in your own projects as you deem fit. I might as well find a decent publisher for this if there is any interest.

Click here to download the incomplete pdf


I will update the contents soon. I will also upload the full source code on my git handle @mmmovania.

Enjoy!!!

Friday, April 20, 2018

Replicating Matlab sort function in c++

Like most scientist out there, I also use Matlab often. Sometimes for my papers, I need to replicate functionality of some Matlab functions. For a recent project, I needed to replicate the functionality of the Matlab sort function i.e. ([sorted, indices] = sort(data)) in C++. As always, I went online and searched Google, which gave me quite a few links but the best of them all which gives a very detailed explanation of the function was Alec Jacobsen's http://www.alecjacobson.com/weblog/?p=1527. The function he gives is almost correct however it has one slight issue. The indices array returned is not sorted on the range of repeats of the value which is how Matlab does in the sort function. 

To do this, the index array has to be range sorted (before the indices array is returned ) as follows:

//get index ranges and sort
int start = 0;
for (int i = 0; i < sorted_values.size() - 1; ++i) {
   if (sorted_values[i] != sorted_values[i + 1]) {
      sort(idx.begin() + start, idx.begin() + (i + 1));
      start = i + 1;
   }

}

This gives the correct result. This is added in the sort_indexes function.

To sum up, the following is the complete implementation. I am replicating my complete code here to keep this post self contained for reference later.

// This implementation is O(n), but also uses O(n) extra memory
template< class T >
void reorder(
    std::vector< T > & unordered,
    std::vector< size_t > const & index_map,
    std::vector< T > & ordered)
{
    // copy for the reorder according to index_map, because unsorted may also be
    // sorted
    std::vector< T > copy = unordered;
    ordered.resize(index_map.size());
    for (int i = 0; i < index_map.size(); i++)
    {
        ordered[i] = copy[index_map[i]];
    }
}


std::vector< size_t > sort_indexes(std::vector< float > &data,
                                 std::vector< float >& sorted_values)
{
    // initialize original index locations
    std::vector< size_t > idx(data.size());
    std::iota(idx.begin(), idx.end(), 0);

    //sort data
    //copy data
    std::copy(data.begin(), data.end(), std::back_inserter(sorted_values));
    sort(sorted_values.begin(), sorted_values.end(), [](float a, float b) {return a < b; });
   
    // sort indexes based on comparing values in data
    sort(idx.begin(), idx.end(),[data](size_t i1, size_t i2) {return data[i1] < data[i2]; });
       
    //get index ranges and sort
    int start = 0;
    for (int i = 0; i < sorted_values.size() - 1; ++i) {
        if (sorted_values[i] != sorted_values[i + 1]) {
            sort(idx.begin() + start, idx.begin() + (i + 1));
            start = i + 1;
        }
    }

    return idx;
}

Thursday, July 27, 2017

WebGL Insights book goes free for download

A good news. The book WebGLInsights in which I contributed a book chapter is now free to download from the book website. http://www.webglinsights.com

Thanks to the publishers and the contributors.

Sunday, October 30, 2016

Glass effect in Three.js

I have been frequenting Philip Rideout's  blog. Recently, I had to implement the glass effect in three.js. I found out a nifty technique thanks to ofcourse Philip who details a pretty useful technique here. I managed to port it to three.js and then I added in specular highlights. The result ...
Dragon
Stanford bunny
Armadillo

I will detail the internals if there is some interest.

Sunday, January 3, 2016

Preview of my article in Game Engine Gems 3

My article in Game Engine Gems 3 is about implementing deformables using Strain based Dynamics.
Some excerpts from the Introduction

 This chapter provides a simple and straightforward implementation of strain based dynamics for both surface (cloth) and mesh models (tetrahedral mesh). A snapshot from an implementation of the technique described in this chapter is shown in Figure [xx].

Snapshots from the included demo:

Strain based dynamics for simulating tetrahedral meshes

Strain based dynamics for simulating anisotropic cloth
Live manipulation of cloth mesh

The book will be published at GDC2016. Additional information may be obtained from the original book website Game Engine Gems 3. Hope all of you will have a lot of fun reading this chapter. I had a lot of fun writing it. Hope all of you will love this book as it contains a lot of cool chapters. Really looking forward to it.

Thursday, September 3, 2015

My profile included in featured author list of AK Peters CRC Press

Alhamdulillah, I have been selected in the featured author list of A.K. Peters/CRC Press featured author list.

Snapshot from the webpage


Featured authors page url: https://www.crcpress.com/authors/featured
Direct url to my CRC Press author profile page:  https://www.crcpress.com/authors/i12607-muhammad-mobeen-movania

Popular Posts

Copyright (C) 2011 - Movania Muhammad Mobeen. Awesome Inc. theme. Powered by Blogger.