Plot 3D with specific x and y ILNumerics - arrays

I have a 3D array, I want to plot it as a surface in ILNumerics. Here is my code:
ILArray<float> plot = ILMath.tosingle(hasil);
var scene = new ILScene();
ILColormap cm = new ILColormap(Colormaps.Jet);
ILArray<float> data = cm.Data;
scene.Add(
new ILPlotCube(twoDMode: false){
new ILSurface(plot[":;:;2"]){
Wireframe = { Color = Color.FromArgb(50, Color.LightGray)},
Colormap = new ILColormap(data),
Children = { new ILColorbar()}
}
}
);
ilPanel1.Scene = scene;
And here is the result:
Actually my array includes the x posisition (plot[":;:;0"]) and y position (plot[":;:;1"]). How to use that for ILSurface in order to get the correct grid positions and value? Rather than indexed value in the range 0-100?

Well, it was simply. I already got the answer.
new ILSurface(plot[":;:;2"],plot[":;:;0"],plot[":;:;1"])

Related

Set the Y position of the X axis in OxyPlot

I am plotting a basic LineSeries with the excellent OxyPlot library :
I can't find how to set the X axis to be centered at the 0 Y value and not at the bottom of the PlotArea.
My code-behind is as follow :
Model = new PlotModel();
LineSeries RightingLever = new LineSeries();
RightingLever.Title = "Righting Lever";
// adding points
Model.Series.Add(RightingLever);
PlotView.Model = Model;
I was looking for the PositionAtZeroCrossing property of the Axis class.
foreach (var axis in Model.Axes)
{
axis.PositionAtZeroCrossing = true;
axis.AxislineStyle = LineStyle.Automatic;
}

Hide some points in Oxyplot Line series

I need to show/hide some data points in oxyplot line series. Is it possible?
Though some markers are invisible, the line should go through the invisible markers.
You could make use of two series to achieve this. The first one would draw the complete points (and line) without the marker. The second series would draw the visible points(with marker,but with line style set to none). For Example
DataPoint[] points = new DataPoint[]
{
new DataPoint(1,12),
new DataPoint(2,10),
new DataPoint(3,9),
new DataPoint(4,13),
new DataPoint(5,14),
new DataPoint(6,10)
};
var seriesComplete = new OxyPlot.Series.LineSeries();
seriesComplete.Points.AddRange(points);
var seriesVisible = new OxyPlot.Series.LineSeries();
seriesVisible.Points.AddRange(points.Where(x => x.Y % 2 == 0));
seriesVisible.MarkerFill = OxyColors.Blue;
seriesVisible.MarkerType = MarkerType.Circle;
seriesVisible.MarkerSize = 10;
seriesVisible.LineStyle = LineStyle.None;
this.MyModel.Series.Add(seriesComplete);
this.MyModel.Series.Add(seriesVisible);
Result is attached as image

laying out images in Word document programatically

I'm trying to generate a Word document through my application coded in WPF. In that document, I also need to layout few images along with caption as shown in the image below.
All the images are stored in database as base64 string. I'm able to load the images as "BitmapImage" object in the document however not sure how to layout the images as shown in image. Code snippet to load the images in document is as below :
var bookmarks = wordDoc.Bookmarks;
var range = bookmarks["ExternalImage"].Range;
foreach (var image in ExternalImages) // here image is "BitmapImage" object
{
float scaleHeight = (float)250 / (float)image.Image.PixelHeight;
float scaleWidth = (float)250 / (float)image.Image.PixelWidth;
var min = Math.Min(scaleHeight, scaleWidth);
var bitmap = new TransformedBitmap(image, new ScaleTransform(min, min));
System.Windows.Clipboard.SetImage(bitmap);
range.Paste();
}
How can I lay out the images as shown in image above along with caption? Note that I'm not loading images from file but from memory object.
Based on the direction provided by #CindyMeister in comments, following is the working code snippet to layout the images using code :
imageTable = wordDoc.Tables.Add(sel.Range, rows, cols, ref oMissing, ref oMissing);
imageTable.AllowAutoFit = true;
row = 1; col = 1;
foreach (var image in Images)
{
float scaleHeight = (float)475 / (float)image.PixelHeight;
// here 475 is approx image size I want in word document
float scaleWidth = (float)475 / (float)image.PixelWidth;
var min = Math.Min(scaleHeight, scaleWidth);
var bitmap = new TransformedBitmap(image, new ScaleTransform(min, min));
System.Windows.Clipboard.SetImage(bitmap);
//more efficient/faster in C# if you don't "drill down" multiple times to get an object
Word.Cell cel = imageTable.Cell(row, col);
Word.Range rngCell = cel.Range;
Word.Range rngTable = imageTable.Range;
rngCell.Paste();
cel.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
rngCell.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
// set caption below image
rngTable.ParagraphFormat.SpaceAfter = 6;
rngCell.InsertAfter(image.Caption);
rngTable.Font.Name = "Arial Bold";
row++;
}
This code I have posted for reference, only, to let people have some starting point. Any suggestions welcome.

Xcode SceneKit Shadows Will Not Render

I am creating a simple project using SceneKit and cannot get any shadows to appear in the Scene Editor or in the compiled application no matter what I try.
I have tried creating a simple box, placing it on a plane and adding a spot light. Code would be as follows:
// Create some properties
var scnView: SCNView!
var scnMasterScene: SCNScene!
var boxNode: SCNNode!
var cameraPerspNode: SCNNode!
var cameraOrthNode: SCNNode!
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
setupView()
createAndAddBoxScene()
setupCamera()
createAndAddSpotLight()
}
// Setup the view.
func setupView() {
scnView = self.sceneView as SCNView
// Set the scnView properties.
scnView.showsStatistics = true
scnView.autoenablesDefaultLighting = false
scnView.allowsCameraControl = true
// Create a Master scene.
scnMasterScene = SCNScene()
// Set the scene view's scene node to the master scene.
scnView.scene = scnMasterScene
}
// Setup the scene.
func createAndAddBoxScene() {
// Create a box of type SCNGeometry
let boxGeometry: SCNGeometry = SCNBox(width: 2000, height: 2000, length: 2000, chamferRadius: 100)
// Add a difuse colour to the box' first material.
boxGeometry.firstMaterial?.diffuse.contents = NSColor.redColor()
// Create a node of type SCNNode and attach the boxGeometry to it.
// Note: A node can only have 1 geometry object attached to it.
boxNode = SCNNode(geometry: boxGeometry)
// Add the new boxNode to the scene's root node.
scnMasterScene.rootNode.addChildNode(boxNode)
// Create a floor plane.
let floorGeometry: SCNGeometry = SCNPlane(width: 20000, height: 20000)
// Add a difuse colour to the floor's first material.
floorGeometry.firstMaterial?.diffuse.contents = NSColor.yellowColor()
// Create a floorPlaneNode and attach the floor plane to it.
let floorNode: SCNNode = SCNNode(geometry: floorGeometry)
// Tilt the floorPlaneNode in x.
let floorNodeTiltDegreesX: Double = -90
let floorNodeTiltRadiansX: Double = floorNodeTiltDegreesX * (π/180)
floorNode.rotation = SCNVector4Make(1, 0, 0, CGFloat(floorNodeTiltRadiansX))
// Add the floorPlaneNode to the master scene.
scnMasterScene.rootNode.addChildNode(floorNode)
}
// Create a camera, position it and add it to the scene.
func setupCamera() {
// Create a camera node which will be used to contain the camera.
cameraPerspNode = SCNNode()
// Create a new camera.
let cameraPersp: SCNCamera = SCNCamera()
// Set camera properties.
cameraPersp.name = "myPerspCamera"
cameraPersp.usesOrthographicProjection = false
cameraPersp.orthographicScale = 9
cameraPersp.xFov = 30
cameraPersp.zNear = 1
cameraPersp.zFar = 20000
// Assign the camera to the .camera property of the node.
cameraPerspNode.camera = cameraPersp
// Set the position and rotation of the camera node (NOT the camera).
cameraPerspNode.position = SCNVector3(x: 0, y: 4000, z: 6000)
let cameraPerspTiltDegrees: Double = -30
let cameraPerspTiltRadians: Double = cameraPerspTiltDegrees * (π/180)
cameraPerspNode.rotation = SCNVector4Make(1, 0, 0, CGFloat(cameraPerspTiltRadians))
// Add the new cameraNode to the scene's root.
scnMasterScene.rootNode.addChildNode(cameraPerspNode)
}
func createAndAddSpotLight() -> Void {
let spot = SCNLight()
spot.type = SCNLightTypeSpot
spot.castsShadow = true
spot.color = NSColor(hue: 1, saturation: 0, brightness: 0, alpha: 1)
spot.spotInnerAngle = 30
spot.spotOuterAngle = 60
let spotNode = SCNNode()
spotNode.light = spot
spotNode.position = SCNVector3(x: 0, y: 2000, z: 2000)
let lookAt = SCNLookAtConstraint(target: boxNode)
spotNode.constraints = [lookAt]
}
If I bring in a .dae filed add a spot light, or directional light, using the Scene Editor I can light the scene but there are no shadows when I set the Cast Shadows property in the Attributes Inspector.
Can anyone shine any light on my problem?
Thanks
The scene is large because the 3D model has been created at 1:1 and it depicts a large building. After much trial and error I finally found the solution - I changed the scale of the light to 10, 10, 10 and the shadows appeared.
the dimensions in your scene are huge (in SceneKit 1 unit = 1 meter). You'll want to change your light's zFar property (and probably zNear too) accordingly.

Why Geometry intersection does not give the expected result with polylines with more than one line?

I need to calculate the intersection between two geometries to check if one is fully inside the other or not.
The Geometry "container", based on a System.Windows.Shapes.Polygon, is created as follows:
List<PathSegment> basePolygonSegments = new List<PathSegment> {
new PolyLineSegment(basePolygon.Points, true) };
PathGeometry baseGeometry = new PathGeometry();
baseGeometry.Figures.Add(
new PathFigure(basePolygon.Points[0], basePolygonSegments, true));
The Geometry "contained" can be:
another System.Windows.Shapes.Polygon
a System.Windows.Shapes.Polyline, that can have only one line or three lines (the shape is a |_|, or U)
The Polyline is created as follows:
Polyline bracketDrawingPolyline = new Polyline();
foreach(Point p in listOfPoints)
bracketDrawingPolyline.Points.Add(p);
LineGeometry lineGeometry =
new LineGeometry(
bracketDrawingPolyline.Points[0],
bracketDrawingPolyline.Points[bracketDrawingPolyline.Points.Count - 1]);
PathGeometry bracketGeometry = new PathGeometry();
bracketGeometry = lineGeometry.GetWidenedPathGeometry(
new Pen(Brushes.Black, 1.0));
To understand if the "contained" Geometry is contained in the "container", I do the following:
CombinedGeometry intersectionGeometry =
new CombinedGeometry(GeometryCombineMode.Intersect,
baseGeometry, bracketGeometry);
double intersectionArea =
intersectionGeometry.GetArea(0.0001, ToleranceType.Absolute);
double bracketArea = bracketGeometry.GetArea(0.0001, ToleranceType.Absolute);
if (intersectionArea < bracketArea)
{
//the second Geometry is not fully contained in the "container" Geometry
}
else
//it is fully contained
....
In case of Polygon or Polyline with only one line everything works as expected. But with Polyline U, intersectionArea and bracketArea are always the same.
I've also tried to perform the following checks:
bool result = baseGeometry.FillContains(bracketGeometry);
IntersectionDetail idtl =
baseGeometry.FillContainsWithDetail(bracketGeometry);
but I have the same results.
I've found a solution on my own, but I don't know if it is the best one.
Considered that with a single line everything works well, I just do the check for each line of the polyline, that is:
for (int i = 1; i < bracketDrawingPolyline.Points.Count; i++)
{
LineGeometry lineGeometry =
new LineGeometry(bracketDrawingPolyline.Points[i - 1],
bracketDrawingPolyline.Points[i]);
...//continue with the check of the line as described in the post...
}

Resources