Author Topic: PJSR: Any way to find if two ImageWindow are the same?  (Read 5584 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
The following code

Code: [Select]
var a = ImageWindow.windows;
var b = ImageWindow.windows;
Console.writeln(a[0], " " , b[0] , " " , a[0]==b[0], " ", a[0]===b[0])
results in

Code: [Select]
[object ImageWindow] [object ImageWindow] false false
although a[0]and b[0] represent the same window.  I need to check if two windows are the same, is there any way?

-- bitli

Offline NKV

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 677
Re: PJSR: Any way to find if two ImageWindow are the same?
« Reply #1 on: 2012 April 01 08:41:49 »
Do it via View.FullId

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: PJSR: Any way to find if two ImageWindow are the same?
« Reply #2 on: 2012 April 01 09:34:57 »
Thanks. Unfortunately this does not solve my problem as I want to known which windows are new after a process. If a window is closed and then recreated, it may have the same id (as 'star_mask') even if it is new.

Anyhow closing the window from the script does not completely work either (signaled in the Bug list, the workaround I mentionned there does not work actually), so I need to find another approach.

-- bitli

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PJSR: Any way to find if two ImageWindow are the same?
« Reply #3 on: 2012 April 01 13:11:39 »
I had a related problem, here is my workaround, which may or may not apply to you.

StarAlignment's 'Detect Stars' working mode creates a new view/window named <name>_stars<n> where <name> is the fullId of the target view and <n> is a typically a one or a two digit suffix added for uniqueness by StarAlignment. My script needs to determine the fullId of this new view. Of course my script knows <name> but not <n>.

So immediately prior to executing the process, my script generates a sequence of fullId's <name>_stars, <name>_stars1, <name>_stars2, ... The first name in the sequence that is NOT the fullId of an open view is assumed to be the name StarAlignment will use.

The code below is a helper function. For StarAlignment the "%d" format is appropriate. For other processes "%02d" is a better choice.

After executing StarAlignment I look for a view with the predicted name, using View.viewById(). If found, great, if not the prediction failed and I throw an error.

This scheme is designed to handle cases like this: Suppose prior to execution <name>_stars, <name>_stars1, and <name>_stars3 are open views. StarAlignment will use <name>_stars2. If no prediction is used and you do the simple thing of looking for the name with the largest <n> suffix, you will fail to find the proper view.

Code: [Select]
function uniqueViewId1(baseId) {
   var id = baseId;
   for (var i = 1; !View.viewById(id).isNull; ++i) {
      id = baseId + format("%d", i);
   }
   return id;
}
« Last Edit: 2012 April 01 13:36:37 by mschuster »

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: Any way to find if two ImageWindow are the same?
« Reply #4 on: 2012 April 01 17:08:46 »
Quote
StarAlignment's 'Detect Stars' working mode creates a new view/window named <name>_stars<n> where <name> is the fullId of the target view and <n> is a typically a one or a two digit suffix added for uniqueness by StarAlignment.

Unfortunately StarAlignment only provides output properties for registered target images:

Table StarAlignment.outputData

(See the corresponding entry in the reference documentation). Another workaround is to create a complete (full-size) preview on the image window of interest. If you execute the StarAlignment instance in star detection mode (or other control mode such as structure detection) on the preview, it will be replaced and no new image window will be generated.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: Any way to find if two ImageWindow are the same?
« Reply #5 on: 2012 April 03 10:44:24 »
This problem is also fixed in the new core version 1.7.6.793. A new property of the View object:

String View.uniqueId

provides access to the unique identifier of a view. View.uniqueId is guaranteed to be unique for each newly created view on the whole PixInsight platform. By comparing unique identifiers, a script can know if a given view identifier refers to the same object at different times.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/