tag:blogger.com,1999:blog-84253137415362328932024-03-19T13:38:46.161+05:45Sushant Kafle's BlogAnonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.comBlogger33125tag:blogger.com,1999:blog-8425313741536232893.post-12133502415686605552015-07-19T21:27:00.000+05:452015-07-20T09:44:14.535+05:45Simulating Physics!<div dir="ltr" style="text-align: left;" trbidi="on">
I tried do this for a while now and I have to admit it was more challenging than I thought. I had to revise some topics on physics just to get a clear handle on theories I was trying to simulate. Overall, it was a fun project and I am glad it came out just well.<br />
<br />
My intentions were to simulate physics based environment where object would be acted upon my real-world-like physical forces. I know there are libraries out there that does this for us and also provide better performance and speed. But, I wanted to try it on my own.<br />
<br />
Here's how I divided my work:<br />
<br />
<b>1. The Core</b><br />
The Core package consisted mostly of physical quantities such as Position, Velocity and Acceleration. They mostly had the simple mathematics in them, that did most of the dirty works.<br />
<br />
<b>2. The Environment</b><br />
The environment provides room for existence to the elements and it was my main engine where the elements were added and were acted up. Environment had its own properties like gravity, air frictions and boundary.<br />
<br />
This piece of code represents general work in this module:<br />
<br />
<pre style="background-color: white; font-family: 'Courier New'; font-size: 12pt;"><span style="color: navy; font-weight: bold;">for </span>element <span style="color: navy; font-weight: bold;">in </span><span style="color: #94558d;">self</span>.elements:
<span style="color: navy; font-weight: bold;">if </span>element != selectedParticle:
element.animate()<span style="color: blue;">
</span><span style="color: blue;"> </span>element.draw(<span style="color: #94558d;">self</span>.screen)
<span style="color: #94558d;">self</span>.handleCollision(element)</pre>
<br />
<b>3. The Element</b><br />
Element was my abstract representation of real-world object which had properties like mass, color, velocity, position and many others. Elements were added to the environment and where subjected to forces in the environment.<br />
<br />
<b>4. Objects</b><br />
I started with a Circle, that represented a ball like object, and worked my way up-to simulating square blocks. Circles, besides representing a real-world ball, acted as pressure-points for other objects. Pressure-points were useful because these were the actual points that worked as points for exchanging forces upon collision which simulated all sorts of interesting properties like translation and rotation easily.<br />
<br />
For example a bar consisted of two pressure points at either end. This would allow us to easily simulate bar-like properties especially rotation experienced due to difference in direction of force at either end of the bar.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPM7VGZAOshpf_owjXXL8UmxC-iHPPo57vPRnsfZIXzl8gDsdmTn2Jd0YFfFBc9oBlQl0cMMTYA-wSDZivJmbdEtS_DVdsfYOhG058sp3sNpDyfhoADeF6a1q0EIsI-z24EbiSsgPxin8/s1600/before.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPM7VGZAOshpf_owjXXL8UmxC-iHPPo57vPRnsfZIXzl8gDsdmTn2Jd0YFfFBc9oBlQl0cMMTYA-wSDZivJmbdEtS_DVdsfYOhG058sp3sNpDyfhoADeF6a1q0EIsI-z24EbiSsgPxin8/s400/before.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="margin-left: 1em; margin-right: 1em; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMIoI9MJSmHc1e4yX12076_SA6EksObJmvRFUNBZFchv219pwOM0aj37yUkGo9DcUlAMgUngvcPFDd2z9kc5QprkPrjzfisNCwiX6pjFVgPCMOMQgmvvcwvdHukNR_QXN8HqteCy9XLYQ/s1600/After.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMIoI9MJSmHc1e4yX12076_SA6EksObJmvRFUNBZFchv219pwOM0aj37yUkGo9DcUlAMgUngvcPFDd2z9kc5QprkPrjzfisNCwiX6pjFVgPCMOMQgmvvcwvdHukNR_QXN8HqteCy9XLYQ/s400/After.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The point of collision besides those pressure points could be interpolated easily. Square had a similar layout. It had these bars as its edges, protecting it from all angles.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>4. Collision Handling</b></div>
<div class="separator" style="clear: both; text-align: left;">
Collision Handling was modeled using the principle of conservation of linear momentum combined with law of conservation of energy. There was a small problem I face while implementing this approach to my models. The problem was the behavior of objects upon interaction while there velocity neared zero. There was only one force acting that time, and it was gravity which was constantly pulling objects downwards. This was a problem, because when the objects were on top of each other, the object would collapse, unrealistically, because they had no force left in them to counteract gravity. There was a simple workaround to the problem, but it was not a wise one. Whenever two object came in contact with one another, a small force(in all four direction) would always be acting to prevent collapsing thus separating objects apart.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
This was the model I went with. I am planning to share the code in near future as well. Here's a small video of the program in action:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/s_vi/wh_jFnfXG30/default.jpg?sqp=CMyCr60F&rs=AOn4CLDt44j9KK4u_t74Xvm928gYhfG7Gw" frameborder="0" height="266" src="https://www.youtube.com/embed/wh_jFnfXG30?feature=player_embedded" width="320"></iframe></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
It's not much, but it was a fun :) Let me know if you have any suggestions or feedback. Thanks!</div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-43009519793619035872015-03-06T16:28:00.000+05:452015-03-06T18:03:12.952+05:45BusyNote! - What is it?<div dir="ltr" style="text-align: left;" trbidi="on">
I recently uploaded a small app called <a href="http://kaflesushant.com.np/BusyNote" target="_blank">BusyNote</a> on PlayStore. So, in this post I am going to talk about what it is, what it does, and also share some useful resources that I used to make the app.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0751xMD6jz5iLhiEYO1rB1V_K90RUvcDms1CbQjKBtf4OQW6blRjTtctnM0XOw2ixht01hWuHe7tWHdU4Yxpb47p6fS4bA33KeEqvZdcwN5kA5lRzDihkdWDOrca-VJynH8V8OopXUOg/s1600/busynote_web.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0751xMD6jz5iLhiEYO1rB1V_K90RUvcDms1CbQjKBtf4OQW6blRjTtctnM0XOw2ixht01hWuHe7tWHdU4Yxpb47p6fS4bA33KeEqvZdcwN5kA5lRzDihkdWDOrca-VJynH8V8OopXUOg/s1600/busynote_web.png" height="320" width="320" /></a></div>
<br />
<br />
BusyNote is basically an app to let people know that you are currently busy and you are not currently available for cellular contact. So, when activated this app just detects missed calls and sends pre-defined notification to callers letting them know you are in a "situation" and can't answer the phone. The need to the app was initially personal. When I was on my bike, I couldn't answer my calls (obviously) and this was a problem when I was travelling during late hours and the caller was generally my parents worried and trying to reach me. So, I thought why not make an app to help my situation. And here-we-are!<br />
<br />
The app is available on PlayStore and you can find it from this link: <a href="https://play.google.com/store/apps/details?id=com.busynote.android" target="_blank">BusyNote</a><br />
<br />
<h3 style="text-align: left;">
Useful resources</h3>
Here are some resources that I used to build this app.<br />
<br />
<br />
<ol style="text-align: left;">
<li><a href="http://ormlite.com/" target="_blank">Ormlite</a><br /><br /><div style="text-align: justify;">
Object Relational Mapping Lite (ORM Lite) provides some lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages. It supports a number of SQL databases using JDBC and also supports Sqlite with native calls to Android OS database APIs. It is very handy and very easy to use.<br /><br /></div>
</li>
<li><a href="https://github.com/markushi/android-circlebutton" target="_blank">Android Circle Button</a><br /><br />Android Circle Button is a widget for android, easily available via gradle. The widget is very stylish and looks good on mobile phones. I used a modified version of the widget to support "Texts" and also added small extra features.<br /><br /></li>
<li><a href="https://github.com/umano/AndroidSlidingUpPanel/tree/master/library" target="_blank">Android Sliding Up Panel</a><br /><br />Android Sliding Up Panel is a widget by Umano Team, and I loved it. It is available on github and you can easily import it to your project via Gradle. It provides simple way to add a draggable sliding up panel to your Android application.</li>
</ol>
<div>
Hope you find these resources useful. Also, don't forget to try the app (follow this <a href="https://play.google.com/store/apps/details?id=com.busynote.android" target="_blank">link</a>) and give it some love ;) </div>
<div>
<br />
Please let me know what you thought of it or if you have any such feedbacks. Thanks!</div>
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-14587396530418312482014-12-13T18:49:00.000+05:452014-12-13T18:49:24.773+05:45My Bash Script Editor - The Rights and Wrongs of how I went at it!<div dir="ltr" style="text-align: left;" trbidi="on">
I have been working on developing a "Bash Script Editor" and I have been at it for weeks dedicating at least an hour a day. While I was working on it, I realized that I was doing it all wrong and now I'm in this dilemma of whether I should keep working on it till I get atleast a beta version or I should just leave it undone and concentrate on more important things.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8YWTloXZ4ipcI5nxyDDeXNlLIFruvyeNkklkSpSXaGozAomuskrp3nN_meFE63lpfYrlU_IIQSMQVLUpfTR3hjzSBRsyPRPnZJKmCTgVi5q0W4xSfK2ftVSEWQqnYKuqTMyoQURqgISg/s1600/bash-editor.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8YWTloXZ4ipcI5nxyDDeXNlLIFruvyeNkklkSpSXaGozAomuskrp3nN_meFE63lpfYrlU_IIQSMQVLUpfTR3hjzSBRsyPRPnZJKmCTgVi5q0W4xSfK2ftVSEWQqnYKuqTMyoQURqgISg/s1600/bash-editor.png" height="207" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Snapshot of my Bash Script Editor</td></tr>
</tbody></table>
<br />
While I was working on ETL scripts at my work, I was using Notepad++ as my editor. It worked absolutely fine except I was totally new with the scripts to know where the functions referred in the scripts were actually called from. Having been working with powerful IDEs in the past, a simple editor to manage such a huge project seemed impossible to me and that was it. Thats what triggered me to build a more powerful editor just for Bash scripts.<br />
<br />
The idea first seemed fine to me expect when I realized how big of a task it was and I was the only one really eager to do it. So, here I am sharing my experience so that I or anybody reading not to do/repeat such things with a list of -the rights and wrongs with my approach.<br />
<br />
<h3 style="text-align: left;">
What did I do right?</h3>
<b>1.</b> The concept seemed valid and I was eager to do it.<br />
<br />
<h3 style="text-align: left;">
What did I do wrong?</h3>
<b>1.</b> I didn't sketch a plan of how I was going to do it. A simple list to features to add, scope of functionalities to look into or may be a rough class diagram to build upon would have eased things up abit. I remember I was hesitant to do it because I thought I should just get right at it and get it done quickly. That simple hesitation went on destroying my whole effort in the end.<br />
<br />
<b>2.</b> I was working on it alone. A small team of 3-4 people collaboratively working on modules would have been brilliant. With a team, the work would have been more organized, faster and optimized.<br />
<br />
<b>3.</b> If I wanted to do it so eagerly, I should have first searched for any relevant open sourced projects that I could contribute with the feature. It is always a good habit to do it, only I didn't do that.<br />
<br />
<b>4.</b> If I didn't want to make it big and just wanted to do it for experience and fun, then I should have done something that I could learn from. Throwing random line of codes and scratching your head to think of a solution just to make up for dirty codes done earlier is a very unhealthy habit and something that every programmer should avoid.<br />
<br />
<b>5.</b> Stop before its too late. If you realize, even in slightest, that you are doing it wrong and you are only making things complicated by just adding random features, you should probably pause and look at what you've done. This would have saved a lot of my precious time.<br />
<br />
<b>6.</b> Always start with a solid base to work upon. Defining abstract classes and building your way up with it is always a good habit. A good base will always keep things organized.<br />
<br />
<br />
So, there you go. Before you go and laugh at me or maybe judge me as a programmer, please note that I was doing it all during my office hours. I didn't have enough breathing space to look at what I was doing, all I wanted to do was to complete the task in hand when I had free time. Despite knowing it all, deep down inside, my major regret is that I started the work anyway completely underestimating the difficulty of the task.<br />
<br />
Here's the link to the project : <a href="https://github.com/SushantKafle/Bash-Editor" target="_blank">Bash-Script Editor</a> (try not to laugh too hard :P)<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com2tag:blogger.com,1999:blog-8425313741536232893.post-49628715843391508162014-11-14T16:35:00.002+05:452014-11-14T18:34:13.564+05:45Perlin Noise [Implementation in Java]<div dir="ltr" style="text-align: left;" trbidi="on">
I had previously talked in detail about Perlin Noise and its properties, <a href="http://blog.kaflesushant.com.np/2013/11/introduction-to-perlin-noise-theory.html" target="_blank">here</a>. Now in this blog post I will write about the implementation. My implementation is based on an excellent writeup which I found in this link (<a href="http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html">http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html</a>).<br />
<br />
<h4 style="text-align: left;">
<b>Short Description</b></h4>
<br />
<div>
<b><br />
</b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivEbNT6jdpkVRzNbrvZq1EDtZLjKuSlD4huziVY27nCMBHI1LGmswLh_zHb1TTp1UPGCCPg1zz4oXPq2iqIaS-A8AHbEuaPraO0hUwjSzIA1n9YXHhsRlIpcP75QctvKpte_PgPYGfP9o/s1600/PerlingNoise2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivEbNT6jdpkVRzNbrvZq1EDtZLjKuSlD4huziVY27nCMBHI1LGmswLh_zHb1TTp1UPGCCPg1zz4oXPq2iqIaS-A8AHbEuaPraO0hUwjSzIA1n9YXHhsRlIpcP75QctvKpte_PgPYGfP9o/s200/PerlingNoise2.png" width="200" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcD5pYupmjgspuccuL9yaxoWbLmrhLbI4gV6Hs_HAbDuVCf-bhxWtVP-SVRrCtuIfLUEElgnT6D2_IjqEefMzf46bIY8SamZnUXB-YqEnk_DOIUTl6Fz2jw9622lClS3518wnEB2Tzmbw/s1600/Noise.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcD5pYupmjgspuccuL9yaxoWbLmrhLbI4gV6Hs_HAbDuVCf-bhxWtVP-SVRrCtuIfLUEElgnT6D2_IjqEefMzf46bIY8SamZnUXB-YqEnk_DOIUTl6Fz2jw9622lClS3518wnEB2Tzmbw/s200/Noise.png" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-small;">Fig: Perlin Noise(left), Noise(right)</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Perlin noise is a function for generating coherent(smooth) noise over a space. I've have come across multiple implementations of Perlin Noise function and most of them are based on smoothing of multiple noise functions to generate a coherent noise. The one I am discussing in this blog post is alittle different and more or less conforms with the original implementation that Ken Perlin came up with.<br />
<br />
<br />
<h4 style="text-align: left;">
Requirement</h4>
Perlin Noise (2D) function is a function that takes two points (<i>x</i> and <i>y</i>) and returns a noise value (say <i>z</i>). <i>x</i>, <i>y</i> and <i>z</i> are all floating point numbers.<br />
<br />
<h4 style="text-align: left;">
The Grid</h4>
The concept of accepting floating point numbers can be explained from the concept of Grid. The space, which the noise function operates on, is assumed to be composed of grids. Grid, in terms of <i>x</i> and <i>y</i>, are the whole numbers. So, any decimal (fractions) are points lying inside a grid cell.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxLR5sjA1Ml3iTn4H4eDo8SNmoRROmnn0lMeLZFj2eLUBfLgj7NomKu2jiUrAWEqSNBdSiFM8gnzKuJJ1n1mT1iLF8mOKBNk6Ifc2As9Oc4q13NbKx3kZTDFIRjFn-1pJhEmO6Cb7vDa0/s1600/image1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxLR5sjA1Ml3iTn4H4eDo8SNmoRROmnn0lMeLZFj2eLUBfLgj7NomKu2jiUrAWEqSNBdSiFM8gnzKuJJ1n1mT1iLF8mOKBNk6Ifc2As9Oc4q13NbKx3kZTDFIRjFn-1pJhEmO6Cb7vDa0/s200/image1.png" width="200" /></a></div>
<br />
<br />
In the figure, <i>(x0,y0), (x1,y1), (x0,y1), (x1,y0) </i>represents grid points and <i>(x,y)</i> lies inside a grid.<br />
<br />
<h4 style="text-align: left;">
Pseudorandom Gradient</h4>
Pseudorandom Gradient function takes the grid coordinates and generates pseudorandom gradient of length 1 as:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>g(xgrid, ygrid) = (gx, gy)<br />
<br />
These gradients can be visualized as:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRxw7yLZEp7e93LhbSwU5nMTraROxp2Ydw6jOS5YmEnDHog-ohfEhAmcwlCh1UyhWdhb_AOHaw6mluWt03UPM87Rs3shapPy13T_eGPQjyYuWloWtXq1FDFJgG635_gYizxrsqOyTdZ-s/s1600/image2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRxw7yLZEp7e93LhbSwU5nMTraROxp2Ydw6jOS5YmEnDHog-ohfEhAmcwlCh1UyhWdhb_AOHaw6mluWt03UPM87Rs3shapPy13T_eGPQjyYuWloWtXq1FDFJgG635_gYizxrsqOyTdZ-s/s200/image2.png" width="200" /></a></div>
<br />
<br />
<h4 style="text-align: left;">
Calculating grid influences</h4>
Next, We need to calculate a vector directing from grip points to the point <i>(x,y)</i>.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>vec00 = (x-x0,y-y0);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>vec01 = (x-x0,y-y1);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>vec10 = (x-x1,y-y0);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>vec11 = (x-x1,y-y1);<br />
<br />
The influence can be calculated by performing dot operation on the gradient and the vector as:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>s = g(x0, y0) · vec00;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>t = g(x1, y0) · vec10;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>u = g(x0, y1) · vec01;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>v = g(x1, y1) · vec11;<br />
<br />
<br />
<h4 style="text-align: left;">
Interpolation</h4>
A smoothing function, characterized by the curver 3p<sup>2</sup> - 2p<sup>3</sup>, is used to get a weight <i>Sx</i> at <i>(x-x0)</i> in the curve as:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>S<sub>x</sub> = smoothParam(x-x0);<br />
<br />
and also at (y-y0) as:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>S<sub>y</sub> = smoothParam(y-y0);<br />
<br />
where smoothParam(p) = 3p<sup>2</sup> - 2p<sup>3</sup> , then parameter representing weighted average of <i>s</i> and <i>t </i>is obtained by constructing a linear function mapping 0 to<i> s </i>and 1 to <i>t</i>, and evaluating it at our <i>x</i> dimension weight S<sub>x</sub>. We call this ax.<br />
<br />
ax = s + S<sub>x</sub>*(t - s);<br />
<br />
We also calculate <i>bx </i>using <i>u </i>and <i>v </i>as:<br />
<br />
bx = u + S<sub>x</sub>*(v - u);<br />
<br />
Then the final result <i>z </i>can be obtained as:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>z = ax + S<sub>y</sub>*(bx - ax);<br />
<br />
<h4 style="text-align: left;">
Implementation</h4>
I have implemented this algorithm in Java, and I have uploaded the project in github. You can view it from the link <a href="https://github.com/SushantKafle/PerlinNoise" target="_blank">here</a>.<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com10tag:blogger.com,1999:blog-8425313741536232893.post-89703123400590693552014-10-27T22:21:00.000+05:452014-10-28T08:39:37.940+05:45Triplet Extraction from Sentence [Implementation]<div dir="ltr" style="text-align: left;" trbidi="on">
Many sentiment analysis tasks require extraction of sentence triplets, ie. Subject - Verb - Object, from a sentence. While there are many approaches to the problem, I recently stumbled upon a fairly easy-to-implement algorithm in a research paper (<a href="http://ailab.ijs.si/dunja/SiKDD2007/Papers/Rusu_Trippels.pdf">http://ailab.ijs.si/dunja/SiKDD2007/Papers/Rusu_Trippels.pdf</a>).<br />
<div>
<br />
<a name='more'></a></div>
<h3 style="text-align: left;">
<span style="font-size: large;">The algorithm</span></h3>
<div>
<pre class="c:collapse" name="code">function TRIPLET-EXTRACTION(sentence) returns a solution, or failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← EXTRACT-SUBJECT(NP_subtree) ∪ EXTRACT-PREDICATE(VP_subtree) ∪ EXTRACT-OBJECT(VP_siblings)
<span class="Apple-tab-span" style="white-space: pre;"> </span>if result ≠ failure then return result
<span class="Apple-tab-span" style="white-space: pre;"> </span>else return failure
function EXTRACT-ATTRIBUTES(word) returns a solution, or failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>// search among the word’s siblings
<span class="Apple-tab-span" style="white-space: pre;"> </span>if adjective(word)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← all RB siblings
<span class="Apple-tab-span" style="white-space: pre;"> </span>else
<span class="Apple-tab-span" style="white-space: pre;"> </span>if noun(word)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← all DT, PRP$, POS, JJ, CD, ADJP, QP, NP siblings
<span class="Apple-tab-span" style="white-space: pre;"> </span>else
<span class="Apple-tab-span" style="white-space: pre;"> </span>if verb(word)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← all ADVP siblings
<span class="Apple-tab-span" style="white-space: pre;"> </span>
<span class="Apple-tab-span" style="white-space: pre;"> </span>// search among the word’s uncles
<span class="Apple-tab-span" style="white-space: pre;"> </span>if noun(word) or adjective(word)
<span class="Apple-tab-span" style="white-space: pre;"> </span>if uncle = PP
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← uncle subtree
<span class="Apple-tab-span" style="white-space: pre;"> </span>else
<span class="Apple-tab-span" style="white-space: pre;"> </span>if verb(word) and (uncle = verb)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← uncle subtree
<span class="Apple-tab-span" style="white-space: pre;"> </span>if result ≠ failure then return result
<span class="Apple-tab-span" style="white-space: pre;"> </span>else return failure
function EXTRACT-SUBJECT(NP_subtree) returns a solution, or failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>subject ← first noun found in NP_subtree
<span class="Apple-tab-span" style="white-space: pre;"> </span>subjectAttributes ← EXTRACT-ATTRIBUTES(subject)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← subject ∪ subjectAttributes
<span class="Apple-tab-span" style="white-space: pre;"> </span>if result ≠ failure then return result
<span class="Apple-tab-span" style="white-space: pre;"> </span>else return failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>
function EXTRACT-PREDICATE(VP_subtree) returns solution, or failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>predicate ← deepest verb found in VP_subtree
<span class="Apple-tab-span" style="white-space: pre;"> </span>predicateAttributes ← EXTRACT-ATTRIBUTES(predicate)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← predicate ∪ predicateAttributes
<span class="Apple-tab-span" style="white-space: pre;"> </span>if result ≠ failure then return result
<span class="Apple-tab-span" style="white-space: pre;"> </span>else return failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>
function EXTRACT-OBJECT(VP_sbtree) returns a solution, or failure
<span class="Apple-tab-span" style="white-space: pre;"> </span>siblings ← find NP, PP and ADJP siblings of VP_subtree
<span class="Apple-tab-span" style="white-space: pre;"> </span>for each value in siblings do
<span class="Apple-tab-span" style="white-space: pre;"> </span>if value = NP or PP
<span class="Apple-tab-span" style="white-space: pre;"> </span>object ← first noun in value
<span class="Apple-tab-span" style="white-space: pre;"> </span>else
<span class="Apple-tab-span" style="white-space: pre;"> </span>object ← first adjective in value
<span class="Apple-tab-span" style="white-space: pre;"> </span>objectAttributes ← EXTRACT-ATTRIBUTES(object)
<span class="Apple-tab-span" style="white-space: pre;"> </span>result ← object ∪ objectAttributes
<span class="Apple-tab-span" style="white-space: pre;"> </span>if result ≠ failure then return result
<span class="Apple-tab-span" style="white-space: pre;"> </span>else return failure</pre>
</div>
<div>
</div>
<br />
<div>
<br /></div>
<h3 style="text-align: left;">
<span style="font-family: inherit;">Implementation</span></h3>
<div>
<span style="font-family: inherit;"><br />
</span></div>
<div>
The above algorithm works on the parsed tree generated by parser such as "Stanford Parser", "OpenNLP Parser". I was using the "Stanford Parser" and the parsed tree generated by the parser was supplied to my Triplet extractor for the result. For my work, I needed the Sentence Triplets along with its sentiment supportive attributes(not all). So, my implementation ignores the extraction of attributes from the "word's uncles", mentioned in the algorithm.</div>
<div>
<br /></div>
<div>
I have implemented the algorithm in java. You can find my work at this link: (<a href="https://github.com/SushantKafle/TripletExtraction">https://github.com/SushantKafle/TripletExtraction</a>).</div>
<div>
<span style="font-size: large;"><br />
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-25621101823861420022014-08-13T19:20:00.000+05:452014-10-28T08:39:30.122+05:45Morphological Analyzer for Nepali Text<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Morphology is the part of linguistics that deals with the study of words, their internal structure and syntactically their meanings. A Morphological Analysis is the process of providing grammatical information of a word by detecting its morphemes. A morphological analysis generally consists of following information:<br />
<div style="text-align: left;">
<blockquote class="tr_bq">
<b>Word segmentation<br />
Part-of-speech tagging<br />
Lemmatization</b></blockquote>
</div>
<div style="text-align: left;">
<br />
These are the very basics of linguistics which lays ground to many other applications. There are various different tools and resources available for morphology analysis of popular languages such as English, but morphological analysis of Nepali texts had been in a shadow for long. Fortunately, the need of these analysis has slowly been recognized.<br />
<a name='more'></a><br />
There has been remarkable developments in Nepali Linguistics in the past 6-7 years, especially from projects at Madan Puraskar Pustakalaya, Nepal.<br />
<br />
Projects such as "Dobhase", an english to nepali translator, Spell Checker for Nepali Language, Text-to-Speech for Nepali, has encouraged the development of works in Nepali linguistics. There also has been researches on projects to build a "Morphology Analyzer" for Nepali text as well. "A Morphological Analyzer and a stemmer for Nepali" is a paper by Prof Bal Krishna Bal and Prajol Shrestha, K.U. /Madan Puraskar Pustakalaya, Nepal, and based on the paper I also tried to develop a simple Morpho-Analyzer of Nepali text.<br />
<br />
The morpho-analyzer I developed is a derivate of the paper. <a href="http://www.panl10n.net/english/outputs/Working%20Papers/Nepal/Microsoft%20Word%20-%206_OK_N_331.pdf" target="_blank">Link here</a> I used a small set of POS-tag to begin with and small list of Prefixes and Suffixes good enough to test the analyzer. As in the paper, I used XML for the output of the result.<br />
<br />
Below are some of the snapshots:<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgStkqOOGZsAJsvZ2izaus-MMUxzta79TSzbKeLpP_Mz_m48dvSDopp_yhdMTK9sHaHCEv-h2f4C7m78S6jenlc7TyQT7f_zECT5_OhKLRxJslinvOxxyXMfFu49qHWVKj3I8SGDWmfgkE/s1600/terminal.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgStkqOOGZsAJsvZ2izaus-MMUxzta79TSzbKeLpP_Mz_m48dvSDopp_yhdMTK9sHaHCEv-h2f4C7m78S6jenlc7TyQT7f_zECT5_OhKLRxJslinvOxxyXMfFu49qHWVKj3I8SGDWmfgkE/s1600/terminal.png" height="71" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Morpho Analyzer</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1FbiSlC5xaTj4sdJC59oSb_6W70tdq-16ktk47sTjIjME1OwIID5iMezkZIwm_YHaqxV92anxLKx7sgedQG35XIBkbgKHP_4vnd-ItKeUTG_Su-az6ARZb6MzDOPRNkk5V_TlLUCJYYo/s1600/sent.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1FbiSlC5xaTj4sdJC59oSb_6W70tdq-16ktk47sTjIjME1OwIID5iMezkZIwm_YHaqxV92anxLKx7sgedQG35XIBkbgKHP_4vnd-ItKeUTG_Su-az6ARZb6MzDOPRNkk5V_TlLUCJYYo/s1600/sent.png" height="155" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">XML output</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
</div>
</div>
<br />
I am hoping to build this up and work on methodologies to improve what I have today.</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com7tag:blogger.com,1999:blog-8425313741536232893.post-69925871444866608152014-05-19T08:56:00.001+05:452014-05-19T18:06:12.599+05:45Rubik's Cube Simulation and Solver.<div dir="ltr" style="text-align: left;" trbidi="on">
On the auspicious occasion of 40th Anniversary of Rubik's Cube I would like to share with you my "Rubik's Cube Simulator and Solver". I made it some years back, so many of you might know of this (from my facebook).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Rubik's_cube.svg/220px-Rubik's_cube.svg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Rubik's_cube.svg/220px-Rubik's_cube.svg.png" /></a></div>
<br />
<a name='more'></a><br />
Despite many requests, I haven't planned to share my source code of this application. Its not because I don't want to share, its because I coded it two years back with <a href="https://www.facebook.com/Swapnil.sneham" target="_blank">Swapnil Sneham</a> and its all spaghetti in there. We had to complete it in limited time, and we had other projects in hand as well. Due to this, the app is still not well finished and might even be buggy.<br />
<br />
For those who haven't seen it, I would like say few things before sharing :D<br />
<br />
<div>
The algorithm is kinda slow, takes a lot of time to solve the cube. I haven't optimized it nor touched the code since. It was all in rush, and all I could do then :)<br />
The algorithm used is the basic rubik's cube solving trick. It's very simple and even simpler to implement. Only thing challenging was the cube distance calculation. Once you figure-out a good way to represent and calculate it, the overall application is piece of cake :D<br />
<br />
So, here is the video:</div>
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/vnps_VzTjPo" width="420"></iframe><br />
<br />
Enjoy!<br />
<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com2tag:blogger.com,1999:blog-8425313741536232893.post-18717685770905123872014-05-03T09:00:00.000+05:452014-05-10T19:35:51.838+05:45Farty Bird :D<div dir="ltr" style="text-align: left;" trbidi="on">
Finally my month-long exam is over and I can finally concerntrate on one or two projects in hand and I will certainly be blogging about it.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL0jbErfghKpj9BqYgPo_c1cjqfzu4-TYrt3lSkDyd2AOm0XSvezhBdRvKs6wQAPVH4G8qe5Y2jCEpus3RrP7Y09UuxN6gnuFNaVtSlo8ciCn7yhnayo7O7kinDX6Y5EKDUknbTV-_N3c/s1600/farty.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL0jbErfghKpj9BqYgPo_c1cjqfzu4-TYrt3lSkDyd2AOm0XSvezhBdRvKs6wQAPVH4G8qe5Y2jCEpus3RrP7Y09UuxN6gnuFNaVtSlo8ciCn7yhnayo7O7kinDX6Y5EKDUknbTV-_N3c/s1600/farty.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px;">The Farty Bird :D</td></tr>
</tbody></table>
<i>So what's with the "Farty Bird" you may ask?</i> Well, my 11-yr old brother wanted me to make him a game, which he wished to call the "Farty Bird" and he also promised to help me during the development process, the offer I couldn't reject. <br />
<a name='more'></a>Especially when you have nothing to do except watch GOT all day. He loves and misses "Flappy Bird" and wanted "Farty" to be just like "Flappy" :D<br />
<div>
<div>
</div>
<br />
My brother helped me with the graphics ( he used paint to draw scence and the bird :P ) and sounds while I worked on the game.I am not that familier with web-development yet, but after a few small "getting-to-know" projects which I've been doing for past 6-7 months or so, the development of FartyBird was fairly easily and we finished it in few hours :D<br />
<div>
<div>
<br />
Here the link to the game: <a href="http://kaflesushant.com.np/FartyBird/" target="_blank"><b>FartyBird</b></a><br />
<br />
Its not much, but it sure made my little brother happy.<br />
<br />
<b>P.S</b>: My best score is 102 :)</div>
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-38877059559603359782014-02-24T17:04:00.001+05:452014-03-22T21:06:01.319+05:45"Sorry, Ubuntu 13.04 has experienced an internal error" Arghh!!<div dir="ltr" style="text-align: left;" trbidi="on">
Are you annoyed with "<i><b>Sorry, Ubuntu 13.04 has experienced an internal error" </b></i>message? I know I am! Tried reporting the program expecting a fix or least know what the error, that it keeps warning us about, is. But it doesn't work.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdzI0-kWYJueH8pu6YOpzdebF9xqFCDSrbDRqD1NG2jggT7k1Bq0ML611S3fnKvglsb77HYZIRJnXNJgIiS4W34-haw0PPdns-UqlHIt2xTWbGAb0Ww97cJKQKTs1L0hA6eDd3_1tbkHw/s1600/apport+message.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdzI0-kWYJueH8pu6YOpzdebF9xqFCDSrbDRqD1NG2jggT7k1Bq0ML611S3fnKvglsb77HYZIRJnXNJgIiS4W34-haw0PPdns-UqlHIt2xTWbGAb0Ww97cJKQKTs1L0hA6eDd3_1tbkHw/s1600/apport+message.png" height="129" width="320" /></a></div>
<br />
<a name='more'></a><br />
<u>Apport</u>, with what I have known, is a debugging tool used to generate crash reports. I don't know why it's enabled by default, but its pop-ups are really getting annoying. Here's how you can disable it. It is not the best solution I would recommend but I am atleast going to do this for now.<br />
<br />
Open up the "default" folder located in /etc and edit the apport file:<br />
<blockquote>
<i><b>sudo gedit /etc/default/apport</b></i></blockquote>
Change the enable to '0' to disable it.<br />
<br />
Now, stop the apport service from running state. To do this just type:<br />
<blockquote class="tr_bq">
<i><b>sudo service apport stop</b></i></blockquote>
This will stop apport from runnig completely.<br />
<br />
To run it back again you can start the service by:<br />
<blockquote class="tr_bq">
<b><i>sudo service apport start</i></b></blockquote>
To start it permanently, just edit the file /etc/default/apport and enable it.</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com3tag:blogger.com,1999:blog-8425313741536232893.post-9627627264330457822014-02-17T18:22:00.002+05:452014-05-10T19:35:53.446+05:45DBSCAN Algorithm (Implementation in Python)<div dir="ltr" style="text-align: left;" trbidi="on">
DBSCAN Algorithm is a density-based data Clustering algorithm. It's a very handy algorithm and a popular one too. I have tried to implement it in python, as my college assignment.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPt61ctl1crGMvko-LqZ4XaOfDI-Pg3zdzyo1G6jCmDT8aqbTDqa2wldaBi8cKY2bJZtuN-7mm5GhjIeTq2fRsgiQcbuXDo7_jjqoe5KHfaSOryXYMyj6MyUoHPb0TN_EfwG0nFB5jw9k/s1600/figure_1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPt61ctl1crGMvko-LqZ4XaOfDI-Pg3zdzyo1G6jCmDT8aqbTDqa2wldaBi8cKY2bJZtuN-7mm5GhjIeTq2fRsgiQcbuXDo7_jjqoe5KHfaSOryXYMyj6MyUoHPb0TN_EfwG0nFB5jw9k/s1600/figure_1.png" height="241" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig: Output of DBSCAN</td></tr>
</tbody></table>
<br />
<br />
<a name='more'></a><br />
More about the DBSCAN Clustering Algorithm here: <a href="http://en.wikipedia.org/wiki/DBSCAN" target="_blank">Wikipedia</a><br />
<br />
<h3 style="text-align: left;">
<b>Description:</b></h3>
<div style="text-align: left;">
My implementation is a very simple one. It takes two dimensional data represented in a (.csv) file, clusters it and displays it as a plot. It is not an optimized version as well and it's as elaborative as possible.</div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
<b>Inputs:</b></h3>
1. Two dimensional dataset represented in CSV format.<br />
2. A config file with 'eps' and 'MinPts' values.<br />
<br />
<h3 style="text-align: left;">
<b>Source Code:</b></h3>
I have uploaded the project source code in Github. Here is the link: <a href="https://github.com/SushantKafle/DBSCAN" target="_blank">Source Code</a>.</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com43tag:blogger.com,1999:blog-8425313741536232893.post-67028459197988912592014-01-31T00:00:00.001+05:452014-05-10T19:35:54.914+05:45Decision Tree Generator (Implementation in Javascript)<div dir="ltr" style="text-align: left;" trbidi="on">
Recently I tried making a simple Decision Tree Generator not because it wasn't there before but as a fun project to engage myself and learn abit of Javascript and also to know HTML5 Canvas a little more :)<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiksGlnOKXRMqPBLvHL3rTQsMjm538zsK1rd-rjgFbGmu_0m7omYp5TaPRq0Tk8_lsVWaN3pZMJ6DtF8HX9VAG9Pmvy3eodaOxr4lMkVlRF6DMGYS1GRsaLB1kdoqT96KqmTYRH_3G3fW4/s1600/dt.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiksGlnOKXRMqPBLvHL3rTQsMjm538zsK1rd-rjgFbGmu_0m7omYp5TaPRq0Tk8_lsVWaN3pZMJ6DtF8HX9VAG9Pmvy3eodaOxr4lMkVlRF6DMGYS1GRsaLB1kdoqT96KqmTYRH_3G3fW4/s1600/dt.png" height="320" width="309" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">fig: Output of Decision Tree Generator</td></tr>
</tbody></table>
<br />
<br />
<a name='more'></a><br />
<br />
<b><span style="font-size: large;">What's so good about it?</span></b><br />
<br />
Well there's not much to say, but hear it out anyway :D<br />
<br />
<b>1. Automatic Generator:</b><br />
It gathers data, and automatically generates tree based on the data. Though I haven't tested it thoroughly, it worked for two of my example sets (that's good enough right ;) ? )<br />
<br />
<b>2. Interactive:</b><br />
I have tried my best to make it as interactive as possible. I have added a bit of Jquery to make it more interesting :D<br />
<br />
<b>3. ID3 Algorithm Implementation:</b><br />
It implements ID3 Algorithm for Decision Tree generation. More on the algorithm? Follow the link : <a href="http://en.wikipedia.org/wiki/ID3_algorithm" target="_blank">Wikipedia</a><br />
<br />
<b>4. Source Code:</b><br />
I have uploaded the project in github, so feel free to browse and help me with updates and suggestion. Here is the link: <a href="https://github.com/SushantKafle/DecisionTree" target="_blank">Project Source</a><br />
<br />
<br />
<b><span style="font-size: large;">How does it work?</span></b><br />
<br />
Well, it takes your data as input. The data must be discrete and must contain a class ( outcome ). The algorithm begins with data set 'S' as the root node. On each iteration of the algorithm, it loops through every unused attribute of 'S' and calculates the entropy H(S) (or information gain IG(A)) for that attribute.<br />
<br />
Then selects the attribute which has the smallest entropy (or largest information gain) value. The set 'S' is then split by the selected attribute to produce subsets of the data. The algorithm continues to recurse on each subset, considering only attributes never selected before.<br />
<br />
<br />
<b><span style="font-size: large;">Wanna see it live?</span></b><br />
<br />
Decision Tree Generator is live, here is the link: <a href="http://kaflesushant.com.np/DecisionTree/" target="_blank">DecisionTree Generator</a></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com3tag:blogger.com,1999:blog-8425313741536232893.post-47787695384207103962014-01-11T23:16:00.002+05:452014-05-10T19:35:56.656+05:45What is Marching Square? (with Implementation)<div dir="ltr" style="text-align: left;" trbidi="on">
I haven't been blogging for a while but I had been planning to share a blog post on Marching Cube Algorithm for long. For those who don't know about Marching Cube algorithm, you can check out this <a href="http://en.wikipedia.org/wiki/Marching_squares" target="_blank">Wikipedia-link</a>.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UB8np2zICFcryaZ6ZnmpeZCILi9kg0qwHQiVrj8EomIgOjvGXcsljVFD8erOeVBJTUlqp9fXqEY8Y_5DJiUEZSbInOGXBbYhebIKSDX0l6m9oxbtIswH9ECT1JaWUixvkmShTsil-7k/s1600/final1.png" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UB8np2zICFcryaZ6ZnmpeZCILi9kg0qwHQiVrj8EomIgOjvGXcsljVFD8erOeVBJTUlqp9fXqEY8Y_5DJiUEZSbInOGXBbYhebIKSDX0l6m9oxbtIswH9ECT1JaWUixvkmShTsil-7k/s1600/final1.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Circle using Marching Square </td></tr>
</tbody></table>
<a name='more'></a>Marching Cube is simply a algorithm for surface reconstruction from a three dimensional scalar field. Pretty neat right? :D<br />
<br />
Well, this post is not exactly about Marching Cubes, its about Marching Square, which will be a-lot helpful to grasp the overall concept of Marching Cube Algorithm.<br />
Marching Cubes, as the name suggests, constructs 3D surface where as Marching Square works in 2D.<br />
<br />
I have created a series of steps as algorithms to compute marching square:<br />
<br />
<b>1. Define a 2D scalar function.</b><br />
<br />
This function can be a circle define by its equation:<br />
<blockquote class="tr_bq">
<i>x^2 + y^2 - r^2 = 0</i></blockquote>
<br />
<b>2. Define a grid size.</b><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcnEgEUWIcOZ_DMk_3Tf8YSiBjYbjxb4xZflX_gJ1BATfDGj_ASzcKARBaASrOrtLjryhfFR3fyPgfKxJZrmfZXg01Xt3h0NhIQisSv0JBb3VVgjVT44TB9HdcpQ4Xmle-367f3ruwr0Y/s1600/grid.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcnEgEUWIcOZ_DMk_3Tf8YSiBjYbjxb4xZflX_gJ1BATfDGj_ASzcKARBaASrOrtLjryhfFR3fyPgfKxJZrmfZXg01Xt3h0NhIQisSv0JBb3VVgjVT44TB9HdcpQ4Xmle-367f3ruwr0Y/s1600/grid.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Window with grids</td></tr>
</tbody></table>
Grid size is the size of grid with which our window is segmented.<br />
<br />
<b>3. Compute scalar values at each vertex of each grid-cell.</b><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXkfc0GHs3cC5dqYcmveVuhILL_fz_6TTaCeyTnupkuSnsF7O2kgEBpVh62hIxg1GDkJpUiiaECIO40GOzvtHW2Mr3U2RagAYlNJqrEj_DZlnDsZNUKSr5VBoLsoripkFo33qMhWfqgWc/s1600/sv.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXkfc0GHs3cC5dqYcmveVuhILL_fz_6TTaCeyTnupkuSnsF7O2kgEBpVh62hIxg1GDkJpUiiaECIO40GOzvtHW2Mr3U2RagAYlNJqrEj_DZlnDsZNUKSr5VBoLsoripkFo33qMhWfqgWc/s1600/sv.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Find Scalar Value at each vertex (denoted by red dots)</td></tr>
</tbody></table>
<br />
<b>4. At each gridcell, check if isoline exists.</b><br />
<blockquote class="tr_bq">
Scalar value > 0 means its outside the region ( circle )<br />
Scalar value < 0 means its inside the region ( circle )<br />
Scalar value = 0 means its at the region (circle)</blockquote>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHqO5YIjIjMiLAdeiA9RoDtsYggUZ-ixICq9WwngFdD1eD8jMHMaqNeB_2dFSRNLRDUlK9vIvIFU5lOUd3HIRFlvvYgIE6xR5GFQXEGJCHhgjQMycGEiealRf32PqSKDrcPBVchNEIFjA/s1600/in.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHqO5YIjIjMiLAdeiA9RoDtsYggUZ-ixICq9WwngFdD1eD8jMHMaqNeB_2dFSRNLRDUlK9vIvIFU5lOUd3HIRFlvvYgIE6xR5GFQXEGJCHhgjQMycGEiealRf32PqSKDrcPBVchNEIFjA/s1600/in.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Green dots are the intersecting points.<br />
Red line is the isoline. </td></tr>
</tbody></table>
So, to check if isoline exists, we need to see if there's an edge with one scalar value positive and other negative. If there is any, then it means the region defined by scalar field intersects the grid cell and the line connecting those two intersecting point define a isoline.<br />
<br />
<b>5. If there's an intersection, use interpolation technique to find the exact intersection point.</b><br />
<br />
After we find the edge that is intersect, we need to find the exact point of intersection. For this purpose we use interpolation.<b> </b>We can use the formula below:<br />
<blockquote class="tr_bq">
<i>P = P1 + (isovalue - V1)(P2-P1)/(V2-V1)</i></blockquote>
<i><b> </b>where P1 and P2 are the two points of intersected Edges. V1 and V2 are the scalar values at that point.</i><br />
<br />
<b>6. Save the intersection points ( two intersection point forms a isoline ) and draw them.</b><br />
<b></b><br />
After collecting all the isoline, we can just draw them to get the region defined by scalar field. Here is the final image:<br />
<br />
<table border="0"><tbody style="text-align: center;">
<tr><td style="text-align: center;"><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UB8np2zICFcryaZ6ZnmpeZCILi9kg0qwHQiVrj8EomIgOjvGXcsljVFD8erOeVBJTUlqp9fXqEY8Y_5DJiUEZSbInOGXBbYhebIKSDX0l6m9oxbtIswH9ECT1JaWUixvkmShTsil-7k/s1600/final1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UB8np2zICFcryaZ6ZnmpeZCILi9kg0qwHQiVrj8EomIgOjvGXcsljVFD8erOeVBJTUlqp9fXqEY8Y_5DJiUEZSbInOGXBbYhebIKSDX0l6m9oxbtIswH9ECT1JaWUixvkmShTsil-7k/s1600/final1.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">With grid lines</td></tr>
</tbody></table>
</td><td style="text-align: center;"><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSYFjRuauE2lL2v_3P6cQuxuCF3kEUM5Zfw4KhrOjXXSCrln_f646FYDqEUZQozr15e21pcB3E0BZqIwquTHYrRr761gkWqzOMSP__m3QR5bzDT4ci_0BikxluUZInY9PeCA-V0uAo6eY/s1600/final2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSYFjRuauE2lL2v_3P6cQuxuCF3kEUM5Zfw4KhrOjXXSCrln_f646FYDqEUZQozr15e21pcB3E0BZqIwquTHYrRr761gkWqzOMSP__m3QR5bzDT4ci_0BikxluUZInY9PeCA-V0uAo6eY/s1600/final2.png" height="200" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Without grid lines</td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
</td> </tr>
</tbody></table>
<br />
Now that you know how it works, you can easily implement it. The concept of Marching Square is pretty straight forward and this will be helpful to grasp the concept of Marching Cubes as well.<br />
<br />
If you have any problems implementing it, you can refer the project here: <a href="https://github.com/SushantKafle/MarchingSquares" target="_blank">Marching Square Implementation</a></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-15304267545319328572013-12-28T14:25:00.004+05:452013-12-28T14:27:17.171+05:45Installing Chrome on CentOS 6.X<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I tried installing the Chrome browser in CentOS by simplying downloading the provided rpm by Google.Unfortunaltely I came to know that Google no longer supports the most popular commercial Linux (Red Hat Enterprise Linux) and its free equivalents CentOs and Scientific Linux.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvwN4DlPyA1syfl_kAIoTMCwTBuhfDobD8MfL8NmwzRgBpImf9ZB4sTPy8DWDev_RT_81aWCDDSsgK6p_IoCCAngYu19Rmsm0z-AVpLC0mzao8TLhIrxFpKdDfCKk_XcAcZdE44t1W3dg/s1600/chrome-os-2odl-800.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvwN4DlPyA1syfl_kAIoTMCwTBuhfDobD8MfL8NmwzRgBpImf9ZB4sTPy8DWDev_RT_81aWCDDSsgK6p_IoCCAngYu19Rmsm0z-AVpLC0mzao8TLhIrxFpKdDfCKk_XcAcZdE44t1W3dg/s200/chrome-os-2odl-800.jpg" width="200" /></a></div>
<br />
<a name='more'></a><br />
<br />
Fortunately for us <a href="http://chrome.richardlloyd.org.uk/" target="_blank">Richard Lloyd</a> says, Chrome Browser can be sucessfully installed on CentOS 6.4 and latter by grabbing the libraries from a more recent Linux Distro and by putting them in /opt/google/chrome/lib. These libraries are what Google Chrome look for and now that they are there, Chrome can run of CentOS 6.4+<br />
<br />
Here is the script he wrote to do so: <a href="http://chrome.richardlloyd.org.uk/install_chrome.sh">install_chrome.sh</a><br />
<br />
Here is the code you can run to install Google Chrome in your CentOS machine:<br />
<code><br />
# wget http://chrome.richardlloyd.org.uk/install_chrome.sh<br />
# chmod u+x install_chrome.sh<br />
# ./install_chrome.sh</code></div>
<br />
Enjoy!!</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-72745855939191083542013-12-20T17:15:00.001+05:452013-12-20T17:15:28.477+05:45Get Battery Status from Terminal<div dir="ltr" style="text-align: left;" trbidi="on">
I wanted to trigger an application based on the current status of the battery, so I wanted to get the information about the current battery charge status.<br />
Its fairly simple in Linux. 'acpi' is very handy for the purpose. If you haven't installed it yet (you can check it using the code below):<br />
<br />
<blockquote class="tr_bq">
rpm -qa acpi</blockquote>
You can install it easily using apt-get in Ubuntu or if your machine is rpm based like mine, you can look for it in web.<br />
<a name='more'></a> <br /><br />
For CentOS 6 users, the download link is <a href="ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/cathay4t:/misc-rhel6/CentOS_CentOS-6/i686/acpi-1.6-4.1.i686.rpm" target="_blank">here</a>.<br />
<br />
Here are some cool things you can do with acpi:<br />
<br />
<b>1. Check battey status</b><br />
<br />
<blockquote class="tr_bq">
acpi</blockquote>
<br />
<b>2. Check Battery Temperature</b><br />
<br />
<blockquote class="tr_bq">
acpi -t</blockquote>
<br />
<b>3. Check Battey Temperature ( in Fahrenheit )</b><br />
<br />
<blockquote class="tr_bq">
acpi -t -f</blockquote>
<br />
<b>4. Check power status</b><br />
<br />
<blockquote class="tr_bq">
acpi -a</blockquote>
<br />
<b>5. Show every device</b><br />
<br />
<blockquote class="tr_bq">
acpi -V </blockquote>
<br />
Now that you have the information, you can play with it as you want. Here a simple bash script to get the battery information only:<br />
<br />
<blockquote class="tr_bq">
#!/bin/bash<br />data=$(acpi)<br />battery=(${data//,/ })<br />echo ${battery[3]}</blockquote>
<br />
Enjoy :)</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-47933957683594201502013-12-10T20:25:00.000+05:452014-05-10T19:35:58.145+05:45Completed my Particle Viewer App<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
Finally, my "Particle Viewer" Application is complete. I have been working on it for long and it really feels good to see it running. For those who don't know, its a 3D particle analysing tool that is used to study particle behaviour inside a container. The containers are the STL files which are also rendered using the application.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkUpzgubpOy187N9_Jjkp7MnQJJYZSQmEnZtir73lkU6E_tmKjHSGkh3dCKk-XKg0mJDOLSqUXWgah5bw6I0haz9sA1Glp5UlFE9V1hXYETKDTnphelq-SVvIooNESYPpUl0d99JpdMkI/s1600/12.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkUpzgubpOy187N9_Jjkp7MnQJJYZSQmEnZtir73lkU6E_tmKjHSGkh3dCKk-XKg0mJDOLSqUXWgah5bw6I0haz9sA1Glp5UlFE9V1hXYETKDTnphelq-SVvIooNESYPpUl0d99JpdMkI/s400/12.png" height="235" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Particle Viewer</td></tr>
</tbody></table>
<a name='more'></a><br />
Now, that this project is complete I will have more time to concertrate on other things and hopefully I will start blogging often as well :)<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-20515656715116202013-11-30T14:49:00.000+05:452013-11-30T14:50:35.178+05:45"Shaking Divs" using CSS<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
</div>
I was quite familiar with the implementation of periodic shake motion of div's using Javascript. But, now that CSS3 is here, implementing shakes of div's has been fairly easier. I didn't knew this was so easy and so efficient using just CSS.<br />
<br />
Here's the link to the implementation of the shake:<br />
<a name='more'></a><br />
<a href="http://www.kaflesushant.com.np/" target="_blank"><span class="shakeHover">Demo Link</span></a><br />
<br />
Its a link of my Github page. The "shaking links" are all dead though, so don't bother clicking them :P<br />
To know how its done, you can go through the source code of the page: <a href="https://github.com/SushantKafle/sushantkafle.github.io" target="_blank">Page Source Code</a><br />
<br />
Enjoy!<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-21570077804993922582013-11-23T15:04:00.001+05:452014-05-10T19:35:59.857+05:45Reflection, Refraction using CubeMapping.<div dir="ltr" style="text-align: left;" trbidi="on">
Reflection, Refraction is fairly easy in OpenGL using both Shader and normal OpenGL pipeline. Today I tried both the classical method of Reflection Mapping and also using shaders.<br />
<div>
The main objective of today's work was to render shiny Metals and Glass. The shiny metal needed a simple reflection mapping. The result is shown in the figure below:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOJ-5WCYBdeQzY14BTFOqKIaVg8Y0NgzgH28jkFsaM72AtLnSpBWMg8xNlB3Jjy3RomwdzXJhMFyiZ60TiG8_c9lcZC2aMuj7teRzLMvhxGW7n6rttozn1tc1wpeFTY_F-TcQS2Dnn3yI/s1600/shinymetal1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOJ-5WCYBdeQzY14BTFOqKIaVg8Y0NgzgH28jkFsaM72AtLnSpBWMg8xNlB3Jjy3RomwdzXJhMFyiZ60TiG8_c9lcZC2aMuj7teRzLMvhxGW7n6rttozn1tc1wpeFTY_F-TcQS2Dnn3yI/s320/shinymetal1.png" height="176" width="320" /></a></div>
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdoZGnres8mhTRo49ssrISnhbpOR4jhiCneix7z-AbU6EGGxATNTyTpRjP9pgeKf_OIJDeoPwVacSKoFbG9-j4My9jRfcdU0eYAHtrDpXJFP35hJlLKvwOjPiWxSiqMJ6w3q4L0s0yM_U/s1600/shinymetal2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdoZGnres8mhTRo49ssrISnhbpOR4jhiCneix7z-AbU6EGGxATNTyTpRjP9pgeKf_OIJDeoPwVacSKoFbG9-j4My9jRfcdU0eYAHtrDpXJFP35hJlLKvwOjPiWxSiqMJ6w3q4L0s0yM_U/s320/shinymetal2.png" height="187" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Then I tried simple refraction mapping as well. To render glass, I needed both reflection as well as refraction. So, I mixed both reflection and refraction for my object.</div>
<div class="separator" style="clear: both; text-align: left;">
Here is the ouput:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKWSC-Zw-S9mtyYhC-9V6PqREiokh0IR2QRMIgJ-idDVzRJaNjmG3VTpjIZ1Da2Zlq2EJUMazLjApDeVsEts4fkP2vAWkt_ozG9OeKrQWD1MVpWejYP2bubmt3z8TvQInUN0uoQslkJKg/s1600/glass1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKWSC-Zw-S9mtyYhC-9V6PqREiokh0IR2QRMIgJ-idDVzRJaNjmG3VTpjIZ1Da2Zlq2EJUMazLjApDeVsEts4fkP2vAWkt_ozG9OeKrQWD1MVpWejYP2bubmt3z8TvQInUN0uoQslkJKg/s320/glass1.png" height="190" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxWyN6pu8L2Rhf8qMluOBWfHlDkDXxGe0KDhlDCn_fvwwadmoETOJ2PvGybmW75JGGPnSj25yYSsBnV7CQv7D2P4C0zSxArRbSv-ylPEWsPapYUumctzyfMcYbhjCHudrBqtbfZE6VV08/s1600/glass2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxWyN6pu8L2Rhf8qMluOBWfHlDkDXxGe0KDhlDCn_fvwwadmoETOJ2PvGybmW75JGGPnSj25yYSsBnV7CQv7D2P4C0zSxArRbSv-ylPEWsPapYUumctzyfMcYbhjCHudrBqtbfZE6VV08/s320/glass2.png" height="204" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div>
Note: I have used static Mapping techine.</div>
<div>
<br />
For additional refrences you can follow this site: <a href="http://antongerdelan.net/opengl/cubemaps.html" target="_blank">Cube Maps: Sky Boxes and Environment Mapping</a><br />
<br /></div>
<div>
The source code for the shaders used in above program are uploaded on my github: <a href="https://github.com/SushantKafle/GLSL-Sandbox" target="_blank">GLSL Source Code</a></div>
<div>
Hope it helps :)</div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-46353353842711939732013-11-22T22:38:00.000+05:452014-05-10T19:41:42.965+05:45Setting up Github Home Page.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: left;">
Today I did a very basic CSS to design my Github Homepage. I am not much of a designer and have only basic CSS skills, so I was preety excited to work on it. Though, there's not much to see, the page is still under construction, I am happy with what I have for now :D </div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR83GZWTIJztGDjBHbRpPhNXUWVWYGFQqNbc-o-hTisHpCFwjgLV3ZyRz_iyqQrLaHsuAmFYSQZA8dpkedA3jCDxUOVbIWzwkX-L1iBXL1vTdIgZLsAYg5gtxt__5qKB2rzDVV9lZeolM/s1600/githubpage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR83GZWTIJztGDjBHbRpPhNXUWVWYGFQqNbc-o-hTisHpCFwjgLV3ZyRz_iyqQrLaHsuAmFYSQZA8dpkedA3jCDxUOVbIWzwkX-L1iBXL1vTdIgZLsAYg5gtxt__5qKB2rzDVV9lZeolM/s320/githubpage.png" height="160" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<a name='more'></a><br />
<div style="text-align: left;">
I have some designs on paper for the page but I think it will take a while for me to really work on it and finish it. So for now, have a early look at the page :)<br />
<br />
Git Hub Page : s<a href="http://sushantkafle.github.io/" target="_blank">ushantkafle.github.io</a></div>
<div style="text-align: left;">
Source Code : <a href="https://github.com/SushantKafle/sushantkafle.github.io/" target="_blank">Github</a><br />
<br />
Do suggest me some tips to make it better :D and thanks for reading !!</div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-66574128004684880162013-11-20T20:52:00.001+05:452014-05-10T19:43:11.762+05:45Displaying Excel in Webpage. [Excel2HTML]<div dir="ltr" style="text-align: left;" trbidi="on">
Working on my report generation project, today I tried to display Excel data in JSF powered pages using Java. First I looked for existing libraries/extension for Java that would help me display Excel data in HTML. I found a pretty good library too, called the ZKSpreadSheet. Here's the link : <a href="https://code.google.com/p/zkspreadsheet/" target="_blank">zkspreadsheet</a>. It's very powerful, but not exactly what I had in mind.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT9nH59apTKF585kBgXnaXFUx2FN0lqbkC_Hgcgba70j6t9MVRLkaz3_n6yqimDk0QUWsS0l28s9LHG5uEawmQT20YPIiZ7mr2ZTgTkQLneaH1XZ5AY9VvGKtka7ckMTf-DRNI_o5lLc0/s1600/fig.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT9nH59apTKF585kBgXnaXFUx2FN0lqbkC_Hgcgba70j6t9MVRLkaz3_n6yqimDk0QUWsS0l28s9LHG5uEawmQT20YPIiZ7mr2ZTgTkQLneaH1XZ5AY9VvGKtka7ckMTf-DRNI_o5lLc0/s320/fig.png" height="143" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Snapshot of Excel Display in HTML</td></tr>
</tbody></table>
<br />
<a name='more'></a><br />
<br />
Looking deeper into the Web, I found a POI example project : <a href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/" target="_blank">POI Example</a> which works pretty good as well, and converts both<i> .xls</i> and <i>.xlsx</i> to <i>.html</i>. Only problem that bothered me was that I couldn't display all Sheets of my Excel File. It only looks into a single Sheet at position '<i>0</i>' from by Workbook. So, I took a little time to upgrade it and changed some layout for the Sheets as well :)<br />
<br />
Some of the notable features I updated:<br />
1. Now displays all the Sheets from the Workbook.<br />
2. Better Display of Sheets in tabs using jQuery UI<br />
<br />
Here the link of the updated Project: <a href="https://github.com/SushantKafle/Excel2HTML" target="_blank">Excel2HTML</a><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-41028859196736107162013-11-18T17:32:00.002+05:452014-05-10T19:36:01.454+05:45Metal Effect using GLSL in OpenGL.<div dir="ltr" style="text-align: left;" trbidi="on">
Today I tried to produce a like-metal effect to objects in OpenGL using GLSL. I implemented Phong's Per pixel shading in GLSL on top of a Brushed Metal Texture. I set the metal's material property using references from the internet.<br />
<br />
I haven't added reflection (cube mapping) here, as it looks fine and also because its just a simple STL viewing interface.<br />
<br />
Here are some of the snapshots:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKvpR265tKvUs5Ab0jExXfaSpEofF_zR_d4cl-931IQufQb5pIshveP3F1rgKLPWJ9Y6WWJoj4ZCpbm22BisQuNlYcu0VJYp-kfbZGUQ9XZYg-IDJOoPm6Ax04zjnpIlE35D-ETu4Ay1M/s1600/metal-ring.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKvpR265tKvUs5Ab0jExXfaSpEofF_zR_d4cl-931IQufQb5pIshveP3F1rgKLPWJ9Y6WWJoj4ZCpbm22BisQuNlYcu0VJYp-kfbZGUQ9XZYg-IDJOoPm6Ax04zjnpIlE35D-ETu4Ay1M/s320/metal-ring.png" height="206" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju3prfwlnqUNLrSq7iDmU5OamM3kMrXcsC2kRmm7KhXqCuthibwRn9WbHurbLZ2-TipXpyt8fjkeTky9fvsl-N5tu3Us_e5lWN7ecOe7yWuJnzQFTHdf8ktqmEed-UInmDHF8UlbxANiI/s1600/metal-shader.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju3prfwlnqUNLrSq7iDmU5OamM3kMrXcsC2kRmm7KhXqCuthibwRn9WbHurbLZ2-TipXpyt8fjkeTky9fvsl-N5tu3Us_e5lWN7ecOe7yWuJnzQFTHdf8ktqmEed-UInmDHF8UlbxANiI/s320/metal-shader.png" height="233" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPcAus4wj7ZFcbeAJ3UD-bMAy7aAQSkI0mK89x2pGJ6Ija4KHOlZNgo6WTgbVEnpxtvlvRBLu26r_5lQCqvuxUrDhpOZq8O9NzZd6m6orqwsW-RJatnKAhYghYE8j2bhnLslKWij37tjM/s1600/metal-ring2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPcAus4wj7ZFcbeAJ3UD-bMAy7aAQSkI0mK89x2pGJ6Ija4KHOlZNgo6WTgbVEnpxtvlvRBLu26r_5lQCqvuxUrDhpOZq8O9NzZd6m6orqwsW-RJatnKAhYghYE8j2bhnLslKWij37tjM/s320/metal-ring2.png" height="236" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
Here is the link to the materal property references: <a href="http://devernay.free.fr/cours/opengl/materials.html" target="_blank">Material Properties</a><br />
Here's the theory on Phong's Per Pixel Shading: <a href="http://en.wikipedia.org/wiki/Phong_shading" target="_blank">Phong's Shading</a><br />
<br />
*Source codes are available upon request :)<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-71957657717576280972013-11-16T17:40:00.000+05:452013-11-16T22:20:49.190+05:45Introduction to Perlin Noise [ Theory ]<div dir="ltr" style="text-align: left;" trbidi="on">
In this blog post I will try my best to describe you what Perlin Noise is and why is it so popular. I will walk you through the very basics of Perlin Noise and help you grasp some basic concepts on it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8KUGKAH9L3f_9tj_p73EMpz9v5MV3nuq0c-bUpf5mhDq9BSS6zJJBl1Xoi0yHiSUUK4QuEL7BhZfq9DGoVwnwJLngzGz7jg6DkClwaLVJqQtrh_nwG64BSNDa_ii9uj8_2mpFP736j2Y/s1600/Perlin_noise.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8KUGKAH9L3f_9tj_p73EMpz9v5MV3nuq0c-bUpf5mhDq9BSS6zJJBl1Xoi0yHiSUUK4QuEL7BhZfq9DGoVwnwJLngzGz7jg6DkClwaLVJqQtrh_nwG64BSNDa_ii9uj8_2mpFP736j2Y/s200/Perlin_noise.jpg" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<i>fig: Two-dimensional slice through 3D Perlin noise</i></div>
<div class="separator" style="clear: both; text-align: center;">
<i>Source: Wikipedia</i></div>
<div class="separator" style="clear: both; text-align: center;">
<i></i></div>
<a name='more'></a><i><br /></i>
<div>
<h3 style="text-align: left;">
Why use Random Number?</h3>
</div>
<div>
<br /></div>
<div>
Random Numbers are used to introduce unpredictability. Unpredictability is generally used to define nature. Most of our daily tasks has random patterns. Even the tasks we do, the things we see and sounds we hear. It has been quite difficult to handle this randomness of nature and this difficulty was quite prominent in Computer Graphics. Generating nature like texture for items such as woods, clouds, metals, stones etc was difficult. Using a texture image would cost memory as it would require us to use many such texture for a single item. So, use of random number to generate texture could be solution.</div>
<div>
<br />
<br /></div>
<h3 style="text-align: left;">
Is it enough?</h3>
<table><tbody>
<tr><td><br />
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Ll5zygPk3d16xnn4WjuO84M1L3vARWnADEEOCboEBMrSexJA_yDNkuJcGPHM_K9v7Yvqywvu0avkKjoBnkYDJ0unoDAkIShrGMsWmiLEEuMIsUWP3AmCzQ1MpwWtozsy4ZXNWbGf0sA/s1600/perlin_noise.png" /></td> <td><br />
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikQqGANonWwT6KzMXldg0-VlCYDJUvBGiTn356-aq5HZ8qMwEA2Uzamy27GkvxS4pJIiVye3vhTLgtwNPRqoQfYujEV8yUQAsj4nDC8dqua4N-IZYi1p0rsugY7dv10de8WeCmsXnEMiQ/s1600/perlin_noise_64.png" /></td> </tr>
</tbody></table>
<i>Right:Generated By Random No. Generator</i><br />
<i>Left: Perlin Noise</i><br />
<div>
<br /></div>
<div>
<table></table>
So, Random numbers could certainly be used to introduce Unpredictability, but often their uncontrollable output can look unnatural. As Ken Perlin said in one of his presentations, </div>
<blockquote class="tr_bq">
<i>"Noise appears random, but isn't really. If it were really random, then you'd get a different result every time you call it. Instead, it's <b>"pseudo-random"</b> - it gives the appearance of randomness."</i></blockquote>
He clearly states that a Random Number Generator won't be enough to define noise. He says noise is not random but he defines it as a "pseudo-random" pattern. He also says,<br />
<blockquote class="tr_bq">
<i>"Noise is band-limited - almost all of its energy (when looked at as a signal) is concentrated in a small part of the frequency spectrum."</i></blockquote>
So, it pretty much explains why a simple Random Number Generator, that we are familiar with, wont be enough to define Noise.<br />
<br />
<br />
<h3 style="text-align: left;">
The "Noise Function"</h3>
<div>
<br /></div>
<div>
A noise function is a special random number generating function which takes an integer parameter, and returns a random number based on the input parameter. It is a Rn -> R mapping function when n defines the number of input parameters(dimensions). If you pass the same parameter twice, it returns the same output.<br />
<br />
<h3 style="text-align: left;">
Nature of Noise Function(1D).</h3>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJj9X1i1eKiWld4zzOU96q_q_yLOLSB49n2Imp4y3iCtSH9Iz_4NQaFYqHt-YgEWqPZ6NtGCglQM1MHSKx5o0Mn-Tp8kSrZZSAr_T_4o1tMO27NBJQA_GIkuymgXzvS9WmClv20Ag6SJQ/s1600/interpolating.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="315" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJj9X1i1eKiWld4zzOU96q_q_yLOLSB49n2Imp4y3iCtSH9Iz_4NQaFYqHt-YgEWqPZ6NtGCglQM1MHSKx5o0Mn-Tp8kSrZZSAr_T_4o1tMO27NBJQA_GIkuymgXzvS9WmClv20Ag6SJQ/s320/interpolating.png" width="320" /></a></div>
<div>
<br /></div>
<div>
Noise function takes some input parameter, lets say 1D parameter X and retruns a random number, lets say between (0 and 1). We can't just caculate values for every possible points in a given range. So, we can say its discrete. But we make it smooth using various interpolation techniques.</div>
<div>
<br />
<br /></div>
<h3 style="text-align: left;">
Creating Perlin Noise Function</h3>
<div>
<br /></div>
<div>
Now, that you have a noise function with a particular Amplitude and Frequency [1/(wavelength)]. We can create a Perlin Noise function. If you take lots of such smooth functions, with varying frequencies and amplitudes, you can add them all together to create a Perlin Noise Function.</div>
</div>
<div>
<br />
<h3 style="text-align: left;">
Choosing Frequency and Amplitude</h3>
</div>
<div>
<br /></div>
<div>
We know that Perlin Noise Function is the sum of different smooth Noise Function with various frequencies and amplitudes. The choise of these frequecies and amplitude define the Nature of Noise. So, Mandelbrot coined the term "Persistence" help define these parameters. </div>
<div>
<br /></div>
<h3 style="text-align: left;">
Persistence</h3>
<div>
<br /></div>
<div>
Persistence basically defines the value of amplitude for each successive noise function to be added. It is defined by the formula below:<br />
<br />
<code><br />
Frequency = 2 ^ i<br />
Amplitude = Persistence ^ i<br />
</code><br />
<br />
Where i is the ith noise function to be added<br />
<br />
So, for Persistence = 1/4, we have the following values of frequency and amplitude:<br />
<br />
<table border="1"><tbody>
<tr><td>Frequency:</td><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>Amplitude:</td><td>1</td><td>1/4</td><td>1/16</td><td>1/64</td></tr>
</tbody></table>
<br />
<div>
</div>
</div>
<h3 style="text-align: left;">
Octaves</h3>
<div>
<br /></div>
<div>
Each sucesssively added Noise function is an Octave. They are called octaves because one Noise function differs from its sucessive other by 2*frequency.<br />
<br />
<br />
<h3 style="text-align: left;">
Interpolating and Smoothing</h3>
<div>
<br /></div>
Many of us might be quite familiar with interpolation, to those who are not, its just a process of predicting projection of values. To create a continious noise function various Interpolation is used. The most commonly used technique is the Cubic Interpolation technique.<br />
<br />
Psuedo Code for obtaining Cubic Interpolation Values:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ881crNkFfSA2yBMrq6PwuGu92e42QSRJud0V3dKwwILwJ3rZFL1h5e-0i0yjA8Kl_OVN7d5IpjSXewOD2BDkk3y2HF-gS2y_wX-kbl8h5Kl-bw0k6CsAtI4I4o4qdFVaw17C70ysW8U/s1600/interpolating1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ881crNkFfSA2yBMrq6PwuGu92e42QSRJud0V3dKwwILwJ3rZFL1h5e-0i0yjA8Kl_OVN7d5IpjSXewOD2BDkk3y2HF-gS2y_wX-kbl8h5Kl-bw0k6CsAtI4I4o4qdFVaw17C70ysW8U/s200/interpolating1.png" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
For a value X between V2 and V3 from the figure:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both;">
function CubicInterpolate(v1, v2, v3, v4,x)</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>P = (v4 - v3) - (v1 - v2)</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>Q = (v1 - v2) - P</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>R = v3 - v1</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>S = v2</div>
<div class="separator" style="clear: both;">
</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>return Px3 + Qx2 + Rx + S</div>
<div class="separator" style="clear: both;">
end of function</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
After Interplolation, we can also smoothen the output of the noise function to make it more realistic or natural by trimming of the unwanted sharpness or edges. Smoothing works by accounting neighbouring values to supress surges and picks.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<h3 style="text-align: left;">
That's All</h3>
<div>
<br /></div>
<div class="separator" style="clear: both;">
So, there you go. These are the very basics of Perlin Noise.</div>
<div class="separator" style="clear: both;">
For more infomation you can check out these useful links:</div>
<div class="separator" style="clear: both;">
1. <a href="http://devmag.org.za/2009/04/25/perlin-noise/" target="_blank">How to Use Perlin Noise in your Games</a></div>
<div class="separator" style="clear: both;">
2. <a href="http://en.wikipedia.org/wiki/Perlin_noise" target="_blank">Wikipedia: Perlin Noise</a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
Hope this post was useful. I will soon try to publish the code/implementation of Perlin Noise.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-63132529854370300512013-11-14T15:42:00.000+05:452014-05-10T19:36:03.114+05:45Automatic POI Excel Builder [Source Code]<div dir="ltr" style="text-align: left;" trbidi="on">
Yesterday I blogged about my work on Excel Report Generation and how I thought of automating the report generation process. Blog link <a href="http://blog.kaflesushant.com.np/2013/11/working-on-excel-report-generation.html" target="_blank">here</a>.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS1LDvtk7uexUC_pUZh8H4KzUCMOgTesZBNbZrx6_wwkMbqyh3_EL5OXkq91S3oqCmBJ7sIjCeLlTglIOYzPHZr4wZjLBth_euZ5aLMIU5WGG9eyR3oYUCp7nfqNgiwo3htrsbMOQvgw0/s1600/group-logo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS1LDvtk7uexUC_pUZh8H4KzUCMOgTesZBNbZrx6_wwkMbqyh3_EL5OXkq91S3oqCmBJ7sIjCeLlTglIOYzPHZr4wZjLBth_euZ5aLMIU5WGG9eyR3oYUCp7nfqNgiwo3htrsbMOQvgw0/s1600/group-logo.jpg" /></a></div>
<br />
<br />
<a name='more'></a><br />
<br />
Today, I thought of sharing the code I used. Its not much, but it might help you get the idea of what I am doing and how I did it. It would help you understand the basics of POI, such as formatting cell, auto-adjusting of table columns and even the overall idea of how I automated the process, only if you are not that familiar with it :)<br />
<br />
Here is the link to source code: <a href="http://cur.lv/4oltn" target="_blank">Automatic-POIExcelBuilder</a><br />
Hope it's useful !!</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-45173290011943127832013-11-13T21:11:00.001+05:452013-11-13T21:16:06.554+05:45Working on Excel Report Generation using Java (POI) [Automation]<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
I am currently working on a Java Project that automates Report Generation using POI. Given necessary parameters, it would extract data from database and construct an appropriate Excel table.</div>
Sounds pretty straightforward, isn't it? Well, it certainly is not. A good table would require proper coloring of Cells, setting required Formulations, appropriate Merging of cells and even setting proper column width and many more.<br />
<a name='more'></a><br />
I was initially asked if I could automate these sorts of Report Generation and make them dynamic and good looking. At first thought, I believed the task was too hypothetical. Automating Report Generation given any data, would not be possible, or at least not easy :D. But I was allowed to format the data as I wanted from the database. That means, I was given enough freedom to get the data in the format I required using my own PL/SQL scripts for the extraction. Well, then it would be quite possible to automate it and make it dynamic as well.<br />
It was pretty fun problem to work on but not as hard as I thought. Here's are some of my outputs generated automatically and the formation of table is generated totally by my script without human help, considering solely on format in which the data is supplied.<br />
<br />
<b>Result from Dummy DataSet 1:</b><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqfnQVwlSZdHc06_6-rWg5H6rGUycAnZnLiXtKDrwaw5hvq-1zkt50XmO_JOfYuO5bazGEn5Zn9xQMEWYyt91oOm3nanMO1cKIB-RifnDmiH4scI4kBimAePxiTfjQkd4b5Kqzmen_XqQ/s1600/Samp1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqfnQVwlSZdHc06_6-rWg5H6rGUycAnZnLiXtKDrwaw5hvq-1zkt50XmO_JOfYuO5bazGEn5Zn9xQMEWYyt91oOm3nanMO1cKIB-RifnDmiH4scI4kBimAePxiTfjQkd4b5Kqzmen_XqQ/s400/Samp1.png" width="400" /></a><br />
<br />
<br />
<b>Result from Dummy DataSet 2:</b><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyN8Bmfr0vRld_vLzHD2hzt3m86-uxuxC_85CbZUTn43-AW4WzGbR2B9kqmurZMD3gM-d7eBgNsu60w8-O_ln3Ic4EfA7Pb1PlgaOoJPqvYz_1Xh59DBaRKWMsoZiSdRgx_D8GKYfPgQ0/s1600/Samp2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="118" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyN8Bmfr0vRld_vLzHD2hzt3m86-uxuxC_85CbZUTn43-AW4WzGbR2B9kqmurZMD3gM-d7eBgNsu60w8-O_ln3Ic4EfA7Pb1PlgaOoJPqvYz_1Xh59DBaRKWMsoZiSdRgx_D8GKYfPgQ0/s400/Samp2.png" width="400" /></a><br />
<br />
<br />
<b>Result from Dummy DataSet 3:</b><br />
<b><br /></b>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCNWUfEv9v7Q7DdeVjk4B-swfEvY88Ovj7m79R46m_WZIxTh2kEaef25Zyl1YuthZ35acHFbiDa0GhtAslfhyphenhyphenJnJQHsaDEvv0VTBk3dPkkhUL1-K8Hj56UN1yM_ICNNCG8qt490DdrB7s/s1600/Samp3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCNWUfEv9v7Q7DdeVjk4B-swfEvY88Ovj7m79R46m_WZIxTh2kEaef25Zyl1YuthZ35acHFbiDa0GhtAslfhyphenhyphenJnJQHsaDEvv0VTBk3dPkkhUL1-K8Hj56UN1yM_ICNNCG8qt490DdrB7s/s400/Samp3.png" width="400" /></a><br />
<br />
Result were pretty accurate for the dummy data. But I have still alot to do to make it fully functional.<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-3560897085440034122013-11-12T22:03:00.001+05:452013-11-13T19:39:47.774+05:45Understanding Delaunay Triangulation.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
I have posted earlier about the <a href="http://blog.kaflesushant.com.np/2013/10/understanding-vorohoi-diagrams.html" target="_blank">Voronoi Diagrams</a>. Well, simlar to that diagram there is another diagram called the Delaunay Triangulation.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Delaunay_circumcircles.png/280px-Delaunay_circumcircles.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="200" src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Delaunay_circumcircles.png/280px-Delaunay_circumcircles.png" width="195" /></a></div>
<br />
<a name='more'></a>The Delaunay triangulation of a collection of point is a set of edges satisfying an "empty circle" property. Empty Circle property specifies that for each edge, we can find a circle containing the edge's endpoints but not containing any other points.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNG2nzKrJQkcMxV160dnYy25YOSatUZ5daBVA7FzHAdsERvAK1D3VFCdzAQuP1lAeJB9DbhKqja3qqyykzFUXN1LVpGPOmkXmYL4yTRS-ZQjdeIZmDMmX8YYyQTuCqv-8R7BMOBcHUge0/s1600/delaunay.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNG2nzKrJQkcMxV160dnYy25YOSatUZ5daBVA7FzHAdsERvAK1D3VFCdzAQuP1lAeJB9DbhKqja3qqyykzFUXN1LVpGPOmkXmYL4yTRS-ZQjdeIZmDMmX8YYyQTuCqv-8R7BMOBcHUge0/s320/delaunay.png" width="320" /></a></div>
<br />
<br />
<br />
The Delaunay triangulation is the dual structure of the Voronoi diagram in R².<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWD0n-zIUnbSIx4vJyrjnSSdvxxdXi9cC8qfRj1LJMsIhWTQXknANU3nkxIsTOOOShU-SzKqggRxId5ABLxluX47EhdNTFQwxV0Z0qojuTbbpmVexN4H1CB72l7v4MEIcyE2_4RVME4B4/s1600/dt.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Delauney Triangulation" border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWD0n-zIUnbSIx4vJyrjnSSdvxxdXi9cC8qfRj1LJMsIhWTQXknANU3nkxIsTOOOShU-SzKqggRxId5ABLxluX47EhdNTFQwxV0Z0qojuTbbpmVexN4H1CB72l7v4MEIcyE2_4RVME4B4/s200/dt.gif" title="Delauney Triangulation (on top of Voronoi Diagram)" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Delaunay Triangulation (on top of Voronoi Diagram)</td></tr>
</tbody></table>
<h3 style="text-align: left;">
<br />Delaunay From Voronoi</h3>
Looking at the above diagram we can clearly see, drawing a line segment between two Voronoi vertices if their Voronoi polygons have a common edge, forms the Delaunay Triangulation. Or, in more mathematical terminology: there is a natural bijection between the two which reverses the face inclusions.<br />
<br />
<h3 style="text-align: left;">
Voronoi From Delaunay</h3>
The circumcircle of a Delaunay triangle is called a Delaunay circle and the center of these Delaunay Circles if connected gives the Voronoi Diagrams.<br />
<br />
More information of Delaunay Triangulation can be found here : <a href="http://en.wikipedia.org/wiki/Delaunay_triangulation" target="_blank">Wikipedia Delaunay Triag.</a><br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0tag:blogger.com,1999:blog-8425313741536232893.post-6013755961626734692013-11-09T16:25:00.000+05:452013-11-11T09:23:46.874+05:45Working on my "ParticleViewer".<div dir="ltr" style="text-align: left;" trbidi="on">
I have been quite busy working on my current project, called the Particle Viewer, which is a Graphical User Interface that is used to analyze the particle behaviour inside a container.<br />
Here's a little Snapshot of the application:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl6HeAyoPcJ-6su7_BDWwCIMATvzqh97k1AtV7JSW7KjCKG08mut6U0fDjFg_8w4-yaZkiTzwVy61FYWTwEVyO4NQkxQ_YNmEUWS20fprWlOppbV6ENe4opT30X91GX-MJxW2Z0eYZmEc/s1600/ParticleViewer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="129" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl6HeAyoPcJ-6su7_BDWwCIMATvzqh97k1AtV7JSW7KjCKG08mut6U0fDjFg_8w4-yaZkiTzwVy61FYWTwEVyO4NQkxQ_YNmEUWS20fprWlOppbV6ENe4opT30X91GX-MJxW2Z0eYZmEc/s320/ParticleViewer.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<a name='more'></a><br />
I know the picture shows nothing relevant to what I just described. Its just a snapshot of the application loading a STL file :D<br />
<br />
It still needs a lot of work, so I might have to work on it alittle longer.<br />
Then, I should start posting more regularly :)</div>
Anonymoushttp://www.blogger.com/profile/07077632288228955810noreply@blogger.com0