Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_tracking.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2340345c1c633c1d2cb0318608b17a355ff1d81c (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Blender Foundation,
 *                 Sergey Sharybin
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_tracking.c
 *  \ingroup RNA
 */


#include <stdlib.h>
#include <limits.h>

#include "MEM_guardedalloc.h"

#include "BLI_math.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"

#include "RNA_access.h"
#include "RNA_define.h"

#include "rna_internal.h"

#include "DNA_movieclip_types.h"
#include "DNA_object_types.h"   /* SELECT */
#include "DNA_scene_types.h"

#include "WM_types.h"

#ifdef RNA_RUNTIME

#include "BKE_depsgraph.h"
#include "BKE_node.h"

#include "IMB_imbuf.h"

#include "WM_api.h"

static MovieTrackingObject *tracking_object_from_track(MovieClip *clip,
                                                       MovieTrackingTrack *track)
{
	MovieTracking *tracking = &clip->tracking;
	ListBase *tracksbase = &tracking->tracks;
	/* TODO: it's a bit difficult to find list track came from knowing just
	 *       movie clip ID and MovieTracking structure, so keep this naive
	 *       search for a while */
	if (BLI_findindex(tracksbase, track) == -1) {
		MovieTrackingObject *object = tracking->objects.first;
		while (object) {
			if (BLI_findindex(&object->tracks, track) != -1) {
				return object;
			}
			object = object->next;
		}
	}
	return NULL;
}

static ListBase *tracking_tracksbase_from_track(MovieClip *clip,
                                                MovieTrackingTrack *track)
{
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingObject *object = tracking_object_from_track(clip, track);
	if (object != NULL) {
		return &object->tracks;
	}
	return &tracking->tracks;
}

static MovieTrackingObject *tracking_object_from_plane_track(
        MovieClip *clip,
        MovieTrackingPlaneTrack *plane_track)
{
	MovieTracking *tracking = &clip->tracking;
	ListBase *plane_tracks_base = &tracking->plane_tracks;
	/* TODO: it's a bit difficult to find list track came from knowing just
	 *       movie clip ID and MovieTracking structure, so keep this naive
	 *       search for a while */
	if (BLI_findindex(plane_tracks_base, plane_track) == -1) {
		MovieTrackingObject *object = tracking->objects.first;
		while (object) {
			if (BLI_findindex(&object->plane_tracks, plane_track) != -1) {
				return object;
			}
			object = object->next;
		}
	}
	return NULL;
}

static ListBase *tracking_tracksbase_from_plane_track(
        MovieClip *clip,
        MovieTrackingPlaneTrack *plane_track)
{
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingObject *object = tracking_object_from_plane_track(clip,
	                                                               plane_track);
	if (object != NULL) {
		return &object->plane_tracks;
	}
	return &tracking->plane_tracks;
}

static char *rna_tracking_path(PointerRNA *UNUSED(ptr))
{
	return BLI_sprintfN("tracking");
}

static void rna_tracking_defaultSettings_patternUpdate(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingSettings *settings = &tracking->settings;

	if (settings->default_search_size < settings->default_pattern_size)
		settings->default_search_size = settings->default_pattern_size;
}

static void rna_tracking_defaultSettings_searchUpdate(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingSettings *settings = &tracking->settings;

	if (settings->default_pattern_size > settings->default_search_size)
		settings->default_pattern_size = settings->default_search_size;
}

static char *rna_trackingTrack_path(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingTrack *track = (MovieTrackingTrack *)ptr->data;
	MovieTrackingObject *object = tracking_object_from_track(clip, track);
	char track_name_esc[sizeof(track->name) * 2];
	BLI_strescape(track_name_esc, track->name, sizeof(track_name_esc));
	if (object == NULL) {
		return BLI_sprintfN("tracking.tracks[\"%s\"]", track_name_esc);
	}
	else {
		char object_name_esc[sizeof(object->name) * 2];
		BLI_strescape(object_name_esc, object->name, sizeof(object_name_esc));
		return BLI_sprintfN("tracking.objects[\"%s\"].tracks[\"%s\"]",
		                    object_name_esc,
		                    track_name_esc);
	}
}

static void rna_trackingTracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	rna_iterator_listbase_begin(iter, &clip->tracking.tracks, NULL);
}

static void rna_trackingPlaneTracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	rna_iterator_listbase_begin(iter, &clip->tracking.plane_tracks, NULL);
}

static void rna_trackingObjects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	rna_iterator_listbase_begin(iter, &clip->tracking.objects, NULL);
}

static int rna_tracking_active_object_index_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	return clip->tracking.objectnr;
}

static void rna_tracking_active_object_index_set(PointerRNA *ptr, int value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	clip->tracking.objectnr = value;
	BKE_tracking_dopesheet_tag_update(&clip->tracking);
}

static void rna_tracking_active_object_index_range(PointerRNA *ptr, int *min, int *max,
                                                   int *UNUSED(softmin), int *UNUSED(softmax))
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	*min = 0;
	*max = max_ii(0, clip->tracking.tot_object - 1);
}

static PointerRNA rna_tracking_active_track_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking);

	return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingTrack, act_track);
}

static void rna_tracking_active_track_set(PointerRNA *ptr, PointerRNA value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingTrack *track = (MovieTrackingTrack *)value.data;
	ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
	int index = BLI_findindex(tracksbase, track);

	if (index != -1)
		clip->tracking.act_track = track;
	else
		clip->tracking.act_track = NULL;
}

static PointerRNA rna_tracking_active_plane_track_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingPlaneTrack *act_plane_track = BKE_tracking_plane_track_get_active(&clip->tracking);

	return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingPlaneTrack, act_plane_track);
}

static void rna_tracking_active_plane_track_set(PointerRNA *ptr, PointerRNA value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingPlaneTrack *plane_track = (MovieTrackingPlaneTrack *) value.data;
	ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking);
	int index = BLI_findindex(plane_tracks_base, plane_track);

	if (index != -1)
		clip->tracking.act_plane_track = plane_track;
	else
		clip->tracking.act_plane_track = NULL;
}

static void rna_trackingTrack_name_set(PointerRNA *ptr, const char *value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingTrack *track = (MovieTrackingTrack *)ptr->data;
	ListBase *tracksbase = tracking_tracksbase_from_track(clip, track);
	BLI_strncpy(track->name, value, sizeof(track->name));
	BKE_tracking_track_unique_name(tracksbase, track);
}

static int rna_trackingTrack_select_get(PointerRNA *ptr)
{
	MovieTrackingTrack *track = (MovieTrackingTrack *)ptr->data;

	return TRACK_SELECTED(track);
}

static void rna_trackingTrack_select_set(PointerRNA *ptr, int value)
{
	MovieTrackingTrack *track = (MovieTrackingTrack *)ptr->data;

	if (value) {
		track->flag |= SELECT;
		track->pat_flag |= SELECT;
		track->search_flag |= SELECT;
	}
	else {
		track->flag &= ~SELECT;
		track->pat_flag &= ~SELECT;
		track->search_flag &= ~SELECT;
	}
}

static void rna_trackingPlaneMarker_frame_set(PointerRNA *ptr, int value)
{
	MovieClip *clip = (MovieClip *) ptr->id.data;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingPlaneMarker *plane_marker = (MovieTrackingPlaneMarker *) ptr->data;
	MovieTrackingObject *tracking_object;
	bool found = false;
	MovieTrackingPlaneTrack *plane_track = NULL;

	for (tracking_object = tracking->objects.first;
	     tracking_object;
	     tracking_object = tracking_object->next)
	{
		ListBase *tracksbase = BKE_tracking_object_get_plane_tracks(tracking, tracking_object);

		for (plane_track = tracksbase->first;
		     plane_track;
		     plane_track = plane_track->next)
		{
			if (plane_marker >= plane_track->markers && plane_marker < plane_track->markers + plane_track->markersnr) {
				found = true;
				break;
			}
		}

		if (found) {
			break;
		}
	}

	if (found) {
		MovieTrackingPlaneMarker new_plane_marker = *plane_marker;
		new_plane_marker.framenr = value;

		BKE_tracking_plane_marker_delete(plane_track, plane_marker->framenr);
		BKE_tracking_plane_marker_insert(plane_track, &new_plane_marker);
	}
}

static char *rna_trackingPlaneTrack_path(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingPlaneTrack *plane_track = (MovieTrackingPlaneTrack *)ptr->data;
	char track_name_esc[sizeof(plane_track->name) * 2];
	MovieTrackingObject *object = tracking_object_from_plane_track(clip, plane_track);
	BLI_strescape(track_name_esc, plane_track->name, sizeof(track_name_esc));
	if (object == NULL) {
		return BLI_sprintfN("tracking.plane_tracks[\"%s\"]", track_name_esc);
	}
	else {
		char object_name_esc[sizeof(object->name) * 2];
		BLI_strescape(object_name_esc, object->name, sizeof(object_name_esc));
		return BLI_sprintfN("tracking.objects[\"%s\"].plane_tracks[\"%s\"]",
		                    object_name_esc,
		                    track_name_esc);
	}
}

static void rna_trackingPlaneTrack_name_set(PointerRNA *ptr, const char *value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingPlaneTrack *plane_track = (MovieTrackingPlaneTrack *)ptr->data;
	ListBase *plane_tracks_base = tracking_tracksbase_from_plane_track(clip, plane_track);
	BLI_strncpy(plane_track->name, value, sizeof(plane_track->name));
	BKE_tracking_plane_track_unique_name(plane_tracks_base, plane_track);
}

static char *rna_trackingCamera_path(PointerRNA *UNUSED(ptr))
{
	return BLI_sprintfN("tracking.camera");
}

static float rna_trackingCamera_focal_mm_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingCamera *camera = &clip->tracking.camera;
	float val = camera->focal;

	if (clip->lastsize[0])
		val = val * camera->sensor_width / (float)clip->lastsize[0];

	return val;
}

static void rna_trackingCamera_focal_mm_set(PointerRNA *ptr, float value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingCamera *camera = &clip->tracking.camera;

	if (clip->lastsize[0])
		value = clip->lastsize[0] * value / camera->sensor_width;

	if (value >= 0.0001f)
		camera->focal = value;
}

static char *rna_trackingStabilization_path(PointerRNA *UNUSED(ptr))
{
	return BLI_sprintfN("tracking.stabilization");
}

static int rna_track_2d_stabilization(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	MovieTrackingTrack *track = (MovieTrackingTrack *)data;

	if ((track->flag & TRACK_USE_2D_STAB) == 0)
		return 1;

	return 0;
}

static int rna_track_2d_stabilization_rotation(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	MovieTrackingTrack *track = (MovieTrackingTrack *)data;

	if ((track->flag & TRACK_USE_2D_STAB_ROT) == 0)
		return 1;

	return 0;
}

static void rna_tracking_stabTracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	rna_iterator_listbase_begin(iter, &clip->tracking.tracks, rna_track_2d_stabilization);
}

static int rna_tracking_stabTracks_active_index_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	return clip->tracking.stabilization.act_track;
}

static void rna_tracking_stabTracks_active_index_set(PointerRNA *ptr, int value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	clip->tracking.stabilization.act_track = value;
}

static void rna_tracking_stabTracks_active_index_range(PointerRNA *ptr, int *min, int *max,
                                                       int *UNUSED(softmin), int *UNUSED(softmax))
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	*min = 0;
	*max = max_ii(0, clip->tracking.stabilization.tot_track - 1);
}

static void rna_tracking_stabRotTracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	rna_iterator_listbase_begin(iter, &clip->tracking.tracks, rna_track_2d_stabilization_rotation);
}

static int rna_tracking_stabRotTracks_active_index_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	return clip->tracking.stabilization.act_rot_track;
}

static void rna_tracking_stabRotTracks_active_index_set(PointerRNA *ptr, int value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	clip->tracking.stabilization.act_rot_track = value;
}

static void rna_tracking_stabRotTracks_active_index_range(PointerRNA *ptr, int *min, int *max,
                                                          int *UNUSED(softmin), int *UNUSED(softmax))
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	*min = 0;
	*max = max_ii(0, clip->tracking.stabilization.tot_rot_track - 1);
}

static void rna_tracking_flushUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	nodeUpdateID(scene->nodetree, &clip->id);

	WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
	WM_main_add_notifier(NC_SCENE, NULL);
	DAG_id_tag_update(&clip->id, 0);
}

static void rna_tracking_resetIntrinsics(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTracking *tracking = &clip->tracking;

	if (tracking->camera.intrinsics) {
		BKE_tracking_distortion_free(tracking->camera.intrinsics);
		tracking->camera.intrinsics = NULL;
	}
}

static void rna_trackingObject_tracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieTrackingObject *object = (MovieTrackingObject *)ptr->data;

	if (object->flag & TRACKING_OBJECT_CAMERA) {
		MovieClip *clip = (MovieClip *)ptr->id.data;

		rna_iterator_listbase_begin(iter, &clip->tracking.tracks, NULL);
	}
	else {
		rna_iterator_listbase_begin(iter, &object->tracks, NULL);
	}
}

static void rna_trackingObject_plane_tracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	MovieTrackingObject *object = (MovieTrackingObject *)ptr->data;

	if (object->flag & TRACKING_OBJECT_CAMERA) {
		MovieClip *clip = (MovieClip *)ptr->id.data;

		rna_iterator_listbase_begin(iter, &clip->tracking.plane_tracks, NULL);
	}
	else {
		rna_iterator_listbase_begin(iter, &object->plane_tracks, NULL);
	}
}

static PointerRNA rna_trackingObject_reconstruction_get(PointerRNA *ptr)
{
	MovieTrackingObject *object = (MovieTrackingObject *)ptr->data;

	if (object->flag & TRACKING_OBJECT_CAMERA) {
		MovieClip *clip = (MovieClip *)ptr->id.data;

		return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingReconstruction, &clip->tracking.reconstruction);
	}
	else {
		return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingReconstruction, &object->reconstruction);
	}
}

static PointerRNA rna_tracking_active_object_get(PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingObject *object = BLI_findlink(&clip->tracking.objects, clip->tracking.objectnr);

	return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingObject, object);
}

static void rna_tracking_active_object_set(PointerRNA *ptr, PointerRNA value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingObject *object = (MovieTrackingObject *)value.data;
	int index = BLI_findindex(&clip->tracking.objects, object);

	if (index != -1) clip->tracking.objectnr = index;
	else clip->tracking.objectnr = 0;
}

static void rna_trackingObject_name_set(PointerRNA *ptr, const char *value)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingObject *object = (MovieTrackingObject *)ptr->data;

	BLI_strncpy(object->name, value, sizeof(object->name));

	BKE_tracking_object_unique_name(&clip->tracking, object);
}

static void rna_trackingObject_flushUpdate(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;

	WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, NULL);
	DAG_id_tag_update(&clip->id, 0);
}

static void rna_trackingMarker_frame_set(PointerRNA *ptr, int value)
{
	MovieClip *clip = (MovieClip *) ptr->id.data;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingMarker *marker = (MovieTrackingMarker *) ptr->data;
	MovieTrackingObject *tracking_object;
	bool found = false;
	MovieTrackingTrack *track = NULL;

	for (tracking_object = tracking->objects.first;
	     tracking_object;
	     tracking_object = tracking_object->next)
	{
		ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);

		for (track = tracksbase->first;
		     track;
		     track = track->next)
		{
			if (marker >= track->markers && marker < track->markers + track->markersnr) {
				found = true;
				break;
			}
		}

		if (found) {
			break;
		}
	}

	if (found) {
		MovieTrackingMarker new_marker = *marker;
		new_marker.framenr = value;

		BKE_tracking_marker_delete(track, marker->framenr);
		BKE_tracking_marker_insert(track, &new_marker);
	}
}

static void rna_tracking_markerPattern_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieTrackingMarker *marker = (MovieTrackingMarker *)ptr->data;

	BKE_tracking_marker_clamp(marker, CLAMP_PAT_DIM);
}

static void rna_tracking_markerSearch_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieTrackingMarker *marker = (MovieTrackingMarker *)ptr->data;

	BKE_tracking_marker_clamp(marker, CLAMP_SEARCH_DIM);
}

static void rna_tracking_markerPattern_boundbox_get(PointerRNA *ptr, float *values)
{
	MovieTrackingMarker *marker = (MovieTrackingMarker *)ptr->data;
	float min[2], max[2];

	BKE_tracking_marker_pattern_minmax(marker, min, max);

	copy_v2_v2(values, min);
	copy_v2_v2(values + 2, max);
}

static void rna_trackingDopesheet_tagUpdate(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	MovieClip *clip = (MovieClip *)ptr->id.data;
	MovieTrackingDopesheet *dopesheet = &clip->tracking.dopesheet;

	dopesheet->ok = 0;
}

/* API */

static MovieTrackingTrack *add_track_to_base(MovieClip *clip, MovieTracking *tracking, ListBase *tracksbase,
                                             const char *name, int frame)
{
	int width, height;
	MovieClipUser user = {0};
	MovieTrackingTrack *track;

	user.framenr = 1;

	BKE_movieclip_get_size(clip, &user, &width, &height);

	track = BKE_tracking_track_add(tracking, tracksbase, 0, 0, frame, width, height);

	if (name && name[0]) {
		BLI_strncpy(track->name, name, sizeof(track->name));
		BKE_tracking_track_unique_name(tracksbase, track);
	}

	return track;
}

static MovieTrackingTrack *rna_trackingTracks_new(ID *id, MovieTracking *tracking, const char *name, int frame)
{
	MovieClip *clip = (MovieClip *) id;
	MovieTrackingTrack *track;

	track = add_track_to_base(clip, tracking, &tracking->tracks, name, frame);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, clip);

	return track;
}

static MovieTrackingTrack *rna_trackingObject_tracks_new(ID *id, MovieTrackingObject *object, const char *name,
                                                         int frame)
{
	MovieClip *clip = (MovieClip *) id;
	ListBase *tracksbase = &object->tracks;
	MovieTrackingTrack *track;

	if (object->flag & TRACKING_OBJECT_CAMERA)
		tracksbase = &clip->tracking.tracks;

	track = add_track_to_base(clip, &clip->tracking, tracksbase, name, frame);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);

	return track;
}

static MovieTrackingObject *rna_trackingObject_new(MovieTracking *tracking, const char *name)
{
	MovieTrackingObject *object = BKE_tracking_object_add(tracking, name);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);

	return object;
}

static void rna_trackingObject_remove(MovieTracking *tracking, ReportList *reports, PointerRNA *object_ptr)
{
	MovieTrackingObject *object = object_ptr->data;
	if (BKE_tracking_object_delete(tracking, object) == false) {
		BKE_reportf(reports, RPT_ERROR, "MovieTracking '%s' cannot be removed", object->name);
		return;
	}

	RNA_POINTER_INVALIDATE(object_ptr);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);
}

static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr, int exact)
{
	if (exact)
		return BKE_tracking_marker_get_exact(track, framenr);
	else
		return BKE_tracking_marker_get(track, framenr);
}

static MovieTrackingMarker *rna_trackingMarkers_insert_frame(MovieTrackingTrack *track, int framenr, float *co)
{
	MovieTrackingMarker marker, *new_marker;

	memset(&marker, 0, sizeof(marker));
	marker.framenr = framenr;
	copy_v2_v2(marker.pos, co);

	/* a bit arbitrary, but better than creating markers with zero pattern
	 * which is forbidden actually
	 */
	copy_v2_v2(marker.pattern_corners[0], track->markers[0].pattern_corners[0]);
	copy_v2_v2(marker.pattern_corners[1], track->markers[0].pattern_corners[1]);
	copy_v2_v2(marker.pattern_corners[2], track->markers[0].pattern_corners[2]);
	copy_v2_v2(marker.pattern_corners[3], track->markers[0].pattern_corners[3]);

	new_marker = BKE_tracking_marker_insert(track, &marker);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);

	return new_marker;
}

static void rna_trackingMarkers_delete_frame(MovieTrackingTrack *track, int framenr)
{
	if (track->markersnr == 1)
		return;

	BKE_tracking_marker_delete(track, framenr);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);
}

static MovieTrackingPlaneMarker *rna_trackingPlaneMarkers_find_frame(MovieTrackingPlaneTrack *plane_track,
                                                                     int framenr, int exact)
{
	if (exact)
		return BKE_tracking_plane_marker_get_exact(plane_track, framenr);
	else
		return BKE_tracking_plane_marker_get(plane_track, framenr);
}

static MovieTrackingPlaneMarker *rna_trackingPlaneMarkers_insert_frame(MovieTrackingPlaneTrack *plane_track,
                                                                       int framenr)
{
	MovieTrackingPlaneMarker plane_marker, *new_plane_marker;

	memset(&plane_marker, 0, sizeof(plane_marker));
	plane_marker.framenr = framenr;

	/* a bit arbitrary, but better than creating zero markers */
	copy_v2_v2(plane_marker.corners[0], plane_track->markers[0].corners[0]);
	copy_v2_v2(plane_marker.corners[1], plane_track->markers[0].corners[1]);
	copy_v2_v2(plane_marker.corners[2], plane_track->markers[0].corners[2]);
	copy_v2_v2(plane_marker.corners[3], plane_track->markers[0].corners[3]);

	new_plane_marker = BKE_tracking_plane_marker_insert(plane_track, &plane_marker);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);

	return new_plane_marker;
}

static void rna_trackingPlaneMarkers_delete_frame(MovieTrackingPlaneTrack *plane_track, int framenr)
{
	if (plane_track->markersnr == 1)
		return;

	BKE_tracking_plane_marker_delete(plane_track, framenr);

	WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);
}

static MovieTrackingObject *find_object_for_reconstruction(MovieTracking *tracking,
                                                           MovieTrackingReconstruction *reconstruction)
{
	MovieTrackingObject *object;

	for (object = tracking->objects.first; object; object = object->next) {
		if (object->flag & TRACKING_OBJECT_CAMERA) {
			if (&tracking->reconstruction == reconstruction) {
				return object;
			}
		}
		else if (&object->reconstruction == reconstruction) {
			return object;
		}
	}

	return NULL;
}

static MovieReconstructedCamera *rna_trackingCameras_find_frame(ID *id, MovieTrackingReconstruction *reconstruction, int framenr)
{
	MovieClip *clip = (MovieClip *) id;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingObject *object = find_object_for_reconstruction(tracking, reconstruction);
	return BKE_tracking_camera_get_reconstructed(tracking, object, framenr);
}

static void rna_trackingCameras_matrix_from_frame(ID *id, MovieTrackingReconstruction *reconstruction, int framenr, float matrix[16])
{
	float mat[4][4];

	MovieClip *clip = (MovieClip *) id;
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingObject *object = find_object_for_reconstruction(tracking, reconstruction);
	BKE_tracking_camera_get_reconstructed_interpolate(tracking, object, framenr, mat);

	memcpy(matrix, mat, sizeof(float) * 16);
}

#else

static EnumPropertyItem tracker_motion_model[] = {
	{TRACK_MOTION_MODEL_HOMOGRAPHY, "Perspective", 0, "Perspective",
	              "Search for markers that are perspectively deformed (homography) between frames"},
	{TRACK_MOTION_MODEL_AFFINE, "Affine", 0, "Affine",
	              "Search for markers that are affine-deformed (t, r, k, and skew) between frames"},
	{TRACK_MOTION_MODEL_TRANSLATION_ROTATION_SCALE, "LocRotScale", 0, "LocRotScale",
	              "Search for markers that are translated, rotated, and scaled between frames"},
	{TRACK_MOTION_MODEL_TRANSLATION_SCALE, "LocScale", 0, "LocScale",
	              "Search for markers that are translated and scaled between frames"},
	{TRACK_MOTION_MODEL_TRANSLATION_ROTATION, "LocRot", 0, "LocRot",
	              "Search for markers that are translated and rotated between frames"},
	{TRACK_MOTION_MODEL_TRANSLATION, "Loc", 0, "Loc",
	              "Search for markers that are translated between frames"},
	{0, NULL, 0, NULL, NULL}
};

static EnumPropertyItem pattern_match_items[] = {
	{TRACK_MATCH_KEYFRAME, "KEYFRAME", 0, "Keyframe", "Track pattern from keyframe to next frame"},
	{TRACK_MATCH_PREVFRAME, "PREV_FRAME", 0, "Previous frame", "Track pattern from current frame to next frame"},
	{0, NULL, 0, NULL, NULL}
};

static void rna_def_trackingSettings(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem speed_items[] = {
		{0, "FASTEST", 0, "Fastest", "Track as fast as it's possible"},
		{TRACKING_SPEED_DOUBLE, "DOUBLE", 0, "Double", "Track with double speed"},
		{TRACKING_SPEED_REALTIME, "REALTIME", 0, "Realtime", "Track with realtime speed"},
		{TRACKING_SPEED_HALF, "HALF", 0, "Half", "Track with half of realtime speed"},
		{TRACKING_SPEED_QUARTER, "QUARTER", 0, "Quarter", "Track with quarter of realtime speed"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem cleanup_items[] = {
		{TRACKING_CLEAN_SELECT, "SELECT", 0, "Select", "Select unclean tracks"},
		{TRACKING_CLEAN_DELETE_TRACK, "DELETE_TRACK", 0, "Delete Track", "Delete unclean tracks"},
		{TRACKING_CLEAN_DELETE_SEGMENT, "DELETE_SEGMENTS", 0, "Delete Segments", "Delete unclean segments of tracks"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem refine_items[] = {
		{0, "NONE", 0, "Nothing", "Do not refine camera intrinsics"},
		{REFINE_FOCAL_LENGTH, "FOCAL_LENGTH", 0, "Focal Length", "Refine focal length"},
		{REFINE_FOCAL_LENGTH | REFINE_RADIAL_DISTORTION_K1, "FOCAL_LENGTH_RADIAL_K1", 0, "Focal length, K1",
		 "Refine focal length and radial distortion K1"},
		{REFINE_FOCAL_LENGTH |
		 REFINE_RADIAL_DISTORTION_K1 |
		 REFINE_RADIAL_DISTORTION_K2, "FOCAL_LENGTH_RADIAL_K1_K2", 0, "Focal length, K1, K2",
		 "Refine focal length and radial distortion K1 and K2"},
		{REFINE_FOCAL_LENGTH |
		 REFINE_PRINCIPAL_POINT |
		 REFINE_RADIAL_DISTORTION_K1 |
		 REFINE_RADIAL_DISTORTION_K2, "FOCAL_LENGTH_PRINCIPAL_POINT_RADIAL_K1_K2", 0,
		 "Focal Length, Optical Center, K1, K2",
		 "Refine focal length, optical center and radial distortion K1 and K2"},
		{REFINE_FOCAL_LENGTH |
		 REFINE_PRINCIPAL_POINT, "FOCAL_LENGTH_PRINCIPAL_POINT", 0, "Focal Length, Optical Center",
		 "Refine focal length and optical center"},
		{REFINE_RADIAL_DISTORTION_K1 |
		 REFINE_RADIAL_DISTORTION_K2, "RADIAL_K1_K2", 0, "K1, K2",
		 "Refine radial distortion K1 and K2"},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "MovieTrackingSettings", NULL);
	RNA_def_struct_ui_text(srna, "Movie tracking settings", "Match moving settings");

	/* speed */
	prop = RNA_def_property(srna, "speed", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, speed_items);
	RNA_def_property_ui_text(prop, "Speed",
	                         "Limit speed of tracking to make visual feedback easier "
	                         "(this does not affect the tracking quality)");

	/* use keyframe selection */
	prop = RNA_def_property(srna, "use_keyframe_selection", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "reconstruction_flag", TRACKING_USE_KEYFRAME_SELECTION);
	RNA_def_property_ui_text(prop, "Keyframe Selection",
	                         "Automatically select keyframes when solving camera/object motion");

	/* intrinsics refinement during bundle adjustment */
	prop = RNA_def_property(srna, "refine_intrinsics", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "refine_camera_intrinsics");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, refine_items);
	RNA_def_property_ui_text(prop, "Refine", "Refine intrinsics during camera solving");

	/* tool settings */

	/* distance */
	prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "dist");
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_text(prop, "Distance", "Distance between two bundles used for scene scaling");

	/* frames count */
	prop = RNA_def_property(srna, "clean_frames", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "clean_frames");
	RNA_def_property_range(prop, 0, INT_MAX);
	RNA_def_property_ui_text(prop, "Tracked Frames",
	                         "Effect on tracks which are tracked less than the specified amount of frames");

	/* re-projection error */
	prop = RNA_def_property(srna, "clean_error", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "clean_error");
	RNA_def_property_range(prop, 0, FLT_MAX);
	RNA_def_property_ui_text(prop, "Reprojection Error", "Effect on tracks which have a larger re-projection error");

	/* cleanup action */
	prop = RNA_def_property(srna, "clean_action", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "clean_action");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, cleanup_items);
	RNA_def_property_ui_text(prop, "Action", "Cleanup action to execute");

	/* ** default tracker settings ** */
	prop = RNA_def_property(srna, "show_default_expanded", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_SETTINGS_SHOW_DEFAULT_EXPANDED);
	RNA_def_property_ui_text(prop, "Show Expanded", "Show default options expanded in the user interface");
	RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);

	/* ** extra tracker settings ** */
	prop = RNA_def_property(srna, "show_extra_expanded", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_SETTINGS_SHOW_EXTRA_EXPANDED);
	RNA_def_property_ui_text(prop, "Show Expanded", "Show extra options expanded in the user interface");
	RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);

	/* solver settings */
	prop = RNA_def_property(srna, "use_tripod_solver", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "motion_flag", TRACKING_MOTION_TRIPOD);
	RNA_def_property_ui_text(prop, "Tripod Motion",
	                         "Use special solver to track a stable camera position, such as a tripod");

	/* default_limit_frames */
	prop = RNA_def_property(srna, "default_frames_limit", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "default_frames_limit");
	RNA_def_property_range(prop, 0, SHRT_MAX);
	RNA_def_property_ui_text(prop, "Frames Limit", "Every tracking cycle, this number of frames are tracked");

	/* default_pattern_match */
	prop = RNA_def_property(srna, "default_pattern_match", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_sdna(prop, NULL, "default_pattern_match");
	RNA_def_property_enum_items(prop, pattern_match_items);
	RNA_def_property_ui_text(prop, "Pattern Match",
	                         "Track pattern from given frame when tracking marker to next frame");

	/* default_margin */
	prop = RNA_def_property(srna, "default_margin", PROP_INT, PROP_PIXEL);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "default_margin");
	RNA_def_property_range(prop, 0, 300);
	RNA_def_property_ui_text(prop, "Margin", "Default distance from image boundary at which marker stops tracking");

	/* default_tracking_motion_model */
	prop = RNA_def_property(srna, "default_motion_model", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, tracker_motion_model);
	RNA_def_property_ui_text(prop, "Motion model", "Default motion model to use for tracking");

	/* default_use_brute */
	prop = RNA_def_property(srna, "use_default_brute", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_BRUTE);
	RNA_def_property_ui_text(prop, "Prepass", "Use a brute-force translation-only initialization when tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* default_use_brute */
	prop = RNA_def_property(srna, "use_default_mask", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_MASK);
	RNA_def_property_ui_text(prop, "Use Mask",
	                         "Use a grease pencil data-block as a mask to use only specified areas of pattern "
	                         "when tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* default_use_normalization */
	prop = RNA_def_property(srna, "use_default_normalization", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_NORMALIZATION);
	RNA_def_property_ui_text(prop, "Normalize", "Normalize light intensities while tracking (slower)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* default minmal correlation */
	prop = RNA_def_property(srna, "default_correlation_min", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "default_minimum_correlation");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.05, 3);
	RNA_def_property_ui_text(prop, "Correlation",
	                         "Default minimum value of correlation between matched pattern and reference "
	                         "that is still treated as successful tracking");

	/* default pattern size */
	prop = RNA_def_property(srna, "default_pattern_size", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "default_pattern_size");
	RNA_def_property_range(prop, 5, 1000);
	RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_patternUpdate");
	RNA_def_property_ui_text(prop, "Pattern Size", "Size of pattern area for newly created tracks");

	/* default search size */
	prop = RNA_def_property(srna, "default_search_size", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "default_search_size");
	RNA_def_property_range(prop, 5, 1000);
	RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_searchUpdate");
	RNA_def_property_ui_text(prop, "Search Size", "Size of search area for newly created tracks");

	/* default use_red_channel */
	prop = RNA_def_property(srna, "use_default_red_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "default_flag", TRACK_DISABLE_RED);
	RNA_def_property_ui_text(prop, "Use Red Channel", "Use red channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* default_use_green_channel */
	prop = RNA_def_property(srna, "use_default_green_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "default_flag", TRACK_DISABLE_GREEN);
	RNA_def_property_ui_text(prop, "Use Green Channel", "Use green channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* default_use_blue_channel */
	prop = RNA_def_property(srna, "use_default_blue_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "default_flag", TRACK_DISABLE_BLUE);
	RNA_def_property_ui_text(prop, "Use Blue Channel", "Use blue channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	prop = RNA_def_property(srna, "default_weight", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Weight", "Influence of newly created track on a final solution");

	/* ** object tracking ** */

	/* object distance */
	prop = RNA_def_property(srna, "object_distance", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "object_distance");
	RNA_def_property_ui_text(prop, "Distance", "Distance between two bundles used for object scaling");
	RNA_def_property_range(prop, 0.001, 10000);
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_range(prop, 0.001, 10000.0, 1, 3);
}

static void rna_def_trackingCamera(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem distortion_model_items[] = {
		{TRACKING_DISTORTION_MODEL_POLYNOMIAL, "POLYNOMIAL", 0, "Polynomial", "Radial distortion model which fits common cameras"},
		{TRACKING_DISTORTION_MODEL_DIVISION, "DIVISION", 0, "Divisions", "Division distortion model which "
		                                                                 "better represents wide-angle cameras"},
		{0, NULL, 0, NULL, NULL}
	};

	static EnumPropertyItem camera_units_items[] = {
		{CAMERA_UNITS_PX, "PIXELS", 0, "px", "Use pixels for units of focal length"},
		{CAMERA_UNITS_MM, "MILLIMETERS", 0, "mm", "Use millimeters for units of focal length"},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "MovieTrackingCamera", NULL);
	RNA_def_struct_path_func(srna, "rna_trackingCamera_path");
	RNA_def_struct_ui_text(srna, "Movie tracking camera data", "Match-moving camera data for tracking");

	/* Distortion model */
	prop = RNA_def_property(srna, "distortion_model", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, distortion_model_items);
	RNA_def_property_ui_text(prop, "Distortion Model", "Distortion model used for camera lenses");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_resetIntrinsics");

	/* Sensor */
	prop = RNA_def_property(srna, "sensor_width", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "sensor_width");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0.0f, 500.0f);
	RNA_def_property_ui_text(prop, "Sensor", "Width of CCD sensor in millimeters");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* Focal Length */
	prop = RNA_def_property(srna, "focal_length", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "focal");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0.0001f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0001f, 5000.0f, 1, 2);
	RNA_def_property_float_funcs(prop, "rna_trackingCamera_focal_mm_get", "rna_trackingCamera_focal_mm_set", NULL);
	RNA_def_property_ui_text(prop, "Focal Length", "Camera's focal length");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* Focal Length in pixels */
	prop = RNA_def_property(srna, "focal_length_pixels", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "focal");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 5000.f, 1, 2);
	RNA_def_property_ui_text(prop, "Focal Length", "Camera's focal length");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* Units */
	prop = RNA_def_property(srna, "units", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "units");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, camera_units_items);
	RNA_def_property_ui_text(prop, "Units", "Units used for camera focal length");

	/* Principal Point */
	prop = RNA_def_property(srna, "principal", PROP_FLOAT, PROP_PIXEL);
	RNA_def_property_array(prop, 2);
	RNA_def_property_float_sdna(prop, NULL, "principal");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Principal Point", "Optical center of lens");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* Radial distortion parameters */
	prop = RNA_def_property(srna, "k1", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "k1");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_range(prop, -10, 10, 0.1, 3);
	RNA_def_property_ui_text(prop, "K1", "First coefficient of third order polynomial radial distortion");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_flushUpdate");

	prop = RNA_def_property(srna, "k2", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "k2");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_range(prop, -10, 10, 0.1, 3);
	RNA_def_property_ui_text(prop, "K2", "Second coefficient of third order polynomial radial distortion");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_flushUpdate");

	prop = RNA_def_property(srna, "k3", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "k3");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_range(prop, -10, 10, 0.1, 3);
	RNA_def_property_ui_text(prop, "K3", "Third coefficient of third order polynomial radial distortion");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_flushUpdate");

	/* Division distortion parameters */
	prop = RNA_def_property(srna, "division_k1", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_range(prop, -10, 10, 0.1, 3);
	RNA_def_property_ui_text(prop, "K1", "First coefficient of second order division distortion");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_flushUpdate");

	prop = RNA_def_property(srna, "division_k2", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_range(prop, -10, 10, 0.1, 3);
	RNA_def_property_ui_text(prop, "K2", "First coefficient of second order division distortion");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_flushUpdate");

	/* pixel aspect */
	prop = RNA_def_property(srna, "pixel_aspect", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_float_sdna(prop, NULL, "pixel_aspect");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0.1f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.1f, 5000.0f, 1, 2);
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_text(prop, "Pixel Aspect Ratio", "Pixel aspect ratio");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");
}

static void rna_def_trackingMarker(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static int boundbox_dimsize[] = {2, 2};

	srna = RNA_def_struct(brna, "MovieTrackingMarker", NULL);
	RNA_def_struct_ui_text(srna, "Movie tracking marker data", "Match-moving marker data for tracking");

	/* position */
	prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_float_sdna(prop, NULL, "pos");
	RNA_def_property_ui_text(prop, "Position", "Marker position at frame in normalized coordinates");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* frame */
	prop = RNA_def_property(srna, "frame", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "framenr");
	RNA_def_property_ui_text(prop, "Frame", "Frame number marker is keyframed on");
	RNA_def_property_int_funcs(prop, NULL, "rna_trackingMarker_frame_set", NULL);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* enable */
	prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", MARKER_DISABLED);
	RNA_def_property_ui_text(prop, "Mode", "Is marker muted for current frame");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* pattern */
	prop = RNA_def_property(srna, "pattern_corners", PROP_FLOAT, PROP_MATRIX);
	RNA_def_property_float_sdna(prop, NULL, "pattern_corners");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_ui_text(prop, "Pattern Corners",
	                         "Array of coordinates which represents pattern's corners in "
	                         "normalized coordinates relative to marker position");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_markerPattern_update");

	prop = RNA_def_property(srna, "pattern_bound_box", PROP_FLOAT, PROP_NONE);
	RNA_def_property_multi_array(prop, 2, boundbox_dimsize);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_float_funcs(prop, "rna_tracking_markerPattern_boundbox_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Pattern Bounding Box", "Pattern area bounding box in normalized coordinates");

	/* search */
	prop = RNA_def_property(srna, "search_min", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_float_sdna(prop, NULL, "search_min");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Search Min",
	                         "Left-bottom corner of search area in normalized coordinates relative "
	                         "to marker position");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_markerSearch_update");

	prop = RNA_def_property(srna, "search_max", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_float_sdna(prop, NULL, "search_max");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Search Max",
	                         "Right-bottom corner of search area in normalized coordinates relative "
	                         "to marker position");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_markerSearch_update");

	/* is marker keyframed */
	prop = RNA_def_property(srna, "is_keyed", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", MARKER_TRACKED);
	RNA_def_property_ui_text(prop, "Keyframed", "Whether the position of the marker is keyframed or tracked");
}

static void rna_def_trackingMarkers(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "MovieTrackingMarkers");
	srna = RNA_def_struct(brna, "MovieTrackingMarkers", NULL);
	RNA_def_struct_sdna(srna, "MovieTrackingTrack");
	RNA_def_struct_ui_text(srna, "Movie Tracking Markers", "Collection of markers for movie tracking track");

	func = RNA_def_function(srna, "find_frame", "rna_trackingMarkers_find_frame");
	RNA_def_function_ui_description(func, "Get marker for specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to find marker for", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	RNA_def_boolean(func, "exact", true, "Exact",
	                "Get marker at exact frame number rather than get estimated marker");
	parm = RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Marker for specified frame");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "insert_frame", "rna_trackingMarkers_insert_frame");
	RNA_def_function_ui_description(func, "Insert a new marker at the specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to insert marker to", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	RNA_def_float_vector(func, "co", 2, NULL, -1.0, 1.0, "Coordinate",
	                     "Place new marker at the given frame using specified in normalized space coordinates",
	                     -1.0, 1.0);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm = RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Newly created marker");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "delete_frame", "rna_trackingMarkers_delete_frame");
	RNA_def_function_ui_description(func, "Delete marker at specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to delete marker from", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
}

static void rna_def_trackingTrack(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	rna_def_trackingMarker(brna);

	srna = RNA_def_struct(brna, "MovieTrackingTrack", NULL);
	RNA_def_struct_path_func(srna, "rna_trackingTrack_path");
	RNA_def_struct_ui_text(srna, "Movie tracking track data", "Match-moving track data for tracking");
	RNA_def_struct_ui_icon(srna, ICON_ANIM_DATA);

	/* name */
	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_ui_text(prop, "Name", "Unique name of track");
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_trackingTrack_name_set");
	RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);
	RNA_def_struct_name_property(srna, prop);

	/* limit frames */
	prop = RNA_def_property(srna, "frames_limit", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "frames_limit");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0, SHRT_MAX);
	RNA_def_property_ui_text(prop, "Frames Limit", "Every tracking cycle, this number of frames are tracked");

	/* pattern match */
	prop = RNA_def_property(srna, "pattern_match", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_sdna(prop, NULL, "pattern_match");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, pattern_match_items);
	RNA_def_property_ui_text(prop, "Pattern Match",
	                         "Track pattern from given frame when tracking marker to next frame");

	/* margin */
	prop = RNA_def_property(srna, "margin", PROP_INT, PROP_PIXEL);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "margin");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0, 300);
	RNA_def_property_ui_text(prop, "Margin", "Distance from image boundary at which marker stops tracking");

	/* tracking motion model */
	prop = RNA_def_property(srna, "motion_model", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_enum_items(prop, tracker_motion_model);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Motion model", "Default motion model to use for tracking");

	/* minimum correlation */
	prop = RNA_def_property(srna, "correlation_min", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "minimum_correlation");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.05, 3);
	RNA_def_property_ui_text(prop, "Correlation",
	                         "Minimal value of correlation between matched pattern and reference "
	                         "that is still treated as successful tracking");

	/* use_brute */
	prop = RNA_def_property(srna, "use_brute", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "algorithm_flag", TRACK_ALGORITHM_FLAG_USE_BRUTE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Prepass", "Use a brute-force translation only pre-track before refinement");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* use_brute */
	prop = RNA_def_property(srna, "use_mask", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "algorithm_flag", TRACK_ALGORITHM_FLAG_USE_MASK);
	RNA_def_property_ui_text(prop, "Use Mask",
	                         "Use a grease pencil data-block as a mask to use only specified areas of pattern "
	                         "when tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* use_normalization */
	prop = RNA_def_property(srna, "use_normalization", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "algorithm_flag", TRACK_ALGORITHM_FLAG_USE_NORMALIZATION);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Normalize", "Normalize light intensities while tracking. Slower");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* markers */
	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_ui_text(prop, "Markers", "Collection of markers in track");
	rna_def_trackingMarkers(brna, prop);

	/* ** channels ** */

	/* use_red_channel */
	prop = RNA_def_property(srna, "use_red_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", TRACK_DISABLE_RED);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Use Red Channel", "Use red channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* use_green_channel */
	prop = RNA_def_property(srna, "use_green_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", TRACK_DISABLE_GREEN);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Use Green Channel", "Use green channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* use_blue_channel */
	prop = RNA_def_property(srna, "use_blue_channel", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", TRACK_DISABLE_BLUE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Use Blue Channel", "Use blue channel from footage for tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* preview_grayscale */
	prop = RNA_def_property(srna, "use_grayscale_preview", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_PREVIEW_GRAYSCALE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Grayscale", "Display what the tracking algorithm sees in the preview");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* preview_alpha */
	prop = RNA_def_property(srna, "use_alpha_preview", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_PREVIEW_ALPHA);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Alpha", "Apply track's mask on displaying preview");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* has bundle */
	prop = RNA_def_property(srna, "has_bundle", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_HAS_BUNDLE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Has Bundle", "True if track has a valid bundle");

	/* bundle position */
	prop = RNA_def_property(srna, "bundle", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 3);
	RNA_def_property_float_sdna(prop, NULL, "bundle_pos");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Bundle", "Position of bundle reconstructed from this track");
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);

	/* hide */
	prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_HIDDEN);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Hide", "Track is hidden");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* select */
	prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_trackingTrack_select_get", "rna_trackingTrack_select_set");
	RNA_def_property_ui_text(prop, "Select", "Track is selected");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* select_anchor */
	prop = RNA_def_property(srna, "select_anchor", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
	RNA_def_property_ui_text(prop, "Select Anchor", "Track's anchor point is selected");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* select_pattern */
	prop = RNA_def_property(srna, "select_pattern", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "pat_flag", SELECT);
	RNA_def_property_ui_text(prop, "Select Pattern", "Track's pattern area is selected");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* select_search */
	prop = RNA_def_property(srna, "select_search", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "search_flag", SELECT);
	RNA_def_property_ui_text(prop, "Select Search", "Track's search area is selected");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* locked */
	prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_LOCKED);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Lock", "Track is locked and all changes to it are disabled");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* custom color */
	prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACK_CUSTOMCOLOR);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Custom Color", "Use custom color instead of theme-defined");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* color */
	prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Color",
	                         "Color of the track in the Movie Clip Editor and the 3D viewport after a solve");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* average error */
	prop = RNA_def_property(srna, "average_error", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "error");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Average Error", "Average error of re-projection");

	/* grease pencil */
	prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "gpd");
	RNA_def_property_struct_type(prop, "GreasePencil");
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
	RNA_def_property_ui_text(prop, "Grease Pencil", "Grease pencil data for this track");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* weight */
	prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "weight");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Weight", "Influence of this track on a final solution");

	/* weight_stab */
	prop = RNA_def_property(srna, "weight_stab", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "weight_stab");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Stab Weight", "Influence of this track on 2D stabilization");

	/* offset */
	prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_float_sdna(prop, NULL, "offset");
	RNA_def_property_ui_text(prop, "Offset", "Offset of track from the parenting point");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);
}

static void rna_def_trackingPlaneMarker(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MovieTrackingPlaneMarker", NULL);
	RNA_def_struct_ui_text(srna, "Movie Tracking Plane Marker Data", "Match-moving plane marker data for tracking");

	/* frame */
	prop = RNA_def_property(srna, "frame", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "framenr");
	RNA_def_property_ui_text(prop, "Frame", "Frame number marker is keyframed on");
	RNA_def_property_int_funcs(prop, NULL, "rna_trackingPlaneMarker_frame_set", NULL);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* Corners */
	prop = RNA_def_property(srna, "corners", PROP_FLOAT, PROP_MATRIX);
	RNA_def_property_float_sdna(prop, NULL, "corners");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
	RNA_def_property_ui_text(prop, "Corners",
	                         "Array of coordinates which represents UI rectangle corners in "
	                         "frame normalized coordinates");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);

	/* enable */
	prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", PLANE_MARKER_DISABLED);
	RNA_def_property_ui_text(prop, "Mode", "Is marker muted for current frame");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);
}

static void rna_def_trackingPlaneMarkers(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "MovieTrackingPlaneMarkers");
	srna = RNA_def_struct(brna, "MovieTrackingPlaneMarkers", NULL);
	RNA_def_struct_sdna(srna, "MovieTrackingPlaneTrack");
	RNA_def_struct_ui_text(srna, "Movie Tracking Plane Markers",
	                       "Collection of markers for movie tracking plane track");

	func = RNA_def_function(srna, "find_frame", "rna_trackingPlaneMarkers_find_frame");
	RNA_def_function_ui_description(func, "Get plane marker for specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to find marker for", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	RNA_def_boolean(func, "exact", true, "Exact",
	                "Get plane marker at exact frame number rather than get estimated marker");
	parm = RNA_def_pointer(func, "plane_marker", "MovieTrackingPlaneMarker", "", "Plane marker for specified frame");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "insert_frame", "rna_trackingPlaneMarkers_insert_frame");
	RNA_def_function_ui_description(func, "Insert a new plane marker at the specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to insert marker to", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm = RNA_def_pointer(func, "plane_marker", "MovieTrackingPlaneMarker", "", "Newly created plane marker");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "delete_frame", "rna_trackingPlaneMarkers_delete_frame");
	RNA_def_function_ui_description(func, "Delete plane marker at specified frame");
	parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
	                   "Frame number to delete plane marker from", MINFRAME, MAXFRAME);
	RNA_def_property_flag(parm, PROP_REQUIRED);
}

static void rna_def_trackingPlaneTrack(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	rna_def_trackingPlaneMarker(brna);

	srna = RNA_def_struct(brna, "MovieTrackingPlaneTrack", NULL);
	RNA_def_struct_path_func(srna, "rna_trackingPlaneTrack_path");
	RNA_def_struct_ui_text(srna, "Movie tracking plane track data", "Match-moving plane track data for tracking");
	RNA_def_struct_ui_icon(srna, ICON_ANIM_DATA);

	/* name */
	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_ui_text(prop, "Name", "Unique name of track");
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_trackingPlaneTrack_name_set");
	RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);
	RNA_def_struct_name_property(srna, prop);

	/* markers */
	prop = RNA_def_property(srna, "markers", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingPlaneMarker");
	RNA_def_property_collection_sdna(prop, NULL, "markers", "markersnr");
	RNA_def_property_ui_text(prop, "Markers", "Collection of markers in track");
	rna_def_trackingPlaneMarkers(brna, prop);

	/* select */
	prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
	RNA_def_property_ui_text(prop, "Select", "Plane track is selected");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* auto keyframing */
	prop = RNA_def_property(srna, "use_auto_keying", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", PLANE_TRACK_AUTOKEY);
	RNA_def_property_ui_text(prop, "Auto Keyframe", "Automatic keyframe insertion when moving plane corners");
	RNA_def_property_ui_icon(prop, ICON_REC, 0);

	/* image */
	prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Image");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Image", "Image displayed in the track during editing in clip editor");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* image opacity */
	prop = RNA_def_property(srna, "image_opacity", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, 0.0, 1.0);
	RNA_def_property_ui_text(prop, "Image Opacity", "Opacity of the image");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
}

static void rna_def_trackingStabilization(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem filter_items[] = {
		{TRACKING_FILTER_NEAREST,  "NEAREST",  0, "Nearest",  "No interpolation, use nearest neighbor pixel"},
		{TRACKING_FILTER_BILINEAR, "BILINEAR", 0, "Bilinear", "Simple interpolation between adjacent pixels"},
		{TRACKING_FILTER_BICUBIC,  "BICUBIC",  0, "Bicubic",  "High quality pixel interpolation"},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "MovieTrackingStabilization", NULL);
	RNA_def_struct_path_func(srna, "rna_trackingStabilization_path");
	RNA_def_struct_ui_text(srna, "Movie tracking stabilization data", "2D stabilization based on tracking markers");

	/* 2d stabilization */
	prop = RNA_def_property(srna, "use_2d_stabilization", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_2D_STABILIZATION);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Use 2D stabilization", "Use 2D stabilization for footage");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* use_stabilize_rotation */
	prop = RNA_def_property(srna, "use_stabilize_rotation", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_STABILIZE_ROTATION);
	RNA_def_property_ui_text(prop, "Stabilize Rotation", "Stabilize detected rotation around center of frame");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* use_stabilize_scale */
	prop = RNA_def_property(srna, "use_stabilize_scale", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_STABILIZE_SCALE);
	RNA_def_property_ui_text(prop, "Stabilize Scale", "Compensate any scale changes relative to center of rotation");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* tracks */
	prop = RNA_def_property(srna, "tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_tracking_stabTracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_ui_text(prop, "Translation Tracks",
	                         "Collection of tracks used for 2D stabilization (translation)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* active track index */
	prop = RNA_def_property(srna, "active_track_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "act_track");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_funcs(prop, "rna_tracking_stabTracks_active_index_get",
	                           "rna_tracking_stabTracks_active_index_set",
	                           "rna_tracking_stabTracks_active_index_range");
	RNA_def_property_ui_text(prop, "Active Track Index",
	                         "Index of active track in translation stabilization tracks list");

	/* tracks used for rotation stabilization */
	prop = RNA_def_property(srna, "rotation_tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_tracking_stabRotTracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_ui_text(prop, "Rotation Tracks", "Collection of tracks used for 2D stabilization (translation)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* active rotation track index */
	prop = RNA_def_property(srna, "active_rotation_track_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "act_rot_track");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_funcs(prop, "rna_tracking_stabRotTracks_active_index_get",
	                           "rna_tracking_stabRotTracks_active_index_set",
	                           "rna_tracking_stabRotTracks_active_index_range");
	RNA_def_property_ui_text(prop, "Active Rotation Track Index",
	                         "Index of active track in rotation stabilization tracks list");

	/* anchor frame */
	prop = RNA_def_property(srna, "anchor_frame", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "anchor_frame");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_range(prop, MINFRAME, MAXFRAME);
	RNA_def_property_ui_text(prop, "Anchor Frame",
	                         "Reference point to anchor stabilization "
	                         "(other frames will be adjusted relative to this frame's position)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* target position */
	prop = RNA_def_property(srna, "target_position", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3); /* increment in steps of 0.01 and show 3 digit after point */
	RNA_def_property_float_sdna(prop, NULL, "target_pos");
	RNA_def_property_ui_text(prop, "Expected Position",
	                         "Known relative offset of original shot, will be subtracted "
	                         "(e.g. for panning shot, can be animated)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* target rotation */
	prop = RNA_def_property(srna, "target_rotation", PROP_FLOAT, PROP_ANGLE);
	RNA_def_property_float_sdna(prop, NULL, "target_rot");
	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 10.0f, 3);
	RNA_def_property_ui_text(prop, "Expected Rotation",
	                         "Rotation present on original shot, will be compensated (e.g. for deliberate tilting)");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* target scale */
	prop = RNA_def_property(srna, "target_scale", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "scale");
	RNA_def_property_range(prop, FLT_EPSILON, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.01f, 10.0f, 0.001f, 3); /* increment in steps of 0.001. Show 3 digit after point */
	RNA_def_property_ui_text(prop, "Expected Scale",
	                         "Explicitly scale resulting frame to compensate zoom of original shot");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* autoscale */
	prop = RNA_def_property(srna, "use_autoscale", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_AUTOSCALE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_ui_text(prop, "Autoscale",
	                         "Automatically scale footage to cover unfilled areas when stabilizing");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* max scale */
	prop = RNA_def_property(srna, "scale_max", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "maxscale");
	RNA_def_property_range(prop, 0.0f, 10.0f);
	RNA_def_property_ui_text(prop, "Maximal Scale", "Limit the amount of automatic scaling");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* influence_location */
	prop = RNA_def_property(srna, "influence_location", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "locinf");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Location Influence", "Influence of stabilization algorithm on footage location");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* influence_scale */
	prop = RNA_def_property(srna, "influence_scale", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "scaleinf");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Scale Influence", "Influence of stabilization algorithm on footage scale");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* influence_rotation */
	prop = RNA_def_property(srna, "influence_rotation", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_float_sdna(prop, NULL, "rotinf");
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Rotation Influence", "Influence of stabilization algorithm on footage rotation");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* filter */
	prop = RNA_def_property(srna, "filter_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "filter");
	RNA_def_property_enum_items(prop, filter_items);
	RNA_def_property_ui_text(prop, "Interpolate",
	                         "Interpolation to use for sub-pixel shifts and rotations due to stabilization");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_tracking_flushUpdate");

	/* UI display : show participating tracks */
	prop = RNA_def_property(srna, "show_tracks_expanded", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_SHOW_STAB_TRACKS);
	RNA_def_property_ui_text(prop, "Show Tracks", "Show UI list of tracks participating in stabilization");
	RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
}

static void rna_def_reconstructedCamera(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MovieReconstructedCamera", NULL);
	RNA_def_struct_ui_text(srna, "Movie tracking reconstructed camera data",
	                       "Match-moving reconstructed camera data from tracker");

	/* frame */
	prop = RNA_def_property(srna, "frame", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_sdna(prop, NULL, "framenr");
	RNA_def_property_ui_text(prop, "Frame", "Frame number marker is keyframed on");

	/* matrix */
	prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
	RNA_def_property_float_sdna(prop, NULL, "mat");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
	RNA_def_property_ui_text(prop, "Matrix", "Worldspace transformation matrix");

	/* average_error */
	prop = RNA_def_property(srna, "average_error", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "error");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Average Error", "Average error of reconstruction");
}

static void rna_def_trackingReconstructedCameras(BlenderRNA *brna)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;

	srna = RNA_def_struct(brna, "MovieTrackingReconstructedCameras", NULL);
	RNA_def_struct_sdna(srna, "MovieTrackingReconstruction");
	RNA_def_struct_ui_text(srna, "Reconstructed Cameras", "Collection of solved cameras");

	func = RNA_def_function(srna, "find_frame", "rna_trackingCameras_find_frame");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
	RNA_def_function_ui_description(func, "Find a reconstructed camera for a give frame number");
	RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "Frame number to find camera for", MINFRAME, MAXFRAME);
	parm = RNA_def_pointer(func, "camera", "MovieReconstructedCamera", "", "Camera for a given frame");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "matrix_from_frame", "rna_trackingCameras_matrix_from_frame");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
	RNA_def_function_ui_description(func, "Return interpolated camera matrix for a given frame");
	RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "Frame number to find camera for", MINFRAME, MAXFRAME);
	parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, -FLT_MAX, FLT_MAX, "Matrix",
	                            "Interpolated camera matrix for a given frame", -FLT_MAX, FLT_MAX);
	RNA_def_property_flag(parm, PROP_THICK_WRAP);  /* needed for string return value */
	RNA_def_function_output(func, parm);
}

static void rna_def_trackingReconstruction(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	rna_def_reconstructedCamera(brna);

	srna = RNA_def_struct(brna, "MovieTrackingReconstruction", NULL);
	RNA_def_struct_ui_text(srna, "Movie tracking reconstruction data",
	                       "Match-moving reconstruction data from tracker");

	/* is_valid */
	prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_RECONSTRUCTED);
	RNA_def_property_ui_text(prop, "Reconstructed", "Is tracking data contains valid reconstruction information");

	/* average_error */
	prop = RNA_def_property(srna, "average_error", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "error");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Average Error", "Average error of reconstruction");

	/* cameras */
	prop = RNA_def_property(srna, "cameras", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieReconstructedCamera");
	RNA_def_property_collection_sdna(prop, NULL, "cameras", "camnr");
	RNA_def_property_ui_text(prop, "Cameras", "Collection of solved cameras");
	RNA_def_property_srna(prop, "MovieTrackingReconstructedCameras");

}

static void rna_def_trackingTracks(BlenderRNA *brna)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *prop;
	PropertyRNA *parm;

	srna = RNA_def_struct(brna, "MovieTrackingTracks", NULL);
	RNA_def_struct_sdna(srna, "MovieTracking");
	RNA_def_struct_ui_text(srna, "Movie Tracks", "Collection of movie tracking tracks");

	func = RNA_def_function(srna, "new", "rna_trackingTracks_new");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
	RNA_def_function_ui_description(func, "Create new motion track in this movie clip");
	RNA_def_string(func, "name", NULL, 0, "", "Name of new track");
	RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "Frame number to add track on", MINFRAME, MAXFRAME);
	parm = RNA_def_pointer(func, "track", "MovieTrackingTrack", "", "Newly created track");
	RNA_def_function_return(func, parm);

	/* active track */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_pointer_funcs(prop, "rna_tracking_active_track_get", "rna_tracking_active_track_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
	RNA_def_property_ui_text(prop, "Active Track", "Active track in this tracking data object");
}

static void rna_def_trackingPlaneTracks(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MovieTrackingPlaneTracks", NULL);
	RNA_def_struct_sdna(srna, "MovieTracking");
	RNA_def_struct_ui_text(srna, "Movie Plane Tracks", "Collection of movie tracking plane tracks");

	/* TODO(sergey): Add API to create new plane tracks */

	/* active plane track */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingPlaneTrack");
	RNA_def_property_pointer_funcs(prop, "rna_tracking_active_plane_track_get", "rna_tracking_active_plane_track_set",
	                               NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
	RNA_def_property_ui_text(prop, "Active Plane Track", "Active plane track in this tracking data object");
}

static void rna_def_trackingObjectTracks(BlenderRNA *brna)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *prop;
	PropertyRNA *parm;

	srna = RNA_def_struct(brna, "MovieTrackingObjectTracks", NULL);
	RNA_def_struct_sdna(srna, "MovieTrackingObject");
	RNA_def_struct_ui_text(srna, "Movie Tracks", "Collection of movie tracking tracks");

	func = RNA_def_function(srna, "new", "rna_trackingObject_tracks_new");
	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
	RNA_def_function_ui_description(func, "create new motion track in this movie clip");
	RNA_def_string(func, "name", NULL, 0, "", "Name of new track");
	RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "Frame number to add tracks on", MINFRAME, MAXFRAME);
	parm = RNA_def_pointer(func, "track", "MovieTrackingTrack", "", "Newly created track");
	RNA_def_function_return(func, parm);

	/* active track */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_pointer_funcs(prop, "rna_tracking_active_track_get", "rna_tracking_active_track_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
	RNA_def_property_ui_text(prop, "Active Track", "Active track in this tracking data object");
}

static void rna_def_trackingObjectPlaneTracks(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MovieTrackingObjectPlaneTracks", NULL);
	RNA_def_struct_sdna(srna, "MovieTrackingObject");
	RNA_def_struct_ui_text(srna, "Plane Tracks", "Collection of tracking plane tracks");

	/* active track */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_pointer_funcs(prop, "rna_tracking_active_plane_track_get", "rna_tracking_active_plane_track_set",
	                               NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
	RNA_def_property_ui_text(prop, "Active Track", "Active track in this tracking data object");
}

static void rna_def_trackingObject(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "MovieTrackingObject", NULL);
	RNA_def_struct_ui_text(srna, "Movie tracking object data", "Match-moving object tracking and reconstruction data");

	/* name */
	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_ui_text(prop, "Name", "Unique name of object");
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_trackingObject_name_set");
	RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, NULL);
	RNA_def_struct_name_property(srna, prop);

	/* is_camera */
	prop = RNA_def_property(srna, "is_camera", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_OBJECT_CAMERA);
	RNA_def_property_ui_text(prop, "Camera", "Object is used for camera tracking");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* tracks */
	prop = RNA_def_property(srna, "tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_trackingObject_tracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_ui_text(prop, "Tracks", "Collection of tracks in this tracking data object");
	RNA_def_property_srna(prop, "MovieTrackingObjectTracks");

	/* plane tracks */
	prop = RNA_def_property(srna, "plane_tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_trackingObject_plane_tracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingPlaneTrack");
	RNA_def_property_ui_text(prop, "Plane Tracks", "Collection of plane tracks in this tracking data object");
	RNA_def_property_srna(prop, "MovieTrackingObjectPlaneTracks");

	/* reconstruction */
	prop = RNA_def_property(srna, "reconstruction", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingReconstruction");
	RNA_def_property_pointer_funcs(prop, "rna_trackingObject_reconstruction_get", NULL, NULL, NULL);

	/* scale */
	prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_float_sdna(prop, NULL, "scale");
	RNA_def_property_range(prop, 0.0001f, 10000.0f);
	RNA_def_property_ui_range(prop, 0.0001f, 10000.0, 1, 4);
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_text(prop, "Scale", "Scale of object solution in camera space");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_trackingObject_flushUpdate");

	/* keyframe_a */
	prop = RNA_def_property(srna, "keyframe_a", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "keyframe1");
	RNA_def_property_ui_text(prop, "Keyframe A", "First keyframe used for reconstruction initialization");

	/* keyframe_b */
	prop = RNA_def_property(srna, "keyframe_b", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_sdna(prop, NULL, "keyframe2");
	RNA_def_property_ui_text(prop, "Keyframe B", "Second keyframe used for reconstruction initialization");
}

static void rna_def_trackingObjects(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	PropertyRNA *prop;

	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "MovieTrackingObjects");
	srna = RNA_def_struct(brna, "MovieTrackingObjects", NULL);
	RNA_def_struct_sdna(srna, "MovieTracking");
	RNA_def_struct_ui_text(srna, "Movie Objects", "Collection of movie tracking objects");

	func = RNA_def_function(srna, "new", "rna_trackingObject_new");
	RNA_def_function_ui_description(func, "Add tracking object to this movie clip");
	parm = RNA_def_string(func, "name", NULL, 0, "", "Name of new object");
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm = RNA_def_pointer(func, "object", "MovieTrackingObject", "", "New motion tracking object");
	RNA_def_function_return(func, parm);

	func = RNA_def_function(srna, "remove", "rna_trackingObject_remove");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	RNA_def_function_ui_description(func, "Remove tracking object from this movie clip");
	parm = RNA_def_pointer(func, "object", "MovieTrackingObject", "", "Motion tracking object to be removed");
	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
	RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);

	/* active object */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingObject");
	RNA_def_property_pointer_funcs(prop, "rna_tracking_active_object_get",
	                               "rna_tracking_active_object_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
	RNA_def_property_ui_text(prop, "Active Object", "Active object in this tracking data object");
}

static void rna_def_trackingDopesheet(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	static EnumPropertyItem sort_items[] = {
		{TRACKING_DOPE_SORT_NAME, "NAME", 0, "Name", "Sort channels by their names"},
		{TRACKING_DOPE_SORT_LONGEST, "LONGEST", 0, "Longest", "Sort channels by longest tracked segment"},
		{TRACKING_DOPE_SORT_TOTAL, "TOTAL", 0, "Total", "Sort channels by overall amount of tracked segments"},
		{TRACKING_DOPE_SORT_AVERAGE_ERROR, "AVERAGE_ERROR", 0, "Average Error",
		                                   "Sort channels by average reprojection error of tracks after solve"},
		{0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "MovieTrackingDopesheet", NULL);
	RNA_def_struct_ui_text(srna, "Movie Tracking Dopesheet", "Match-moving dopesheet data");

	/* dopesheet sort */
	prop = RNA_def_property(srna, "sort_method", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "sort_method");
	RNA_def_property_enum_items(prop, sort_items);
	RNA_def_property_ui_text(prop, "Dopesheet Sort Field", "Method to be used to sort channels in dopesheet view");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_trackingDopesheet_tagUpdate");

	/* invert_dopesheet_sort */
	prop = RNA_def_property(srna, "use_invert_sort", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_DOPE_SORT_INVERSE);
	RNA_def_property_ui_text(prop, "Invert Dopesheet Sort", "Invert sort order of dopesheet channels");
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_trackingDopesheet_tagUpdate");

	/* show_only_selected */
	prop = RNA_def_property(srna, "show_only_selected", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_DOPE_SELECTED_ONLY);
	RNA_def_property_ui_text(prop, "Only Selected", "Only include channels relating to selected objects and data");
	RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, 0);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_trackingDopesheet_tagUpdate");

	/* show_hidden */
	prop = RNA_def_property(srna, "show_hidden", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_DOPE_SHOW_HIDDEN);
	RNA_def_property_ui_text(prop, "Display Hidden", "Include channels from objects/bone that aren't visible");
	RNA_def_property_ui_icon(prop, ICON_GHOST_ENABLED, 0);
	RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_trackingDopesheet_tagUpdate");
}

static void rna_def_tracking(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	rna_def_trackingSettings(brna);
	rna_def_trackingCamera(brna);
	rna_def_trackingTrack(brna);
	rna_def_trackingPlaneTrack(brna);
	rna_def_trackingTracks(brna);
	rna_def_trackingPlaneTracks(brna);
	rna_def_trackingObjectTracks(brna);
	rna_def_trackingObjectPlaneTracks(brna);
	rna_def_trackingStabilization(brna);
	rna_def_trackingReconstructedCameras(brna);
	rna_def_trackingReconstruction(brna);
	rna_def_trackingObject(brna);
	rna_def_trackingDopesheet(brna);

	srna = RNA_def_struct(brna, "MovieTracking", NULL);
	RNA_def_struct_path_func(srna, "rna_tracking_path");
	RNA_def_struct_ui_text(srna, "Movie tracking data", "Match-moving data for tracking");

	/* settings */
	prop = RNA_def_property(srna, "settings", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingSettings");

	/* camera properties */
	prop = RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingCamera");

	/* tracks */
	prop = RNA_def_property(srna, "tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_trackingTracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingTrack");
	RNA_def_property_ui_text(prop, "Tracks", "Collection of tracks in this tracking data object");
	RNA_def_property_srna(prop, "MovieTrackingTracks");

	/* tracks */
	prop = RNA_def_property(srna, "plane_tracks", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_trackingPlaneTracks_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingPlaneTrack");
	RNA_def_property_ui_text(prop, "Plane Tracks", "Collection of plane tracks in this tracking data object");
	RNA_def_property_srna(prop, "MovieTrackingPlaneTracks");

	/* stabilization */
	prop = RNA_def_property(srna, "stabilization", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingStabilization");

	/* reconstruction */
	prop = RNA_def_property(srna, "reconstruction", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingReconstruction");

	/* objects */
	prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_trackingObjects_begin", "rna_iterator_listbase_next",
	                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
	                                  NULL, NULL, NULL, NULL);
	RNA_def_property_struct_type(prop, "MovieTrackingObject");
	RNA_def_property_ui_text(prop, "Objects", "Collection of objects in this tracking data object");
	rna_def_trackingObjects(brna, prop);

	/* active object index */
	prop = RNA_def_property(srna, "active_object_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "objectnr");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
	RNA_def_property_int_funcs(prop, "rna_tracking_active_object_index_get", "rna_tracking_active_object_index_set",
	                           "rna_tracking_active_object_index_range");
	RNA_def_property_ui_text(prop, "Active Object Index", "Index of active object");
	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);

	/* dopesheet */
	prop = RNA_def_property(srna, "dopesheet", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "MovieTrackingDopesheet");
}

void RNA_def_tracking(BlenderRNA *brna)
{
	rna_def_tracking(brna);
}

#endif