Saturday, 31 December 2016

SceneKit Sample - Globe surrounded by clouds

Recently I have been learning SceneKit framework provided by Apple on iOS and macOS platform. I have created a Swift playground sample using Xcode 8 and Swift 3.0 to display globle surrounded by clouds.

Note: The code and resources have been taken from the sample provided in WWDC 2013 - SceneKit session.

The output of the playground is as shown below:


The sample can be found in the github repository: SceneKitSample. You can get more explanation about the code here.

Besides playground sample, I have created an Application sample which could be run on the device. This allows you to switch on/off features to see how those impact the output. Also scenekit output quality on the device is much better than the simulator so I would recommend you to run this sample on the actual device.

The output will look like as shown below:


Wednesday, 20 January 2016

iOS Swift- Sending Photos peer-to-peer using NSNetServices and NSStream

Recently I have been exploring NSNetServices and NSStream to send data between two iOS devices. The easiest way to do it is using Apple Multipeer Connectivity. However, I wanted to explore NSNetService and NSStream. There are few reasons why I used those APIs. First this has helped me to understand the complexity and issues while implementing networking Apps at a lower level. Second the concepts are useful while connecting the iOS devices with low Bluetooth energy devices.

In the sample App two iOS devices can send photos to each other. You can download my sample App from here.  Please click on the video to see the demo of the App.



I have used NSNetService to publish and browse photo sharing service. NSNetService can be used to publish the service and NSNetServiceBrowser can be used to browse published services. Once service is found and resolved then NSOutputStream is used to send photos and NSInputStream is used to receive photos.

I have used following resources to implement the sample App:
NSNetServices and CFNetworking programming guide
WiTap Sample
Stream Programming Guide

I plan to write more about the topic and update my code as I get a better understanding of the topic. Please let me know if you find any problems in the code.


Monday, 20 January 2014

Cassandra Data Modelling - Primary Keys

In the previous blog we discussed how data is stored in Cassandra by creating a keyspace and a table. We also inserted rows into the table. The rows in Cassandra are stored in the form of variable key/value pairs or columns. We also observed that each row in a table is referenced by a primary key or a row key. In this post we are going to discuss more about primary keys. Primary key concept in Cassandra is different from Relational databases. Therefore it is worth spending time to understand this concept.


In our last post we created a person table which had a person_id as a primary key column.
create table person (person_id int primary key, fname text, lname text, dateofbirth timestamp, email text, phone text );
We saw that the person_id was used as a row key to refer to person data.

Thursday, 14 November 2013

Cassandra Data Modelling - Tables


In this series of posts I will discuss the basic concepts of data modelling in Apache Cassandra. It is important to understand those concepts as it will help us to design an efficient system using Cassandra. In this post I will discuss basic concept called tables in Cassandra.

I am assuming that you have installed Cassandra 1.2 or above with CQL3. You can download Cassandra from Apache Cassandra website. CQL 3.0 is the language which helps to work with Cassandra object same as SQL language helps to works with SQL objects.

Thursday, 12 April 2012

d-touch Mobile- Part 3

In our last two posts we discussed about d-touch markers and how d-touch mobile library can be configured and used in an Android application. In this post we are going to discuss the architecture of the d-touch mobile library.

There are three main entities or classes of the d-touch mobile library.
  1. HIPreference
  2. DetectMarker
  3. MarkerConstraint
The sequence diagram of these entities is shown in figure 1:

Figure 1: Sequence diagram of d-touch mobile library

Wednesday, 11 April 2012

d-touch Mobile - Part 2

In our last post we discussed a brief introduction of  d-touch markers.In this post we will see how to use d-touch mobile library in an Android project. The output of our sample project would look like as shown in picture 1. You can find the library in DtouchMobile folder and the sample code in DtouchSample1 folder on the github.
Picture 1: Sample camera preview with marker detection window.

Thursday, 5 April 2012

d-touch Mobile - Part 1

d-touch markers are visual markers which are easy to design and easy to communicate to humans. Enrico Costanza has introduced these markers and has launched a dedicated d-touch website for this project. d-touch markers can be used in mixed reality application. As part of the research project for Horizon Digital Economy Research Institute, University of Nottingham , I have developed a d-touch library for Android system. In this post I will give an introduction of the d-touch markers. In our next post I will show how to create a sample application using d-touch mobile library. The library and sample source code is available on the github. Please feel free to use this for building cool projects! Here are few example outputs of the sample code in DtouchSample folder on the github.

Youtube marker
Youtube dtouch marker

Friday, 8 July 2011

UIImageView curl shadow effect using shadowPath

In my last post I discussed how to display UIImageView with border and shadow. One important thing to consider while displaying shadow is performance. This can be improved by explicitly specifying shadow path property in CALayer class. According to iOS CALayer class reference documentation "Specifying an explicit path usually improves rendering performance".  If shadowPath property is not defined then the shadow is created using layers composited alpha channel. In this post we will see how to create curl shadow effect using shadowPath property. The output of our image will look like as shown in figure 1.
Figure1: (a) original photo (b) photo with border and curl shadow

Sunday, 19 June 2011

UIImageView with border and shadow

In iPhone or iPad applications we sometimes need to display images or photos with borders and shadows around them. There are few ways to achieve this but generally I tend to use UIImageView. There are few reasons why I prefer this solution. First according to iOS documentation, UIImageView is optimized to display images. Second it is less lines of code. I will discuss how we can convert image as shown in figure 1 to image with border and shadow in figure 2. Once you understand the basic concept of drawing borders and shadows I would invite you to read my next post: UIImageView curl shadow effect using shadowPath. This post discusses how to render shadows efficiently.

Figure1: image without border.
Figure 2: image with white border and a shadow.

Friday, 10 June 2011

Understanding the Image Reflection - Masking

In our previous posts we have discussed Image inversion and Gradient. Today we will discuss about masking. We will also conclude Reflection example provided by Apple. Source code of our example is available at github. Please feel free to modify or test this code on your machine.

Image Masking:
I believe we are all familiar with the idea of bit masking. In bit masking we change bits in input data to on, off or invert by applying bit operators. For example if input bits are 0110 and if we apply OR bit operator on this data using some mask such as 1111 then the result of this operation would be 1111. Similarly in Image mask we apply a mask on a given image to switch on, off or modify part of the image. In iOS there are different techniques to mask an image.
  1. Masking using an image mask.
  2. Masking using an image.
  3. Masking using colors.
  4. Masking using Context clip.
In Apple reflection example context clip masking is used to display reflected image.

Masking using an image mask
A bitmap image mask contains sample values (S) at each point corresponding to an image. Each sample value is represented through 1, 2, 4 or 8 bits per components and it specifies the amount that the current fill color is masked at each location in the image.
Lets take an example to understand image masking. Suppose we have an image of a bus and we only want to display part of it. To obtain this, we mask bus image with an image mask as shown in figure 1:
Figure1: Bus image is masked with image mask. (a)original image (b) image mask (c) masked image.

Thursday, 26 May 2011

Understanding the Image Reflection - Gradient

This is my second post about image reflection. In our first post we discussed about basic principles of image inversion. We discussed translation, scaling and bitmap context to understand image inversion. Today we will discuss about gray scale images and gradients. These concepts are important not only to understand reflection but these could also be used in other scenarios. Our main goal is to understand image reflection which is implemented in Reflection sample provided by Apple. All examples which we are going to discussed today can be downloaded from github repository. If you are looking for complete example of Reflection which covers image inversion, gradient and masking then I would refer you to my post about image masking.

Gray Scale images:
As we know pixels are basic elements of digital image. Each pixel contains number of values which determine the type of image. There are mainly three types of images: black & white, gray scale and color. Black & white images are also called binary images as each pixel has a value either 0 or 1. The next complex type is a gray scale image where each pixel stores value of gray level or gray scale. For example if an image is 8-bit grayscale then each pixel can contain value between 0 to 256 inclusive.

Wednesday, 18 May 2011

Understanding the image reflection

There is a sample provided by Apple to demonstrate UIImageView reflection effect as implemented in iTunes and iPod player applications. Although it is a small sample but it covers number of concepts which if understood properly could be very helpful for developers and could be used  in other scenarios. In next couple of posts, I would like to cover following concepts which are used in this example:
  1. Image inversion.
  2. Gradient
  3. Masking
Today I will discuss image inversion. In my next posts I have discussed Gradient and Masking. If you are looking for complete example which includes image inversion, gradient and masking then you can refer my post about image masking. For this post, I have provided sample code which you can download and test on your machine. The output of our application will look like as in the picture below. Note that we not only want to vertically invert our image but we also want to control the height of reflection which is being displayed.



Sunday, 8 May 2011

iPhone - Custom Alert View

Recently while developing an iPhone application I  needed to display a message box which is similar to UIAlertView but which could be modified by adding different objects like Activity indicator. I also wanted to replicate animation of UIAlertView. I created my custom alert view which I would like to post here. I hope some of the techniques I have used here could be useful to other developers. You can download code from github repository. Please note that I have taken some ideas from Brad Larson's iTunes lecture: Quartz 2D drawing. Here is how the Custom alert view looks like.
CustomAlertView class :
First we need to create a CustomAlertView class in our project. This class is derived from UIView class.

Implement init method
Init method will receive frame and the text which needs to be displayed.
-(id)initWithFrame:(CGRect)frame withText:(NSString*)text{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self initTextLabel:text];
        [self initActivityIndicator];
    }
    return self;
}
We call initTextLabel function which creates label and adjusts its position. The second function initActivityIndicator adjusts activity indicator control.

Friday, 8 April 2011

Start small think big

I attended a presentation by Natie Kirsh at London Business School. Natie is South Africa's wealthiest entrepreneur. His story is remarkable. He started building his empire while he was very young and lost significant amount of his wealth in 1986. Later on he migrated to New York and started building his business again. Today he has businesses through out the world.
While listening to his presentation I wondered how small businesses can replicate similar success. Few messages which came across from his presentations were that it requires lots of hard work, focus and sacrifice of social life. During his presentation video, I noticed one sign,which was hanging in one of his business staff room and it had a message something like this: "Do not spend too much time, Competition is eating your lunch".  I asked him a question later on that from his presentation it feels like that he has always started with big businesses and he replied: No it is not like that. Start small but think big. I believe this is an important lesson to all small businesses that we should always have high ambitions for our businesses but keep our costs down.