feat: link douglas peucker to real drawing area
This commit is contained in:
parent
28c4250334
commit
f80b344aa7
34164
SegmentationDouglasPeucker.Flutter/Dali.Segmentation.DouglasPeucker.h
Normal file
34164
SegmentationDouglasPeucker.Flutter/Dali.Segmentation.DouglasPeucker.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,4 +3,4 @@ headers:
|
||||
entry-points:
|
||||
- 'Dali.Segmentation.DouglasPeucker.h'
|
||||
# - 'MathLib.h'
|
||||
- 'MyLib.Managed.h'
|
||||
# - 'MyLib.Managed.h'
|
||||
|
@ -21,6 +21,6 @@
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>11.0</string>
|
||||
<string>12.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -358,7 +358,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
@ -483,7 +483,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@ -532,7 +532,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
|
@ -23,6 +23,16 @@ class DaliPoint {
|
||||
|
||||
return DaliPoint(x, y);
|
||||
}
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is DaliPoint &&
|
||||
runtimeType == other.runtimeType &&
|
||||
x == other.x &&
|
||||
y == other.y;
|
||||
|
||||
@override
|
||||
int get hashCode => x.hashCode ^ y.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
@ -7,62 +7,68 @@ import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart
|
||||
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
||||
|
||||
abstract class Douglas {
|
||||
static void runExample() {
|
||||
final NativeLibrary nativeLibrary = NativeLibrary(Lib.init('Dali.Segmentation.DouglasPeucker'));
|
||||
static List<DaliPoint> transformDouglasPeucker(
|
||||
List<DaliPoint> originePoints) {
|
||||
final NativeLibrary nativeLibrary =
|
||||
NativeLibrary(Lib.init('Dali.Segmentation.DouglasPeucker'));
|
||||
|
||||
final Pointer<System_Exception_t> exception = calloc();
|
||||
print('Exception allocated ! ($exception)');
|
||||
|
||||
final System_Type_t type = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||
|
||||
final System_Drawing_Point_t point1 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
|
||||
|
||||
print('Point1: $daliPoint1');
|
||||
|
||||
final System_Drawing_Point_t point2 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
|
||||
|
||||
print('Point2: $daliPoint2');
|
||||
|
||||
final System_Drawing_Point_t point3 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
|
||||
|
||||
print('Point3: $daliPoint3');
|
||||
|
||||
final System_Collections_Generic_List_A1_t points =
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||
type,
|
||||
3,
|
||||
originePoints.length,
|
||||
exception,
|
||||
);
|
||||
|
||||
exception.handle(onException: print);
|
||||
for (final point in originePoints) {
|
||||
final System_Drawing_Point_t nativePoint =
|
||||
nativeLibrary.System_Drawing_Point_Create(
|
||||
point.x,
|
||||
point.y,
|
||||
exception,
|
||||
);
|
||||
|
||||
print('Points list created ! ($points)');
|
||||
exception.handle();
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, type, nativePoint, exception);
|
||||
exception.handle();
|
||||
}
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, type, point1, exception);
|
||||
final douglasPeuckerList = nativeLibrary
|
||||
.DALI_Segmentation_SegmentationDouglasPeucker_DouglasPeuckerReduction(
|
||||
points,
|
||||
1,
|
||||
exception,
|
||||
);
|
||||
exception.handle();
|
||||
|
||||
print('Point1 added !');
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, type, point2, exception);
|
||||
final count = nativeLibrary.System_Collections_Generic_List_A1_Count_Get(
|
||||
douglasPeuckerList,
|
||||
type,
|
||||
exception,
|
||||
);
|
||||
exception.handle();
|
||||
|
||||
print('Point2 added !');
|
||||
final List<DaliPoint> dartList = [];
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, type, point3, exception);
|
||||
exception.handle();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final douglasPoint =
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Item_Get(
|
||||
douglasPeuckerList,
|
||||
type,
|
||||
i,
|
||||
exception,
|
||||
);
|
||||
|
||||
print('Point3 added !');
|
||||
exception.handle();
|
||||
dartList.add(
|
||||
DaliPoint.fromPointer(douglasPoint),
|
||||
);
|
||||
}
|
||||
|
||||
return dartList;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/douglas.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/sketcher_line.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/sketcher_points.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MainApp());
|
||||
@ -28,77 +31,56 @@ class Main extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MainState extends State<Main> {
|
||||
List<DaliPoint> _points = [];
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// MyLib.runExample();
|
||||
Douglas.runExample();
|
||||
|
||||
return const Text('Hello World!');
|
||||
|
||||
// final int sum = nativeLibrary.MathLib_Math_Sum(mathLib, list, outException)
|
||||
|
||||
// final System_Object_t point1 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 400, nullptr);
|
||||
// final System_Object_t point2 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 500, nullptr);
|
||||
// final System_Object_t point3 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 600, nullptr);
|
||||
// final System_Object_t point4 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 700, nullptr);
|
||||
// final System_Type_t type = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||
|
||||
// print(DaliPoint.fromPointer(point1));
|
||||
|
||||
// final correctType = nativeLibrary.DNObjectIs(point1, type);
|
||||
|
||||
// print('Correct type: $correctType');
|
||||
|
||||
// final points = nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||
// type,
|
||||
// 4,
|
||||
// exception,
|
||||
// );
|
||||
|
||||
// DotNetException.handle(exception);
|
||||
|
||||
// final count = nativeLibrary.System_Collections_Generic_List_A1_Count_Get(
|
||||
// points,
|
||||
// type,
|
||||
// exception,
|
||||
// );
|
||||
|
||||
// print('Count: $count');
|
||||
|
||||
// DotNetException.handle(exception);
|
||||
|
||||
// return const Text('Hello World!');
|
||||
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, pointType, point1, nullptr);
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, nullptr, point2, nullptr);
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, nullptr, point3, nullptr);
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, nullptr, point4, nullptr);
|
||||
|
||||
// final reduction = nativeLibrary
|
||||
// .DALI_Segmentation_SegmentationDouglasPeucker_DouglasPeuckerReduction(
|
||||
// points.cast(), 1, nullptr);
|
||||
|
||||
// final reducted = <DaliPoint>[];
|
||||
|
||||
// for (var i = 0; i < count; i++) {
|
||||
// final item = nativeLibrary.System_Collections_Generic_List_A1_Item_Get(
|
||||
// reduction, nullptr, i, nullptr);
|
||||
// reducted.add(DaliPoint.fromPointer(item));
|
||||
// }
|
||||
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Destroy(reduction);
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Destroy(points);
|
||||
|
||||
// print(reducted);
|
||||
|
||||
// return Text('Hello World! ${reducted.length}');
|
||||
return Stack(
|
||||
alignment: Alignment.topRight,
|
||||
children: [
|
||||
Listener(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onPointerMove: (event) {
|
||||
setState(() {
|
||||
_points.add(
|
||||
DaliPoint(
|
||||
event.localPosition.dx.toInt(),
|
||||
event.localPosition.dy.toInt(),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
child: SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: Stack(
|
||||
children: [
|
||||
CustomPaint(
|
||||
painter: SketcherLine(
|
||||
points: _points,
|
||||
),
|
||||
),
|
||||
CustomPaint(
|
||||
painter: SketcherPoints(
|
||||
points: _points,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
final newPoints = Douglas.transformDouglasPeucker(_points);
|
||||
setState(() {
|
||||
_points = newPoints;
|
||||
});
|
||||
},
|
||||
child: const Text('Apply Douglas Peucker'),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,87 +1,87 @@
|
||||
import 'dart:ffi';
|
||||
// import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/dotnet_exception.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart';
|
||||
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
||||
// import 'package:ffi/ffi.dart';
|
||||
// import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||
// import 'package:segmentation_douglas_peucker_flutter/dotnet_exception.dart';
|
||||
// import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart';
|
||||
// import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
||||
|
||||
abstract class MyLib {
|
||||
static void runExample() {
|
||||
final NativeLibrary nativeLibrary =
|
||||
NativeLibrary(Lib.init('MyLib.Managed'));
|
||||
// abstract class MyLib {
|
||||
// static void runExample() {
|
||||
// final NativeLibrary nativeLibrary =
|
||||
// NativeLibrary(Lib.init('MyLib.Managed'));
|
||||
|
||||
final Pointer<System_Exception_t> exception = calloc();
|
||||
print('Exception allocated ! ($exception)');
|
||||
// final Pointer<System_Exception_t> exception = calloc();
|
||||
// print('Exception allocated ! ($exception)');
|
||||
|
||||
final MyLib_Hello_t hello = nativeLibrary.MyLib_Hello_Create(exception);
|
||||
exception.handle();
|
||||
// final MyLib_Hello_t hello = nativeLibrary.MyLib_Hello_Create(exception);
|
||||
// exception.handle();
|
||||
|
||||
print('Hello created ! ($hello)');
|
||||
// print('Hello created ! ($hello)');
|
||||
|
||||
final MathLib_Math_t mathLib =
|
||||
nativeLibrary.MyLib_Hello_GetMath(hello, exception);
|
||||
exception.handle();
|
||||
// final MathLib_Math_t mathLib =
|
||||
// nativeLibrary.MyLib_Hello_GetMath(hello, exception);
|
||||
// exception.handle();
|
||||
|
||||
print('MathLib created ! ($mathLib)');
|
||||
// print('MathLib created ! ($mathLib)');
|
||||
|
||||
final System_Drawing_Point_t point1 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
|
||||
// final System_Drawing_Point_t point1 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
|
||||
// exception.handle();
|
||||
// final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
|
||||
|
||||
print('Point1: $daliPoint1');
|
||||
// print('Point1: $daliPoint1');
|
||||
|
||||
final System_Drawing_Point_t point2 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
|
||||
// final System_Drawing_Point_t point2 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
|
||||
// exception.handle();
|
||||
// final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
|
||||
|
||||
print('Point2: $daliPoint2');
|
||||
// print('Point2: $daliPoint2');
|
||||
|
||||
final System_Drawing_Point_t point3 =
|
||||
nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
|
||||
// final System_Drawing_Point_t point3 =
|
||||
// nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
|
||||
// exception.handle();
|
||||
// final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
|
||||
|
||||
print('Point3: $daliPoint3');
|
||||
// print('Point3: $daliPoint3');
|
||||
|
||||
final System_Type_t pointType = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||
// final System_Type_t pointType = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||
|
||||
final System_Collections_Generic_List_A1_t points =
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||
pointType,
|
||||
3,
|
||||
exception,
|
||||
);
|
||||
// final System_Collections_Generic_List_A1_t points =
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||
// pointType,
|
||||
// 3,
|
||||
// exception,
|
||||
// );
|
||||
|
||||
exception.handle();
|
||||
// exception.handle();
|
||||
|
||||
print('Points list created ! ($points)');
|
||||
// print('Points list created ! ($points)');
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, pointType, point1, exception);
|
||||
exception.handle();
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, pointType, point1, exception);
|
||||
// exception.handle();
|
||||
|
||||
print('Point1 added !');
|
||||
// print('Point1 added !');
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, pointType, point2, exception);
|
||||
exception.handle();
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, pointType, point2, exception);
|
||||
// exception.handle();
|
||||
|
||||
print('Point2 added !');
|
||||
// print('Point2 added !');
|
||||
|
||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
points, pointType, point3, exception);
|
||||
exception.handle();
|
||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||
// points, pointType, point3, exception);
|
||||
// exception.handle();
|
||||
|
||||
print('Point3 added !');
|
||||
// print('Point3 added !');
|
||||
|
||||
final pointSum =
|
||||
nativeLibrary.MathLib_Math_SumPoints(mathLib, points, exception);
|
||||
exception.handle();
|
||||
final DaliPoint daliPointSum = DaliPoint.fromPointer(pointSum);
|
||||
// final pointSum =
|
||||
// nativeLibrary.MathLib_Math_SumPoints(mathLib, points, exception);
|
||||
// exception.handle();
|
||||
// final DaliPoint daliPointSum = DaliPoint.fromPointer(pointSum);
|
||||
|
||||
print('Point sum: $daliPointSum');
|
||||
}
|
||||
}
|
||||
// print('Point sum: $daliPointSum');
|
||||
// }
|
||||
// }
|
||||
|
44
SegmentationDouglasPeucker.Flutter/lib/sketcher_line.dart
Normal file
44
SegmentationDouglasPeucker.Flutter/lib/sketcher_line.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart' hide TextStyle;
|
||||
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||
|
||||
class SketcherLine extends CustomPainter {
|
||||
SketcherLine({
|
||||
required this.points,
|
||||
});
|
||||
|
||||
final List<DaliPoint> points;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final Paint paint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 10;
|
||||
|
||||
// Set the paint options.
|
||||
paint.color = Colors.blue;
|
||||
|
||||
final path = Path();
|
||||
|
||||
if (points.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, draw a line that connects each point with a curve.
|
||||
path.moveTo(
|
||||
points[0].x.toDouble(),
|
||||
points[0].y.toDouble(),
|
||||
);
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
path.lineTo(
|
||||
points[i].x.toDouble(),
|
||||
points[i].y.toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(SketcherLine oldDelegate) => true;
|
||||
}
|
46
SegmentationDouglasPeucker.Flutter/lib/sketcher_points.dart
Normal file
46
SegmentationDouglasPeucker.Flutter/lib/sketcher_points.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart' hide TextStyle;
|
||||
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||
|
||||
class SketcherPoints extends CustomPainter {
|
||||
SketcherPoints({
|
||||
required this.points,
|
||||
});
|
||||
|
||||
final List<DaliPoint> points;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final Paint paint = Paint();
|
||||
|
||||
paint.color = Colors.red;
|
||||
|
||||
final path = Path();
|
||||
|
||||
if (points.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, draw a line that connects each point with a curve.
|
||||
path.moveTo(
|
||||
points[0].x.toDouble(),
|
||||
points[0].y.toDouble(),
|
||||
);
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
path.addOval(
|
||||
Rect.fromCircle(
|
||||
center: Offset(
|
||||
points[i].x.toDouble(),
|
||||
points[i].y.toDouble(),
|
||||
),
|
||||
radius: 5,
|
||||
),
|
||||
);
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(SketcherPoints oldDelegate) => true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user