Redraw problems when scrolling with ScrollGraphicalViewer - swt

Environment: Eclipse Neon on Win10.
I have an older GEF/SWT RCP application that uses a ScrollingGraphicalViewer to handle scrolling. When I scroll, the original image that should be preserved in the scroll is moved properly, but the new area is not drawn. Sometimes, minimizing and restoring the application window gets it to redraw correctly. although at other times, it will show the image as if it hadn't been scrolled, but the scroll bar indicates that it has.
This happens with both horizontal and vertical scrolling. I'm only testing with thumb scrolling because it's a single move rather than a continuous operation with lots of redraws.
Here's a code sample. It's the paintFigure() method from one of my figures that goes the full width.
protected void paintFigure (Graphics graphics)
{
if (log.isTraceEnabled ()) {
final Rectangle dummy = new Rectangle ();
log.trace (String.format ("Paint rung %s, bounds %s, clip %s", rungId.getText (), getBounds (), graphics.getClip (dummy))); //$NON-NLS-1$
}
super.paintFigure (graphics);
// Draw the vertical bars
Rectangle r = getBounds ().getCopy ();
r.width -= LINE_WIDTH;
r.width += 1; // Coming up 1 short for some reason
r.shrink (MARGIN, 0);
if (log.isTraceEnabled ()) {
log.trace (String.format ("Adjusted bounds %s", r)); //$NON-NLS-1$
}
final int connectionY = r.y + connectionYOffset;
int connectionXStart = instructionsFigure.getBounds ().right ();
int connectionXStop = r.right ();
graphics.drawLine (connectionXStart, connectionY, connectionXStop, connectionY);
connectionXStart = r.x-4;
connectionXStop = instructionsFigure.getBounds ().x;
graphics.drawLine (connectionXStart, connectionY, connectionXStop, connectionY);
graphics.setLineWidth (LINE_WIDTH);
graphics.drawLine (r.getTopRight (), r.getBottomRight ());
graphics.drawLine (r.x - 4, r.y, r.x - 4, r.y+r.height);
}
Here is some trace output. Note that LadderLayer is the parent figure to the Rung.
Initial display:
TRACE 2018-06-30 10:08:56,289 10099 com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main] Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(0.0, 0.0, 1070.0, 673.0)
TRACE 2018-06-30 10:08:56,289 10099 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(3.0, 3.0, 1067.0, 384.0)
TRACE 2018-06-30 10:08:56,290 10100 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Not sure what is being drawn here:
TRACE 2018-06-30 10:08:56,370 10180 com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main] Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(1047.0, 15.0, 23.0, 658.0)
TRACE 2018-06-30 10:08:56,370 10180 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(1047.0, 15.0, 23.0, 372.0)
TRACE 2018-06-30 10:08:56,370 10180 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Thumb scroll right:
TRACE 2018-06-30 10:10:16,244 90054 com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main] Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(940.0, 0.0, 130.0, 673.0)
TRACE 2018-06-30 10:10:16,245 90055 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(940.0, 3.0, 130.0, 384.0)
TRACE 2018-06-30 10:10:16,245 90055 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Redraw after minimize/restore:
TRACE 2018-06-30 10:11:56,406 190216 com.bas.basplc.ui.editors.ladder_editor.figures.LadderLayer [main] Paint ladder layer, bounds Rectangle(0.0, 0.0, 1200.0, 2190.0), clip Rectangle(0.0, 0.0, 1070.0, 673.0)
TRACE 2018-06-30 10:11:56,406 190216 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Paint rung 0, bounds Rectangle(3.0, 3.0, 1200.0, 384.0), clip Rectangle(3.0, 3.0, 1067.0, 384.0)
TRACE 2018-06-30 10:11:56,407 190217 com.bas.basplc.ui.editors.ladder_editor.figures.RungFigure [main] Adjusted bounds Rectangle(63.0, 3.0, 1078.0, 384.0)
Before the thumb scroll:
After the thumb scroll:

Solved! I was using SimpleRootEditPart, Viewport, LayeredPane, Layer, AbstractLayout. Switching to the Freeform versions of these and I can now scroll cleanly.

Related

invert image black to white in flutter

I have a bitmap image with black and white color I just need to invert the image and display how can I convert and display image. I have inverted bitmap image in java using this code can anyone suggest me how to do this in a flutter.
private Bitmap createInvertedBitmap(Bitmap src) {
ColorMatrix colorMatrix_Inverted =
new ColorMatrix(new float[] {
-1, 0, 0, 0, 255,
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0});
ColorFilter ColorFilter_Sepia = new ColorMatrixColorFilter(
colorMatrix_Inverted);
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(ColorFilter_Sepia);
canvas.drawBitmap(src, 0, 0, paint);
return bitmap;
}
Now it is possible to change/invert the color via ColorFiltered class
You can refer to this blog for more details: https://www.burkharts.net/apps/blog/over-the-rainbow-colour-filters/
Another solution
You can try using ShaderMask class, and try passing it to the corresponding Shader, such as InvertColorShader. Currently, no shader can do this as of now.
Also check out BlendMode class to achieve your desired result.

How to add a CIFilter to MTLTexture Using ARMatteGenerator?

I am working off of Apple's sample project related to using the ARMatteGenerator to generate a a MTLTexture that can be used as an occlusion matte in the people occlusion technology.
I would like to determine how I could run the generated matte through a CIFilter. In my code, I am "filtering" the matte like such;
func updateMatteTextures(commandBuffer: MTLCommandBuffer) {
guard let currentFrame = session.currentFrame else {
return
}
var targetImage: CIImage?
alphaTexture = matteGenerator.generateMatte(from: currentFrame, commandBuffer: commandBuffer)
dilatedDepthTexture = matteGenerator.generateDilatedDepth(from: currentFrame, commandBuffer: commandBuffer)
targetImage = CIImage(mtlTexture: alphaTexture!, options: nil)
monoAlphaCIFilter?.setValue(targetImage!, forKey: kCIInputImageKey)
monoAlphaCIFilter?.setValue(CIColor.red, forKey: kCIInputColorKey)
targetImage = (monoAlphaCIFilter?.outputImage)!
let drawingBounds = CGRect(origin: .zero, size: CGSize(width: alphaTexture!.width, height: alphaTexture!.height))
context.render(targetImage!, to: alphaTexture!, commandBuffer: commandBuffer, bounds: drawingBounds, colorSpace: CGColorSpaceCreateDeviceRGB())
}
When I go to composite the matte texture and backgrounds, there is no filtering effect applied to the matte. This is how the textures are being composited;
func compositeImagesWithEncoder(renderEncoder: MTLRenderCommandEncoder) {
guard let textureY = capturedImageTextureY, let textureCbCr = capturedImageTextureCbCr else {
return
}
// Push a debug group allowing us to identify render commands in the GPU Frame Capture tool
renderEncoder.pushDebugGroup("CompositePass")
// Set render command encoder state
renderEncoder.setCullMode(.none)
renderEncoder.setRenderPipelineState(compositePipelineState)
renderEncoder.setDepthStencilState(compositeDepthState)
// Setup plane vertex buffers
renderEncoder.setVertexBuffer(imagePlaneVertexBuffer, offset: 0, index: 0)
renderEncoder.setVertexBuffer(scenePlaneVertexBuffer, offset: 0, index: 1)
// Setup textures for the composite fragment shader
renderEncoder.setFragmentBuffer(sharedUniformBuffer, offset: sharedUniformBufferOffset, index: Int(kBufferIndexSharedUniforms.rawValue))
renderEncoder.setFragmentTexture(CVMetalTextureGetTexture(textureY), index: 0)
renderEncoder.setFragmentTexture(CVMetalTextureGetTexture(textureCbCr), index: 1)
renderEncoder.setFragmentTexture(sceneColorTexture, index: 2)
renderEncoder.setFragmentTexture(sceneDepthTexture, index: 3)
renderEncoder.setFragmentTexture(alphaTexture, index: 4)
renderEncoder.setFragmentTexture(dilatedDepthTexture, index: 5)
// Draw final quad to display
renderEncoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4)
renderEncoder.popDebugGroup()
}
How could I apply the CIFilter to only the alphaTexture generated by the ARMatteGenerator?
I don't think you want to apply a CIFilter to the alphaTexture. I assume you're using Apple's Effecting People Occlusion in Custom Renderers sample code. If you watch this year's Bringing People into AR WWDC session, they talk about generating a segmentation matte using ARMatteGenerator, which is what is being done with alphaTexture = matteGenerator.generateMatte(from: currentFrame, commandBuffer: commandBuffer). alphaTexture is a MTLTexture that is essentially an alpha mask for where humans have been detected in the camera frame (i.e. complete opaque where a human is and completely transparent where a human is not).
Adding a filter to the alpha texture won't filter the final rendered image but will simply affect the mask that is used in the compositing. If you're trying to achieve the video linked in your previous question, I would recommend adjusting the metal shader where the compositing occurs. In the session, they point out that they compare the dilatedDepth and the renderedDepth to see if they should draw virtual content or pixels from the camera:
fragment half4 customComposition(...) {
half4 camera = cameraTexture.sample(s, in.uv);
half4 rendered = renderedTexture.sample(s, in.uv);
float renderedDepth = renderedDepthTexture.sample(s, in.uv);
half4 scene = mix(rendered, camera, rendered.a);
half matte = matteTexture.sample(s, in.uv);
float dilatedDepth = dilatedDepthTexture.sample(s, in.uv);
if (dilatedDepth < renderedDepth) { // People in front of rendered
// mix together the virtual content and camera feed based on the alpha provided by the matte
return mix(scene, camera, matte);
} else {
// People are not in front so just return the scene
return scene
}
}
Unfortunately, this is done sightly differently in the sample code, but it's still fairly easy to modify. Open up Shaders.metal. Find the compositeImageFragmentShader function. Toward the end of the function you'll see half4 occluderResult = mix(sceneColor, cameraColor, alpha); This is essentially the same operation as mix(scene, camera, matte); that we saw above. We're deciding if we should use a pixel from the scene or a pixel from camera feed based on the segmentation matte. We can easily replace the camera image pixel with an arbitrary rgba value by replacing cameraColor with a half4 that represents a color. For example, we could use half4(float4(0.0, 0.0, 1.0, 1.0)) to paint all of the pixels within the segmentation matte blue:
…
// Replacing camera color with blue
half4 occluderResult = mix(sceneColor, half4(float4(0.0, 0.0, 1.0, 1.0)), alpha);
half4 mattingResult = mix(sceneColor, occluderResult, showOccluder);
return mattingResult;
Of course, you can apply other effects as well. Dynamic grayscale static is pretty easy to achieve.
Above compositeImageFragmentShader add:
float random(float offset, float2 tex_coord, float time) {
// pick two numbers that are unlikely to repeat
float2 non_repeating = float2(12.9898 * time, 78.233 * time);
// multiply our texture coordinates by the non-repeating numbers, then add them together
float sum = dot(tex_coord, non_repeating);
// calculate the sine of our sum to get a range between -1 and 1
float sine = sin(sum);
// multiply the sine by a big, non-repeating number so that even a small change will result in a big color jump
float huge_number = sine * 43758.5453 * offset;
// get just the numbers after the decimal point
float fraction = fract(huge_number);
// send the result back to the caller
return fraction;
}
(taken from #twostraws ShaderKit)
Then modify compositeImageFragmentShader to:
…
float randFloat = random(1.0, cameraTexCoord, rgb[0]);
half4 occluderResult = mix(sceneColor, half4(float4(randFloat, randFloat, randFloat, 1.0)), alpha);
half4 mattingResult = mix(sceneColor, occluderResult, showOccluder);
return mattingResult;
You should get:
Finally, the debugger seems to have a hard time keeping up with the app. For me, when running attached Xcode, the app would freeze shortly after launch, but was typically smooth when running on its own.

How to interact with 3D objects in RealityKit

Problems with interaction of 3D objects. I've found some beta-functions of RealityKit such as PhysicsBodyComponent, applyImpulse, addForce, applyAngularImpulse and etc.
I was trying to add physics characteristics to object 'vase' and making an impulse to object on event a tap or something like that.
It's really strange, after execution the commands, the physics characteristics are added normal and at same time impulses and force aren't added into object(see below at debugging output).
Output of debugging print:
Something 1 Optional(RealityKit.PhysicsBodyComponent(mode: RealityKit.PhysicsBodyMode.dynamic, massProperties: RealityKit.PhysicsMassProperties(mass: 0.2, inertia: SIMD3(0.1, 0.1, 0.1), centerOfMass: (position: SIMD3(0.0, 0.0, 0.0), orientation: simd_quatf(real: 1.0, imag: SIMD3(0.0, 0.0, 0.0)))), material: RealityKit.PhysicsMaterialResource, isTranslationLocked: (x: false, y: false, z: false), isRotationLocked: (x: false, y: false, z: false), isContinuousCollisionDetectionEnabled: false, teleport: false, userForce: SIMD3(0.0, 0.0, 0.0), userTorque: SIMD3(0.0, 0.0, 0.0), userLinearImpulse: SIMD3(0.0, 0.0, 0.0), userAngularImpulse: SIMD3(0.0, 0.0, 0.0)))
Something 5 Optional(RealityKit.PhysicsBodyComponent(mode: RealityKit.PhysicsBodyMode.dynamic, massProperties: RealityKit.PhysicsMassProperties(mass: 0.2, inertia: SIMD3(0.1, 0.1, 0.1), centerOfMass: (position: SIMD3(0.0, 0.0, 0.0), orientation: simd_quatf(real: 1.0, imag: SIMD3(0.0, 0.0, >0.0)))), material: RealityKit.PhysicsMaterialResource, isTranslationLocked: (x: false, y: false, z: false), isRotationLocked: (x: false, y: false, z: false), isContinuousCollisionDetectionEnabled: false, teleport: false, userForce: SIMD3(0.0, 0.0, 0.0), userTorque: SIMD3(0.0, 0.0, 0.0), userLinearImpulse: SIMD3(0.0, 0.0, 0.0), userAngularImpulse: SIMD3(0.0, 0.0, 0.0)))
As we can see, functions doesn't add impulses and force to the object 'vase'. Maybe I make something wrong.
I don't think you're supposed to create instances of ModelEntity directly. I think that is an internal component of the Entity class representing just the mesh. You augment the interactions/animations directly with components in RealityKit. These apply to the entire entity object. I think it's similar to how if you create a Metal view, you need it to be backed by a Core Animation layer in order to get access to user interactions.
If you look at the SwiftStrike sample application they do not directly instantiate ModelEntity which leads me to believe that it's not best practice to create those outside of an Entity object.
I believe you would add your vase to the project through Reality Composer. You can apply materials and collisions to it there. You can also add behaviors like responding to touch. Then you can access the vase through the reality composer file in Xcode and add components to the vase entity that will transform its position. All entities have a transform component, which is documented here.
RealityKit feels like it was designed to abstract as much code away from the programmer as possible, so a lot of the underlying architecture isn't really exposed or documented. It's also not organized the way that I would organize it, but I don't have a lot of familiarity with the Entity-Component design pattern.
If you don't like how RealityKit is laid out you also have the option to use SceneKit as a renderer. That does not abstract away as much of the functionality and allows you to use Core Animation commands directly on objects.

How to use DrawNode with RenderTexture cocos2d-x

I cannot draw a simple line or a dot with DrawNode and RenderTexture.
This is how to I implemented:
AppDelegate.cpp
auto scene = Scene::create();
auto layer = BackgroundLayer::create();
scene->addChild(layer);
// run
director->runWithScene(scene);
BackgroundLayer.cpp
bool BackgroundLayer::init()
{
if ( !LayerColor::initWithColor(Color4B::WHITE) )
{
return false;
}
auto renderTexture = RenderTexture::create(300, 200);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(250, 250), 20, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(this->getContentSize()/2);
this->addChild(renderTexture, 10000);
}
I tried with some complex shape with DrawNode, but the result is just a black rectangle stayed in the center of the screen.
I compile with cocos2d-x v3.6 & VS2013.
auto renderTexture = RenderTexture::create(50, 50);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(10, 10), 2, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(SCREENSIZE.width/2,SCREENSIZE.height/2);
this->addChild(renderTexture, 10000);
Try this it will create red dot on the texture

unable to set background color on iTextSharp signature appearance

Does anyone have any ideas on how to set the background color on the PdfSignatureAppearance rectangle in iTextSharp? I create the PdfSignatureAppearance object and can set its positioning on the page, but the rectangle only has a transparent background. I'm trying to apply a color (any really).
I've tried creating a new iTextSharp.text.Rectangle then setting the rect.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow); That doesn't work. I saw someone else trying to something similar by applying the styles to the layer2 of the signature appearance object. I've tried these with no luck.
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.SetGrayFill(2);
sigAppLayer2.BoundingBox.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow);
Anytime I try one of the above styling changes to the layer2 the visible signature disappears on the PDF. If I try applying it to layer 0 or layer 1 then nothing happens. I'm assuming then I'm touching the correct layer (2).
Any ideas? The goal is to just get a background on the signature box vs having it be transparent.
See comment below. I tried this as well setting against layer 2 and layer 0. Both result in a red box, but the signature text is missing.
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
PdfTemplate sigAppLayer0 = appearance.GetLayer(0);
sigAppLayer0.SetRGBColorFill(255, 0, 0);
sigAppLayer0.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer0.Fill();
You need to draw the rectangle and fill that rectangle with the fill color.
From memory (untested), you need something like this:
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer2.Fill();
This is the way:
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer2.Fill();
sigAppLayer2.ResetRGBColorFill();// <--------- you needs this
sigAppLayer2.BeginText() ...etc