Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 25 Oct 2011 19:06:53 +0000 (19:06 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 25 Oct 2011 19:06:53 +0000 (19:06 +0000)
===========================

More fixes for reports from codereview.

source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/makesdna/DNA_movieclip_types.h
source/blender/makesrna/intern/rna_tracking.c

index 8d45b5ae2181b48dab3cd3a0f6a7353e38c6fced..11b6c7fff65ef3cd6d5ddf7dc272b7b40916783b 100644 (file)
@@ -98,7 +98,7 @@ void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr
 struct ImBuf *BKE_tracking_stabilize(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf, float loc[2], float *scale, float *angle);
 void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]);
 
-/* Distoriton/Undistortion */
+/* Distortion/Undistortion */
 struct MovieDistortion *BKE_tracking_distortion_create(void);
 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, struct MovieTracking *tracking,
index 3fb51c09bc240d514f3e3b30361302033208354b..b94891ced4996e4daeba0a90b4d8b0f5530ae951 100644 (file)
@@ -2030,18 +2030,6 @@ void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const sho
                                        flush_pointcache_reset(sce, itA->node, lasttime, 0);
                        }
                }
-
-               /* also all objects which are parented to tracking data should be re-calculated */
-               for(ob=bmain->object.first; ob; ob= ob->id.next){
-                       bConstraint *con;
-                       for (con = ob->constraints.first; con; con=con->next) {
-                               bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
-                               if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) {
-                                       ob->recalc |= OB_RECALC_OB;
-                                       break;
-                               }
-                       }
-               }
        }
        
        dag_tag_renderlayers(sce, lay);
index e135f964729b4cdfe305767c1bb9b53e7b184919..b917bf7b9bf5d82d4d8ebdb5441e437804b93436 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_constraint_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_movieclip_types.h"
-#include "DNA_object_types.h"  /* SELECT */
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
 
 #include "BLI_utildefines.h"
 
@@ -61,6 +64,7 @@
 #include "BLI_mempool.h"
 #include "BLI_threads.h"
 
+#include "BKE_constraint.h"
 #include "BKE_library.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
@@ -79,7 +83,7 @@ static int sequence_guess_offset(const char *full_name, int head_len, int numlen
 {
        char num[FILE_MAX]= {0};
 
-       strncpy(num, full_name+head_len, numlen);
+       BLI_strncpy(num, full_name+head_len, numlen);
 
        return atoi(num);
 }
@@ -259,7 +263,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in
 /*********************** image buffer cache *************************/
 
 typedef struct MovieClipCache {
-       /* regular moive cache */
+       /* regular movie cache */
        struct MovieCache *moviecache;
 
        /* cache for stable shot */
@@ -1004,21 +1008,56 @@ void unlink_movieclip(Main *bmain, MovieClip *clip)
        bScreen *scr;
        ScrArea *area;
        SpaceLink *sl;
+       Scene *sce;
+       Object *ob;
 
-       /* text space */
        for(scr= bmain->screen.first; scr; scr= scr->id.next) {
                for(area= scr->areabase.first; area; area= area->next) {
                        for(sl= area->spacedata.first; sl; sl= sl->next) {
                                if(sl->spacetype==SPACE_CLIP) {
-                                       SpaceClip *sc= (SpaceClip*) sl;
+                                       SpaceClip *sc= (SpaceClip *) sl;
 
-                                       if(sc->clip==clip) {
+                                       if(sc->clip==clip)
                                                sc->clip= NULL;
+                               }
+                               else if(sl->spacetype==SPACE_VIEW3D) {
+                                       View3D *v3d= (View3D *) sl;
+                                       BGpic *bgpic;
+
+                                       for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
+                                               if(bgpic->clip==clip)
+                                                       bgpic->clip= NULL;
                                        }
                                }
                        }
                }
        }
 
+       for(sce= bmain->scene.first; sce; sce= sce->id.next) {
+               if(sce->clip==clip)
+                       sce->clip= NULL;
+       }
+
+       for(ob= bmain->object.first; ob; ob= ob->id.next) {
+               bConstraint *con= ob->constraints.first;
+
+               for (con= ob->constraints.first; con; con= con->next) {
+                       bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
+
+                       if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) {
+                               bFollowTrackConstraint *data= (bFollowTrackConstraint *) con->data;
+
+                               if(data->clip==clip)
+                                       data->clip= NULL;
+                       }
+                       else if(cti->type==CONSTRAINT_TYPE_CAMERASOLVER) {
+                               bCameraSolverConstraint *data= (bCameraSolverConstraint *) con->data;
+
+                               if(data->clip==clip)
+                                       data->clip= NULL;
+                       }
+               }
+       }
+
        clip->id.us= 0;
 }
index 9348aaf52e8a369e134fef0ce52ebedc7714d85f..7bdc9d6b48b668b145a3a95857e62876a005ed09 100644 (file)
@@ -727,13 +727,13 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
                        int pixel= tmpibuf->x*y + x;
 
                        if(tmpibuf->rect_float) {
-                               float *rrgbf= ibuf->rect_float + pixel*4;
+                               float *rrgbf= tmpibuf->rect_float + pixel*4;
 
-                               *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2])/255;
+                               *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
                        } else {
                                char *rrgb= (char*)tmpibuf->rect + pixel*4;
 
-                               *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255;
+                               *fp= FTOCHAR(0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2]);
                        }
 
                        fp++;
@@ -745,12 +745,39 @@ static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT
        return pixels;
 }
 
+static unsigned char *get_ucharbuf(ImBuf *ibuf)
+{
+       int x, y;
+       unsigned char *pixels, *cp;
+
+       cp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf");
+       for(y= 0; y<ibuf->y; y++) {
+               for (x= 0; x<ibuf->x; x++) {
+                       int pixel= ibuf->x*y + x;
+
+                       if(ibuf->rect_float) {
+                               float *rrgbf= ibuf->rect_float + pixel*4;
+
+                               *cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]);
+                       } else {
+                               char *rrgb= (char*)ibuf->rect + pixel*4;
+
+                               *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
+                       }
+
+                       cp++;
+               }
+       }
+
+       return pixels;
+}
+
 static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
                        int *width_r, int *height_r, float pos[2], int origin[2])
 {
        ImBuf *tmpibuf;
-       unsigned char *pixels, *fp;
-       int x, y, width, height;
+       unsigned char *pixels;
+       int width, height;
 
        width= (track->search_max[0]-track->search_min[0])*ibuf->x;
        height= (track->search_max[1]-track->search_min[1])*ibuf->y;
@@ -761,24 +788,7 @@ static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track,
        *width_r= width;
        *height_r= height;
 
-       fp= pixels= MEM_callocN(width*height*sizeof(unsigned char), "tracking byteBuf");
-       for(y= 0; y<(int)height; y++) {
-               for (x= 0; x<(int)width; x++) {
-                       int pixel= tmpibuf->x*y + x;
-
-                       if(tmpibuf->rect_float) {
-                               float *rrgbf= ibuf->rect_float + pixel*4;
-
-                               *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2]);
-                       } else {
-                               char *rrgb= (char*)tmpibuf->rect + pixel*4;
-
-                               *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2]);
-                       }
-
-                       fp++;
-               }
-       }
+       pixels= get_ucharbuf(tmpibuf);
 
        IMB_freeImBuf(tmpibuf);
 
@@ -1496,35 +1506,6 @@ void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float
 #endif
 }
 
-#ifdef WITH_LIBMV
-static unsigned char *get_ucharbuf(ImBuf *ibuf)
-{
-       int x, y;
-       unsigned char *pixels, *fp;
-
-       fp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf");
-       for(y= 0; y<ibuf->y; y++) {
-               for (x= 0; x<ibuf->x; x++) {
-                       int pixel= ibuf->x*y + x;
-
-                       if(ibuf->rect_float) {
-                               float *rrgbf= ibuf->rect_float + pixel*4;
-
-                               *fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2];
-                       } else {
-                               char *rrgb= (char*)ibuf->rect + pixel*4;
-
-                               *fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
-                       }
-
-                       fp++;
-               }
-       }
-
-       return pixels;
-}
-#endif
-
 static int point_in_stroke(bGPDstroke *stroke, float x, float y)
 {
        int i, prev;
index fdec96e28dbc12179378a49a471c5fbd758e399d..fc21f26fa32bce4980eadc4d525a2f1cdf26ef61 100644 (file)
@@ -86,7 +86,7 @@ typedef struct MovieClip {
 } MovieClip;
 
 typedef struct MovieClipScopes {
-       int ok;                                                 /* 1 means scopes are ok and re-calculaito is unneeded */
+       int ok;                                                 /* 1 means scopes are ok and recalculation is unneeded */
        int track_preview_height;               /* height of track preview widget */
        struct ImBuf *track_preview;    /* ImBuf displayed in track preview */
        float track_pos[2];                             /* sub-pizel position of marker in track ImBuf */
index 38f4ddc328bab1527400381b083089d206c884b6..14509ad3d7be1da8e198ad4f9a91f4880e15be23 100644 (file)
@@ -96,28 +96,23 @@ void rna_trackingTrack_name_set(PointerRNA *ptr, const char *value)
 
 static void rna_tracking_trackerPattern_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
-       MovieClip *clip= (MovieClip*)ptr->id.data;
-       MovieTrackingTrack *track;
+       MovieTrackingTrack *track= (MovieTrackingTrack *)ptr->data;
 
-       /* XXX: clamp modified marker only */
-       track= clip->tracking.tracks.first;
-       while(track) {
-               BKE_tracking_clamp_track(track, CLAMP_PAT_DIM);
-               track= track->next;
-       }
+       BKE_tracking_clamp_track(track, CLAMP_PAT_DIM);
 }
 
 static void rna_tracking_trackerSearch_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
-       MovieClip *clip= (MovieClip*)ptr->id.data;
-       MovieTrackingTrack *track;
+       MovieTrackingTrack *track= (MovieTrackingTrack *)ptr->data;
 
-       /* XXX: clamp modified marker only */
-       track= clip->tracking.tracks.first;
-       while(track) {
-               BKE_tracking_clamp_track(track, CLAMP_SEARCH_DIM);
-               track= track->next;
-       }
+       BKE_tracking_clamp_track(track, CLAMP_SEARCH_DIM);
+}
+
+static int rna_tracking_markers_length(PointerRNA *ptr)
+{
+       MovieTrackingTrack *track= (MovieTrackingTrack *)ptr->data;
+
+       return track->markersnr;
 }
 
 static float rna_trackingCamera_focal_get(PointerRNA *ptr)
@@ -475,6 +470,7 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        prop= RNA_def_property(srna, "markers", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_struct_type(prop, "MovieTrackingMarker");
        RNA_def_property_collection_sdna(prop, NULL, "markers", "markersnr");
+       RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, "rna_tracking_markers_length", NULL, NULL, NULL);
        RNA_def_property_ui_text(prop, "Markers", "Collection of markers in track");
 
        /* ** channels ** */