Configuring and compiling VTK 6.1 on Mac OS X 10.9.2 + simple example of VTK usage

Hello. In this short post I will explain how to build static libraries of VTK.
Main reason why it needs: Because official “How to” has just 2 lines without any explanations. And by default will be builded dynamic libraries. With which I had a problem like link to vtkCocoaGLView was not found, but it actually was in a library.

Let’s start. You will need CMake to build and VTK sources.

- Launch CMake from your Application folder. In main menu go to “Tool” -> “Install for Command Line Use”, in case if you did not install yet.
- Unpack VTK to some directory, working place.
- Enter to VTK directory and create directory with name build

Now you can configure and generate makefile or Xcode project file from console or User interface of CMake application.
If you would like to build with makefile in terminal go to next steps, if not jump to Build with Xcode section.
Continue reading

How to extend existing method

With blocks it’s more easy if you need extend your method. But if you will need extend some method of another class, not yours, and you will not be able to get the sources then this solution for you. (And if you will not be able or does not have any reason for creating a subclass)

1. You need create a category of class

2. import runtime in implementation file (.m)

1
#import

3. implement your method inside category, for example :

1
2
3
4
5
6
7
8
9
- (void) extend_method {

// your code

//  here will be performed the original method
    [self extend_method];
   
// your code
}

It looks like this method has recursive calls itself, but it’s not true. Look next step

4. add method for replace (you can use +initialize or +load)

1
2
3
4
5
+ (void) initialize {
    Method original = class_getInstanceMethod(self, @selector(method));
    Method replacement = class_getInstanceMethod(self, @selector(extend_method));
    method_exchangeImplementations(original, replacement);
}

Done!

ANSI escape sequences for coloring

More about ANSI escape code

I modify my twitter script from previous post and now timeline looks like this:

1.Open terminal

2. Install next gem yajl-ruby, twitter, htmlentities

1
sudo gem install yajl-ruby twitter htmlentities

3. create app on and copy keys

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/ruby
# Copyright Vladimir Boychentsov, 2012
# site https://developers-life.com/
# Released under BSD

require 'rubygems'
require 'twitter'
require 'htmlentities'

Twitter.configure do |config|
  config.consumer_key = "Ytg46GtAB8piXffx1lc1Q"
  config.consumer_secret = "gq53DKEx0flbe0l7hTP3HgdMlMVEqX0Knq1Ne65s0g"
  config.oauth_token = "53885581-qADcvoP9lFlxXQ5RyS1FHuKFCB7aYZFaQAKZ5QbuV"
  config.oauth_token_secret = "jTHhJrRL0dxIJBOzWAdbHOoQvf8tN5px9BeuoWFNgE"
end

decoder = HTMLEntities.new

tweets = Twitter.home_timeline()
for tweet in tweets
  printf "%s: %s",tweet.user.screen_name,decoder.decode(tweet.text) + "\n\n"
end

NSTableView with custom header

Default header looks like this

First we want change height of header:

1
2
NSTableHeaderView *tableHeaderView = [[NSTableHeaderView alloc] initWithFrame:NSMakeRect(0, 0, 120, 60)];
    [_tableView setHeaderView:tableHeaderView];

Next step we want change NSTableHeaderCell, can make category for this class or make subclass. So, I wrote category.

Empty category

Continue reading

NSRegularExpression sample for comment syntax highlighting

I have this text:

1
word1 word2 " word3 //" word4

I wrote simple solution. I know it can be better. I know about Back Reference, but i don’t have experience with it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"((@\"|\").*?(\"))"
                                          options:NSRegularExpressionDotMatchesLineSeparators
                                            error:nil];
NSArray *textArray = [expression matchesInString:textString options:0 range:NSMakeRange(0, [textString length])];

for (NSTextCheckingResult *result in textArray) {
    // set color for range
}


// Comments
expression = [NSRegularExpression regularExpressionWithPattern:@"(//[^\"\n]*)"
                                                options:0
                                                error:nil];

NSArray * arrayComments = [expression matchesInString:textString options:0 range:NSMakeRange(0, [textString length])];

for (NSTextCheckingResult *resultComment in arrayComments) {

    BOOL inside = NO;
    for (NSTextCheckingResult *resultText in textArray) {
        NSInteger from = resultText.range.location;
        NSInteger to = resultText.range.location+resultText.range.length;
        NSInteger now = resultComment.range.location;
        if (from < now && now < to) {
            inside = YES;
            break;
        }
    }
    if (!inside) {
        // set color for range
    }
}

DDProgressView – Custom Progress View

DDProgressView is a custom progress view à la Twitter for iPhone.

DDProgressView works on both iOS and Mac OS. You must also compile the AppKitCompatibility.m file when targeting Mac OS.

Thanks, Damien DeVille!

Get Geo tags from image

Little application for getting geo location from photo

Continue reading

1 2 3 Next »