How to use the various Forge Viewer transforms - autodesk-forge

Below are the various transforms I have found so far using NOP_VIEWER.model.getData().
I'm using the transforms to bring a position into viewer space, and I haven't been able to find any good documentation describing what they all do. My hope here is that this question can help by providing some documentation of the role of these transforms and how/when to use them.
The model originally comes from Revit.
GlobalOffset (Vector3)
placementWithOffset (Matrix4) - seems to be just the inverse of GlobalOffset as a matrix?
placementTransform (Matrix4) - undefined in all models I've tested, I've seen some hints that this is a user defined matrix.
refPointTransform (Matrix4)
Also, there are some transforms in the NOP_VIEWER.model.getData().metadata. These may be Revit specific:
metadata.georeference.positionLL84 (Array[3]) - this is where the model's GPS coords are stored
metadata.georeference.refPointLMV (Array[3]) - no idea what this is, and it has huge and seemingly random values on many models. For example, on my current model it is [-17746143.211481072, -6429345.318822183, 27.360225423452952]
metadata.[custom values].angleToTrueNorth - I guess this is specifying whether the model is aligned to true or magnetic north?
metadata.[custom values].refPointTransform - (Array[12]) - data used to create the refPointTransform matrix above
Can someone help by documenting what these transforms do?
Related: Place a custom object into viewer space using GPS coords

As an alternative solution, the Viewer works with extensions. The Autodesk.Geolocation extension provides a few methods to handle the data structure you mentioned:
Load extension:
let geoExt;
NOP_VIEWER.loadExtension('Autodesk.Geolocation').then((e) => {geoExt = e});
Or get already loaded extension:
let geoExt = NOP_VIEWER.getLoadedExtensions()['Autodesk.Geolocation']
Then use the methods to convert the coordinates
geoExt.lmvToLonLat
geoExt.lonLatToLmv
Here is a quick article on it.
You may .activate() the extension to see additional information on the model geo location.

Related

How can I load only specifc objects in the forge viewer using SFV2?

SVF2 has different objectids/dbids than SVF1. In this SO-Answer, it was advised to use externalId instead of objectid. However, viewer.loadModel(svfUrl,{ids:[dbIds...]}) takes dbIds to load only specified objects. How can I load only specified objects using SVF2 and the https://developer.api.autodesk.com/modelderivative/v2/regions/eu/designdata/:urn /metadata/:guid/properties endpoint? Can I access the svf2 objectIds anywhere or can I use the externalIds when calling Viewer3d::loadModel?
You're right, there's a difference between the "SVF1 dbIDs" and the "SVF2 dbIDs" - the IDs in SVF2 format are "persistent", meaning that in different versions of the same design file, a single ID will reference the same design element (which was not the case in SVF1).
Unfortunately, there are parts of the platform (like the loadModel viewer method and the /modelderivative/v2/regions/eu/designdata/:urn /metadata/:guid/properties endpoint) that have not "caught up" with SVF2 yet. And before those updates are available, you would have to map "between the old and new dbIDs" manually which is itself another, non-trivial task.

Implementing shorted path Algorithm in autodesk forge viewer

I am trying to draw a geometry on my viewer based on shortest path between 2 object.
till now I know how we can draw custom geometry using vector3.
also I have figured out which algorithm I can use to find the shortest path between point A to Point B.
here are few :
Dijkstra's
A* Search
I have seen this example where this algorithm is been implemented and I am trying similar solution in forge viewer here is the Link
also if someone can help me how can I restrict first person view to through walls like in the above sample. right now in forge viewer I can penetrate through wall which I want to avoid or is there any way that I can Identify the walls
Unfortunately the viewer does not provide a lot of support for path-finding, so most of it you would have to do manually.
Here's some of the functionality that is available that might be handy in your case:
you can "shoot rays" inside the scene and compute their intersections with the nearest geometry, for example, using viewer.impl.rayIntersect(ray, ignoreTransparent)
for example, this could be used to detect collisions with walls if you had some kind of an avatar inside the scene
if needed, you can retrieve the geometry of individual objects in the scene using the "fragment list":
let frags = viewer.model.getFragmentList();
let tree = viewer.model.getInstanceTree();
tree.enumNodeFragments(dbid, function (fragid) {
let mesh = frags.getVizmesh(fragid);
// Do something with the mesh...
});

Where exactly does trainable_variables method belong in Tensorflow?

I'm a newbie in both deep learning and tensorflow and now trying to learn how to implement deep learning codes based on function API (not keras) by following example codes.
Inside the codes I'm looking at, I found out sources saying 'gradients=tape.gradient(loss,model.trainable variables)'
I intuitionally got what trainable variables mean, however in order to understand clearly,I tried to search on tensorflow documentation (which module or class the method belongs to, which are key arguments, etc) ,but I wasn't able to find the information I want. ('trainable variables' method was not in their documentation index and I'm wondering why)
So can anyone please tell me the module/class which trainable_variable method belongs to, and which arguments it takes, and also how it is able to judge and get all the trainable variables from the model ?
The reason you did not find this method is because trainable_variables is not a method, but an attribute/property. The Model class has a trainable_variables attribute, which is not documented officialy. It is inherited from the base class Layer, and to put it shortly, the list (of trainable variables) gets populated as new layers are added, since all layers have an init parameter trainable (this comes from base class Layer too). You can check the source code if you want to: "the source of the property", "adding new weights to layer appends to the list".

MapBox: How do I create a featureCollection programmatically?

I want to create clutering in my map. When looking at guides and in the Docs, the FeatureCollection Json is always pulled from some external link. But how do I just create it programmatically as I read data from my server? I don't have it all ready in one place and it will always be changing anyway depends on the user.
I've been stuck with this issue before and ended up using some duck tape solution, but it won't work now. Can anyone please shed some light on this please?
You're able to create a FeatureCollection using an existing Feature object or array/list of Feature objects. This could be turned into a method that you could use to generate a new FeatureCollection whenever you receive a new dataset.
Given the information that you've provided, I am going to have to make some assumptions here - I hope that the following code snippet helps guide you in the right direction:
public FeatureCollection getFeatureCollectionFromCoordinateList(List<Coordinate> coords) {
List<Feature> pointsList = new ArrayList<>();
for (Coordinate coord : coords) {
Feature feature = Feature.fromGeometry(Point.fromLngLat(coord.getLongitude(), coord.getLatitude()));
pointsList.add(feature);
}
return FeatureCollection.fromFeatures(pointsList);
}
In the above example, the object I've used to represent data from the server is called Coordinate which I've given a getLatitude() and getLongitude() method to demonstrate using latitudinal/longitudinal information to generate a Mapbox FeatureCollection from a List of Feature objects which are created using the Feature.fromGeometry() method, passing in a Point.fromLngLat().
Please note that this mightn't be the best way to go about what you're trying to achieve here. That said, I hope it illustrates another way in which you can instantiate of FeatureCollection without reading in a JSON data source.

JTreeTable model updating

I'm following the example of JTreeTable filesystem2 taken from the sun site http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html#updating_the
My problem is that I can't update my model (and then my JTreeTable)...
In fact I create my model, I pass it to the JTreeTable and all work fine...but I need to modify the model...
I've yet answer a similar question, but now I've changed my code, without find a solution.
The problem is when and how I have to call the method fireTreeNodesChanged()...in the example above is used the method getPath() to retrieve information about the root node...but this is a method of File class..not my case...
Does anyone have a link to a simple code which shows how create a TreeTabelModel (with objects as nodes) and how update it?
FileBrowser is a good example of modeling a hierarchical file system as a tree. While its TreeModel is implemented using DefaultTreeModel, an alternative FileTreeModel is shown here. As mentioned in How to Use Trees: Creating a Data Model "the TreeModel interface accepts any kind of object as a tree node."