Code and Stuff

Feb 26, 2013

SVG Filter Tests

Applying SVG filters to various things

Videos

Apply filter to WebRTC Webcam capture. Webcam code was taken from Mozilla.

Or on a normal video (source wikipedia http://en.wikipedia.org/wiki/File:GibraltarpediA_introduction_video.ogg);

Canvas

To test the canvas I will reuse my Image Compositing post "plasma" like animation.

Youtube

Youtube can work using flash or html5. Probably the HTML5 uses a video tag or a canvas (never actually checked that), but we are interested in the flash version. By default, if available, youtube uses flash (as of feb 2013). Click Here for the original Rhett & Link GMM video.

Problems

Mid february 2013 i tested Mac Firefox 19, Mac Chrome 25 and Windows Firefox 19
  • Chome shows some strange behaviour with animated stuff (e.g. convolution not applied)
  • Firefox SVG filters are quite slow (especially the erode and dilate)
  • Firefox SVG filters are not applied to flash videos on Windows. They are on a Mac 10.6

Feb 20, 2013

JSONP EPrints

EPrints supports JSON-P. It is therefore possible to include a list of publication with javascript on a different host without the need for the CORS headers.

Here an example using SUPSI's eprints repository. List of publications with creator being david huber:

    Howto

    You will need the url to the JSON export of the desired search. In other words: perform the search, choose to export as JSON and copy the url. In my case the url was:
    http://repository.supsi.ch/cgi/search/archive/advanced/export_SUPSI_Institutional_Repository_JSON.js?screen=Search&dataset=archive&_action_export=1&output=JSON&exp=0%7C1%7C-date%2Fcreators_name%2Ftitle%7Carchive%7C-%7Ccreators_name%3Acreators_name%3AALL%3AEQ%3Adavid+huber%7C-%7Ceprint_status%3Aeprint_status%3AANY%3AEQ%3Aarchive%7Cmetadata_visibility%3Ametadata_visibility%3AANY%3AEQ%3Ashow&n=&cache=

    Append to that url the JSONP part:

    &jsonp=functionName
    Replace functionName with any desired function name. As expected by JSONP, the new URL will return a javascript that can be used with a script tag and will pass to functionName an array of publication objects.
    <script type="text/javascript" src="the JSONP URL"></script>
    
    This script tag can also be injected in the DOM when needed. For instance at DOM ready with the following JQuery code:
    // execute when DOM is ready
    $(function() {
      $(document.body).append("<script type='text/javascript' src='the JSONP URL'></script>");
    });
    

    Feb 13, 2013

    C++ Polymorphic

    Used to Java I was quite surprised to discover that the RTTI of C++ works "polymorphic" only when the classes contain at least one virtual method. This means that if we have two classes, A and B where B inherits from A, and we ask for the typeid of an instance of B from a dereferenced A pointer, RTTI will tell us the type is B only if A has a virtual method otherwise it will tell us the type is A.

    This is best shown in code:

    #include <iostream>
    #include <typeinfo>
    
    class A { };
    class B : public A { };
    
    class VA {
      virtual void dummy(){ }; 
    };
    
    class VB : public VA { };
    
    int main() {
      B* b = new B; // typeid is B, ok
      A* a = new B; // typeid is A!
    
      std::cout << "b: " << typeid(*b).name() << std::endl;
      std::cout << "a: " << typeid(*a).name() << std::endl;
    
      VB* vb = new VB; // typeid is VB, ok
      VA* va = new VB; // typeid is VB, just like java :-)
    
      std::cout << "vb: " << typeid(*vb).name() << std::endl;
      std::cout << "va: " << typeid(*va).name() << std::endl;
      return 0;
    }
    
    will output the following:
    b: 1B
    a: 1A
    vb: 2VB
    va: 2VB
    
    The second line tells us that the type is A even if we created the object with "new B".

    This implies that we will not be allowed to dynamic_cast an A pointer to a B one. gcc will reports that the cast is not permitted becase the "source type is not polymorphic".

    A* a = new B;
    B* c = dynamic_cast<B*>(a); // compilation error
    
    It is, however, perfectly fine to cast the classes with the virtual method:
    VA* va = new VB;
    VB* vc = dynamic_cast<VB*>(va);