How to Create Emboss and engrave text on OpenCASCADE - opencascade

I am searching an API for creating emboss text on my AIS_Shape , If there is no API any better way to do that ?,I am thinking of creating text extrude and doing cut operation with AIS_Shape , can we extrude Text ?

OCCT doesn't provide direct tool defining an emboss text - so you are right, you have to do that using a general Boolean operation.
A general idea can be found within standard samples coming with Draw Harness - take a look onto "Modeling" -> "OCCT Tutorial bottle sample" sample (source $env(CSF_OCCTSamplesPath)/tcl/bottle.tcl):
Tools to use:
Font_BRepFont to load a font and convert a glyph into a planar TopoDS_Shape.
Font_BRepTextBuilder to format a text using Font_BRepFont.
BRepPrimAPI_MakePrism to define a solid from text.
BRepAlgoAPI_Cut to perform a Boolean operation between text solid and another shape.
Here is a pseudo-code:
// text2brep
const double aFontHeight = 20.0;
Font_BRepFont aFont (Font_NOF_SANS_SERIF, Font_FontAspect_Bold, aFontHeight);
Font_BRepTextBuilder aBuilder;
TopoDS_Shape aTextShape2d = aBuilder.Perform (aFont, "OpenCASCADE");
// prism
const double anExtrusion = 5.0;
BRepPrimAPI_MakePrism aPrismTool (aTextShape2d, gp_Vec (0,0,1) * anExtrusion);
TopoDS_Shape aTextShape3d = aPrismTool->Shape();
//aTextShape3d.SetLocation(); // move where needed
// bopcut
TopoDS_Shape theMainShape; // defined elsewhere
BRepAlgoAPI_Cut aCutTool (theMainShape, aTextShape3d);
if (!aCutTool.IsDone()) { error }
TopoDS_Shape aResult = aCutTool.Shape();

Related

How to convert x y z tile to a geotools bbox or ReferenceEnvelope

i am using a lefleat tile layer with xyz system to query a list of postgis layers,i use a geotools jdbc datastore to fetch layers from database ,but i have to work with bbox or a geotools refernce envelope,how i can transform xyz coordinate to a bbox or a refernce envelope,so i can pass it later to my datastore feature source so i can find geometries or elements in a given bbox ,my coordinate system is EPSG:4326.
You can use the code in gt-tile-client to work with XYZ services.
I think the following should work for you.
String ref = "7/61/53";
String[] parts = ref.split("/");
int z = Integer.valueOf(parts[0]);
int x = Integer.valueOf(parts[1]);
int y = Integer.valueOf(parts[2]);
OSMTile tile = new OSMTile(x, y, new WebMercatorZoomLevel(z), new OSMService("name", "url"));
System.out.println(tile.getExtent());
which gives
ReferencedEnvelope[-8.4375 : -5.625, 27.05912578437406 : 29.535229562948455]

How do I update unlockable characters in SpriteKit game with Swift 3?

I have currently made a game featuring one player. I also made a character screen where the user can choose which character he/she wants to play with. How do I make it so that a certain high score unlocks a certain character, and allows the user to equip this character to use in the game?
Right now my player has his own swift file that defines all the properties of him:
import SpriteKit
class Player: SKSpriteNode, GameSprite {
var initialSize = CGSize(width:150, height: 90)
var textureAtlas: SKTextureAtlas = SKTextureAtlas(named: "Rupert")
let maxFlyingForce: CGFloat = 80000
let maxHeight: CGFloat = 900
var health:Int = 1
var invulnerable = false
var damaged = false
var damageAnimation = SKAction()
var dieAnimation = SKAction()
var forwardVelocity: CGFloat = 190
var powerAnimation = SKAction()
init() {
super.init(texture:nil, color: .clear, size: initialSize)
createAnimations()
self.run(soarAnimation, withKey: "soarAnimation")
let bodyTexture = textureAtlas.textureNamed("pug3")
self.physicsBody = SKPhysicsBody(texture: bodyTexture, size: self.size)
self.physicsBody?.linearDamping = 0.9
self.physicsBody?.mass = 10
self.physicsBody?.allowsRotation = false
self.physicsBody?.categoryBitMask = PhysicsCategory.rupert.rawValue
self.physicsBody?.contactTestBitMask = PhysicsCategory.enemy.rawValue | PhysicsCategory.treat.rawValue | PhysicsCategory.winky.rawValue | PhysicsCategory.ground.rawValue
func createAnimations() {
let rotateUpAction = SKAction.rotate(toAngle: 0.75, duration: 0.475)
rotateUpAction.timingMode = .easeOut
let rotateDownAction = SKAction.rotate(toAngle: 0, duration: 0.475)
rotateDownAction.timingMode = .easeIn
let flyFrames: [SKTexture] = [
textureAtlas.textureNamed("pug1"),
textureAtlas.textureNamed("pug2"),
textureAtlas.textureNamed("pug3"),
textureAtlas.textureNamed("pug4"),
textureAtlas.textureNamed("pug3"),
textureAtlas.textureNamed("pug2")
]
let flyAction = SKAction.animate(with:flyFrames, timePerFrame: 0.07)
flyAnimation = SKAction.group([SKAction.repeatForever(flyAction), rotateUpAction])
let soarFrames:[SKTexture] = [textureAtlas.textureNamed("pug5")]
let soarAction = SKAction.animate(with: soarFrames, timePerFrame: 1)
soarAnimation = SKAction.group([SKAction.repeatForever(soarAction), rotateDownAction])
This is not all the code but you get the point.
I then say: let player = Player() in my Gamescene file which essentially attaches all the attributes in the player file to my player that will be seen in the Gamescene. Even if I am able to replace the initial player with a certain different player, there are so many animations that I don't know how to replace everything at once. I want to set a condition that spans over both the gamescene class and the player class so that it can just sub out certain images for other ones and keep the same actions.
Thank you for any help!
Here are some techniques you can use for making things like this more manageable:
Have a naming convention for your character images and/or sprite sheets, so that you can pass in a name to your Player() constructor. Then, instead of loading texturenamed("pug3"), you load up texturenamed("\(playerName)3"). If the only difference between your characters are the sprite sheets, this is actually all you need on the Player end.
If your characters are more complex, with differences beyond just the images, like being larger or having more health, then you will probably want to go with a more data-oriented approach. There are a couple of approaches to this, but a handy one is to read your texture names, hitbox sizes, health levels, etc., out of a .plist file instead of hard-coding them. Then just pass in the name of the .plist file to load for the character you want. Then, to create a new character, you just create a new .plist file. Another approach would be to create a "character definition" struct that you could pass to the Player constructor that contains the information you need to construct the player (this, in turn, could be loaded from a .plist file, as well, but you could also hard-code them or save them directly using codable serialization).
If neither of the above approaches are sufficient, say if you need different behavior between characters, you could always go the subclassing route - pull the various parts and pieces out into functions, and then override those functions to add the specific functionality you need for more complex characters.

How to display text on GTK label using two different fonts?

I have a GTK label and I am displaying text on it in Arial Rounded Mt Bold by using following code:
PangoFontDescription *df;
df = pango_font_description_new ();
pango_font_description_set_family(df,"Arial Rounded Mt Bold");
pango_font_description_set_size(df,fontsize*PANGO_SCALE);
gtk_widget_modify_font(Message_Label, df);
gtk_label_set_text(GTK_LABEL(Label), "Hello World");
pango_font_description_free (df);
Now this Hello World is displayed in Arial Rounded Mt Bold. But what if I want to display Hello in Arial Rounded Mt Bold and World in some other font for example Arial. Is this possible in GTK label. I am doing it in C. Any advice or any useful links. Thanks.
gtk_widget_modify_font() is deprecated and won't let you do what you want.
You can use a PangoAttrList, which combines attributes (including the individual components of a PangoFontDescriptor) over ranges of text. For instance:
PangoAttrList *attrlist;
PangoAttribute *attr;
PangoFontDescription *df;
attrlist = pango_attr_list_new();
// First, let's set up the base attributes.
// This part is copied from your code (and slightly bugfixed and reformatted):
df = pango_font_description_new();
pango_font_description_set_family(df, "Arial Rounded MT");
pango_font_description_set_size(df, fontsize * PANGO_SCALE);
pango_font_description_set_weight(df, PANGO_WEIGHT_BOLD);
// You can also use pango_font_description_new_from_string() and pass in a string like "Arial Rounded MT Bold (whatever fontsize is)".
// But here's where things change:
attr = pango_attr_font_desc_new(df);
// This is not documented, but pango_attr_font_desc_new() makes a copy of df, so let's release ours:
pango_font_description_free(df);
// Pango and GTK+ use UTF-8, so our string is indexed between 0 and 11.
// Note that the end_index is exclusive!
attr->start_index = 0;
attr->end_index = 11;
pango_attr_list_insert(attrlist, attr);
// And pango_attr_list_insert() takes ownership of attr, so we don't free it ourselves.
// As an alternative to all that, you can have each component of the PangoFontDescriptor be its own attribute; see the PangoAttribute documentation page.
// And now the attribute for the word "World".
attr = pango_attr_family_new("Arial");
// "World" starts at 6 and ends at 11.
attr->start_index = 6;
attr->end_index = 11;
pango_attr_list_insert(attrlist, attr);
// And finally, give the GtkLabel our attribute list.
gtk_label_set_attributes(GTK_LABEL(Label), attrlist);
// And (IIRC this is not documented either) gtk_label_set_attributes() takes a reference on the attribute list, so we can remove ours.
pango_attr_list_unref(attrlist);
You can also use gtk_label_set_markup() to use an HTML-like markup language to set both text and styles in one go:
gtk_label_set_markup(GTK_LABEL(Label),
"<span face=\"Arial Rounded MT\" size=\"(whatever fontsize * PANGO_SCALE is)\" weight=\"bold\">Hello <span face=\"Arial\">World</span></span>");
// Or even...
gtk_label_set_markup(GTK_LABEL(Label),
"<span font=\"Arial Rounded MT Bold (whatever fontsize is)\">Hello <span face=\"Arial\">World</span></span>");

Rotating CGPoints; CIVector CGAffineTransform?

I have 4 CGPoints that form an irregular figure. How can I rotate that figure 90-degrees and get the new CGPoints?
FWIW, I was able to "fake" this when the figure is a CGRect by swapping origin.x and origin.y, and width and height. Will I need to do something similar (calculating distance/direction between points) or is there a AffineTransform I can apply to a CIVector?
Hints and/or pointers to tutorials/guides welcome.
Skippable Project Background:
Users will take pictures of documents and the app will OCR them. Since users have a great deal of trouble getting a non-skewed image, I allow them to create a 4-point figure around the text body and the app skews that back to a rectangle. The camera images coming in are CIImages and so have their origin already in lower-left, so the 4-point figure must be rotated from the UIView to match...
For the record, I used CGAffineTransforms to rotate the points:
CGAffineTransform t1 = CGAffineTransformMakeTranslation(0, cropView.frame.size.height);
CGAffineTransform s = CGAffineTransformMakeScale(1, -1);
CGAffineTransform r = CGAffineTransformMakeRotation(90 * M_PI/180);
CGAffineTransform t2 = CGAffineTransformMakeTranslation(0, -cropView.frame.size.height);
CGPoint a = CGPointMake(70, 23);
a = CGPointApplyAffineTransform(a, t1);
a = CGPointApplyAffineTransform(a, s);
a = CGPointApplyAffineTransform(a, r);
a = CGPointApplyAffineTransform(a, t2);
&c. for the other points.

VirtualEarth: determine min/max visible latitude/longitude

Is there an easy way to determine the maximum and minimum visible latitude and longitude in a VirtualEarth map?
Given that it's not a flat surface (VE uses Mercator projection it looks like) I can see the math getting fairly complicated, I figured somebody may know of a snippet to accomplish this.
Found it! VEMap.GetMapView() returns the bounding rectangle, even works for 3D mode as well (where the boundary is not even a rectangle).
var view = map.GetMapView();
latMin = view.BottomRightLatLong.Latitude;
lonMin = view.TopLeftLatLong.Longitude;
latMax = view.TopLeftLatLong.Latitude;
lonMax = view.BottomRightLatLong.Longitude;
Using the Virtual Earth Interactive SDK, you can see how to convert a pixel point to a LatLong object:
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}
function DoPixelToLL(x, y)
{
var ll = map.PixelToLatLong(new VEPixel(x, y)).toString()
alert("The latitude,longitude of the pixel at (" + x + "," + y + ") is: " + ll)
}
Take a further look here: http://dev.live.com/virtualearth/sdk/ in the menu go to: Get map info --> Convert pixel to LatLong
To get the Max/Min visible LatLong's, you could call the DoPixelToLL method for each corner of the map.

Resources