svn merge ^/trunk/blender -r42221:42245
authorCampbell Barton <ideasman42@gmail.com>
Tue, 29 Nov 2011 06:58:16 +0000 (06:58 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 29 Nov 2011 06:58:16 +0000 (06:58 +0000)
doc/python_api/rst/info_best_practice.rst
extern/libmv/libmv-capi.cpp
extern/libmv/libmv-capi.h
extern/libmv/libmv/tracking/sad.cc
release/scripts/startup/bl_ui/space_clip.py
release/scripts/startup/bl_ui/space_info.py
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/object/object_add.c
source/blender/editors/sculpt_paint/paint_vertex.c

index 180a9fd1aa3028e4b971ad3e5558a425938bd496..f4daed9ad9f0f54159a972240259d3091693368b 100644 (file)
@@ -39,7 +39,7 @@ As well as pep8 we have other conventions used for blender python scripts.
 
   .. code-block:: python
 
-     bpy.context.scene.render.file_format = 'PNG'
+     bpy.context.scene.render.image_settings.file_format = 'PNG'
      bpy.context.scene.render.filepath = "//render_out"
 
 * pep8 also defines that lines should not exceed 79 characters, we felt this is too restrictive so this is optional per script.
@@ -181,7 +181,7 @@ When removing many items in a large list this can provide a good speedup.
 Avoid Copying Lists
 ^^^^^^^^^^^^^^^^^^^
 
-When passing a list/dictionary to a function, it is faster to have the function modify the list rather then returning a new list so python dosn't have tp duplicate the list in memory.
+When passing a list/dictionary to a function, it is faster to have the function modify the list rather then returning a new list so python doesn't have to duplicate the list in memory.
 
 Functions that modify a list in-place are more efficient then functions that create new lists.
 
index f08aea9fbd1359c651359def49a920584e925963..aa05279d7312e344a1634b096c9b754d740a5a51 100644 (file)
@@ -297,16 +297,16 @@ void libmv_regionTrackerDestroy(libmv_RegionTracker *libmv_tracker)
 /* ************ Tracks ************ */
 
 void libmv_SADSamplePattern(unsigned char *image, int stride,
-                       float warp[3][2], unsigned char *pattern)
+                       float warp[3][2], unsigned char *pattern, int pattern_size)
 {
        libmv::mat32 mat32;
 
        memcpy(mat32.data, warp, sizeof(float)*3*2);
 
-       libmv::SamplePattern(image, stride, mat32, pattern, 16);
+       libmv::SamplePattern(image, stride, mat32, pattern, pattern_size);
 }
 
-float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, unsigned char *image, int stride,
+float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, int pattern_size, unsigned char *image, int stride,
                        int width, int height, float warp[3][2])
 {
        float result;
@@ -314,7 +314,7 @@ float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, unsig
 
        memcpy(mat32.data, warp, sizeof(float)*3*2);
 
-       result = libmv::Track(pattern, warped, 16, image, stride, width, height, &mat32, 16, 16);
+       result = libmv::Track(pattern, warped, pattern_size, image, stride, width, height, &mat32, 16, 16);
 
        memcpy(warp, mat32.data, sizeof(float)*3*2);
 
index 536f8a5f14cf4edb5fa631cd965c14ef5733d6ed..321593520b53eeb0ada73b80f6ecc14d47480f26 100644 (file)
@@ -50,8 +50,8 @@ void libmv_regionTrackerDestroy(struct libmv_RegionTracker *libmv_tracker);
 
 /* SAD Tracker */
 void libmv_SADSamplePattern(unsigned char *image, int stride,
-                       float warp[3][2], unsigned char *pattern);
-float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, unsigned char *image,
+                       float warp[3][2], unsigned char *pattern, int pattern_size);
+float libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *warped, int pattern_size, unsigned char *image,
                        int stride, int width, int height, float warp[3][2]);
 
 /* Tracks */
index 9b446bb4c35c0a61f5aed40248e97c136717622a..0876ef2fe731d52772f53b320612bf53905af3a3 100644 (file)
@@ -25,6 +25,7 @@
 #include "libmv/tracking/sad.h"
 #include <stdlib.h>
 #include <math.h>
+#include <stdio.h>
 
 namespace libmv {
 
@@ -78,15 +79,31 @@ void SamplePattern(ubyte* image, int stride, mat32 warp, ubyte* pattern, int siz
 
 #ifdef __SSE2__
 #include <emmintrin.h>
-static uint SAD(const ubyte* pattern, const ubyte* image, int stride, int size) {
+  static uint SAD(/*const*/ ubyte* pattern, /*const*/ ubyte* image, int stride, int size) {
+  uint sad = 0;
   __m128i a = _mm_setzero_si128();
+
   for(int i = 0; i < size; i++) {
-    for(int j = 0; j < size/16; j++) {
+    int j = 0;
+
+    for(j = 0; j < size/16; j++) {
+      if((i*size/16+j) % 32 == 0) {
+        sad += _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4);
+        a = _mm_setzero_si128();
+      }
+
       a = _mm_adds_epu16(a, _mm_sad_epu8( _mm_loadu_si128((__m128i*)(pattern+i*size+j*16)),
                                           _mm_loadu_si128((__m128i*)(image+i*stride+j*16))));
     }
+
+    for(j = j*16; j < size; j++) {
+      sad += abs((int)pattern[i*size+j] - image[i*stride+j]);
+    }
   }
-  return _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4);
+
+  sad += _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4);
+
+  return sad;
 }
 #else
 static uint SAD(const ubyte* pattern, const ubyte* image, int stride, int size) {
index d5171d119f7418aa9b29a8c7997400a1a532abd1..89e15fec828af363eb853202e9faebe5b32b65a2 100644 (file)
@@ -120,9 +120,9 @@ class CLIP_PT_tools_marker(Panel):
 
             col.separator()
 
-            col2 = col.column(align=True)
-            col2.prop(settings, "default_pattern_size")
-            col2.prop(settings, "default_search_size")
+            sub = col.column(align=True)
+            sub.prop(settings, "default_pattern_size")
+            sub.prop(settings, "default_search_size")
 
             col.label(text="Tracker:")
             col.prop(settings, "default_tracker", text="")
@@ -134,9 +134,9 @@ class CLIP_PT_tools_marker(Panel):
 
             col.separator()
 
-            col2 = col.column(align=True)
-            col2.prop(settings, "default_frames_limit")
-            col2.prop(settings, "default_margin")
+            sub = col.column(align=True)
+            sub.prop(settings, "default_frames_limit")
+            sub.prop(settings, "default_margin")
 
             col.label(text="Match:")
             col.prop(settings, "default_pattern_match", text="")
index eaf88fbd2959f0014c082ba431d9bf625f9e9a80..ab8975d60e84c540d21bbd5886b0e1aecec152bc 100644 (file)
@@ -361,7 +361,7 @@ class INFO_MT_help(Menu):
 
         layout = self.layout
 
-        layout.operator("wm.url_open", text="Manual", icon='HELP').url = 'http://wiki.blender.org/index.php/Doc:Manual'
+        layout.operator("wm.url_open", text="Manual", icon='HELP').url = 'http://wiki.blender.org/index.php/Doc:2.6/Manual'
         layout.operator("wm.url_open", text="Release Log", icon='URL').url = 'http://www.blender.org/development/release-logs/blender-260/'
 
         layout.separator()
index 4ebdd40a8fda6beef08209cd06158307d5fd54b6..ac104dfe206057c92b7de95327c6f19ea042a177 100644 (file)
@@ -1017,7 +1017,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        MLoop *mloop;
        MVert *mvert;
        float pmat[4][4], imat[3][3], (*orco)[3] = NULL, w;
-       int lay, oblay, totface, totloop, a;
+       int lay, oblay, totface, a;
        Scene *sce = NULL;
        Group *group = NULL;
        GroupObject *go = NULL;
@@ -1031,30 +1031,17 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
        em = me->edit_btmesh;
 
        if(em) {
-               int totvert;
                dm= editbmesh_get_derived_cage(scene, par, em, CD_MASK_BAREMESH);
-               
-               totface= dm->getNumFaces(dm);
-               mpoly= MEM_mallocN(sizeof(MPoly)*totface, "mface temp");
-               dm->copyPolyArray(dm, mpoly);
-
-               totloop= dm->numLoopData; /* BMESH_TODO, we should have an api function for this! */
-               mloop= MEM_mallocN(sizeof(MLoop)*totloop, "mloop temp");
-               dm->copyLoopArray(dm, mloop);
-
-               totvert= dm->getNumVerts(dm);
-               mvert= MEM_mallocN(sizeof(MVert)*totvert, "mvert temp");
-               dm->copyVertArray(dm, mvert);
        }
        else {
                dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH);
-
-               totface= dm->getNumFaces(dm);
-               mpoly= dm->getPolyArray(dm);
-               mloop= dm->getLoopArray(dm);
-               mvert= dm->getVertArray(dm);
        }
 
+       totface= dm->getNumFaces(dm);
+       mpoly= dm->getPolyArray(dm);
+       mloop= dm->getLoopArray(dm);
+       mvert= dm->getVertArray(dm);
+
        if(G.rendering) {
 
                orco= (float(*)[3])get_mesh_orco_verts(par);
@@ -1199,12 +1186,6 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
                if (sce)        base= base->next;       /* scene loop */
                else            go= go->next;           /* group loop */
        }
-       
-       if(em) {
-               MEM_freeN(mpoly);
-               MEM_freeN(mloop);
-               MEM_freeN(mvert);
-       }
 
        if(orco)
                MEM_freeN(orco);
index cb94e3f3ec1c50cd1fd06e6e7a872a6134efbefc..2d906a9199b045246d5c7567dd709d58bb59be93 100644 (file)
@@ -718,7 +718,7 @@ typedef struct TrackContext {
        float *patch;                   /* keyframed patch */
 
        /* ** SAD tracker ** */
-       int patsize;                    /* size of pattern (currently only 16x16 due to libmv side) */
+       int pattern_size;               /* size of pattern */
        unsigned char *pattern; /* keyframed pattern */
        unsigned char *warped;  /* warped version of reference */
 #else
@@ -786,12 +786,16 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
 
 #ifdef WITH_LIBMV
                                        {
+                                               float patx, paty;
+                                               patx= (int)((track->pat_max[0]-track->pat_min[0])*width);
+                                               paty= (int)((track->pat_max[1]-track->pat_min[1])*height);
+
                                                if(track->tracker==TRACKER_KLT) {
                                                        float search_size_x= (track->search_max[0]-track->search_min[0])*width;
                                                        float search_size_y= (track->search_max[1]-track->search_min[1])*height;
                                                        float pattern_size_x= (track->pat_max[0]-track->pat_min[0])*width;
                                                        float pattern_size_y= (track->pat_max[1]-track->pat_min[1])*height;
-                                                       int wndx, wndy;
+                                                       int wndx= (int)patx/2, wndy= (int)paty/2;
 
                                                        /* compute the maximum pyramid size */
                                                        float search_to_pattern_ratio= MIN2(search_size_x,  search_size_y)
@@ -804,13 +808,10 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
                                                         * than the search size */
                                                        int level= MIN2(track->pyramid_levels, max_pyramid_levels);
 
-                                                       wndx= (int)((track->pat_max[0]-track->pat_min[0])*width)/2;
-                                                       wndy= (int)((track->pat_max[1]-track->pat_min[1])*height)/2;
-
                                                        track_context.region_tracker= libmv_regionTrackerNew(100, level, MAX2(wndx, wndy));
                                                }
                                                else if(track->tracker==TRACKER_SAD) {
-                                                       /* nothing to initialize */
+                                                       track_context.pattern_size= MAX2(patx, paty);
                                                }
                                        }
 #endif
@@ -1093,10 +1094,10 @@ static void get_warped(TrackContext *track_context, int x, int y, int width, uns
 {
        int i, j;
 
-       for(i=0; i<track_context->patsize; i++) {
-               for(j=0; j<track_context->patsize; j++) {
-                       track_context->warped[i*track_context->patsize+j]=
-                                       image[(y+i-track_context->patsize/2)*width+x+j-track_context->patsize/2];
+       for(i=0; i<track_context->pattern_size; i++) {
+               for(j=0; j<track_context->pattern_size; j++) {
+                       track_context->warped[i*track_context->pattern_size+j]=
+                                       image[(y+i-track_context->pattern_size/2)*width+x+j-track_context->pattern_size/2];
                }
        }
 }
@@ -1226,13 +1227,12 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                        warp[2][0]= pos[0];
                                        warp[2][1]= pos[1];
 
-                                       /* pattern size is hardcoded to 16x16px in libmv */
-                                       track_context->patsize= 16;
-
-                                       if(!track_context->pattern)
-                                               track_context->pattern= MEM_callocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackking pattern");
+                                       if(!track_context->pattern) {
+                                               int square= track_context->pattern_size*track_context->pattern_size;
+                                               track_context->pattern= MEM_callocN(sizeof(unsigned char)*square, "trackking pattern");
+                                       }
 
-                                       libmv_SADSamplePattern(image, width, warp, track_context->pattern);
+                                       libmv_SADSamplePattern(image, width, warp, track_context->pattern, track_context->pattern_size);
 
                                        MEM_freeN(image);
                                        IMB_freeImBuf(ibuf);
@@ -1245,8 +1245,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
 
                                        ibuf= get_frame_ibuf(context, curfra);
 
-                                       if(track_context->warped==NULL)
-                                               track_context->warped= MEM_callocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackking warped");
+                                       if(track_context->warped==NULL) {
+                                               int square= track_context->pattern_size*track_context->pattern_size;
+                                               track_context->warped= MEM_callocN(sizeof(unsigned char)*square, "trackking warped");
+                                       }
 
                                        image_old= get_search_bytebuf(ibuf, track, marker, &width, &height, pos, origin);
                                        get_warped(track_context, pos[0], pos[1], width, image_old);
@@ -1260,7 +1262,8 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                warp[2][0]= pos[0];
                                warp[2][1]= pos[1];
 
-                               correlation= libmv_SADTrackerTrack(track_context->pattern, track_context->warped, image_new, width, width, height, warp);
+                               correlation= libmv_SADTrackerTrack(track_context->pattern, track_context->warped,
+                                                       track_context->pattern_size, image_new, width, width, height, warp);
 
                                x2= warp[2][0];
                                y2= warp[2][1];
index 57cd3ab853772dd270c68822f07ea8020e586aa5..aa44eca0605f5ac7b318cabd99696d97f9935ba0 100644 (file)
@@ -12690,6 +12690,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        {
                Scene *sce;
                MovieClip *clip;
+               bScreen *sc;
 
                for(sce = main->scene.first; sce; sce = sce->id.next) {
                        if (sce->r.im_format.depth == 0) {
@@ -12708,6 +12709,19 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                settings->default_search_size= 51;
                        }
                }
+
+               for (sc= main->screen.first; sc; sc= sc->id.next) {
+                       ScrArea *sa;
+                       for (sa= sc->areabase.first; sa; sa= sa->next) {
+                               SpaceLink *sl;
+                               for (sl= sa->spacedata.first; sl; sl= sl->next) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *v3d= (View3D *)sl;
+                                               v3d->flag2&= ~V3D_RENDER_SHADOW;
+                                       }
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index b168a9c4cf317aae01faa9beb3b9505ed92493d4..1d0e09c17c05d69e7b73a845995b752f88256832 100644 (file)
@@ -330,7 +330,9 @@ Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot,
 
        DAG_id_type_tag(bmain, ID_OB);
        DAG_scene_sort(bmain, scene);
-       ED_render_id_flush_update(bmain, ob->data);
+       if (ob->data) {
+               ED_render_id_flush_update(bmain, ob->data);
+       }
 
        if(enter_editmode)
                ED_object_enter_editmode(C, EM_IGNORE_LAYER);
@@ -1817,7 +1819,9 @@ Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag
        set_sca_new_poins_ob(ob);
 
        DAG_scene_sort(bmain, scene);
-       ED_render_id_flush_update(bmain, ob->data);
+       if (ob->data) {
+               ED_render_id_flush_update(bmain, ob->data);
+       }
 
        return basen;
 }
index 2382f34299eb70e5f1d3687e86a268b7b95b770e..a988fa6db02056c3a992b7ed9456ec56df95d48e 100644 (file)
@@ -1229,7 +1229,7 @@ static char *gen_lock_flags(Object* ob, int defbase_tot)
                lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0);
                is_locked |= lock_flags[i];
        }
-       if(is_locked){
+       if (is_locked) {
                return lock_flags;
        }
 
@@ -1352,12 +1352,12 @@ static float redistribute_change(MDeformVert *ndv, char *change_status, int chan
        /* left overs */
        return totchange;
 }
-
+static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_change);
 /* observe the changes made to the weights of groups.
  * make sure all locked groups on the vertex have the same deformation
  * by moving the changes made to groups onto other unlocked groups */
-static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot,
-                          const char *lock_flags, const char *vgroup_validmap, char do_auto_normalize)
+static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, char *defbase_sel,
+                          const char *lock_flags, const char *vgroup_validmap, char do_auto_normalize, char do_multipaint)
 {
        float totchange = 0.0f;
        float totchange_allowed = 0.0f;
@@ -1368,13 +1368,10 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot,
        unsigned int i;
        MDeformWeight *ndw;
        MDeformWeight *odw;
-       MDeformWeight *ndw2;
-       MDeformWeight *odw2;
-       int designatedw = -1;
-       int designatedw_changed = FALSE;
-       float storedw;
+
+       float changed_sum = 0.0f;
+
        char *change_status;
-       char new_weight_has_zero = FALSE;
 
        if(!lock_flags || !has_locked_group(ndv, lock_flags)) {
                return;
@@ -1387,7 +1384,7 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot,
                odw = defvert_find_index(odv, i);
                /* the weights are zero, so we can assume a lot */
                if(!ndw || !odw) {
-                       if (!lock_flags[i] && vgroup_validmap[i]){
+                       if (!lock_flags[i] && vgroup_validmap[i]) {
                                defvert_verify_index(odv, i);
                                defvert_verify_index(ndv, i);
                                total_valid++;
@@ -1401,16 +1398,11 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot,
                }
                else if(ndw->weight != odw->weight) { /* changed groups are handled here */
                        totchange += ndw->weight - odw->weight;
+                       changed_sum += ndw->weight;
                        change_status[i] = 2; /* was altered already */
                        total_changed++;
-                       if(ndw->weight == 0) {
-                               new_weight_has_zero = TRUE;
-                       }
-                       else if(designatedw == -1){
-                               designatedw = i;
-                       }
                } /* unchanged, unlocked bone groups are handled here */
-               else if (vgroup_validmap[i]){
+               else if (vgroup_validmap[i]) {
                        totchange_allowed += ndw->weight;
                        total_valid++;
                        change_status[i] = 1; /* can be altered while redistributing */
@@ -1448,30 +1440,12 @@ static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot,
                        totchange_allowed = redistribute_change(ndv, change_status, 1, -1, totchange_allowed, total_valid, do_auto_normalize);
                        left_over += totchange_allowed;
                        if(left_over) {
-                               /* more than one nonzero weights were changed with the same ratio, so keep them changed that way! */
-                               if(total_changed > 1 && !new_weight_has_zero && designatedw >= 0) {
-                                       /* this dw is special, it is used as a base to determine how to change the others */
-                                       ndw = defvert_find_index(ndv, designatedw);
-                                       odw = defvert_find_index(odv, designatedw);
-                                       storedw = ndw->weight;
-                                       for(i = 0; i < ndv->totweight; i++) {
-                                               if(ndv->dw[i].def_nr == designatedw) {
-                                                       continue;
-                                               }
-                                               ndw2 = &ndv->dw[i];
-                                               if(change_status[ndw2->def_nr] == 2) {
-                                                       odw2 = &odv->dw[i];
-                                                       
-                                                       if(!designatedw_changed) {
-                                                               ndw->weight = (-left_over + odw->weight + odw2->weight)/(1.0f + ndw2->weight/ndw->weight);
-                                                               designatedw_changed = TRUE;
-                                                       }
-                                                       ndw2->weight = ndw->weight * ndw2->weight / storedw;
-                                               }
-                                       }
-                               }
-                               /* a weight was changed to zero, only one weight was changed,
-                                * or designatedw is still -1 put weight back as evenly as possible */
+                               /* more than one nonzero weights were changed with the same ratio with multipaint, so keep them changed that way! */
+                               if(total_changed > 1 && do_multipaint) {
+                                       float undo_change = get_mp_change(ndv, defbase_sel, left_over);
+                                       multipaint_selection(ndv, undo_change, defbase_sel, defbase_tot);
+                               }       
+                               /* or designatedw is still -1 put weight back as evenly as possible */
                                else {
                                        redistribute_change(ndv, change_status, 2, -2, left_over, total_changed, do_auto_normalize);
                                }
@@ -1592,7 +1566,7 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi,
        }
        clamp_weights(dv);
 
-       enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap, wpi->do_auto_normalize);
+       enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags, wpi->vgroup_validmap, wpi->do_auto_normalize, wpi->do_multipaint);
 
        do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap, wpi->do_auto_normalize);